void unpackPlanarImage(byte[] rawData, int[] cPixels, boolean topDown) {
        int w = dwWidth, h = dwHeight;
        int uP =  w*h, vP = w*h;                    // pointers in U, V array
        int uvInc = (dataCompression==NV12_COMPRESSION || dataCompression==NV21_COMPRESSION) ?
                2 : 1;  // NV12, NV21 have interleaved u,v
        if (dataCompression == YV12_COMPRESSION)    // separate planes for U and V, 2-fold subsampling in x&y
            uP += w*h/4; // first V, then U
        else if (dataCompression == I420_COMPRESSION)
            vP += w*h/4; // first U, then V
        else if (dataCompression == NV12_COMPRESSION)
            vP++;  //interleaved U, then V
        else //NV21_COMPRESSION
            uP++;
        int lineOutInc = topDown ? w : -w;
        for (int line=0; line<h; line+=2) {
            int pRaw0 = line*w;
            int pRawEnd = pRaw0 + w;
            int pOut = topDown ? line*w : (h-line-1)*w;
            for (int pRaw = pRaw0; pRaw < pRawEnd; ) {
                int u = rawData[uP] ^ 0xffffff80;   // u and v for 2x2-pixel block
                int v = rawData[vP] ^ 0xffffff80;
                writeRGBfromYUV(rawData[pRaw] & 0xff, u, v, cPixels, pOut);
                writeRGBfromYUV(rawData[pRaw+w] & 0xff, u, v, cPixels, pOut+lineOutInc);
                pRaw++; pOut++;
                writeRGBfromYUV(rawData[pRaw] & 0xff, u, v, cPixels, pOut);
                writeRGBfromYUV(rawData[pRaw+w] & 0xff, u, v, cPixels, pOut+lineOutInc);
                pRaw++; pOut++;
                uP+=uvInc; vP+=uvInc;
            }
        }
    }