, fOffset(offset)
, fStreamBuffer(new uint8_t[RLEBytes])
, fRLEBytes(RLEBytes)
+ , fOrigRLEBytes(RLEBytes)
, fCurrRLEByte(0)
, fSampleX(1)
{}
// Reset fSampleX. If it needs to be a value other than 1, it will get modified by
// the sampler.
fSampleX = 1;
+ fLinesToSkip = 0;
+
// Create the color table if necessary and prepare the stream for decode
// Note that if it is non-NULL, inputColorCount will be modified
if (!this->createColorTable(inputColorCount)) {
copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount);
// Initialize a buffer for encoded RLE data
+ fRLEBytes = fOrigRLEBytes;
if (!this->initializeStreamBuffer()) {
SkCodecPrintf("Error: cannot initialize stream buffer.\n");
return SkCodec::kInvalidConversion;
static const uint8_t RLE_EOF = 1;
static const uint8_t RLE_DELTA = 2;
- // Set constant values
const int width = this->getInfo().width();
- const int height = info.height();
+ int height = info.height();
// Account for sampling.
SkImageInfo dstInfo = info.makeWH(get_scaled_dimension(width, fSampleX), height);
- // Destination parameters
- int x = 0;
- int y = 0;
-
// Set the background as transparent. Then, if the RLE code skips pixels,
// the skipped pixels will be transparent.
// Because of the need for transparent pixels, kN32 is the only color
SkASSERT(kN32_SkColorType == dstInfo.colorType());
SkSampler::Fill(dstInfo, dst, dstRowBytes, SK_ColorTRANSPARENT, opts.fZeroInitialized);
+ // Adjust the height and the dst if the previous call to decodeRows() left us
+ // with lines that need to be skipped.
+ if (height > fLinesToSkip) {
+ height -= fLinesToSkip;
+ dst = SkTAddOffset<void>(dst, fLinesToSkip * dstRowBytes);
+ fLinesToSkip = 0;
+ } else {
+ fLinesToSkip -= height;
+ return height;
+ }
+
+ // Destination parameters
+ int x = 0;
+ int y = 0;
+
while (true) {
// If we have reached a row that is beyond the requested height, we have
// succeeded.
const uint8_t dy = fStreamBuffer.get()[fCurrRLEByte++];
x += dx;
y += dy;
- if (x > width || y > height) {
+ if (x > width) {
SkCodecPrintf("Warning: invalid RLE input.\n");
return y - dy;
+ } else if (y > height) {
+ fLinesToSkip = y - height;
+ return height;
}
break;
}
const uint32_t fOffset;
SkAutoTDeleteArray<uint8_t> fStreamBuffer;
size_t fRLEBytes;
+ const size_t fOrigRLEBytes;
uint32_t fCurrRLEByte;
int fSampleX;
SkAutoTDelete<SkSampler> fSampler;
+ // Scanline decodes allow the client to ask for a single scanline at a time.
+ // This can be tricky when the RLE encoding instructs the decoder to jump down
+ // multiple lines. This field keeps track of lines that need to be skipped
+ // on subsequent calls to decodeRows().
+ int fLinesToSkip;
+
typedef SkBmpCodec INHERITED;
};