Open stephane-archer opened 3 months ago
here is the image:
if I do in the main:
image = image.convert(format: img.Format.uint8, numChannels: 3);
I don't get the Index out of range
exception but:
if (!pixel.isValid) {
throw StateError("invalid pixel");
}
some pixels are not valid (but their RGB values are correct) so doing the convert
and removing the isValid
check makes the code work but I still don't understand what is going on, and there is something wrong here with what I do or the library
I think this is related to the fact that my image has a PaletteUint8
that make things go out of bounds on:
num get(int index, int channel) =>
channel < numChannels ? data[index * numChannels + channel] : 0;
called from:
num _getChannel(int ci) => palette == null
? numChannels > ci
? _get(ci)
: 0
: palette!.get(_get(0), ci);
but I'm not able to understand this code and what it is doing:
int _get(int ci) {
var i = _index;
var bi = 7 - (_bitIndex + ci);
if (bi < 0) {
bi += 8;
i++;
}
if (i >= image.data.length) {
return 0;
}
return (image.data[i] >> bi) & 0x1;
}
converting my input file not to use the palette removes the issue so there is something wrong with nt _get(int ci)
and PNG palette support
Here is the error I observe, I might do something wrong:
The input is a simple png of 5x5 yellow pixels.
Here is the code:
The error occurs on
num red = pixel.r;
(when I try to access the pixel value) in_tileToKey
my usage of
img.copyCrop
might be the issue.