public boolean is_INT_PACK_BYTE_COMP(SampleModel srcSM, SampleModel alpSM) {
    // Check SampleModel types DirectColorModel
    if (!(srcSM instanceof SinglePixelPackedSampleModel)) return false;
    if (!(alpSM instanceof ComponentSampleModel)) return false;

    // Check transfer types
    if (srcSM.getDataType() != DataBuffer.TYPE_INT) return false;
    if (alpSM.getDataType() != DataBuffer.TYPE_BYTE) return false;

    SinglePixelPackedSampleModel sppsm;
    sppsm = (SinglePixelPackedSampleModel) srcSM;

    int[] masks = sppsm.getBitMasks();
    if (masks.length != 4) return false;
    if (masks[0] != 0x00ff0000) return false;
    if (masks[1] != 0x0000ff00) return false;
    if (masks[2] != 0x000000ff) return false;
    if (masks[3] != 0xff000000) return false;

    ComponentSampleModel csm;
    csm = (ComponentSampleModel) alpSM;
    if (csm.getNumBands() != 1) return false;
    if (csm.getPixelStride() != 1) return false;

    return true;
  }
  public WritableRaster INT_PACK_BYTE_COMP_Impl(WritableRaster wr) {
    // Get my source.
    CachableRed srcRed = (CachableRed) getSources().get(0);
    CachableRed alphaRed = (CachableRed) getSources().get(1);

    // Already has alpha channel so we use it.
    srcRed.copyData(wr);

    Rectangle rgn = wr.getBounds();
    rgn = rgn.intersection(alphaRed.getBounds());

    Raster r = alphaRed.getData(rgn);

    ComponentSampleModel csm;
    csm = (ComponentSampleModel) r.getSampleModel();
    final int alpScanStride = csm.getScanlineStride();

    DataBufferByte alpDB = (DataBufferByte) r.getDataBuffer();
    final int alpBase =
        (alpDB.getOffset()
            + csm.getOffset(
                rgn.x - r.getSampleModelTranslateX(), rgn.y - r.getSampleModelTranslateY()));

    // Access the pixel data array
    final byte[] alpPixels = alpDB.getBankData()[0];

    SinglePixelPackedSampleModel sppsm;
    sppsm = (SinglePixelPackedSampleModel) wr.getSampleModel();
    final int srcScanStride = sppsm.getScanlineStride();

    DataBufferInt srcDB = (DataBufferInt) wr.getDataBuffer();
    final int srcBase =
        (srcDB.getOffset()
            + sppsm.getOffset(
                rgn.x - wr.getSampleModelTranslateX(), rgn.y - wr.getSampleModelTranslateY()));

    // Access the pixel data array
    final int[] srcPixels = srcDB.getBankData()[0];

    ColorModel cm = srcRed.getColorModel();

    if (cm.isAlphaPremultiplied()) {
      // For alpha premult we need to multiply all comps.
      for (int y = 0; y < rgn.height; y++) {
        int sp = srcBase + y * srcScanStride;
        int ap = alpBase + y * alpScanStride;
        int end = sp + rgn.width;

        while (sp < end) {
          int a = ((int) alpPixels[ap++]) & 0xFF;
          final int pix = srcPixels[sp];
          srcPixels[sp] =
              ((((((pix >>> 24)) * a) & 0xFF00) << 16)
                  | (((((pix >>> 16) & 0xFF) * a) & 0xFF00) << 8)
                  | (((((pix >>> 8) & 0xFF) * a) & 0xFF00))
                  | (((((pix) & 0xFF) * a) & 0xFF00) >> 8));
          sp++;
        }
      }

    } else {
      // For non-alpha premult we only need to multiply alpha.
      for (int y = 0; y < rgn.height; y++) {
        int sp = srcBase + y * srcScanStride;
        int ap = alpBase + y * alpScanStride;
        int end = sp + rgn.width;
        while (sp < end) {
          int a = ((int) alpPixels[ap++]) & 0xFF;
          int sa = srcPixels[sp] >>> 24;
          srcPixels[sp] = ((((sa * a) & 0xFF00) << 16) | srcPixels[sp] & 0x00FFFFFF);
          sp++;
        }
      }
    }

    return wr;
  }