星期二, 11月 06, 2012

Convert Side by Side image to Blue & Red 3D stereo mode

Convert Side by Side image to Blue & Red 3D stereo mode           

Bitmap dst = null;
int w = src_bitmap.getWidth();
int h = src_bitmap.getHeight();
int [] dst_pixs = new int[w * h];
int[] left_pixs;
int[] right_pixs;
int alpha;
int r;
int g;
int b;
// fix if width or height is odd will cause crash
if (w % 2 == 1){
    w = w-1;
}
if (h % 2 == 1){
    h = h-1;
}
//
int totals = w * h;

left_pixs = new int[(w / 2) * h];
right_pixs = new int[(w / 2) * h];
// Get Left and Right Pixs
src.getPixels(left_pixs, 0, w/2, 0, 0, w/2, h);
src.getPixels(right_pixs, 0, w/2, w/2, 0, w/2, h);
//
dst = Bitmap.createBitmap(w, h, Config.ARGB_8888);

for (i = 0; i < totals - 1; i++) {
                // Convert color , For blue & red ==> (left.a, left.r, right.g, right.b)
                alpha = left_pixs[i/2] & 0xff000000;
                r = (left_pixs[i/2] >> 16) & 0xff;
                g = (right_pixs[i/2] >> 8) & 0xff;
                b = right_pixs[i/2] & 0xff;
                dst_pixs[i] = alpha | (r << 16) | (g << 8) | b;
                // end conver color  
 }
dst.setPixels(dst_pixs, 0, w, 0, 0, w, h);

沒有留言: