colorIndexInverseTransform method Null safety

void colorIndexInverseTransform(
  1. int yStart,
  2. int yEnd,
  3. Uint32List inData,
  4. int src,
  5. Uint32List outData,
  6. int dst
)

Implementation

void colorIndexInverseTransform(int yStart, int yEnd, Uint32List inData,
    int src, Uint32List outData, int dst) {
  final bitsPerPixel = 8 >> bits;
  final width = xsize;
  final colorMap = data;
  if (bitsPerPixel < 8) {
    final pixelsPerByte = 1 << bits;
    final countMask = pixelsPerByte - 1;
    final bit_mask = (1 << bitsPerPixel) - 1;
    for (var y = yStart; y < yEnd; ++y) {
      var packed_pixels = 0;
      for (var x = 0; x < width; ++x) {
        // We need to load fresh 'packed_pixels' once every
        // 'pixels_per_byte' increments of x. Fortunately, pixels_per_byte
        // is a power of 2, so can just use a mask for that, instead of
        // decrementing a counter.
        if ((x & countMask) == 0) {
          packed_pixels = _getARGBIndex(inData[src++]);
        }
        outData[dst++] = _getARGBValue(colorMap![packed_pixels & bit_mask]);
        packed_pixels >>= bitsPerPixel;
      }
    }
  } else {
    for (var y = yStart; y < yEnd; ++y) {
      for (var x = 0; x < width; ++x) {
        outData[dst++] =
            _getARGBValue(colorMap![_getARGBIndex(inData[src++])]);
      }
    }
  }
}