Update level 3 color tables for 16-level products

This commit is contained in:
Dan Paulat 2022-04-10 10:41:30 -05:00
parent 2dcd87700c
commit 304297be9b
2 changed files with 38 additions and 27 deletions

View file

@ -152,23 +152,26 @@ void Level3ProductView::UpdateColorTable()
float scale = descriptionBlock->scale(); float scale = descriptionBlock->scale();
uint16_t threshold = descriptionBlock->threshold(); uint16_t threshold = descriptionBlock->threshold();
// If the threshold is 2, the range min should be set to 1 for range folding
uint16_t rangeMin = std::min<uint16_t>(1, threshold);
uint16_t numberOfLevels = descriptionBlock->number_of_levels();
uint16_t rangeMax = (numberOfLevels > 0) ? numberOfLevels - 1 : 0;
if (p->savedColorTable_ == p->colorTable_ && // if (p->savedColorTable_ == p->colorTable_ && //
p->savedOffset_ == offset && // p->savedOffset_ == offset && //
p->savedScale_ == scale) p->savedScale_ == scale && //
numberOfLevels > 16)
{ {
// The color table LUT does not need updated // The color table LUT does not need updated
return; return;
} }
// If the threshold is 2, the range min should be set to 1 for range folding // Iterate over [rangeMin, numberOfLevels)
uint16_t rangeMin = std::min<uint16_t>(1, threshold);
uint16_t rangeMax = descriptionBlock->number_of_levels();
boost::integer_range<uint16_t> dataRange = boost::integer_range<uint16_t> dataRange =
boost::irange<uint16_t>(rangeMin, rangeMax + 1); boost::irange<uint16_t>(rangeMin, numberOfLevels);
std::vector<boost::gil::rgba8_pixel_t>& lut = p->colorTableLut_; std::vector<boost::gil::rgba8_pixel_t>& lut = p->colorTableLut_;
lut.resize(rangeMax - rangeMin + 1); lut.resize(numberOfLevels - rangeMin);
lut.shrink_to_fit(); lut.shrink_to_fit();
std::for_each(std::execution::par_unseq, std::for_each(std::execution::par_unseq,
@ -184,26 +187,34 @@ void Level3ProductView::UpdateColorTable()
{ {
float f; float f;
// Different products use different scale/offset formulas // Different products use different scale/offset
switch (descriptionBlock->product_code()) // formulas
if (numberOfLevels > 16)
{ {
case 159: switch (descriptionBlock->product_code())
case 161: {
case 163: case 159:
case 167: case 161:
case 168: case 163:
case 170: case 167:
case 172: case 168:
case 173: case 170:
case 174: case 172:
case 175: case 173:
case 176: case 174:
f = (i - offset) / scale; case 175:
break; case 176:
f = (i - offset) / scale;
break;
default: default:
f = i * scale + offset; f = i * scale + offset;
break; break;
}
}
else
{
f = descriptionBlock->data_level_threshold(i);
} }
lut[i - *dataRange.begin()] = p->colorTable_->Color(f); lut[i - *dataRange.begin()] = p->colorTable_->Color(f);

View file

@ -528,11 +528,11 @@ uint16_t ProductDescriptionBlock::number_of_levels() const
break; break;
case 134: case 134:
numberOfLevels = 254; numberOfLevels = 256;
break; break;
case 135: case 135:
numberOfLevels = 199; numberOfLevels = 200;
break; break;
case 138: case 138: