colorcvt.c
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:289k
- rv = rvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- bu = butab[su[0]];
- y11 = ytab[sy1[0]];
- y12 = ytab[sy1[1]];
- /* output 4 bytes at a time */
- *(unsigned int *)(d1+0) =
- (CLIP5[y11 + bu + DITH5L] << 0) |
- (CLIP5[y11 + guv + DITH5L] << 5) |
- (CLIP5[y11 + rv + DITH5L] << 10) |
- (CLIP5[y12 + bu + DITH5H] << 16) |
- (CLIP5[y12 + guv + DITH5H] << 21) |
- (CLIP5[y12 + rv + DITH5H] << 26) ;
- y21 = ytab[sy2[0]];
- y22 = ytab[sy2[1]];
- *(unsigned int *)(d2+0) =
- (CLIP5[y21 + bu + DITH5H] << 0) |
- (CLIP5[y21 + guv + DITH5H] << 5) |
- (CLIP5[y21 + rv + DITH5H] << 10) |
- (CLIP5[y22 + bu + DITH5L] << 16) |
- (CLIP5[y22 + guv + DITH5L] << 21) |
- (CLIP5[y22 + rv + DITH5L] << 26) ;
- sy1 += 2; sy2 += 2;
- su += 1; sv += 1;
- d1 += 2*BPP2; d2 += 2*BPP2;
- dx -= 2;
- }
- /* convert last 2x1 block: */
- if (dx & 1) {
- rv = rvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- bu = butab[su[0]];
- y11 = ytab[sy1[0]];
- y21 = ytab[sy2[0]];
- /* output 2 bytes at a time */
- *(unsigned short *)(d1+0) =
- (CLIP5[y11 + bu + DITH5L] << 0) |
- (CLIP5[y11 + guv + DITH5L] << 5) |
- (CLIP5[y11 + rv + DITH5L] << 10) ;
- *(unsigned short *)(d2+0) =
- (CLIP5[y21 + bu + DITH5H] << 0) |
- (CLIP5[y21 + guv + DITH5H] << 5) |
- (CLIP5[y21 + rv + DITH5H] << 10) ;
- }
- }
- }
- static void dblineI420toRGB555alpha (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su, unsigned char *sv,
- int src_x, int dx)
- {
- /* check if we have misaligned input/output: */
- if ((src_x ^ dest_x) & 1) {
- ; /* not implemented yet */
- } else {
- /* aligned input/output: */
- register int y11, y12, y21, y22;
- register int ruv, guv, buv;
- register int i;
- /* convert first 2x1 block: */
- if (dest_x & 1) {
- ruv = rutab[su[0]] + rvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- buv = butab[su[0]] + bvtab[sv[0]];
- y11 = ytab[sy1[0]];
- y21 = ytab[sy2[0]];
- /* output 2 bytes at a time */
- *(unsigned short *)(d1+0) =
- (CLIP5[y11 + buv + DITH5L] << 0) |
- (CLIP5[y11 + guv + DITH5L] << 5) |
- (CLIP5[y11 + ruv + DITH5L] << 10) ;
- *(unsigned short *)(d2+0) =
- (CLIP5[y21 + buv + DITH5H] << 0) |
- (CLIP5[y21 + guv + DITH5H] << 5) |
- (CLIP5[y21 + ruv + DITH5H] << 10) ;
- sy1 += 1; sy2 += 1;
- su += 1; sv += 1;
- d1 += BPP2; d2 += BPP2;
- dest_x ++; dx --;
- }
- /* convert first 2x2 block: */
- if (dest_x & 2) {
- ruv = rutab[su[0]] + rvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- buv = butab[su[0]] + bvtab[sv[0]];
- y11 = ytab[sy1[0]];
- y12 = ytab[sy1[1]];
- /* output 4 bytes at a time */
- *(unsigned int *)(d1+0) =
- (CLIP5[y11 + buv + DITH5L] << 0) |
- (CLIP5[y11 + guv + DITH5L] << 5) |
- (CLIP5[y11 + ruv + DITH5L] << 10) |
- (CLIP5[y12 + buv + DITH5H] << 16) |
- (CLIP5[y12 + guv + DITH5H] << 21) |
- (CLIP5[y12 + ruv + DITH5H] << 26) ;
- y21 = ytab[sy2[0]];
- y22 = ytab[sy2[1]];
- *(unsigned int *)(d2+0) =
- (CLIP5[y21 + buv + DITH5H] << 0) |
- (CLIP5[y21 + guv + DITH5H] << 5) |
- (CLIP5[y21 + ruv + DITH5H] << 10) |
- (CLIP5[y22 + buv + DITH5L] << 16) |
- (CLIP5[y22 + guv + DITH5L] << 21) |
- (CLIP5[y22 + ruv + DITH5L] << 26) ;
- sy1 += 2; sy2 += 2;
- su += 1; sv += 1;
- d1 += 2*BPP2; d2 += 2*BPP2;
- dest_x += 2; dx -= 2;
- }
- /* convert all integral 2x4 blocks: */
- for (i = 0; i < dx/4; i ++) {
- /* first 2x2 block */
- ruv = rutab[su[0]] + rvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- buv = butab[su[0]] + bvtab[sv[0]];
- y11 = ytab[sy1[0]];
- y12 = ytab[sy1[1]];
- /* output 4 bytes at a time */
- *(unsigned int *)(d1+0) =
- (CLIP5[y11 + buv + DITH5L] << 0) |
- (CLIP5[y11 + guv + DITH5L] << 5) |
- (CLIP5[y11 + ruv + DITH5L] << 10) |
- (CLIP5[y12 + buv + DITH5H] << 16) |
- (CLIP5[y12 + guv + DITH5H] << 21) |
- (CLIP5[y12 + ruv + DITH5H] << 26) ;
- y21 = ytab[sy2[0]];
- y22 = ytab[sy2[1]];
- *(unsigned int *)(d2+0) =
- (CLIP5[y21 + buv + DITH5H] << 0) |
- (CLIP5[y21 + guv + DITH5H] << 5) |
- (CLIP5[y21 + ruv + DITH5H] << 10) |
- (CLIP5[y22 + buv + DITH5L] << 16) |
- (CLIP5[y22 + guv + DITH5L] << 21) |
- (CLIP5[y22 + ruv + DITH5L] << 26) ;
- /* second 2x2 block */
- ruv = rutab[su[1]] + rvtab[sv[1]];
- guv = gutab[su[1]] + gvtab[sv[1]];
- buv = butab[su[1]] + bvtab[sv[1]];
- y11 = ytab[sy1[2]];
- y12 = ytab[sy1[3]];
- *(unsigned int *)(d1+2*BPP2) =
- (CLIP5[y11 + buv + DITH5L] << 0) |
- (CLIP5[y11 + guv + DITH5L] << 5) |
- (CLIP5[y11 + ruv + DITH5L] << 10) |
- (CLIP5[y12 + buv + DITH5H] << 16) |
- (CLIP5[y12 + guv + DITH5H] << 21) |
- (CLIP5[y12 + ruv + DITH5H] << 26) ;
- y21 = ytab[sy2[2]];
- y22 = ytab[sy2[3]];
- *(unsigned int *)(d2+2*BPP2) =
- (CLIP5[y21 + buv + DITH5H] << 0) |
- (CLIP5[y21 + guv + DITH5H] << 5) |
- (CLIP5[y21 + ruv + DITH5H] << 10) |
- (CLIP5[y22 + buv + DITH5L] << 16) |
- (CLIP5[y22 + guv + DITH5L] << 21) |
- (CLIP5[y22 + ruv + DITH5L] << 26) ;
- /* next 4x2 block */
- sy1 += 4; sy2 += 4;
- su += 2; sv += 2;
- d1 += 4*BPP2; d2 += 4*BPP2;
- }
- /* convert last 2x2 block: */
- if (dx & 2) {
- ruv = rutab[su[0]] + rvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- buv = butab[su[0]] + bvtab[sv[0]];
- y11 = ytab[sy1[0]];
- y12 = ytab[sy1[1]];
- /* output 4 bytes at a time */
- *(unsigned int *)(d1+0) =
- (CLIP5[y11 + buv + DITH5L] << 0) |
- (CLIP5[y11 + guv + DITH5L] << 5) |
- (CLIP5[y11 + ruv + DITH5L] << 10) |
- (CLIP5[y12 + buv + DITH5H] << 16) |
- (CLIP5[y12 + guv + DITH5H] << 21) |
- (CLIP5[y12 + ruv + DITH5H] << 26) ;
- y21 = ytab[sy2[0]];
- y22 = ytab[sy2[1]];
- *(unsigned int *)(d2+0) =
- (CLIP5[y21 + buv + DITH5H] << 0) |
- (CLIP5[y21 + guv + DITH5H] << 5) |
- (CLIP5[y21 + ruv + DITH5H] << 10) |
- (CLIP5[y22 + buv + DITH5L] << 16) |
- (CLIP5[y22 + guv + DITH5L] << 21) |
- (CLIP5[y22 + ruv + DITH5L] << 26) ;
- sy1 += 2; sy2 += 2;
- su += 1; sv += 1;
- d1 += 2*BPP2; d2 += 2*BPP2;
- dx -= 2;
- }
- /* convert last 2x1 block: */
- if (dx & 1) {
- ruv = rutab[su[0]] + rvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- buv = butab[su[0]] + bvtab[sv[0]];
- y11 = ytab[sy1[0]];
- y21 = ytab[sy2[0]];
- /* output 2 bytes at a time */
- *(unsigned short *)(d1+0) =
- (CLIP5[y11 + buv + DITH5L] << 0) |
- (CLIP5[y11 + guv + DITH5L] << 5) |
- (CLIP5[y11 + ruv + DITH5L] << 10) ;
- *(unsigned short *)(d2+0) =
- (CLIP5[y21 + buv + DITH5H] << 0) |
- (CLIP5[y21 + guv + DITH5H] << 5) |
- (CLIP5[y21 + ruv + DITH5H] << 10) ;
- }
- }
- }
- static void dblineI420toRGB8 (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su, unsigned char *sv,
- int src_x, int dx)
- {
- register int y1, y2, rv, guv, bu;
- register int i;
- /* convert first 2x1 block: */
- if (src_x & 1) {
- bu = butab[su[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- rv = rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line BGR0 */
- *(d1+0) = pmap[
- (CLIP4[y1 + bu + DITH4H] << 0) |
- (CLIP4[y1 + guv + DITH4H] << 4) |
- (CLIP4[y1 + rv + DITH4H] << 8)];
- /* second line BGR0 */
- *(d2+0) = pmap[
- (CLIP4[y2 + bu + DITH4L] << 0) |
- (CLIP4[y2 + guv + DITH4L] << 4) |
- (CLIP4[y2 + rv + DITH4L] << 8)];
- sy1 += 1; sy2 += 1;
- su += 1; sv += 1; /* shift luma !!! */
- d1 += BPP1; d2 += BPP1;
- dx --;
- }
- /* convert all integral 2x2 blocks: */
- for (i = 0; i < dx/2; i ++) {
- bu = butab[su[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- rv = rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line BGR0 */
- *(d1+0) = pmap[
- (CLIP4[y1 + bu + DITH4L] << 0) |
- (CLIP4[y1 + guv + DITH4L] << 4) |
- (CLIP4[y1 + rv + DITH4L] << 8)];
- /* second line BGR0 */
- *(d2+0) = pmap[
- (CLIP4[y2 + bu + DITH4H] << 0) |
- (CLIP4[y2 + guv + DITH4H] << 4) |
- (CLIP4[y2 + rv + DITH4H] << 8)];
- /* 2nd column: */
- y1 = ytab[sy1[1]];
- y2 = ytab[sy2[1]];
- /* first line BGR0 */
- *(d1+BPP1) = pmap[
- (CLIP4[y1 + bu + DITH4H] << 0) |
- (CLIP4[y1 + guv + DITH4H] << 4) |
- (CLIP4[y1 + rv + DITH4H] << 8)];
- /* second line BGR0 */
- *(d2+BPP1) = pmap[
- (CLIP4[y2 + bu + DITH4L] << 0) |
- (CLIP4[y2 + guv + DITH4L] << 4) |
- (CLIP4[y2 + rv + DITH4L] << 8)];
- /* next 2x2 block */
- sy1 += 2; sy2 += 2;
- su += 1; sv += 1;
- d1 += 2*BPP1; d2 += 2*BPP1;
- }
- /* convert the last 2x1 block: */
- if (dx & 1) {
- bu = butab[su[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- rv = rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line BGR0 */
- *(d1+0) = pmap[
- (CLIP4[y1 + bu + DITH4L] << 0) |
- (CLIP4[y1 + guv + DITH4L] << 4) |
- (CLIP4[y1 + rv + DITH4L] << 8)];
- /* second line BGR0 */
- *(d2+0) = pmap[
- (CLIP4[y2 + bu + DITH4H] << 0) |
- (CLIP4[y2 + guv + DITH4H] << 4) |
- (CLIP4[y2 + rv + DITH4H] << 8)];
- }
- }
- static void dblineI420toRGB8alpha (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su, unsigned char *sv,
- int src_x, int dx)
- {
- register int y1, y2, ruv, guv, buv;
- register int i;
- /* convert first 2x1 block: */
- if (src_x & 1) {
- buv = butab[su[0]] + bvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- ruv = rutab[su[0]] + rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line BGR0 */
- *(d1+0) = pmap[
- (CLIP4[y1 + buv + DITH4H] << 0) |
- (CLIP4[y1 + guv + DITH4H] << 4) |
- (CLIP4[y1 + ruv + DITH4H] << 8)];
- /* second line BGR0 */
- *(d2+0) = pmap[
- (CLIP4[y2 + buv + DITH4L] << 0) |
- (CLIP4[y2 + guv + DITH4L] << 4) |
- (CLIP4[y2 + ruv + DITH4L] << 8)];
- sy1 += 1; sy2 += 1;
- su += 1; sv += 1; /* shift luma !!! */
- d1 += BPP1; d2 += BPP1;
- dx --;
- }
- /* convert all integral 2x2 blocks: */
- for (i = 0; i < dx/2; i ++) {
- buv = butab[su[0]] + bvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- ruv = rutab[su[0]] + rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line BGR0 */
- *(d1+0) = pmap[
- (CLIP4[y1 + buv + DITH4L] << 0) |
- (CLIP4[y1 + guv + DITH4L] << 4) |
- (CLIP4[y1 + ruv + DITH4L] << 8)];
- /* second line BGR0 */
- *(d2+0) = pmap[
- (CLIP4[y2 + buv + DITH4H] << 0) |
- (CLIP4[y2 + guv + DITH4H] << 4) |
- (CLIP4[y2 + ruv + DITH4H] << 8)];
- y1 = ytab[sy1[1]];
- y2 = ytab[sy2[1]];
- /* first line BGR0 */
- *(d1+BPP1) = pmap[
- (CLIP4[y1 + buv + DITH4H] << 0) |
- (CLIP4[y1 + guv + DITH4H] << 4) |
- (CLIP4[y1 + ruv + DITH4H] << 8)];
- /* second line BGR0 */
- *(d2+BPP1) = pmap[
- (CLIP4[y2 + buv + DITH4L] << 0) |
- (CLIP4[y2 + guv + DITH4L] << 4) |
- (CLIP4[y2 + ruv + DITH4L] << 8)];
- /* next 2x2 block */
- sy1 += 2; sy2 += 2;
- su += 1; sv += 1;
- d1 += 2*BPP1; d2 += 2*BPP1;
- }
- /* convert last 2x1 block: */
- if (dx & 1) {
- buv = butab[su[0]] + bvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- ruv = rutab[su[0]] + rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line BGR0 */
- *(d1+0) = pmap[
- (CLIP4[y1 + buv + DITH4L] << 0) |
- (CLIP4[y1 + guv + DITH4L] << 4) |
- (CLIP4[y1 + ruv + DITH4L] << 8)];
- /* second line BGR0 */
- *(d2+0) = pmap[
- (CLIP4[y2 + buv + DITH4H] << 0) |
- (CLIP4[y2 + guv + DITH4H] << 4) |
- (CLIP4[y2 + ruv + DITH4H] << 8)];
- }
- }
- /*
- * Convert two YUV lines into RGB linebufs.
- * Produces two RGB lines per call.
- * Output in padded RGB format, needed for SIMD interpolation.
- */
- static void dblineI420toXRGB (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su, unsigned char *sv,
- int src_x, int dx)
- {
- register int y1, y2, rv, guv, bu;
- register int i;
- /* convert first 2x1 block: */
- if (src_x & 1) {
- bu = butab[su[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- rv = rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d1+0) =
- (CLIP8[y1 + bu]) |
- (CLIP8[y1 + guv] << 11) |
- (CLIP8[y1 + rv] << 22) ;
- /* second line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d2+0) =
- (CLIP8[y2 + bu]) |
- (CLIP8[y2 + guv] << 11) |
- (CLIP8[y2 + rv] << 22) ;
- sy1 += 1; sy2 += 1;
- su += 1; sv += 1;
- d1 += BPP4; d2 += BPP4;
- dx --;
- }
- /* convert all integral 2x2 blocks: */
- for (i = 0; i < dx/2; i ++) {
- bu = butab[su[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- rv = rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d1+0) =
- (CLIP8[y1 + bu]) |
- (CLIP8[y1 + guv] << 11) |
- (CLIP8[y1 + rv] << 22) ;
- /* second line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d2+0) =
- (CLIP8[y2 + bu]) |
- (CLIP8[y2 + guv] << 11) |
- (CLIP8[y2 + rv] << 22) ;
- /* 2nd row: */
- y1 = ytab[sy1[1]];
- y2 = ytab[sy2[1]];
- /* first line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d1+BPP4) =
- (CLIP8[y1 + bu]) |
- (CLIP8[y1 + guv] << 11) |
- (CLIP8[y1 + rv] << 22) ;
- /* second line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d2+BPP4) =
- (CLIP8[y2 + bu]) |
- (CLIP8[y2 + guv] << 11) |
- (CLIP8[y2 + rv] << 22) ;
- /* next 2x2 block */
- sy1 += 2; sy2 += 2;
- su += 1; sv += 1;
- d1 += 2*BPP4; d2 += 2*BPP4;
- }
- /* convert last 2x1 block: */
- if (dx & 1) {
- bu = butab[su[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- rv = rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d1+0) =
- (CLIP8[y1 + bu]) |
- (CLIP8[y1 + guv] << 11) |
- (CLIP8[y1 + rv] << 22) ;
- /* second line BGR0 */
- *(unsigned int *)(d2+0) =
- (CLIP8[y2 + bu]) |
- (CLIP8[y2 + guv] << 11) |
- (CLIP8[y2 + rv] << 22) ;
- }
- }
- static void dblineI420toXRGBalpha (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su, unsigned char *sv,
- int src_x, int dx)
- {
- register int y1, y2, ruv, guv, buv;
- register int i;
- /* convert first 2x1 block: */
- if (src_x & 1) {
- buv = butab[su[0]] + bvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- ruv = rutab[su[0]] + rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d1+0) =
- (CLIP8[y1 + buv]) |
- (CLIP8[y1 + guv] << 11) |
- (CLIP8[y1 + ruv] << 22);
- /* second line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d2+0) =
- (CLIP8[y2 + buv]) |
- (CLIP8[y2 + guv] << 11) |
- (CLIP8[y2 + ruv] << 22) ;
- sy1 += 1; sy2 += 1;
- su += 1; sv += 1;
- d1 += BPP4; d2 += BPP4;
- dx --;
- }
- /* convert all integral 2x2 blocks: */
- for (i = 0; i < dx/2; i ++) {
- buv = butab[su[0]] + bvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- ruv = rutab[su[0]] + rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d1+0) =
- (CLIP8[y1 + buv]) |
- (CLIP8[y1 + guv] << 11) |
- (CLIP8[y1 + ruv] << 22) ;
- /* second line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d2+0) =
- (CLIP8[y2 + buv]) |
- (CLIP8[y2 + guv] << 11) |
- (CLIP8[y2 + ruv] << 22) ;
- y1 = ytab[sy1[1]];
- y2 = ytab[sy2[1]];
- /* first line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d1+BPP4) =
- (CLIP8[y1 + buv]) |
- (CLIP8[y1 + guv] << 11) |
- (CLIP8[y1 + ruv] << 22) ;
- /* second line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d2+BPP4) =
- (CLIP8[y2 + buv]) |
- (CLIP8[y2 + guv] << 11) |
- (CLIP8[y2 + ruv] << 22) ;
- /* next 2x2 block */
- sy1 += 2; sy2 += 2;
- su += 1; sv += 1;
- d1 += 2*BPP4; d2 += 2*BPP4;
- }
- /* convert last 2x1 block: */
- if (dx & 1) {
- buv = butab[su[0]] + bvtab[sv[0]];
- guv = gutab[su[0]] + gvtab[sv[0]];
- ruv = rutab[su[0]] + rvtab[sv[0]];
- y1 = ytab[sy1[0]];
- y2 = ytab[sy2[0]];
- /* first line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d1+0) =
- (CLIP8[y1 + buv]) |
- (CLIP8[y1 + guv] << 11) |
- (CLIP8[y1 + ruv] << 22) ;
- /* second line 00rrrrrr.rr000ggg.ggggg000.bbbbbbbb: */
- *(unsigned int *)(d2+0) =
- (CLIP8[y2 + buv]) |
- (CLIP8[y2 + guv] << 11) |
- (CLIP8[y2 + ruv] << 22) ;
- }
- }
- /*
- * Interpolate and pack RGB lines into final output
- * Produces two output lines per call.
- * Requires padded RGB for SIMD interpolation.
- */
- #define ROUND888 0x00400801
- /* RGB32 version: */
- static void dblineXRGBtoRGB32x2 (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *s1, unsigned char *s2, int src_x, int dx)
- {
- register unsigned int a, b, c, d, e, f;
- register unsigned int w, x, y, z;
- /* convert first 2x1 block: */
- if (dest_x & 1) {
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- w = a;
- x = a + b + ROUND888;
- /* pack and store */
- *(unsigned int *)(d1+0) =
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6);
- *(unsigned int *)(d1+BPP4) =
- ((x & 0x000001fe) >> 1) |
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 7);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7);
- *(unsigned int *)(d2+BPP4) =
- ((x & 0x000003fc) >> 2) |
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 8);
- /* bump pointers to next block */
- s1 += BPP4; s2 += BPP4;
- d1 += 2*BPP4; d2 += 2*BPP4;
- dx -= 1;
- }
- /* process all integral 2x2 blocks: */
- while (dx > 2) { /* we need to leave at least one block */
- /*
- * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
- *
- * Input pels => Output pels
- * a b e w x y z
- * c d f w' x' y' z'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = *(unsigned int *)(s1+2*BPP4);
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6);
- *(unsigned int *)(d1+BPP4) =
- ((x & 0x000001fe) >> 1) |
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 7);
- *(unsigned int *)(d1+2*BPP4) =
- ((y & 0x000000ff) >> 0) |
- ((y & 0x0007f800) >> 3) |
- ((y & 0x3fc00000) >> 6);
- *(unsigned int *)(d1+3*BPP4) =
- ((z & 0x000001fe) >> 1) |
- ((z & 0x000ff000) >> 4) |
- ((z & 0x7f800000) >> 7);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = *(unsigned int *)(s2+2*BPP4);
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- y = b + d + ROUND888;
- z = b + e + d + f + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7);
- *(unsigned int *)(d2+BPP4) =
- ((x & 0x000003fc) >> 2) |
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 8);
- *(unsigned int *)(d2+2*BPP4) =
- ((y & 0x000001fe) >> 1) |
- ((y & 0x000ff000) >> 4) |
- ((y & 0x7f800000) >> 7);
- *(unsigned int *)(d2+3*BPP4) =
- ((z & 0x000003fc) >> 2) |
- ((z & 0x001fe000) >> 5) |
- ((z & 0xff000000) >> 8);
- /* bump pointers to next 2x2 input */
- s1 += 2*BPP4; s2 += 2*BPP4;
- d1 += 4*BPP4; d2 += 4*BPP4;
- dx -= 2;
- }
- /* check if this is the last 2x2 block: */
- if (dx > 1) {
- /*
- * For last 4 output pels, repeat final input pel
- * for offscreen input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6);
- *(unsigned int *)(d1+BPP4) =
- ((x & 0x000001fe) >> 1) |
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 7);
- *(unsigned int *)(d1+2*BPP4) =
- ((y & 0x000000ff) >> 0) |
- ((y & 0x0007f800) >> 3) |
- ((y & 0x3fc00000) >> 6);
- *(unsigned int *)(d1+3*BPP4) =
- ((z & 0x000001fe) >> 1) |
- ((z & 0x000ff000) >> 4) |
- ((z & 0x7f800000) >> 7);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = d; /* repeat last input pel */
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- y = b + d + ROUND888;
- z = b + e + d + f + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7);
- *(unsigned int *)(d2+BPP4) =
- ((x & 0x000003fc) >> 2) |
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 8);
- *(unsigned int *)(d2+2*BPP4) =
- ((y & 0x000001fe) >> 1) |
- ((y & 0x000ff000) >> 4) |
- ((y & 0x7f800000) >> 7);
- *(unsigned int *)(d2+3*BPP4) =
- ((z & 0x000003fc) >> 2) |
- ((z & 0x001fe000) >> 5) |
- ((z & 0xff000000) >> 8);
- } else {
- /* last 2x1 block: */
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = a; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- /* pack and store */
- *(unsigned int *)(d1+0) =
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6);
- *(unsigned int *)(d1+BPP4) =
- ((x & 0x000001fe) >> 1) |
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 7);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = c; /* repeat last input pel */
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7);
- *(unsigned int *)(d2+BPP4) =
- ((x & 0x000003fc) >> 2) |
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 8);
- }
- }
- /* BGR32 version: */
- static void dblineXRGBtoBGR32x2 (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *s1, unsigned char *s2, int src_x, int dx)
- {
- register unsigned int a, b, c, d, e, f;
- register unsigned int w, x, y, z;
- /* convert first 2x1 block: */
- if (dest_x & 1) {
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- w = a;
- x = a + b + ROUND888;
- /* pack and store */
- *(unsigned int *)(d1+0) =
- ((w & 0x000000ff) << 16)|
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 22);
- *(unsigned int *)(d1+BPP4) =
- ((x & 0x000001fe) << 15)|
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 23);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001fe) << 15)|
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 23);
- *(unsigned int *)(d2+BPP4) =
- ((x & 0x000003fc) << 14)|
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 24);
- /* bump pointers to next block */
- s1 += BPP4; s2 += BPP4;
- d1 += 2*BPP4; d2 += 2*BPP4;
- dx -= 1;
- }
- /* process all integral 2x2 blocks: */
- while (dx > 2) { /* we need to leave at least one block */
- /*
- * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
- *
- * Input pels => Output pels
- * a b e w x y z
- * c d f w' x' y' z'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = *(unsigned int *)(s1+2*BPP4);
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000ff) << 16)|
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 22);
- *(unsigned int *)(d1+BPP4) =
- ((x & 0x000001fe) << 15)|
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 23);
- *(unsigned int *)(d1+2*BPP4) =
- ((y & 0x000000ff) << 16)|
- ((y & 0x0007f800) >> 3) |
- ((y & 0x3fc00000) >> 22);
- *(unsigned int *)(d1+3*BPP4) =
- ((z & 0x000001fe) << 15)|
- ((z & 0x000ff000) >> 4) |
- ((z & 0x7f800000) >> 23);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = *(unsigned int *)(s2+2*BPP4);
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- y = b + d + ROUND888;
- z = b + e + d + f + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001fe) << 15)|
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 23);
- *(unsigned int *)(d2+BPP4) =
- ((x & 0x000003fc) << 14)|
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 24);
- *(unsigned int *)(d2+2*BPP4) =
- ((y & 0x000001fe) << 15)|
- ((y & 0x000ff000) >> 4) |
- ((y & 0x7f800000) >> 23);
- *(unsigned int *)(d2+3*BPP4) =
- ((z & 0x000003fc) << 14)|
- ((z & 0x001fe000) >> 5) |
- ((z & 0xff000000) >> 24);
- /* bump pointers to next 2x2 input */
- s1 += 2*BPP4; s2 += 2*BPP4;
- d1 += 4*BPP4; d2 += 4*BPP4;
- dx -= 2;
- }
- /* check if this is the last 2x2 block: */
- if (dx > 1) {
- /*
- * For last 4 output pels, repeat final input pel
- * for offscreen input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000ff) << 16)|
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 22);
- *(unsigned int *)(d1+BPP4) =
- ((x & 0x000001fe) << 15)|
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 23);
- *(unsigned int *)(d1+2*BPP4) =
- ((y & 0x000000ff) << 16)|
- ((y & 0x0007f800) >> 3) |
- ((y & 0x3fc00000) >> 22);
- *(unsigned int *)(d1+3*BPP4) =
- ((z & 0x000001fe) << 15)|
- ((z & 0x000ff000) >> 4) |
- ((z & 0x7f800000) >> 23);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = d; /* repeat last input pel */
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- y = b + d + ROUND888;
- z = b + e + d + f + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001fe) << 15)|
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 23);
- *(unsigned int *)(d2+BPP4) =
- ((x & 0x000003fc) << 14)|
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 24);
- *(unsigned int *)(d2+2*BPP4) =
- ((y & 0x000001fe) << 15)|
- ((y & 0x000ff000) >> 4) |
- ((y & 0x7f800000) >> 23);
- *(unsigned int *)(d2+3*BPP4) =
- ((z & 0x000003fc) << 14)|
- ((z & 0x001fe000) >> 5) |
- ((z & 0xff000000) >> 24);
- } else {
- /* last 2x1 block: */
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = a; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- /* pack and store */
- *(unsigned int *)(d1+0) =
- ((w & 0x000000ff) << 16)|
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 22);
- *(unsigned int *)(d1+BPP4) =
- ((x & 0x000001fe) << 15)|
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 23);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = c; /* repeat last input pel */
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001fe) << 15)|
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 23);
- *(unsigned int *)(d2+BPP4) =
- ((x & 0x000003fc) << 14)|
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 24);
- }
- }
- /* RGB24 version: */
- static void dblineXRGBtoRGB24x2 (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *s1, unsigned char *s2, int src_x, int dx)
- {
- register unsigned int a, b, c, d, e, f;
- register unsigned int w, x, y, z;
- /* convert first 2x1 block: */
- if (dest_x & 1) {
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- w = a;
- x = a + b + ROUND888;
- /* pack and store */
- *(unsigned int *)d1 = /* brgB */
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6) |
- ((x & 0x000001fe) << 23);
- *(unsigned short *)(d1+4) = /* GR */
- ((x & 0x000ff000) >> 12) |
- ((x & 0x7f800000) >> 15);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 = /* bgrB */
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7) |
- ((x & 0x000003fc) << 22);
- *(unsigned short *)(d2+4) = /* GR */
- ((x & 0x001fe000) >> 13) |
- ((x & 0xff000000) >> 16);
- /* bump pointers to next block */
- s1 += BPP4; s2 += BPP4;
- d1 += 2*BPP3; d2 += 2*BPP3;
- dx -= 1;
- }
- /* process all integral 2x2 blocks: */
- while (dx > 2) { /* we need to leave at least one block */
- /*
- * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
- *
- * Input pels => Output pels
- * a b e w x y z
- * c d f w' x' y' z'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = *(unsigned int *)(s1+2*BPP4);
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)d1 = /* brgB */
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6) |
- ((x & 0x000001fe) << 23);
- *(unsigned int *)(d1+4) = /* GRbg */
- ((x & 0x000ff000) >> 12) |
- ((x & 0x7f800000) >> 15) |
- ((y & 0x000000ff) << 16) |
- ((y & 0x0007f800) << 13);
- *(unsigned int *)(d1+8) = /* rBGR */
- ((y & 0x3fc00000) >> 22) |
- ((z & 0x000001fe) << 7) |
- ((z & 0x000ff000) << 4) |
- ((z & 0x7f800000) << 1);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = *(unsigned int *)(s2+2*BPP4);
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- y = b + d + ROUND888;
- z = b + e + d + f + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 = /* bgrB */
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7) |
- ((x & 0x000003fc) << 22);
- *(unsigned int *)(d2+4) = /* GRbg */
- ((x & 0x001fe000) >> 13) |
- ((x & 0xff000000) >> 16) |
- ((y & 0x000001fe) << 15) |
- ((y & 0x000ff000) << 12);
- *(unsigned int *)(d2+8) = /* rBGR */
- ((y & 0x7f800000) >> 23) |
- ((z & 0x000003fc) << 6) |
- ((z & 0x001fe000) << 3) |
- ((z & 0xff000000) << 0);
- /* next 2x2 input block */
- s1 += 2*BPP4; s2 += 2*BPP4;
- d1 += 4*BPP3; d2 += 4*BPP3;
- dx -= 2;
- }
- /* check if this is the last 2x2 block: */
- if (dx > 1) {
- /*
- * For last 4 output pels, repeat final input pel
- * for offscreen input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)(d1+0) = /* bgrB */
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6) |
- ((x & 0x000001fe) << 23);
- *(unsigned int *)(d1+4) = /* GRbg */
- ((x & 0x000ff000) >> 12) |
- ((x & 0x7f800000) >> 15) |
- ((y & 0x000000ff) << 16) |
- ((y & 0x0007f800) << 13);
- *(unsigned int *)(d1+8) = /* rBGR */
- ((y & 0x3fc00000) >> 22) |
- ((z & 0x000001fe) << 7) |
- ((z & 0x000ff000) << 4) |
- ((z & 0x7f800000) << 1);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = d; /* repeat last input pel */
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- y = b + d + ROUND888;
- z = b + e + d + f + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)(d2+0) = /* bgrB */
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7) |
- ((x & 0x000003fc) << 22);
- *(unsigned int *)(d2+4) = /* GRbg */
- ((x & 0x001fe000) >> 13) |
- ((x & 0xff000000) >> 16) |
- ((y & 0x000001fe) << 15) |
- ((y & 0x000ff000) << 12);
- *(unsigned int *)(d2+8) = /* rBGR */
- ((y & 0x7f800000) >> 23) |
- ((z & 0x000003fc) << 6) |
- ((z & 0x001fe000) << 3) |
- ((z & 0xff000000) << 0);
- } else {
- /* last 2x1 block: */
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = a; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- /* pack and store */
- *(unsigned int *)d1 = /* brgB */
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6) |
- ((x & 0x000001fe) << 23);
- *(unsigned short *)(d1+4) = /* GR */
- ((x & 0x000ff000) >> 12) |
- ((x & 0x7f800000) >> 15);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = c; /* repeat last input pel */
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- /* pack and store */
- *(unsigned int *)d2 = /* bgrB */
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7) |
- ((x & 0x000003fc) << 22);
- *(unsigned short *)(d2+4) = /* GR */
- ((x & 0x001fe000) >> 13) |
- ((x & 0xff000000) >> 16);
- }
- }
- /* RGB565 version: */
- static void dblineXRGBtoRGB565x2 (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *s1, unsigned char *s2, int src_x, int dx)
- {
- register unsigned int a, b, c, d, e, f;
- register unsigned int w, x, y, z;
- /* convert first 2x1 block: */
- if (dest_x & 1) {
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- w = a;
- x = a + b;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007e000) >> 8) |
- ((w & 0x3e000000) >> 14) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000fc000) << 7) |
- ((x & 0x7c000000) << 1);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- w = a + c;
- x = a + b + c + d;
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000fc000) >> 9) |
- ((w & 0x7c000000) >> 15) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f8000) << 6) |
- ((x & 0xf8000000) << 0);
- /* bump pointers to next block */
- s1 += BPP4; s2 += BPP4;
- d1 += 2*BPP2; d2 += 2*BPP2;
- dx -= 1;
- }
- /* process all integral 2x2 blocks: */
- while (dx > 2) { /* we need to leave at least one block */
- /*
- * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
- *
- * Input pels Output pels
- * a b e w x y z
- * c d f w' x' y' z'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = *(unsigned int *)(s1+2*BPP4);
- w = a;
- x = a + b;
- y = b;
- z = b + e;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007e000) >> 8) |
- ((w & 0x3e000000) >> 14) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000fc000) << 7) |
- ((x & 0x7c000000) << 1);
- *(unsigned int *)(d1+2*BPP2) =
- ((y & 0x000000f8) >> 3) |
- ((y & 0x0007e000) >> 8) |
- ((y & 0x3e000000) >> 14) |
- ((z & 0x000001f0) << 12) |
- ((z & 0x000fc000) << 7) |
- ((z & 0x7c000000) << 1);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = *(unsigned int *)(s2+2*BPP4);
- w = a + c;
- x = a + b + c + d;
- y = b + d;
- z = b + e + d + f;
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000fc000) >> 9) |
- ((w & 0x7c000000) >> 15) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f8000) << 6) |
- ((x & 0xf8000000) << 0);
- *(unsigned int *)(d2+2*BPP2) =
- ((y & 0x000001f0) >> 4) |
- ((y & 0x000fc000) >> 9) |
- ((y & 0x7c000000) >> 15) |
- ((z & 0x000003e0) << 11) |
- ((z & 0x001f8000) << 6) |
- ((z & 0xf8000000) << 0);
- /* next 2x2 input block */
- s1 += 2*BPP4; s2 += 2*BPP4;
- d1 += 4*BPP2; d2 += 4*BPP2;
- dx -= 2;
- }
- /* check if this is the last 2x2 block: */
- if (dx > 1) {
- /*
- * For last 4 output pels, repeat final input pel
- * for offscreen input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b;
- y = b;
- z = b + e;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007e000) >> 8) |
- ((w & 0x3e000000) >> 14) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000fc000) << 7) |
- ((x & 0x7c000000) << 1);
- *(unsigned int *)(d1+2*BPP2) =
- ((y & 0x000000f8) >> 3) |
- ((y & 0x0007e000) >> 8) |
- ((y & 0x3e000000) >> 14) |
- ((z & 0x000001f0) << 12) |
- ((z & 0x000fc000) << 7) |
- ((z & 0x7c000000) << 1);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = d; /* repeat last input pel */
- w = a + c;
- x = a + b + c + d;
- y = b + d;
- z = b + e + d + f;
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000fc000) >> 9) |
- ((w & 0x7c000000) >> 15) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f8000) << 6) |
- ((x & 0xf8000000) << 0);
- *(unsigned int *)(d2+2*BPP2) =
- ((y & 0x000001f0) >> 4) |
- ((y & 0x000fc000) >> 9) |
- ((y & 0x7c000000) >> 15) |
- ((z & 0x000003e0) << 11) |
- ((z & 0x001f8000) << 6) |
- ((z & 0xf8000000) << 0);
- } else {
- /* last 2x1 block: */
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = a; /* repeat last input pel */
- w = a;
- x = a + b;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007e000) >> 8) |
- ((w & 0x3e000000) >> 14) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000fc000) << 7) |
- ((x & 0x7c000000) << 1);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = c; /* repeat last input pel */
- w = a + c;
- x = a + b + c + d;
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000fc000) >> 9) |
- ((w & 0x7c000000) >> 15) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f8000) << 6) |
- ((x & 0xf8000000) << 0);
- }
- }
- /* RGB555 version: */
- static void dblineXRGBtoRGB555x2 (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *s1, unsigned char *s2, int src_x, int dx)
- {
- register unsigned int a, b, c, d, e, f;
- register unsigned int w, x, y, z;
- /* convert first 2x1 block: */
- if (dest_x & 1) {
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- w = a;
- x = a + b;
- /* pack and store */
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007c000) >> 9) |
- ((w & 0x3e000000) >> 15) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000f8000) << 6) |
- ((x & 0x7c000000) << 0);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- w = a + c;
- x = a + b + c + d;
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000f8000) >> 10) |
- ((w & 0x7c000000) >> 16) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f0000) << 5) |
- ((x & 0xf8000000) >> 1);
- /* bump pointers to next block */
- s1 += BPP4; s2 += BPP4;
- d1 += 2*BPP2; d2 += 2*BPP2;
- dx -= 1;
- }
- /* process all integral 2x2 blocks: */
- while (dx > 2) { /* we need to leave at least one block */
- /*
- * Input pels Output pels
- * a b e w x y z
- * c d f w' x' y' z'
- *
- * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = *(unsigned int *)(s1+2*BPP4);
- w = a;
- x = a + b;
- y = b;
- z = b + e;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007c000) >> 9) |
- ((w & 0x3e000000) >> 15) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000f8000) << 6) |
- ((x & 0x7c000000) << 0);
- *(unsigned int *)(d1+BPP4) =
- ((y & 0x000000f8) >> 3) |
- ((y & 0x0007c000) >> 9) |
- ((y & 0x3e000000) >> 15) |
- ((z & 0x000001f0) << 12) |
- ((z & 0x000f8000) << 6) |
- ((z & 0x7c000000) << 0);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = *(unsigned int *)(s2+2*BPP4);
- w = a + c;
- x = a + b + c + d;
- y = b + d;
- z = b + e + d + f;
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000f8000) >> 10) |
- ((w & 0x7c000000) >> 16) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f0000) << 5) |
- ((x & 0xf8000000) >> 1);
- *(unsigned int *)(d2+BPP4) =
- ((y & 0x000001f0) >> 4) |
- ((y & 0x000f8000) >> 10) |
- ((y & 0x7c000000) >> 16) |
- ((z & 0x000003e0) << 11) |
- ((z & 0x001f0000) << 5) |
- ((z & 0xf8000000) >> 1);
- /* next 2x2 input block */
- s1 += 2*BPP4; s2 += 2*BPP4;
- d1 += 4*BPP2; d2 += 4*BPP2;
- dx -= 2;
- }
- /* check if this is the last 2x2 block: */
- if (dx > 1) {
- /*
- * For last 4 output pels, repeat final input pel
- * for offscreen input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)(s1+0);
- b = *(unsigned int *)(s1+4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b;
- y = b;
- z = b + e;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007c000) >> 9) |
- ((w & 0x3e000000) >> 15) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000f8000) << 6) |
- ((x & 0x7c000000) << 0);
- *(unsigned int *)(d1+BPP4) =
- ((y & 0x000000f8) >> 3) |
- ((y & 0x0007c000) >> 9) |
- ((y & 0x3e000000) >> 15) |
- ((z & 0x000001f0) << 12) |
- ((z & 0x000f8000) << 6) |
- ((z & 0x7c000000) << 0);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = d; /* repeat last input pel */
- w = a + c;
- x = a + b + c + d;
- y = b + d;
- z = b + e + d + f;
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000f8000) >> 10) |
- ((w & 0x7c000000) >> 16) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f0000) << 5) |
- ((x & 0xf8000000) >> 1);
- *(unsigned int *)(d2+2*BPP2) =
- ((y & 0x000001f0) >> 4) |
- ((y & 0x000f8000) >> 10) |
- ((y & 0x7c000000) >> 16) |
- ((z & 0x000003e0) << 11) |
- ((z & 0x001f0000) << 5) |
- ((z & 0xf8000000) >> 1);
- } else {
- /* last 2x1 block: */
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = a; /* repeat last input pel */
- w = a;
- x = a + b;
- /* pack and store */
- *(unsigned int *)d1 =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007c000) >> 9) |
- ((w & 0x3e000000) >> 15) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000f8000) << 6) |
- ((x & 0x7c000000) << 0);
- /* bottom line */
- c = *(unsigned int *)s2;
- d = c; /* repeat last input pel */
- w = a + c;
- x = a + b + c + d;
- /* pack and store */
- *(unsigned int *)d2 =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000f8000) >> 10) |
- ((w & 0x7c000000) >> 16) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f0000) << 5) |
- ((x & 0xf8000000) >> 1);
- }
- }
- /* RGB8 version: */
- static void dblineXRGBtoRGB8x2 (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *s1, unsigned char *s2, int src_x, int dx)
- {
- register unsigned int a, b, c, d, e, f;
- register unsigned int w, x, y, z;
- /* convert first 2x1 block: */
- if (dest_x & 1) {
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- w = a;
- x = a + b + ROUND888;
- /* pack and store */
- *(d1+0) = pmap[
- ((w & 0x000000f0) >> 4) |
- ((w & 0x00078000) >> 11) |
- ((w & 0x3c000000) >> 18)];
- *(d1+BPP1) = pmap[
- ((x & 0x000001e0) >> 5) |
- ((x & 0x000f0000) >> 12) |
- ((x & 0x78000000) >> 19)];
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- /* pack and store */
- *(d2+0) = pmap[
- ((w & 0x000001e0) >> 5) |
- ((w & 0x000f0000) >> 12) |
- ((w & 0x78000000) >> 19)];
- *(d2+BPP1) = pmap[
- ((x & 0x000003c0) >> 6) |
- ((x & 0x001e0000) >> 13) |
- ((x & 0xf0000000) >> 20)];
- /* bump pointers to next block */
- s1 += BPP4; s2 += BPP4;
- d1 += 2*BPP1; d2 += 2*BPP1;
- dx -= 1;
- }
- /* process all integral 2x2 blocks: */
- while (dx > 2) { /* we need to leave at least one block */
- /*
- * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
- *
- * Input pels => Output pels
- * a b e w x y z
- * c d f w' x' y' z'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = *(unsigned int *)(s1+2*BPP4);
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(d1+0) = pmap[
- ((w & 0x000000f0) >> 4) |
- ((w & 0x00078000) >> 11) |
- ((w & 0x3c000000) >> 18)];
- *(d1+BPP1) = pmap[
- ((x & 0x000001e0) >> 5) |
- ((x & 0x000f0000) >> 12) |
- ((x & 0x78000000) >> 19)];
- *(d1+2*BPP1) = pmap[
- ((y & 0x000000f0) >> 4) |
- ((y & 0x00078000) >> 11) |
- ((y & 0x3c000000) >> 18)];
- *(d1+3*BPP1) = pmap[
- ((z & 0x000001e0) >> 5) |
- ((z & 0x000f0000) >> 12) |
- ((z & 0x78000000) >> 19)];
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = *(unsigned int *)(s2+2*BPP4);
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- y = b + d + ROUND888;
- z = b + e + d + f + (ROUND888<<1);
- /* pack and store */
- *(d2+0) = pmap[
- ((w & 0x000001e0) >> 5) |
- ((w & 0x000f0000) >> 12) |
- ((w & 0x78000000) >> 19)];
- *(d2+BPP1) = pmap[
- ((x & 0x000003c0) >> 6) |
- ((x & 0x001e0000) >> 13) |
- ((x & 0xf0000000) >> 20)];
- *(d2+2*BPP1) = pmap[
- ((y & 0x000001e0) >> 5) |
- ((y & 0x000f0000) >> 12) |
- ((y & 0x78000000) >> 19)];
- *(d2+3*BPP1) = pmap[
- ((z & 0x000003c0) >> 6) |
- ((z & 0x001e0000) >> 13) |
- ((z & 0xf0000000) >> 20)];
- /* bump pointers to next 2x2 input */
- s1 += 2*BPP4; s2 += 2*BPP4;
- d1 += 4*BPP1; d2 += 4*BPP1;
- dx -= 2;
- }
- /* check if this is the last 2x2 block: */
- if (dx > 1) {
- /*
- * For last 4 output pels, repeat final input pel
- * for offscreen input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = *(unsigned int *)(s1+BPP4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(d1+0) = pmap[
- ((w & 0x000000f0) >> 4) |
- ((w & 0x00078000) >> 11) |
- ((w & 0x3c000000) >> 18)];
- *(d1+BPP1) = pmap[
- ((x & 0x000001e0) >> 5) |
- ((x & 0x000f0000) >> 12) |
- ((x & 0x78000000) >> 19)];
- *(d1+2*BPP1) = pmap[
- ((y & 0x000000f0) >> 4) |
- ((y & 0x00078000) >> 11) |
- ((y & 0x3c000000) >> 18)];
- *(d1+3*BPP1) = pmap[
- ((z & 0x000001e0) >> 5) |
- ((z & 0x000f0000) >> 12) |
- ((z & 0x78000000) >> 19)];
- /* bottom line */
- c = *(unsigned int *)s2;
- d = *(unsigned int *)(s2+BPP4);
- f = d; /* repeat last input pel */
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- y = b + d + ROUND888;
- z = b + e + d + f + (ROUND888<<1);
- /* pack and store */
- *(d2+0) = pmap[
- ((w & 0x000001e0) >> 5) |
- ((w & 0x000f0000) >> 12) |
- ((w & 0x78000000) >> 19)];
- *(d2+BPP1) = pmap[
- ((x & 0x000003c0) >> 6) |
- ((x & 0x001e0000) >> 13) |
- ((x & 0xf0000000) >> 20)];
- *(d2+2*BPP1) = pmap[
- ((y & 0x000001e0) >> 5) |
- ((y & 0x000f0000) >> 12) |
- ((y & 0x78000000) >> 19)];
- *(d2+3*BPP1) = pmap[
- ((z & 0x000003c0) >> 6) |
- ((z & 0x001e0000) >> 13) |
- ((z & 0xf0000000) >> 20)];
- } else {
- /* last 2x1 block: */
- /* Input pels => Output pels
- * a b w x
- * c d w' x'
- */
- /* top line */
- a = *(unsigned int *)s1;
- b = a; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- /* pack and store */
- *(d1+0) = pmap[
- ((w & 0x000000f0) >> 4) |
- ((w & 0x00078000) >> 11) |
- ((w & 0x3c000000) >> 18)];
- *(d1+BPP1) = pmap[
- ((x & 0x000001e0) >> 5) |
- ((x & 0x000f0000) >> 12) |
- ((x & 0x78000000) >> 19)];
- /* bottom line */
- c = *(unsigned int *)s2;
- d = c; /* repeat last input pel */
- w = a + c + ROUND888;
- x = a + b + c + d + (ROUND888<<1);
- /* pack and store */
- *(d2+0) = pmap[
- ((w & 0x000001e0) >> 5) |
- ((w & 0x000f0000) >> 12) |
- ((w & 0x78000000) >> 19)];
- *(d2+BPP1) = pmap[
- ((x & 0x000003c0) >> 6) |
- ((x & 0x001e0000) >> 13) |
- ((x & 0xf0000000) >> 20)];
- }
- }
- /* color converter tables: */
- static void (* cc []) (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su,
- unsigned char *sv, int src_x, int dx) = {
- dblineI420toRGB32, dblineI420toRGB24,
- dblineI420toRGB565, dblineI420toRGB555,
- dblineI420toRGB8, dblineI420toBGR32
- };
- static void (* ccalpha []) (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su,
- unsigned char *sv, int src_x, int dx) = {
- dblineI420toRGB32alpha, dblineI420toRGB24alpha,
- dblineI420toRGB565alpha, dblineI420toRGB555alpha,
- dblineI420toRGB8alpha, dblineI420toBGR32alpha
- };
- static void (* ccx2 []) (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *s1, unsigned char *s2, int src_x, int dx) = {
- dblineXRGBtoRGB32x2, dblineXRGBtoRGB24x2,
- dblineXRGBtoRGB565x2, dblineXRGBtoRGB555x2,
- dblineXRGBtoRGB8x2, dblineXRGBtoBGR32x2
- };
- static int bpp [] = {4, 3, 2, 2, 1, 4};
- /* RGB linebuffers */
- static int next[3] = {1, 2, 0}; /* (ibuf+1)%3 table */
- static int next2[3] = {2, 0, 1}; /* (ibuf+2)%3 table */
- #define MAXWIDTH 640 /* max input width */
- static unsigned char linebuf [3*MAXWIDTH*BPP4]; /* space for 3 RGB linebuffers */ /* Flawfinder: ignore */
- /*
- * I420->RGB* driver:
- */
- static int I420toRGB (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy, int ccidx)
- {
- /* scale factors: */
- int scale_x, scale_y;
- /* check arguments: */
- if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
- return -1;
- /* check if bottop-up images: */
- if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
- if (src_pitch <= 0) return -1; /* not supported */
- /* check if 1:1 scale: */
- if (scale_x == 1 && scale_y == 1) {
- /* color converter to use: */
- void (*dbline) (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su, unsigned char *sv,
- int src_x, int dx) = is_alpha? ccalpha [ccidx]: cc [ccidx];
- /* local variables: */
- unsigned char *sy1, *sy2, *su, *sv, *d1, *d2;
- register int j;
- /* get pointers: */
- sy1 = src_ptr + (src_x + src_y * src_pitch); /* luma offset */
- sy2 = sy1 + src_pitch;
- su = src_ptr + src_height * src_pitch + (src_x/2 + src_y/2 * src_pitch);
- sv = su + src_height * src_pitch / 4;
- d1 = dest_ptr + dest_x * bpp [ccidx] + dest_y * dest_pitch; /* RGB offset */
- d2 = d1 + dest_pitch;
- /* convert a top line: */
- if (src_y & 1) { /* chroma shift */
- /* this is a bit inefficient, but who cares??? */
- (* dbline) (d1, d1, dest_x, sy1, sy1, su, sv, src_x, src_dx);
- sy1 += src_pitch; sy2 += src_pitch;
- su += src_pitch/2; sv += src_pitch/2;
- d1 += dest_pitch; d2 += dest_pitch;
- dest_dy --;
- }
- /* convert aligned portion of the image: */
- for (j = 0; j < dest_dy/2; j ++) {
- /* convert two lines a time: */
- (* dbline) (d1, d2, dest_x, sy1, sy2, su, sv, src_x, src_dx);
- sy1 += src_pitch*2; sy2 += src_pitch*2;
- su += src_pitch/2; sv += src_pitch/2;
- d1 += dest_pitch*2; d2 += dest_pitch*2;
- }
- /* convert bottom line (if dest_dy is odd): */
- if (dest_dy & 1) {
- /* convert one line only: */
- (* dbline) (d1, d1, dest_x, sy1, sy1, su, sv, src_x, src_dx);
- }
- return 0;
- }
- /* check if 2:1 scale: */
- if (scale_x == 2 && scale_y == 2) {
- /* color converter & interpolator to use: */
- void (*cvt) (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *sy1, unsigned char *sy2, unsigned char *su, unsigned char *sv,
- int src_x, int dx) = is_alpha? dblineI420toXRGBalpha: dblineI420toXRGB;
- void (*x2) (unsigned char *d1, unsigned char *d2, int dest_x,
- unsigned char *s1, unsigned char *s2, int src_x, int dx) = ccx2 [ccidx];
- /* local variables: */
- unsigned char *sy1, *sy2, *su, *sv, *d1, *d2;
- register dy = src_dy;
- /* line buffers (we want them to be as compact as possible): */
- int ibuf = 0; /* circular buffer index */
- unsigned char * buf[3]; /* actual pointers */ /* Flawfinder: ignore */
- buf[0] = linebuf;
- buf[1] = linebuf + src_dx * BPP4;
- buf[2] = linebuf + 2 * src_dx * BPP4;
- /* get pointers: */
- sy1 = src_ptr + (src_x + src_y * src_pitch); /* luma offset */
- sy2 = sy1 + src_pitch;
- su = src_ptr + src_height * src_pitch + (src_x/2 + src_y/2 * src_pitch);
- sv = su + src_height * src_pitch / 4;
- d1 = dest_ptr + dest_x * bpp[ccidx] + dest_y * dest_pitch; /* RGB offset */
- d2 = d1 + dest_pitch;
- /* check if we have misaligned top line: */
- if (src_y & 1) {
- /* convert an odd first line: */
- (*cvt) (buf[ibuf], buf[ibuf], 0, sy1, sy1, su, sv, src_x, src_dx);
- sy1 += src_pitch; sy2 += src_pitch;
- su += src_pitch/2; sv += src_pitch/2;
- dy --;
- } else {
- /* otherwise, convert first two lines: */
- (*cvt) (buf[next[ibuf]], buf[next2[ibuf]], 0, sy1, sy2, su, sv, src_x, src_dx);
- sy1 += src_pitch*2; sy2 += src_pitch*2;
- su += src_pitch/2; sv += src_pitch/2;
- ibuf = next[ibuf]; /* skip first interpolation: */
- (*x2) (d1, d2, dest_x, buf[ibuf], buf[next[ibuf]], 0, src_dx);
- d1 += dest_pitch*2; d2 += dest_pitch*2;
- ibuf = next[ibuf];
- dy -= 2;
- }
- /*
- * Convert & interpolate the main portion of image:
- *
- * source: temp.store: destination:
- *
- * buf[ibuf] ------- /--> d1
- * x2 --> d2
- * s1 -- /-> buf[next[ibuf]] -< /--> d1'=d1+2*pitch
- * cvt x2 ---> d2'=d2+2*pitch
- * s2 --/ -> buf[next2[ibuf]] /
- */
- while (dy >= 2) {
- /* convert two lines into XRGB buffers: */
- (*cvt) (buf[next[ibuf]], buf[next2[ibuf]], 0, sy1, sy2, su, sv, src_x, src_dx);
- sy1 += src_pitch*2; sy2 += src_pitch*2;
- su += src_pitch/2; sv += src_pitch/2;
- /* interpolate first line: */
- (*x2) (d1, d2, dest_x, buf[ibuf], buf[next[ibuf]], 0, src_dx);
- d1 += dest_pitch*2; d2 += dest_pitch*2;
- ibuf = next[ibuf];
- /* interpolate second one: */
- (*x2) (d1, d2, dest_x, buf[ibuf], buf[next[ibuf]], 0, src_dx);
- d1 += dest_pitch*2; d2 += dest_pitch*2;
- ibuf = next[ibuf];
- dy -= 2;
- }
- /* check the # of remaining rows: */
- if (dy & 1) {
- /* convert the last odd line: */
- (*cvt) (buf[next[ibuf]], buf[next[ibuf]], 0, sy1, sy1, su, sv, src_x, src_dx);
- /* interpolate first line: */
- (*x2) (d1, d2, dest_x, buf[ibuf], buf[next[ibuf]], 0, src_dx);
- d1 += dest_pitch*2; d2 += dest_pitch*2;
- ibuf = next[ibuf];
- /* replicate the last line: */
- (*x2) (d1, d2, dest_x, buf[ibuf], buf[ibuf], 0, src_dx);
- } else {
- /* replicate the last line: */
- (*x2) (d1, d2, dest_x, buf[ibuf], buf[ibuf], 0, src_dx);
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- /*
- * I420->RGB* converters:
- */
- int I420toRGB32 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return I420toRGB (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, 0);
- }
- int I420toRGB24 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return I420toRGB (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, 1);
- }
- int I420toRGB565 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return I420toRGB (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, 2);
- }
- int I420toRGB555 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return I420toRGB (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, 3);
- }
- int I420toRGB8 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return I420toRGB (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, 4);
- }
- int I420toBGR32 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return I420toRGB (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, 5);
- }
- /*
- * "to I420" converters.
- *
- */
- int YV12toI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- /* scale factors: */
- int scale_x, scale_y;
- /* check arguments: */
- if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
- return -1;
- /* remove odd destination pixels: */
- if (!adjust_range (&dest_x, &dest_dx, &src_x, &src_dx, scale_x) ||
- !adjust_range (&dest_y, &dest_dy, &src_y, &src_dy, scale_y))
- return 0;
- /* check if we have matching chroma components: */
- if ((src_x & 1) || (src_y & 1))
- return -1; /* can't shift chromas */
- /* check if bottop-up images: */
- if (dest_pitch <= 0 || src_pitch <= 0)
- return -1; /* not supported */
- /*
- * if (!is_dest_alpha && !is_dest_beta && !is_dest_gamma && !is_dest_kappa)
- */
- {
- /* just move data in, no color adjustments: */
- unsigned char *s, *d;
- int src_uv_offs, dest_uv_offs;
- register int i;
- /* copy Y plane: */
- s = src_ptr + src_x + src_y * src_pitch;
- d = dest_ptr + dest_x + dest_y * dest_pitch;
- for (i = 0; i < dest_dy; i ++) {
- memcpy (d, s, dest_dx); /* Flawfinder: ignore */
- s += src_pitch;
- d += dest_pitch;
- }
- /* get Cr/Cb offsets: */
- src_uv_offs = src_height * src_pitch / 4;
- dest_uv_offs = dest_height * dest_pitch / 4;
- /* copy & flip Cr/Cb planes: */
- s = (src_ptr + src_height * src_pitch) + src_x/2 + src_y/2 * src_pitch/2;
- d = (dest_ptr + dest_height * dest_pitch) + dest_x/2 + dest_y/2 * dest_pitch/2;
- for (i = 0; i < dest_dy/2; i ++) {
- memcpy (d, s + src_uv_offs, dest_dx/2); /* Flawfinder: ignore */
- memcpy (d + dest_uv_offs, s, dest_dx/2); /* Flawfinder: ignore */
- s += src_pitch/2;
- d += dest_pitch/2;
- }
- }
- /*
- * else {
- * put all the color-dependent stuff here ...
- * }
- */
- return 0;
- }
- static void lineYVU9toI420 (unsigned char *d, unsigned char *s, int x, int dx)
- {
- register int i;
- /* first pixel: */
- if (x & 2) {
- d[0] = s[0];
- s += 1;
- d += 1;
- dx -= 2;
- }
- /* the main loop: */
- for (i = 0; i < dx/4; i ++) {
- d[i*2] = s[i];
- d[i*2+1] = s[i];
- }
- /* last pixel: */
- if (dx & 2)
- d[dx/2] = s[dx/4];
- }
- int YVU9toI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- /* scale factors: */
- int scale_x, scale_y;
- /* check arguments: */
- if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
- return -1;
- /* remove odd destination pixels: */
- if (!adjust_range (&dest_x, &dest_dx, &src_x, &src_dx, scale_x) ||
- !adjust_range (&dest_y, &dest_dy, &src_y, &src_dy, scale_y))
- return 0;
- /* check if we have matching chroma components: */
- if ((src_x & 1) || (src_y & 1))
- return -1; /* can't shift chromas */
- /* check if bottop-up images: */
- if (dest_pitch <= 0 || src_pitch <= 0)
- return -1; /* not supported */
- /*
- * if (!is_dest_alpha && !is_dest_beta && !is_dest_gamma && !is_dest_kappa)
- */
- {
- /* no color adjustments: */
- unsigned char *s, *d;
- int src_uv_offs, dest_uv_offs;
- register int j;
- /* copy Y plane: */
- s = src_ptr + src_x + src_y * src_pitch;
- d = dest_ptr + dest_x + dest_y * dest_pitch;
- for (j = 0; j < dest_dy; j ++) {
- memcpy (d, s, dest_dx); /* Flawfinder: ignore */
- s += src_pitch;
- d += dest_pitch;
- }
- /* get Cr/Cb offsets: */
- src_uv_offs = src_height * src_pitch / 16;
- dest_uv_offs = dest_height * dest_pitch / 4;
- /* get pointers: */
- s = (src_ptr + src_height * src_pitch) + src_x/4 + src_y/4 * src_pitch/4;
- d = (dest_ptr + dest_height * dest_pitch) + dest_x/2 + dest_y/2 * dest_pitch/2;
- /* top lines: */
- if (src_y & 2) {
- lineYVU9toI420 (d, s, src_x, dest_dx); /* Cr */
- lineYVU9toI420 (d + dest_uv_offs, s + src_uv_offs, src_x, dest_dx); /* Cb */
- s += src_pitch/4;
- d += dest_pitch/2;
- dest_dy -= 2;
- }
- /* the main loop (processes two lines a time): */
- for (j = 0; j < dest_dy/4; j ++) {
- lineYVU9toI420 (d, s, src_x, dest_dx); /* Cr */
- memcpy (d + dest_pitch/2, d, dest_dx/2); /* Flawfinder: ignore */
- lineYVU9toI420 (d + dest_uv_offs, s + src_uv_offs, src_x, dest_dx); /* Cb */
- memcpy (d + dest_pitch/2 + dest_uv_offs, d + dest_uv_offs, dest_dx/2); /* Flawfinder: ignore */
- s += src_pitch/4;
- d += dest_pitch;
- }
- /* bottom lines: */
- if (dest_dy & 2) {
- lineYVU9toI420 (d, s, src_x, dest_dx); /* Cr */
- lineYVU9toI420 (d + dest_uv_offs, s + src_uv_offs, src_x, dest_dx); /* Cb */
- }
- }
- /*
- * else {
- * put all the color-dependent stuff here ...
- * }
- */
- return 0;
- }
- int YUY2toI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- /* scale factors: */
- int scale_x, scale_y;
- /* check arguments: */
- if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
- return -1;
- /* remove odd destination pixels: */
- if (!adjust_range (&dest_x, &dest_dx, &src_x, &src_dx, scale_x) ||
- !adjust_range (&dest_y, &dest_dy, &src_y, &src_dy, scale_y))
- return 0;
- /* check if we have misaligned source: */
- if (src_x & 1)
- return -1; /* can't shift chromas */
- /* check if bottop-up images: */
- if (dest_pitch <= 0) return -1; /* not supported */
- if (src_pitch < 0) src_ptr -= (src_height-1) * src_pitch;
- /*
- * if (!is_dest_alpha && !is_dest_beta && !is_dest_gamma && !is_dest_kappa)
- */
- {
- /* just move data in, no color adjustments: */
- unsigned char *s1, *s2, *d1, *d2, *dv, *du;
- register int i, j;
- /* get pointers: */
- s1 = src_ptr + src_x * 2 + src_y * src_pitch; /* 2 bytes/pixel */
- s2 = s1 + src_pitch * 2;
- d1 = dest_ptr + dest_x + dest_y * dest_pitch; /* luma offsets */
- d2 = d1 + dest_pitch;
- du = dest_ptr + dest_height * dest_pitch + (dest_x/2 + dest_y/2 * dest_pitch/2);
- dv = du + dest_height * dest_pitch/4;
- /* the main loop (processes lines a time): */
- for (i = 0; i < dest_dy/2; i ++) {
- /* copy 2x2 pixels: */
- for (j = 0; j < dest_dx/2; j ++) {
- /* copy luma components: */
- d1[j*2] = s1[j*4];
- d1[j*2+1] = s1[j*4+2];
- d2[j*2] = s2[j*4];
- d2[j*2+1] = s2[j*4+2];
- /* average chromas: */
- du[j] = (s1[j*4+1] + s2[j*4+1]) / 2;
- dv[j] = (s1[j*4+3] + s2[j*4+3]) / 2;
- }
- s1 += src_pitch*2; s2 += src_pitch*2;
- d1 += dest_pitch*2; d2 += dest_pitch*2;
- du += dest_pitch/2; dv += dest_pitch/2;
- }
- }
- /*
- * else {
- * put all the color-dependent stuff here ...
- * }
- */
- return 0;
- }
- int UYVYtoI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- /* scale factors: */
- int scale_x, scale_y;
- /* check arguments: */
- if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
- return -1;
- /* remove odd destination pixels: */
- if (!adjust_range (&dest_x, &dest_dx, &src_x, &src_dx, scale_x) ||
- !adjust_range (&dest_y, &dest_dy, &src_y, &src_dy, scale_y))
- return 0;
- /* check if we have misaligned source: */
- if (src_x & 1)
- return -1; /* can't shift chromas */
- /* check if bottop-up images: */
- if (dest_pitch <= 0) return -1; /* not supported */
- if (src_pitch < 0) src_ptr -= (src_height-1) * src_pitch;
- /*
- * if (!is_dest_alpha && !is_dest_beta && !is_dest_gamma && !is_dest_kappa)
- */
- {
- /* just move data in, no color adjustments: */
- unsigned char *s1, *s2, *d1, *d2, *dv, *du;
- register int i, j;
- /* get pointers: */
- s1 = src_ptr + src_x * 2 + src_y * src_pitch; /* 2 bytes/pixel */
- s2 = s1 + src_pitch * 2;
- d1 = dest_ptr + dest_x + dest_y * dest_pitch; /* luma offsets */
- d2 = d1 + dest_pitch;
- du = dest_ptr + dest_height * dest_pitch + (dest_x/2 + dest_y/2 * dest_pitch/2);
- dv = du + dest_height * dest_pitch/4;
- /* the main loop (processes lines a time): */
- for (i = 0; i < dest_dy/2; i ++) {
- /* copy 2x2 pixels: */
- for (j = 0; j < dest_dx/2; j ++) {
- /* copy luma components: */
- d1[j*2] = s1[j*4+1];
- d1[j*2+1] = s1[j*4+3];
- d2[j*2] = s2[j*4+1];
- d2[j*2+1] = s2[j*4+3];
- /* average chromas: */
- du[j] = (s1[j*4] + s2[j*4]) / 2;
- dv[j] = (s1[j*4+2] + s2[j*4+2]) / 2;
- }
- s1 += src_pitch*2; s2 += src_pitch*2;
- d1 += dest_pitch*2; d2 += dest_pitch*2;
- du += dest_pitch/2; dv += dest_pitch/2;
- }
- }
- /*
- * else {
- * put all the color-dependent stuff here ...
- * }
- */
- return 0;
- }
- int RGB32toI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return -1; /* not implemented yet... */
- }
- int RGB24toI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- /* scale factors: */
- int scale_x, scale_y;
- /* check arguments: */
- if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
- return -1;
- /* align destination rectangle: */
- if (!adjust_range (&dest_x, &dest_dx, &src_x, &src_dx, scale_x) ||
- !adjust_range (&dest_y, &dest_dy, &src_y, &src_dy, scale_y))
- return 0;
- /* check if bottom-up bitmaps: */
- if (src_pitch < 0) src_ptr -= (src_height-1) * src_pitch;
- if (dest_pitch <= 0) return -1; /* not supported */
- /*
- * if (!is_dest_alpha && !is_dest_beta && !is_dest_gamma && !is_dest_kappa)
- */
- {
- /* just move data in, no color adjustments: */
- unsigned char *s1, *s2, *d1, *d2, *dv, *du;
- register int i, j;
- /* get pointers: */
- s1 = src_ptr + src_x * BPP3 + src_y * src_pitch; /* 3 bytes/pixel */
- s2 = s1 + src_pitch;
- d1 = dest_ptr + dest_x + dest_y * dest_pitch; /* luma offsets */
- d2 = d1 + dest_pitch;
- du = dest_ptr + dest_height * dest_pitch + (dest_x/2 + dest_y/2 * dest_pitch/2); /* chroma offset */
- dv = du + dest_height * dest_pitch/4;
- /* the main loop (processes 2 lines a time): */
- for (i = 0; i < dest_dy/2; i ++) {
- /* convert 2x2 block: */
- for (j = 0; j < dest_dx/2; j ++) {
- int r4, b4, y4;
- /* process lumas: */
- {
- register unsigned int r, b, y;
- r4 = (r = s1[2]); /* BGR */
- b4 = (b = s1[0]);
- y4 = (y = yrtab [r] + ygtab [s1[1]] + ybtab [b]);
- d1[0] = yytab [y];
- r4 += (r = s1[5]); /* bgrBGR */
- b4 += (b = s1[3]);
- y4 += (y = yrtab [r] + ygtab [s1[4]] + ybtab [b]);
- d1[1] = yytab [y];
- r4 += (r = s2[2]); /* BGR */
- b4 += (b = s2[0]);
- y4 += (y = yrtab [r] + ygtab [s2[1]] + ybtab [b]);
- d2[0] = yytab [y];
- r4 += (r = s2[5]); /* bgrBGR */
- b4 += (b = s2[3]);
- y4 += (y = yrtab [r] + ygtab [s2[4]] + ybtab [b]);
- d2[1] = yytab [y];
- }
- /* average chromas: */
- dv[0] = vrytab [VMIN+(r4-y4)/4];
- du[0] = ubytab [UMIN+(b4-y4)/4];
- /* go to the next block: */
- s1 += 2 * BPP3; s2 += 2 * BPP3;
- d1 += 2; d2 += 2;
- du += 1; dv += 1;
- }
- /* switch to the next two lines: */
- s1 += src_pitch * 2 - dest_dx * BPP3;
- s2 += src_pitch * 2 - dest_dx * BPP3;
- d1 += dest_pitch * 2 - dest_dx;
- d2 += dest_pitch * 2 - dest_dx;
- du += (dest_pitch - dest_dx)/2;
- dv += (dest_pitch - dest_dx)/2;
- }
- }
- /*
- * else {
- * put all the color-dependent stuff here ...
- * }
- */
- return 0;
- }
- int RGB565toI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return -1; /* not implemented yet... */
- }
- int RGB555toI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return -1; /* not implemented yet... */
- }
- int RGB8toI420 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- return -1; /* not implemented yet... */
- }
- /*
- * "RGBx to BGR32" converters.
- *
- */
- int RGB32toBGR32 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- /* scale factors: */
- int scale_x, scale_y;
- /* check arguments: */
- if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
- return -1;
- /* check if bottom-up bitmaps: */
- if (src_pitch < 0) src_ptr -= (src_height-1) * src_pitch;
- if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
- /* check if 1:1 scale: */
- if (scale_x == 1 && scale_y == 1) {
- /* local variables: */
- unsigned char *s, *d;
- register int i;
- /* get pointers: */
- s = src_ptr + src_x * BPP4 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
- /* convert image: */
- for (i = 0; i < dest_dy; i ++) {
- /* convert a line: */
- register int ddx = dest_dx;
- while (ddx) {
- register unsigned int a;
- a = *(unsigned int *)s; /* 0x00RRGGBB */
- *(unsigned int *)d =
- ((a & 0x000000ff) << 16) |
- ((a & 0x0000ff00) << 0) |
- ((a & 0x00ff0000) >> 16);
- s += BPP4;
- d += BPP4;
- ddx --;
- }
- s += src_pitch - dest_dx * BPP4;
- d += dest_pitch - dest_dx * BPP4;
- }
- return 0;
- }
- /* check if 2:1 scale: */
- if (scale_x == 2 && scale_y == 2) {
- /* local variables: */
- unsigned char *s, *d;
- register int i;
- /* get pointers: */
- s = src_ptr + src_x * BPP4 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
- /* convert & stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* convert & stretch a line: */
- register int sdx = src_dx;
- while (sdx) {
- register unsigned int a, c;
- a = *(unsigned int *)s;
- c = ((a & 0x000000ff) << 16) |
- ((a & 0x0000ff00) << 0) |
- ((a & 0x00ff0000) >> 16);
- *(unsigned int *)d = c;
- *(unsigned int *)(d+BPP4) = c;
- d += 2*BPP4; s += BPP4;
- sdx --;
- }
- s -= src_dx * BPP4;
- d -= src_dx * 2*BPP4;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP4); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- int RGB24toBGR32 (unsigned char *dest_ptr, int dest_width, int dest_height,
- int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
- unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
- int src_x, int src_y, int src_dx, int src_dy)
- {
- /* scale factors: */
- int scale_x, scale_y;
- /* check arguments: */
- if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
- dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
- src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
- return -1;
- /* check if bottom-up bitmaps: */
- if (src_pitch < 0) src_ptr -= (src_height-1) * src_pitch;
- if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
- /* check if 1:1 scale: */
- if (scale_x == 1 && scale_y == 1) {
- /* local variables: */
- unsigned char *s, *d;
- register int i;
- /* get pointers: */