public static int[] convert2rgba(IImageLineArray line,PngChunkPLTE pal,PngChunkTRNS trns,int[] buf){
  ImageInfo imi=line.getImageInfo();
  int nsamples=imi.cols * 4;
  if (buf == null || buf.length < nsamples)   buf=new int[nsamples];
  int maxval=imi.bitDepth == 16 ? (1 << 16) - 1 : 255;
  Arrays.fill(buf,maxval);
  if (imi.indexed) {
    int tlen=trns != null ? trns.getPalletteAlpha().length : 0;
    for (int s=0; s < imi.cols; s++) {
      int index=line.getElem(s);
      pal.getEntryRgb(index,buf,s * 4);
      if (index < tlen) {
        buf[s * 4 + 3]=trns.getPalletteAlpha()[index];
      }
    }
  }
 else   if (imi.greyscale) {
    int[] unpack=null;
    if (imi.bitDepth < 8)     unpack=ImageLineHelper.DEPTH_UNPACK[imi.bitDepth];
    for (int s=0, i=0, p=0; p < imi.cols; p++) {
      buf[s++]=unpack != null ? unpack[line.getElem(i++)] : line.getElem(i++);
      buf[s]=buf[s - 1];
      s++;
      buf[s]=buf[s - 1];
      s++;
      if (imi.channels == 2)       buf[s++]=unpack != null ? unpack[line.getElem(i++)] : line.getElem(i++);
 else       buf[s++]=maxval;
    }
  }
 else {
    for (int s=0, i=0, p=0; p < imi.cols; p++) {
      buf[s++]=line.getElem(i++);
      buf[s++]=line.getElem(i++);
      buf[s++]=line.getElem(i++);
      buf[s++]=imi.alpha ? line.getElem(i++) : maxval;
    }
  }
  return buf;
}

public static int [ ] convert2rgba ( IImageLineArray line , PngChunkPLTE pal , PngChunkTRNS trns , int [ ] buf ) { ImageInfo imi = line . getImageInfo ( ) ; int nsamples = imi . cols * 4 ; if ( buf == null || buf . length < nsamples ) buf = new int [ nsamples ] ; int maxval = imi . bitDepth == 16 ? ( 1 << 16 ) - 1 : 255 ; Arrays . fill ( buf , maxval ) ; if ( imi . indexed ) { int tlen = trns != null ? trns . getPalletteAlpha ( ) . length : 0 ; for ( int s = 0 ; s < imi . cols ; s ++ ) { int index = line . getElem ( s ) ; pal . getEntryRgb ( index , buf , s * 4 ) ; if ( index < tlen ) { buf [ s * 4 + 3 ] = trns . getPalletteAlpha ( ) [ index ] ; } } } else if ( imi . greyscale ) { int [ ] unpack = null ; if ( imi . bitDepth < 8 ) unpack = ImageLineHelper . DEPTH_UNPACK [ imi . bitDepth ] ; for ( int s = 0 , i = 0 , p = 0 ; p < imi . cols ; p ++ ) { buf [ s ++ ] = unpack != null ? unpack [ line . getElem ( i ++ ) ] : line . getElem ( i ++ ) ; buf [ s ] = buf [ s - 1 ] ; s ++ ; buf [ s ] = buf [ s - 1 ] ; s ++ ; if ( imi . channels == 2 ) buf [ s ++ ] = unpack != null ? unpack [ line . getElem ( i ++ ) ] : line . getElem ( i ++ ) ; else buf [ s ++ ] = maxval ; } } else { for ( int s = 0 , i = 0 , p = 0 ; p < imi . cols ; p ++ ) { buf [ s ++ ] = line . getElem ( i ++ ) ; buf [ s ++ ] = line . getElem ( i ++ ) ; buf [ s ++ ] = line . getElem ( i ++ ) ; buf [ s ++ ] = imi . alpha ? line . getElem ( i ++ ) : maxval ; } } return buf ; }
this is not very efficient , only for tests and troubleshooting
