Hi Skia Team,
I'm working on a custom Skia effect for Android OS.
To implement the effect I need to pass Lut (Look Up Table) in the form of 4 float bitmap (SkColorType::kRGBA_F32_SkColorType), as below (only x-horizontal coord is in focus for simplicity):
fn(std::vector<float> lut, int w, int h) {
SkImageInfo info = SkImageInfo::Make(w, h, SkColorType::kRGBA_F32_SkColorType,
SkAlphaType::kOpaque_SkAlphaType);
SkPixmap map(info, lut.data(), w * 4 * sizeof(float));
bmp.allocPixels(info);
bmp.writePixels(map);
return SkImage::MakeFromBitmap(bmp);
},
where only green channel - ctr % 4 == 1, for every 4th pixel starting from third - x % 4 == 2 is populated in lut:
std::vector<float> lut(w * h * 4, 0);
int ctr = 0;
for (auto &e : lut) {
int x = (ctr / 4) % w;
if (x % 4 == 2 && ctr % 4 == 1)
e = (float) x / (float) w;
ctr++;
}
In the effect I can properly sample and display either:
- uniform shader uContentTexture; // containing processed content
- uniform shader fLutTexture; // containing passed lok up table,
I can see that each pixel is displayed as expected.
But when I sample Lut and use obtained value to sample content, the position is correct, but color is wrong (seem to be incorectly interpolated), code below splits display to three parts:
- top - correctly displayed content (black, red, green, blue repeatedly)
- middle - correctly displayed lut (black, black, green, black repeatedly)
- bottom - incorrectly coloured every 4th pixel (so location is good)
uniform shader uContentTexture;
uniform shader fLut;
uniform fWidth;
vec4 main(float2 p) {
if (p.y < 250) {
return sample(uContentTexture, p);
}
if (p.y < 500) {
return sample(fLut, p);
}
float4 lut = sample(fLut, p);
return sample(uContentTexture, float2(fWidth * lut.y + 0.5, p.y));
}
I suspect some inconsistency in interpolation of content color based on lut.x value, but have no clue how to verify and correct such misalignment.
Any help would be really appreciated.
Best Regards,
Jurek