0

as the title says, how to convert bitmap RGB back to YUV byte[] using ScriptIntrinsicColorMatrix? below is the sample code (cannot be decoded by zxing):

public byte[] getYUVBytes(Bitmap src, boolean initOutAllocOnce){    

    if(!initOutAllocOnce){
        outYUV = null;
    }
    if(outYUV == null){
        outYUV = Allocation.createSized(rs, Element.U8(rs), src.getByteCount());    
    }

    byte[] yuvData = new byte[src.getByteCount()];

    Allocation in;

    in = Allocation.createFromBitmap(rs, src,
            Allocation.MipmapControl.MIPMAP_NONE,
            Allocation.USAGE_SCRIPT);   

    scriptColor.setRGBtoYUV();

    scriptColor.forEach(in, outYUV);
    outYUV.copyTo(yuvData);

    return yuvData;
}

one thing i notice is from original camera YUV byte is 3110400 bytes but after using the ScriptIntrinsicColorMatrix convertion in becomes 8294400, which i think is wrong.

Reason for YUV -> BW -> YUV is I want to convert the image into black and white (not grayscale) and back to YUV for zxing to decode at the same time show the black and white in surfaceview (like a custom camera filter).

tried below code but its a bit slow (can be decoded by zxing).

  int[] intArray  = null;
          intArray = new int[bmp.getWidth() * bmp.getHeight()];  
          bmp.getPixels(intArray, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());  

          LuminanceSource source = new RGBLuminanceSource(cameraResolution.x, cameraResolution.y, intArray);
          data = source.getMatrix();

any other alternative for RGB to YUV that is fast? if ScriptIntrinsicColorMatrix class cannot be done?

please and thank you

vims liu
  • 643
  • 1
  • 9
  • 20
  • what is the zxing tag doing in this code? – ΦXocę 웃 Пepeúpa ツ May 31 '17 at 08:17
  • using zxing's RGBLuminanceSource class, to pass byte[] raw image to zxing to decode qr code, but the int array to RGBLuminanceSource to byte[] data is a bit slow, and caused delay, tried using the ScriptIntrinsicColorMatrix but does not work on zxing to convert rgb to yuv – vims liu May 31 '17 at 08:36
  • Is the input `Bitmap` already in YUV format, or is it in RGB format? The code reads as if it is in RGB and you are trying to covert it to YUV, but your question is worded as if it is YUV and you are trying to apply a black and white treatment to it. – Larry Schiefer Jun 01 '17 at 09:49
  • the bitmap is in RGB format and since bitmap cannot hold YUV color space – vims liu Jun 02 '17 at 03:10

0 Answers0