Expand small tables in SkColorSpaceXform_A2B

Bug: 722855
Change-Id: Id3661be1e9747ac0de1e35b60d334ee8187a5be5
Reviewed-on: https://skia-review.googlesource.com/17312
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Matt Sarett 2017-05-18 10:39:46 -04:00 committed by Skia Commit-Bot
parent d06126a818
commit 9d2d7bfc92
4 changed files with 214 additions and 186 deletions

View File

@ -1 +1 @@
24
26

File diff suppressed because it is too large Load Diff

View File

@ -171,8 +171,8 @@ SkColorSpaceXform_A2B::SkColorSpaceXform_A2B(SkColorSpace_A2B* srcSpace,
gammas.data(channel).fTable.fSize,
};
gammaNeedsRef |= !this->buildTableFn(&table);
this->addTableFn(table, channel);
gammaNeedsRef = true;
} else {
SkColorSpaceTransferFn fn;
SkAssertResult(gamma_to_parametric(&fn, gammas, channel));
@ -297,6 +297,33 @@ void SkColorSpaceXform_A2B::addTransferFn(const SkColorSpaceTransferFn& fn, int
}
}
/**
* |fn| is an in-out parameter. If the table is too small to perform reasonable table-lookups
* without interpolation, we will build a bigger table.
*
* This returns false if we use the original table, meaning we do nothing here but need to keep
* a reference to the original table. This returns true if we build a new table and the original
* table can be discarded.
*/
bool SkColorSpaceXform_A2B::buildTableFn(SkTableTransferFn* fn) {
// Arbitrary, but seems like a reasonable guess.
static constexpr int kMinTableSize = 256;
if (fn->fSize >= kMinTableSize) {
return false;
}
float* outTable = fAlloc.makeArray<float>(kMinTableSize);
float step = 1.0f / (kMinTableSize - 1);
for (int i = 0; i < kMinTableSize; i++) {
outTable[i] = interp_lut(i * step, fn->fData, fn->fSize);
}
fn->fData = outTable;
fn->fSize = kMinTableSize;
return true;
}
void SkColorSpaceXform_A2B::addTableFn(const SkTableTransferFn& fn, int channelIndex) {
switch (channelIndex) {
case 0:

View File

@ -33,6 +33,7 @@ private:
void addTransferFn(const SkColorSpaceTransferFn& fn, int channelIndex);
bool buildTableFn(SkTableTransferFn* table);
void addTableFn(const SkTableTransferFn& table, int channelIndex);
void addMatrix(const SkMatrix44& matrix);