question: public int hleJpegDecodeYCbCr ( BufferedImage bufferedImage , TPointer yCbCrBuffer , int yCbCrBufferSize , int dhtMode ) { int width = bufferedImage . getWidth ( ) ; int height = bufferedImage . getHeight ( ) ; int sizeY = width * height ; int sizeCb = sizeY > > 2 ; int addressY = yCbCrBuffer . getAddress ( ) ; int addressCb = addressY + sizeY ; int addressCr = addressCb + sizeCb ; if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "hleJpegDecodeYCbCr 0x%08X, 0x%08X, 0x%08X" , addressY , addressCb , addressCr ) ) ; } int [ ] bufferCb = new int [ sizeCb ] ; int [ ] bufferCr = new int [ sizeCb ] ; IMemoryWriter imageWriterY = MemoryWriter . getMemoryWriter ( addressY , sizeY , 1 ) ; for ( int y = 0 ; y < height ; y ++ ) { int indexCb = ( y > > 1 ) * ( width > > 1 ) ; for ( int x = 0 ; x < width ; x += 2 , indexCb ++ ) { int argb0 = bufferedImage . getRGB ( x , y ) ; int yCbCr0 = colorARGBToYCbCr ( argb0 ) ; int argb1 = bufferedImage . getRGB ( x + 1 , y ) ; int yCbCr1 = colorARGBToYCbCr ( argb1 ) ; imageWriterY . writeNext ( getY ( yCbCr0 ) ) ; imageWriterY . writeNext ( getY ( yCbCr1 ) ) ; bufferCb [ indexCb ] += getCb ( yCbCr0 ) ; bufferCb [ indexCb ] += getCb ( yCbCr1 ) ; bufferCr [ indexCb ] += getCr ( yCbCr0 ) ; bufferCr [ indexCb ] += getCr ( yCbCr1 ) ; } } imageWriterY . flush ( ) ; IMemoryWriter imageWriterCb = MemoryWriter . getMemoryWriter ( addressCb , sizeCb , 1 ) ; IMemoryWriter imageWriterCr = MemoryWriter . getMemoryWriter ( addressCr , sizeCb , 1 ) ; for ( int i = 0 ; i < sizeCb ; i ++ ) { imageWriterCb . writeNext ( bufferCb [ i ] > > 2 ) ; imageWriterCr . writeNext ( bufferCr [ i ] > > 2 ) ; } imageWriterCb . flush ( ) ; imageWriterCr . flush ( ) ; return getWidthHeight ( width , height ) ; }
target:  Convert an image to YUV420p format. See http://en.wikipedia.org/wiki/Yuv#Y.27UV420p_.28and_Y.27V12_or_YV12.29_to_RGB888_conversion for the description of the YUV420p format: "Y'UV420p is a planar format, meaning that the Y', U, and V values are grouped together instead of interspersed. The reason for this is that by grouping the U and V values together, the image becomes much more compressible. When given an array of an image in the Y'UV420p format, all the Y' values come first, followed by all the U values, followed finally by all the V values. As with most Y'UV formats, there are as many Y' values as there are pixels. Where X equals the height multiplied by the width, the first X indices in the array are Y' values that correspond to each individual pixel. However, there are only one fourth as many U and V values. The U and V values correspond to each 2 by 2 block of the image, meaning each U and V entry applies to four pixels. After the Y' values, the next X/4 indices are the U values for each 2 by 2 block, and the next X/4 indices after that are the V values that also apply to each 2 by 2 block. size.total = size.width * size.height; y = yuv[position.y * size.width + position.x]; u = yuv[(position.y / 2) * (size.width / 2) + (position.x / 2) + size.total]; v = yuv[(position.y / 2) * (size.width / 2) + (position.x / 2) + size.total + (size.total / 4)]; rgb = Y'UV444toRGB888(y, u, v); "