apply method

  1. @override
void apply(
  1. BitmapData bitmapData, [
  2. Rectangle<num>? rectangle
])
override

Implementation

@override
void apply(BitmapData bitmapData, [Rectangle<num>? rectangle]) {
  //dstR = (m[ 0] * srcR) + (m[ 1] * srcG) + (m[ 2] * srcB) + (m[ 3] * srcA) + o[0]
  //dstG = (m[ 4] * srcR) + (m[ 5] * srcG) + (m[ 6] * srcB) + (m[ 7] * srcA) + o[1]
  //dstB = (m[ 8] * srcR) + (m[ 9] * srcG) + (m[10] * srcB) + (m[11] * srcA) + o[2]
  //dstA = (m[12] * srcR) + (m[13] * srcG) + (m[14] * srcB) + (m[15] * srcA) + o[3]

  final isLittleEndianSystem = env.isLittleEndianSystem;

  final num m00 = _colorMatrixList[isLittleEndianSystem ? 00 : 15];
  final num m01 = _colorMatrixList[isLittleEndianSystem ? 01 : 14];
  final num m02 = _colorMatrixList[isLittleEndianSystem ? 02 : 13];
  final num m03 = _colorMatrixList[isLittleEndianSystem ? 03 : 12];
  final num m10 = _colorMatrixList[isLittleEndianSystem ? 04 : 11];
  final num m11 = _colorMatrixList[isLittleEndianSystem ? 05 : 10];
  final num m12 = _colorMatrixList[isLittleEndianSystem ? 06 : 09];
  final num m13 = _colorMatrixList[isLittleEndianSystem ? 07 : 08];
  final num m20 = _colorMatrixList[isLittleEndianSystem ? 08 : 07];
  final num m21 = _colorMatrixList[isLittleEndianSystem ? 09 : 06];
  final num m22 = _colorMatrixList[isLittleEndianSystem ? 10 : 05];
  final num m23 = _colorMatrixList[isLittleEndianSystem ? 11 : 04];
  final num m30 = _colorMatrixList[isLittleEndianSystem ? 12 : 03];
  final num m31 = _colorMatrixList[isLittleEndianSystem ? 13 : 02];
  final num m32 = _colorMatrixList[isLittleEndianSystem ? 14 : 01];
  final num m33 = _colorMatrixList[isLittleEndianSystem ? 15 : 00];

  final num o0 = _colorOffsetList[isLittleEndianSystem ? 00 : 03];
  final num o1 = _colorOffsetList[isLittleEndianSystem ? 01 : 02];
  final num o2 = _colorOffsetList[isLittleEndianSystem ? 02 : 01];
  final num o3 = _colorOffsetList[isLittleEndianSystem ? 03 : 00];

  final renderTextureQuad = rectangle == null
      ? bitmapData.renderTextureQuad
      : bitmapData.renderTextureQuad.cut(rectangle);

  final imageData = renderTextureQuad.getImageData();
  final List<int> data = imageData.data;

  for (var i = 0; i <= data.length - 4; i += 4) {
    final c0 = data[i + 0];
    final c1 = data[i + 1];
    final c2 = data[i + 2];
    final c3 = data[i + 3];
    data[i + 0] = (m00 * c0 + m01 * c1 + m02 * c2 + m03 * c3 + o0).round();
    data[i + 1] = (m10 * c0 + m11 * c1 + m12 * c2 + m13 * c3 + o1).round();
    data[i + 2] = (m20 * c0 + m21 * c1 + m22 * c2 + m23 * c3 + o2).round();
    data[i + 3] = (m30 * c0 + m31 * c1 + m32 * c2 + m33 * c3 + o3).round();
  }

  renderTextureQuad.putImageData(imageData);
}