colorcvt.c
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:289k
- s = src_ptr + src_x * BPP3 + 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) {
- /* RGB -> 0BGR: */
- *(unsigned int *)d = (unsigned int)
- (s[0] << 16) | (s[1] << 8) | s[2];
- d += BPP4; s += BPP3;
- ddx --;
- }
- s += src_pitch - dest_dx * BPP3;
- 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 * BPP3 + 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) {
- /* RGB -> 0BGR: */
- register unsigned int a;
- a = (unsigned int)
- (s[0] << 16) | (s[1] << 8) | s[2];
- *(unsigned int *)d = a;
- *(unsigned int *)(d+BPP4) = a;
- d += 2*BPP4; s += BPP3;
- sdx --;
- }
- s -= src_dx * BPP3;
- 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 RGB565toBGR32 (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 * BPP2 + 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) {
- /* rrrr,rggg,gggb,bbbb -> 0BGR: */
- register unsigned short a;
- a = *(unsigned short *)s;
- *(unsigned int *)d = (unsigned int)
- ((a & 0x001F) << 19)|
- ((a & 0x07E0) << 5) |
- ((a & 0xF800) >> 8);
- d += BPP4; s += BPP2;
- ddx --;
- }
- s += src_pitch - dest_dx * BPP2;
- 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 * BPP2 + 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 short a;
- register unsigned int c;
- a = *(unsigned short *)s;
- c = ((a & 0x001F) << 19)|
- ((a & 0x07E0) << 5) |
- ((a & 0xF800) >> 8);
- *(unsigned int *)d = c;
- *(unsigned int *)(d+BPP4) = c;
- d += 2*BPP4; s += BPP2;
- sdx --;
- }
- s -= src_dx * BPP2;
- 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 RGB555toBGR32 (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 * BPP2 + 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) {
- /* 0rrrr,rgg,gggb,bbbb -> 0BGR: */
- register unsigned short a;
- a = *(unsigned short *)s;
- *(unsigned int *)d = (unsigned int)
- ((a & 0x001F) << 19)|
- ((a & 0x03E0) << 6) |
- ((a & 0x7C00) >> 7);
- d += BPP4; s += BPP2;
- ddx --;
- }
- s += src_pitch - dest_dx * BPP2;
- 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 * BPP2 + 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 short a;
- register unsigned int c;
- a = *(unsigned short *)s;
- c = ((a & 0x001F) << 19)|
- ((a & 0x03E0) << 6) |
- ((a & 0x7C00) >> 7);
- *(unsigned int *)d = c;
- *(unsigned int *)(d+BPP4) = c;
- d += 2*BPP4; s += BPP2;
- sdx --;
- }
- s -= src_dx * BPP2;
- 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 RGB8toBGR32 (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 RGBy" converters.
- *
- ********************************/
- /*
- * RGB32toRGB32() converter:
- * 1:1, 2:1
- */
- int RGB32toRGB32 (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;
- /* copy image: */
- for (i = 0; i < dest_dy; i ++) {
- memcpy (d, s, dest_dx * BPP4); /* copy dest_dx pixels */ /* Flawfinder: ignore */
- s += src_pitch;
- d += dest_pitch;
- }
- 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;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sdx = src_dx;
- while (sdx) {
- register unsigned int a;
- a = *(unsigned int *)s;
- *(unsigned int *)d = a;
- *(unsigned int *)(d+BPP4) = a;
- 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 RGB32toRGB24 (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 RGB32toRGB565 (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 RGB32toRGB555 (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... */
- }
- /*
- * No dithering yet.
- */
- int RGB32toRGB8 (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 * BPP1 + dest_y * dest_pitch;
- /* copy rows: */
- 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; /* BGR0 */
- *d = pmap[
- ((a & 0x000000f0) >> 4) |
- ((a & 0x0000f000) >> 8) |
- ((a & 0x00f00000) >> 12)];
- d += BPP1; s += BPP4;
- ddx --;
- }
- /* bump pointers to the next row: */
- s += src_pitch - dest_dx * BPP4;
- d += dest_pitch - dest_dx * BPP1;
- }
- 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 * BPP1 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sdx = src_dx;
- while (sdx) {
- register unsigned int a;
- register unsigned char c;
- a = *(unsigned int *)s; /* BRG0 */
- c = pmap[
- ((a & 0x000000f0) >> 4) |
- ((a & 0x0000f000) >> 8) |
- ((a & 0x00f00000) >> 12)];
- *(d+0) = c;
- *(d+BPP1) = c;
- d += 2*BPP1; s += BPP4;
- sdx --;
- }
- s -= src_dx * BPP4;
- d -= src_dx * 2*BPP1;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- /*
- * RGB24toRGB32() converter:
- * 1:1, 2:1
- */
- int RGB24toRGB32 (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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
- /* copy rows: */
- for (i = 0; i < dest_dy; i ++) {
- register int sx = src_x, ddx = dest_dx;
- /* process misaligned pixels first: */
- while ((sx & 3) && ddx) {
- /* BGR -> BGR0: */
- *(unsigned int *)d = (unsigned int)s[0] | (s[1] << 8) | (s[2] << 16);
- d += BPP4; s += BPP3;
- sx ++; ddx --;
- }
- /* main loop: process 4 pixels a time: */
- while (ddx >= 4) {
- register unsigned int a, b;
- a = *(unsigned int *)s; /* BGR.B */
- b = *(unsigned int *)(s+4); /* GR.BG */
- *(unsigned int *)d = a & 0x00FFFFFF;
- *(unsigned int *)(d+4) = ((a >> 24) | (b << 8)) & 0x00FFFFFF;
- a = *(unsigned int *)(s+8); /* R.BGR */
- *(unsigned int *)(d+8) = ((b >> 16) | (a << 16)) & 0x00FFFFFF;
- *(unsigned int *)(d+12) = a >> 8;
- d += BPP4*4; s += BPP3*4;
- ddx -= 4;
- }
- /* process the remaining 1..3 pixels: */
- while (ddx) {
- /* RGB -> RGB0: */
- *(unsigned int *)d = (unsigned int)s[0] | (s[1] << 8) | (s[2] << 16);
- d += BPP4; s += BPP3;
- ddx --;
- }
- /* bump pointers to the next row: */
- s += src_pitch - dest_dx * BPP3;
- 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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sx = src_x, sdx = src_dx;
- /* misaligned pixels first: */
- while ((sx & 3) && sdx) {
- /* BGR -> BGR0: */
- register unsigned int a;
- a = (unsigned int)s[0] | (s[1] << 8) | (s[2] << 16);
- *(unsigned int *)d = a;
- *(unsigned int *)(d+BPP4) = a;
- d += 2*BPP4; s += BPP3;
- sx ++; sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 4) {
- register unsigned int a, b, c;
- a = *(unsigned int *)s; /* bgrB */
- b = *(unsigned int *)(s+4); /* GRbg */
- c = a & 0x00FFFFFF;
- *(unsigned int *)(d) = c;
- *(unsigned int *)(d+BPP4) = c;
- c = ((a >> 24) | (b << 8)) & 0x00FFFFFF;
- *(unsigned int *)(d+2*BPP4) = c;
- *(unsigned int *)(d+3*BPP4) = c;
- a = *(unsigned int *)(s+8); /* rBGR */
- c = ((b >> 16) | (a << 16)) & 0x00FFFFFF;
- *(unsigned int *)(d+4*BPP4) = c;
- *(unsigned int *)(d+5*BPP4) = c;
- c = a >> 8;
- *(unsigned int *)(d+6*BPP4) = c;
- *(unsigned int *)(d+7*BPP4) = c;
- d += 4*2*BPP4; s += 4*BPP3;
- sdx -= 4;
- }
- /* the remaining 1..3 pixels: */
- while (sdx) {
- /* BGR -> BGR0: */
- register unsigned int a;
- a = (unsigned int)s[0] | (s[1] << 8) | (s[2] << 16);
- *(unsigned int *)d = a;
- *(unsigned int *)(d+BPP4) = a;
- d += 2*BPP4; s += BPP3;
- sdx --;
- }
- s -= src_dx * BPP3;
- 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;
- }
- /*
- * RGB24toRGB24() converter:
- * 1:1, 2:1
- */
- int RGB24toRGB24 (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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP3 + dest_y * dest_pitch;
- /* copy image: */
- for (i = 0; i < dest_dy; i ++) {
- memcpy (d, s, dest_dx * BPP3); /* copy dest_dx pixels */ /* Flawfinder: ignore */
- s += src_pitch;
- d += dest_pitch;
- }
- 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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP3 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sx = src_x, sdx = src_dx;
- /* misaligned pixels first: */
- while ((sx & 3) && sdx) {
- register unsigned char a;
- a = *s; *d = a; *(d+BPP3) = a;
- a = *(s+1); *(d+1) = a; *(d+1+BPP3) = a;
- a = *(s+2); *(d+2) = a; *(d+2+BPP3) = a;
- d += 2*BPP3; s += BPP3;
- sx ++; sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 4) {
- register unsigned int a, b;
- a = *(unsigned int *)s; /* bgrB */
- b = *(unsigned int *)(s+4); /* GRbg */
- *(unsigned int *)(d) = (a & 0x00FFFFFF) | (a << 24); /* bgrb */
- *(unsigned int *)(d+4) = (a >> 8) | (b << 24); /* grBG */
- *(unsigned int *)(d+2*4) = ((b & 0xFF00) >> 8) | /* RBGR */
- ((a & 0xFF000000) >> 16) | (b << 16);
- a = *(unsigned int *)(s+8); /* rBGR */
- *(unsigned int *)(d+3*4) = (b >> 16) | /* bgrb */
- ((a & 0xFF) << 16) | ((b & 0xFF0000) << 8);
- *(unsigned int *)(d+4*4) = (b >> 24) | (a << 8); /* grBG */
- *(unsigned int *)(d+5*4) = (a >> 24) | (a & 0xFFFFFF00);/* RBGR */
- d += 4*2*BPP3; s += 4*BPP3;
- sdx -= 4;
- }
- /* the remaining 1..3 pixels: */
- while (sdx) {
- register unsigned char a;
- a = *s; *d = a; *(d+BPP3) = a;
- a = *(s+1); *(d+1) = a; *(d+1+BPP3) = a;
- a = *(s+2); *(d+2) = a; *(d+2+BPP3) = a;
- d += 2*BPP3; s += BPP3;
- sdx --;
- }
- s -= src_dx * BPP3;
- d -= src_dx * 2*BPP3;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP3); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- /*
- * RGB24toRGB565() converter:
- * 1:1, 2:1
- */
- int RGB24toRGB565 (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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* copy rows: */
- for (i = 0; i < dest_dy; i ++) {
- register int sx = src_x, ddx = dest_dx;
- /* process misaligned pixels first: */
- while ((sx & 3) && ddx) {
- /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.rrrrrggg: */
- *(unsigned short *)d =
- (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
- d += BPP2; s += BPP3;
- sx ++; ddx --;
- }
- /* main loop: process 4 pixels a time: */
- while (ddx >= 4) {
- register unsigned int a, b;
- a = *(unsigned int *)s; /* BGR.B */
- b = *(unsigned int *)(s+4); /* GR.BG */
- *(unsigned int *)d =
- ((a & 0xF8) >> 3) | ((a & 0xFC00) >> 5) | ((a & 0xF80000) >> 8) |
- ((a & 0xF8000000) >> 11) | ((b & 0xFC) << 19) | ((b & 0xF800) << 16);
- a = *(unsigned int *)(s+8); /* R.BGR */
- *(unsigned int *)(d+4) =
- ((b & 0xF80000) >> 19) | ((b & 0xFC000000) >> 21) | ((a & 0xF8) << 8) |
- ((a & 0xF800) << 5) | ((a & 0xFC0000) << 3) | (a & 0xF8000000);
- d += BPP2*4; s += BPP3*4; ddx -= 4;
- }
- /* process the remaining 1..3 pixels: */
- while (ddx) {
- /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.rrrrrggg: */
- *(unsigned short *)d =
- (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
- d += BPP2; s += BPP3;
- ddx --;
- }
- /* bump pointers to the next row: */
- s += src_pitch - dest_dx * BPP3;
- d += dest_pitch - dest_dx * BPP2;
- }
- 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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sx = src_x, sdx = src_dx;
- /* misaligned pixels first: */
- while ((sx & 3) && sdx) {
- /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
- register unsigned short a;
- a = (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
- *(unsigned short *)d = a;
- *(unsigned short *)(d+BPP2) = a;
- d += 2*BPP2; s += BPP3;
- sx ++; sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 4) {
- register unsigned int a, b, c;
- a = *(unsigned int *)s; /* bgrB */
- b = *(unsigned int *)(s+4); /* GRbg */
- c = ((a & 0xF8) >> 3) | ((a & 0xFC00) >> 5) | ((a & 0xF80000) >> 8);
- *(unsigned int *)d = c | (c << 16);
- c = ((a & 0xF8000000) >> 11) | ((b & 0xFC) << 19) | ((b & 0xF800) << 16);
- *(unsigned int *)(d+2*BPP2) = c | (c >> 16);
- a = *(unsigned int *)(s+8); /* rBGR */
- c = ((b & 0xF80000) >> 19) | ((b & 0xFC000000) >> 21) | ((a & 0xF8) << 8);
- *(unsigned int *)(d+2*2*BPP2) = c | (c << 16);
- c = ((a & 0xF800) << 5) | ((a & 0xFC0000) << 3) | (a & 0xF8000000);
- *(unsigned int *)(d+3*2*BPP2) = c | (c >> 16);
- d += 2*4*BPP2; s += 4*BPP3;
- sdx -= 4;
- }
- /* the remaining pixels: */
- while (sdx) {
- /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
- register unsigned short a;
- a = (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
- *(unsigned short *)d = a;
- *(unsigned short *)(d+BPP2) = a;
- d += 2*BPP2; s += BPP3;
- sdx --;
- }
- s -= src_dx * BPP3;
- d -= src_dx * 2*BPP2;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- /*
- * RGB24toRGB555() converter:
- * 1:1, 2:1
- */
- int RGB24toRGB555 (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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* copy rows: */
- for (i = 0; i < dest_dy; i ++) {
- register int sx = src_x, ddx = dest_dx;
- /* process misaligned pixels first: */
- while ((sx & 3) && ddx) {
- /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
- *(unsigned short *)d =
- (s[0] >> 3) | ((s[1] & 0xF8) << 2) | ((s[2] & 0xF8) << 7);
- d += BPP2; s += BPP3;
- sx ++; ddx --;
- }
- /* main loop: process 4 pixels a time: */
- while (ddx >= 4) {
- register unsigned int a, b;
- a = *(unsigned int *)s; /* bgrB */
- b = *(unsigned int *)(s+4); /* GRbg */
- *(unsigned int *)d =
- ((a & 0xF8) >> 3) | ((a & 0xF800) >> 6) | ((a & 0xF80000) >> 9) |
- ((a & 0xF8000000) >> 11) | ((b & 0xF8) << 18) | ((b & 0xF800) << 15);
- a = *(unsigned int *)(s+8); /* rBGR */
- *(unsigned int *)(d+4) =
- ((b & 0xF80000) >> 19) | ((b & 0xF8000000) >> 22) | ((a & 0xF8) << 7) |
- ((a & 0xF800) << 5) | ((a & 0xF80000) << 2) | ((a & 0xF8000000) >> 1);
- d += BPP2*4; s += BPP3*4; ddx -= 4;
- }
- /* process the remaining 1..3 pixels: */
- while (ddx) {
- /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.rrrrrggg: */
- *(unsigned short *)d =
- (s[0] >> 3) | ((s[1] & 0xF8) << 2) | ((s[2] & 0xF8) << 7);
- d += BPP2; s += BPP3;
- ddx --;
- }
- /* bump pointers to the next row: */
- s += src_pitch - dest_dx * BPP3;
- d += dest_pitch - dest_dx * BPP2;
- }
- 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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sx = src_x, sdx = src_dx;
- /* misaligned pixels first: */
- while ((sx & 3) && sdx) {
- /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
- register unsigned short a;
- a = (s[0] >> 3) | ((s[1] & 0xF8) << 2) | ((s[2] & 0xF8) << 7);
- *(unsigned short *)d = a;
- *(unsigned short *)(d+BPP2) = a;
- d += 2*BPP2; s += BPP3;
- sx ++; sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 4) {
- register unsigned int a, b, c;
- a = *(unsigned int *)s; /* bgrB */
- b = *(unsigned int *)(s+4); /* GRbg */
- c = ((a & 0xF8) >> 3) | ((a & 0xF800) >> 6) | ((a & 0xF80000) >> 9);
- *(unsigned int *)d = c | (c << 16);
- c = ((a & 0xF8000000) >> 11) | ((b & 0xF8) << 18) | ((b & 0xF800) << 15);
- *(unsigned int *)(d+2*BPP2) = c | (c >> 16);
- a = *(unsigned int *)(s+8); /* rBGR */
- c = ((b & 0xF80000) >> 19) | ((b & 0xF8000000) >> 22) | ((a & 0xF8) << 7);
- *(unsigned int *)(d+2*2*BPP2) = c | (c << 16);
- c = ((a & 0xF800) << 5) | ((a & 0xF80000) << 2) | ((a & 0xF8000000) >> 1);
- *(unsigned int *)(d+3*2*BPP2) = c | (c >> 16);
- d += 2*4*BPP2; s += 4*BPP3;
- sdx -= 4;
- }
- /* the remaining pixels: */
- while (sdx) {
- /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
- register unsigned short a;
- a = (s[0] >> 3) | ((s[1] & 0xF8) << 2) | ((s[2] & 0xF8) << 7);
- *(unsigned short *)d = a;
- *(unsigned short *)(d+BPP2) = a;
- d += 2*BPP2; s += BPP3;
- sdx --;
- }
- s -= src_dx * BPP3;
- d -= src_dx * 2*BPP2;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- /*
- * No dithering yet.
- */
- int RGB24toRGB8 (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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
- /* copy rows: */
- for (i = 0; i < dest_dy; i ++) {
- register int sx = src_x, ddx = dest_dx;
- /* process misaligned pixels first: */
- while ((sx & 3) && ddx) {
- /* BGR -> palette index: */
- *d = pmap[(unsigned int)
- ((s[0] & 0xf0) >> 4) |
- ((s[1] & 0xf0) ) |
- ((s[2] & 0xf0) << 4)];
- d += BPP1; s += BPP3;
- sx ++; ddx --;
- }
- /* main loop: process 4 pixels a time: */
- while (ddx >= 4) {
- register unsigned int a, b;
- a = *(unsigned int *)s; /* BGR.B */
- b = *(unsigned int *)(s+4); /* GR.BG */
- *d = pmap[(unsigned int)
- ((a & 0x000000f0) >> 4) |
- ((a & 0x0000f000) >> 8) |
- ((a & 0x00f00000) >> 12)];
- *(d+BPP1) = pmap[(unsigned int)
- ((a & 0xf0000000) >> 28) |
- ((b & 0x000000f0) ) |
- ((b & 0x0000f000) >> 4)];
- a = *(unsigned int *)(s+8); /* R.BGR */
- *(d+2*BPP1) = pmap[(unsigned int)
- ((b & 0x00f00000) >> 20) |
- ((b & 0xf0000000) >> 24) |
- ((a & 0x000000f0) << 4)];
- *(d+3*BPP1) = pmap[(unsigned int)
- ((a & 0x0000f000) >> 12) |
- ((a & 0x00f00000) >> 16) |
- ((a & 0xf0000000) >> 20)];
- d += BPP1*4; s += BPP3*4;
- ddx -= 4;
- }
- /* process the remaining 1..3 pixels: */
- while (ddx) {
- /* RGB -> palette index: */
- *d = pmap[(unsigned int)
- ((s[0] & 0xf0) >> 4) |
- ((s[1] & 0xf0) ) |
- ((s[2] & 0xf0) << 4)];
- d += BPP1; s += BPP3;
- ddx --;
- }
- /* bump pointers to the next row: */
- s += src_pitch - dest_dx * BPP3;
- d += dest_pitch - dest_dx * BPP1;
- }
- 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 * BPP3 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sx = src_x, sdx = src_dx;
- /* misaligned pixels first: */
- while ((sx & 3) && sdx) {
- /* BGR -> palette index: */
- register unsigned char c;
- c = pmap[(unsigned int)
- ((s[0] & 0xf0) >> 4) |
- ((s[1] & 0xf0) ) |
- ((s[2] & 0xf0) << 4)];
- *d = c;
- *(d+BPP1) = c;
- d += 2*BPP1; s += BPP3;
- sx ++; sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 4) {
- register unsigned int a, b;
- register unsigned char c;
- a = *(unsigned int *)s; /* bgrB */
- b = *(unsigned int *)(s+4); /* GRbg */
- c = pmap[(unsigned int)
- ((a & 0x000000f0) >> 4) |
- ((a & 0x0000f000) >> 8) |
- ((a & 0x00f00000) >> 12)];
- *(d+0) = c;
- *(d+BPP1) = c;
- c = pmap[(unsigned int)
- ((a & 0xf0000000) >> 28) |
- ((b & 0x000000f0) ) |
- ((b & 0x0000f000) >> 4)];
- *(d+2*BPP1) = c;
- *(d+3*BPP1) = c;
- a = *(unsigned int *)(s+8); /* rBGR */
- c = pmap[(unsigned int)
- ((b & 0x00f00000) >> 20) |
- ((b & 0xf0000000) >> 24) |
- ((a & 0x000000f0) << 4)];
- *(d+4*BPP1) = c;
- *(d+5*BPP1) = c;
- c = pmap[(unsigned int)
- ((a & 0x0000f000) >> 12) |
- ((a & 0x00f00000) >> 16) |
- ((a & 0xf0000000) >> 20)];
- *(d+6*BPP1) = c;
- *(d+7*BPP1) = c;
- d += 4*2*BPP1; s += 4*BPP3;
- sdx -= 4;
- }
- /* the remaining 1..3 pixels: */
- while (sdx) {
- /* BGR -> palette index: */
- register unsigned char c;
- c = pmap[(unsigned int)
- ((s[0] & 0xf0) >> 4) |
- ((s[1] & 0xf0) ) |
- ((s[2] & 0xf0) << 4)];
- *d = c;
- *(d+BPP1) = c;
- d += 2*BPP1; s += BPP3;
- sdx --;
- }
- s -= src_dx * BPP3;
- d -= src_dx * 2*BPP1;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- int RGB565toRGB32 (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 RGB565toRGB24 (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... */
- }
- /*
- * RGB565toRGB565() converter:
- * 1:1, 2:1
- */
- int RGB565toRGB565 (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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* copy image: */
- for (i = 0; i < dest_dy; i ++) {
- memcpy (d, s, dest_dx * BPP2); /* copy dest_dx pixels */ /* Flawfinder: ignore */
- s += src_pitch;
- d += dest_pitch;
- }
- 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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sdx = src_dx;
- /* misaligned pixel first: */
- if (src_x & 1) {
- register unsigned short a;
- a = *(unsigned short *)s;
- *(unsigned short *)d = a;
- *(unsigned short *)(d+BPP2) = a;
- d += 2*BPP2; s += BPP2;
- sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 2) {
- register unsigned int a;
- a = *(unsigned int *)s;
- *(unsigned int *)d = (a & 0xFFFF) | (a << 16);
- *(unsigned int *)(d+2*BPP2) = (a & 0xFFFF0000) | (a >> 16);
- d += 2*2*BPP2; s += 2*BPP2;
- sdx -= 2;
- }
- /* the remaining odd pixel: */
- if (sdx) {
- register unsigned short a;
- a = *(unsigned short *)s;
- *(unsigned short *)d = a;
- *(unsigned short *)(d+BPP2) = a;
- d += 2*BPP2; s += BPP2;
- }
- s -= src_dx * BPP2;
- d -= src_dx * 2*BPP2;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- int RGB565toRGB555 (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... */
- }
- /*
- * No dithering yet.
- */
- int RGB565toRGB8 (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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
- /* copy rows: */
- for (i = 0; i < dest_dy; i ++) {
- register int ddx = dest_dx;
- /* first odd pixel: */
- if (src_x & 1) {
- /* gggbbbbb.rrrrrggg -> palette index: */
- unsigned short a = *(unsigned short *)s;
- *d = pmap[
- ((a & 0x001E) >> 1) |
- ((a & 0x0780) >> 3) |
- ((a & 0xf000) >> 4)];
- d += BPP1; s += BPP2;
- ddx --;
- }
- /* main loop: process 2 pixels a time: */
- while (ddx >= 2) {
- /* gggbbbbb.rrrrrggg.gggbbbbb.rrrrrggg -> 2 palette indices */
- register unsigned int a;
- a = *(unsigned int *)s;
- *d = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x0780) >> 3) |
- ((a & 0xf000) >> 4)];
- *(d+BPP1) = pmap[
- ((a & 0x001e0000) >> 17) |
- ((a & 0x07800000) >> 19) |
- ((a & 0xf0000000) >> 20)];
- d += BPP1*2; s += BPP2*2;
- ddx -= 2;
- }
- /* the remaining odd pixel: */
- if (ddx) {
- /* gggbbbbb.rrrrrggg -> palette index: */
- unsigned short a = *(unsigned short *)s;
- *d = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x0780) >> 3) |
- ((a & 0xf000) >> 4)];
- d += BPP1; s += BPP2;
- ddx --;
- }
- /* bump pointers to the next row: */
- s += src_pitch - dest_dx * BPP2;
- d += dest_pitch - dest_dx * BPP1;
- }
- 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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sdx = src_dx;
- /* first odd pixel: */
- if (src_x & 1) {
- /* gggbbbbb.rrrrrggg -> palette index: */
- unsigned short a = *(unsigned short *)s;
- register unsigned char c;
- c = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x0780) >> 3) |
- ((a & 0xf000) >> 4)];
- *d = c;
- *(d+BPP1) = c;
- d += 2*BPP1; s += BPP2;
- sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 2) {
- /* gggbbbbb.rrrrrggg.gggbbbbb.rrrrrggg -> 2 palette indices */
- register unsigned int a;
- register unsigned char c;
- a = *(unsigned int *)s;
- c = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x0780) >> 3) |
- ((a & 0xf000) >> 4)];
- *(d+0) = c;
- *(d+BPP1) = c;
- c = pmap[
- ((a & 0x001e0000) >> 17) |
- ((a & 0x07800000) >> 19) |
- ((a & 0xf0000000) >> 20)];
- *(d+2*BPP1) = c;
- *(d+3*BPP1) = c;
- d += 2*2*BPP1; s += 2*BPP2;
- sdx -= 2;
- }
- /* the remaining odd pixel: */
- if (sdx) {
- /* gggbbbbb.rrrrrggg -> palette index: */
- unsigned short a = *(unsigned short *)s;
- register unsigned char c;
- c = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x0780) >> 3) |
- ((a & 0xf000) >> 4)];
- *d = c;
- *(d+BPP1) = c;
- d += 2*BPP1; s += BPP2;
- }
- s -= src_dx * BPP2;
- d -= src_dx * 2*BPP1;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- int RGB555toRGB32 (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 RGB555toRGB24 (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... */
- }
- /*
- * RGB555toRGB565() converter:
- * 1:1, 2:1
- */
- int RGB555toRGB565 (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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* copy rows: */
- for (i = 0; i < dest_dy; i ++) {
- register int sx = src_x, ddx = dest_dx;
- /* process misaligned pixels first: */
- while ((sx & 3) && ddx) {
- /* gggbbbbb.0rrrrrgg -> gg0bbbbb.rrrrrggg : */
- register unsigned short c = *(unsigned short *)s;
- *(unsigned short *)d = (c & 0x1F) | ((c & 0x7FE0) << 1);
- d += BPP2; s += BPP2;
- sx ++; ddx --;
- }
- /* main loop: process 4 pixels a time: */
- while (ddx >= 4) {
- register unsigned int a, b;
- a = *(unsigned int *)s; /* gggbbbbb.0rrrrrgg.gggbbbbb.0rrrrrgg */
- b = *(unsigned int *)(s+4);
- *(unsigned int *)d = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
- *(unsigned int *)(d+4) = (b & 0x1F001F) | ((b & 0x7FE07FE0) << 1);
- d += BPP2*4; s += BPP2*4; ddx -= 4;
- }
- /* process the remaining 1..3 pixels: */
- while (ddx) {
- /* gggbbbbb.0rrrrrgg -> gg0bbbbb.rrrrrggg : */
- register unsigned short c = *(unsigned short *)s;
- *(unsigned short *)d = (c & 0x1F) | ((c & 0x7FE0) << 1);
- d += BPP2; s += BPP2;
- ddx --;
- }
- /* bump pointers to the next row: */
- s += src_pitch - dest_dx * BPP2;
- d += dest_pitch - dest_dx * BPP2;
- }
- 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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sx = src_x, sdx = src_dx;
- /* misaligned pixels first: */
- while ((sx & 3) && sdx) {
- /* gggbbbbb.0rrrrrgg -> gg0bbbbb.rrrrrggg : */
- register unsigned short a, b;
- a = *(unsigned short *)s;
- b = (a & 0x1F) | ((a & 0x7FE0) << 1);
- *(unsigned short *)d = b;
- *(unsigned short *)(d+BPP2) = b;
- d += 2*BPP2; s += BPP2;
- sx ++; sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 4) {
- register unsigned int a, b;
- a = *(unsigned int *)s; /* gggbbbbb.0rrrrrgg.gggbbbbb.0rrrrrgg */
- b = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
- *(unsigned int *)d = (b & 0xFFFF) | (b << 16);
- *(unsigned int *)(d+2*BPP2) = (b & 0xFFFF0000) | (b >> 16);
- a = *(unsigned int *)(s+2*BPP2);
- b = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
- *(unsigned int *)(d+2*2*BPP2) = (b & 0xFFFF) | (b << 16);
- *(unsigned int *)(d+3*2*BPP2) = (b & 0xFFFF0000) | (b >> 16);
- d += 2*4*BPP2; s += 4*BPP2;
- sdx -= 4;
- }
- /* the remaining pixels: */
- while (sdx) {
- /* gggbbbbb.0rrrrrgg -> gg0bbbbb.rrrrrggg : */
- register unsigned short a, b;
- a = *(unsigned short *)s;
- b = (a & 0x1F) | ((a & 0x7FE0) << 1);
- *(unsigned short *)d = b;
- *(unsigned short *)(d+BPP2) = b;
- d += 2*BPP2; s += BPP2;
- sdx --;
- }
- s -= src_dx * BPP2;
- d -= src_dx * 2*BPP2;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- /*
- * RGB555toRGB555() converter:
- * 1:1, 2:1
- */
- int RGB555toRGB555 (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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* copy image: */
- for (i = 0; i < dest_dy; i ++) {
- memcpy (d, s, dest_dx * BPP2); /* copy dest_dx pixels */ /* Flawfinder: ignore */
- s += src_pitch;
- d += dest_pitch;
- }
- 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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sdx = src_dx;
- /* misaligned pixel first: */
- if (src_x & 1) {
- register unsigned short a;
- a = *(unsigned short *)s;
- *(unsigned short *)d = a;
- *(unsigned short *)(d+BPP2) = a;
- d += 2*BPP2; s += BPP2;
- sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 2) {
- register unsigned int a;
- a = *(unsigned int *)s;
- *(unsigned int *)d = (a & 0xFFFF) | (a << 16);
- *(unsigned int *)(d+2*BPP2) = (a & 0xFFFF0000) | (a >> 16);
- d += 2*2*BPP2; s += 2*BPP2;
- sdx -= 2;
- }
- /* the remaining odd pixel: */
- if (sdx) {
- register unsigned short a;
- a = *(unsigned short *)s;
- *(unsigned short *)d = a;
- *(unsigned short *)(d+BPP2) = a;
- d += 2*BPP2; s += BPP2;
- }
- s -= src_dx * BPP2;
- d -= src_dx * 2*BPP2;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- /*
- * No dithering yet.
- */
- int RGB555toRGB8 (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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
- /* copy rows: */
- for (i = 0; i < dest_dy; i ++) {
- register int ddx = dest_dx;
- /* first odd pixel: */
- if (src_x & 1) {
- /* gggbbbbb.0rrrrrgg -> palette index: */
- unsigned short a = *(unsigned short *)s;
- *d = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x03c0) >> 2) |
- ((a & 0x7800) >> 3)];
- d += BPP1; s += BPP2;
- ddx --;
- }
- /* main loop: process 2 pixels a time: */
- while (ddx >= 2) {
- /* gggbbbbb.0rrrrrgg.gggbbbbb.0rrrrrgg -> 2 palette indices */
- register unsigned int a;
- a = *(unsigned int *)s;
- *d = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x03c0) >> 2) |
- ((a & 0x7800) >> 3)];
- *(d+BPP1) = pmap[
- ((a & 0x001e0000) >> 17) |
- ((a & 0x03c00000) >> 18) |
- ((a & 0x78000000) >> 19)];
- d += BPP1*2; s += BPP2*2;
- ddx -= 2;
- }
- /* the remaining odd pixel: */
- if (ddx) {
- /* gggbbbbb.0rrrrrgg -> palette index: */
- unsigned short a = *(unsigned short *)s;
- *d = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x03c0) >> 2) |
- ((a & 0x7800) >> 3)];
- d += BPP1; s += BPP2;
- ddx --;
- }
- /* bump pointers to the next row: */
- s += src_pitch - dest_dx * BPP2;
- d += dest_pitch - dest_dx * BPP1;
- }
- 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 * BPP2 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sdx = src_dx;
- /* first odd pixel: */
- if (src_x & 1) {
- /* gggbbbbb.0rrrrrgg -> palette index: */
- unsigned short a = *(unsigned short *)s;
- register unsigned char c;
- c = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x03c0) >> 2) |
- ((a & 0x7800) >> 3)];
- *d = c;
- *(d+BPP1) = c;
- d += 2*BPP1; s += BPP2;
- sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 2) {
- /* gggbbbbb.0rrrrrgg.gggbbbbb.0rrrrrgg -> 2 palette indices */
- register unsigned int a;
- register unsigned char c;
- a = *(unsigned int *)s;
- c = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x03c0) >> 2) |
- ((a & 0x7800) >> 3)];
- *(d+0) = c;
- *(d+BPP1) = c;
- c = pmap[
- ((a & 0x001e0000) >> 17) |
- ((a & 0x03c00000) >> 18) |
- ((a & 0x78000000) >> 19)];
- *(d+2*BPP1) = c;
- *(d+3*BPP1) = c;
- d += 2*2*BPP1; s += 2*BPP2;
- sdx -= 2;
- }
- /* the remaining odd pixel: */
- if (sdx) {
- /* gggbbbbb.0rrrrrgg -> palette index: */
- unsigned short a = *(unsigned short *)s;
- register unsigned char c;
- c = pmap[
- ((a & 0x001e) >> 1) |
- ((a & 0x03c0) >> 2) |
- ((a & 0x7800) >> 3)];
- *d = c;
- *(d+BPP1) = c;
- d += 2*BPP1; s += BPP2;
- }
- s -= src_dx * BPP2;
- d -= src_dx * 2*BPP1;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- int RGB8toRGB32 (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 RGB8toRGB24 (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 RGB8toRGB565 (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 RGB8toRGB555 (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... */
- }
- /*
- * RGB8toRGB8() converter:
- * 1:1, 2:1
- */
- int RGB8toRGB8 (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 * BPP1 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
- /* copy image: */
- for (i = 0; i < dest_dy; i ++) {
- memcpy (d, s, dest_dx * BPP1); /* copy dest_dx pixels */ /* Flawfinder: ignore */
- s += src_pitch;
- d += dest_pitch;
- }
- 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 * BPP1 + src_y * src_pitch;
- d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
- /* stretch image: */
- for (i = 0; i < src_dy; i ++) {
- /* stretch a line: */
- register int sx = src_x, sdx = src_dx;
- /* misaligned pixels first: */
- while ((sx & 3) && sdx) {
- register unsigned char a;
- a = *s; *d = a; *(d+BPP1) = a;
- d += 2*BPP1; s += BPP1;
- sx ++; sdx --;
- }
- /* main bulk of data: */
- while (sdx >= 4) {
- register unsigned int a;
- a = *(unsigned int *)s;
- *(unsigned int *)d = (a & 0xFF) | ((a & 0xFFFF) << 8) | ((a & 0xFF00) << 16);
- *(unsigned int *)(d+4*BPP1) = (a & 0xFF000000) | ((a & 0xFFFF0000) >> 8) | ((a & 0xFF0000) >> 16);
- d += 2*4*BPP1; s += 4*BPP1;
- sdx -= 4;
- }
- /* the remaining 1..3 pixels: */
- while (sdx) {
- register unsigned char a;
- a = *s; *d = a; *(d+BPP1) = a;
- d += 2*BPP1; s += BPP1;
- sdx --;
- }
- s -= src_dx * BPP1;
- d -= src_dx * 2*BPP1;
- /* replicate a line (vertical stretching): */
- memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
- /* bump pointers to the next row: */
- s += src_pitch;
- d += dest_pitch * 2;
- }
- return 0;
- }
- /* conversion is not supported */
- return -1;
- }
- /*
- * Old I420->RGB converters:
- * Use:
- * void oldI420toRGBXXX (unsigned char *ysrc, unsigned char *usrc,
- * unsigned char *vsrc, int pitchSrc, unsigned char *dst,
- * int width, int height, int pitchDst);
- * Input:
- * ysrc, usrc, vsrc - pointers to Y, Cr, and Cb components of the frame
- * pitchSrc - pitch of the input frame (luminance)
- * dst - pointer to an output buffer
- * width, height - the size of frame to convert
- * pitchDst - pitch of the output buffer (in RGB pixels!!!)
- * Returns:
- * none.
- */
- /* the driver function: */
- static int oldI420toRGB (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst, int bpp,
- 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))
- {
- unsigned char *sy1, *sy2, *sv, *su, *d1, *d2;
- register int j, pitch = pitchDst * bpp;
- /* bump dest to other end, if bottom-up output: */
- if (pitch < 0)
- dst += -pitch * (height-1); /* start of last line */
- /* get pointers: */
- sy1 = ysrc; /* luma offset */
- sy2 = sy1 + pitchSrc;
- su = usrc; /* chroma offset */
- sv = vsrc;
- d1 = dst; /* RGB offset */
- d2 = d1 + pitch;
- /* convert aligned portion of the image: */
- for (j = 0; j < height/2; j ++) {
- /* convert two lines a time: */
- (* dbline) (d1, d2, 0, sy1, sy2, su, sv, 0, width);
- sy1 += pitchSrc*2; sy2 += pitchSrc*2;
- su += pitchSrc/2; sv += pitchSrc/2;
- d1 += pitch*2; d2 += pitch*2;
- }
- return 0;
- }
- /* actual converters: */
- void oldI420toRGB32 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
- {
- oldI420toRGB (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 4,
- is_alpha? dblineI420toRGB32alpha: dblineI420toRGB32);
- }
- void oldI420toRGB24 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
- {
- oldI420toRGB (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 3,
- is_alpha? dblineI420toRGB24alpha: dblineI420toRGB24);
- }
- void oldI420toRGB565 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
- {
- oldI420toRGB (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 2,
- is_alpha? dblineI420toRGB565alpha: dblineI420toRGB565);
- }
- void oldI420toRGB555 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
- {
- oldI420toRGB (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 2,
- is_alpha? dblineI420toRGB555alpha: dblineI420toRGB555);
- }
- /*
- * Convert two YUV lines into RGB linebufs.
- * Produces two RGB lines per call.
- * Output in padded RGB format, needed for SIMD interpolation.
- */
- static void convertI420toXRGB (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- unsigned char *buf1, unsigned char *buf2, int width, int pitchSrc)
- {
- unsigned char * ysrc2 = ysrc + pitchSrc;
- if (is_alpha) {
- /* use full matrix: */
- for (; width; width -= 2) {
- int ruv, guv, buv, y;
- buv = butab[usrc[0]] + bvtab[vsrc[0]];
- guv = gutab[usrc[0]] + gvtab[vsrc[0]];
- ruv = rutab[usrc[0]] + rvtab[vsrc[0]];
- /* store as |00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB| */
- y = ytab[ysrc[0]];
- *(int *)(buf1+0) =
- (CLIP8[y + buv] << 0) |
- (CLIP8[y + guv] << 11) |
- (CLIP8[y + ruv] << 22);
- y = ytab[ysrc[1]];
- *(int *)(buf1+4) =
- (CLIP8[y + buv] << 0) |
- (CLIP8[y + guv] << 11) |
- (CLIP8[y + ruv] << 22);
- y = ytab[ysrc2[0]];
- *(int *)(buf2+0) =
- (CLIP8[y + buv] << 0) |
- (CLIP8[y + guv] << 11) |
- (CLIP8[y + ruv] << 22);
- y = ytab[ysrc2[1]];
- *(int *)(buf2+4) =
- (CLIP8[y + buv] << 0) |
- (CLIP8[y + guv] << 11) |
- (CLIP8[y + ruv] << 22);
- /* next 2x2 block */
- ysrc += 2; ysrc2 += 2;
- usrc += 1; vsrc += 1;
- buf1 += 8; buf2 += 8;
- }
- } else {
- /* no chroma rotation: */
- for (; width; width -= 2) {
- int rv, guv, bu, y;
- bu = butab[usrc[0]];
- guv = gutab[usrc[0]] + gvtab[vsrc[0]];
- rv = rvtab[vsrc[0]];
- /* store as |00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB| */
- y = ytab[ysrc[0]];
- *(int *)(buf1+0) =
- (CLIP8[y + bu] << 0) |
- (CLIP8[y + guv] << 11) |
- (CLIP8[y + rv] << 22);
- y = ytab[ysrc[1]];
- *(int *)(buf1+4) =
- (CLIP8[y + bu] << 0) |
- (CLIP8[y + guv] << 11) |
- (CLIP8[y + rv] << 22);
- y = ytab[ysrc2[0]];
- *(int *)(buf2+0) =
- (CLIP8[y + bu] << 0) |
- (CLIP8[y + guv] << 11) |
- (CLIP8[y + rv] << 22);
- y = ytab[ysrc2[1]];
- *(int *)(buf2+4) =
- (CLIP8[y + bu] << 0) |
- (CLIP8[y + guv] << 11) |
- (CLIP8[y + rv] << 22);
- /* next 2x2 block */
- ysrc += 2; ysrc2 += 2;
- usrc += 1; vsrc += 1;
- buf1 += 8; buf2 += 8;
- }
- }
- }
- /*
- * 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 interpRGB32 (unsigned char *src1, unsigned char *src2,
- unsigned char *dst1, unsigned char *dst2, int width)
- {
- unsigned int a, b, c, d, e, f;
- unsigned int w, x, y, z;
- width >>= 1; /* two per pass */
- while (--width) { /* do all but last pair */
- /*
- * 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 *)(src1+0);
- b = *(unsigned int *)(src1+4);
- e = *(unsigned int *)(src1+8);
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)(dst1+0) =
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6);
- *(unsigned int *)(dst1+4) =
- ((x & 0x000001fe) >> 1) |
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 7);
- *(unsigned int *)(dst1+8) =
- ((y & 0x000000ff) >> 0) |
- ((y & 0x0007f800) >> 3) |
- ((y & 0x3fc00000) >> 6);
- *(unsigned int *)(dst1+12) =
- ((z & 0x000001fe) >> 1) |
- ((z & 0x000ff000) >> 4) |
- ((z & 0x7f800000) >> 7);
- /* bottom line */
- c = *(unsigned int *)(src2+0);
- d = *(unsigned int *)(src2+4);
- f = *(unsigned int *)(src2+8);
- 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 *)(dst2+0) =
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7);
- *(unsigned int *)(dst2+4) =
- ((x & 0x000003fc) >> 2) |
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 8);
- *(unsigned int *)(dst2+8) =
- ((y & 0x000001fe) >> 1) |
- ((y & 0x000ff000) >> 4) |
- ((y & 0x7f800000) >> 7);
- *(unsigned int *)(dst2+12) =
- ((z & 0x000003fc) >> 2) |
- ((z & 0x001fe000) >> 5) |
- ((z & 0xff000000) >> 8);
- /* bump pointers to next 2x2 input */
- src1 += 8; src2 += 8;
- dst1 += 16; dst2 += 16;
- }
- /*
- * 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 *)(src1+0);
- b = *(unsigned int *)(src1+4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)(dst1+0) =
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6);
- *(unsigned int *)(dst1+4) =
- ((x & 0x000001fe) >> 1) |
- ((x & 0x000ff000) >> 4) |
- ((x & 0x7f800000) >> 7);
- *(unsigned int *)(dst1+8) =
- ((y & 0x000000ff) >> 0) |
- ((y & 0x0007f800) >> 3) |
- ((y & 0x3fc00000) >> 6);
- *(unsigned int *)(dst1+12) =
- ((z & 0x000001fe) >> 1) |
- ((z & 0x000ff000) >> 4) |
- ((z & 0x7f800000) >> 7);
- /* bottom line */
- c = *(unsigned int *)(src2+0);
- d = *(unsigned int *)(src2+4);
- 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 *)(dst2+0) =
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7);
- *(unsigned int *)(dst2+4) =
- ((x & 0x000003fc) >> 2) |
- ((x & 0x001fe000) >> 5) |
- ((x & 0xff000000) >> 8);
- *(unsigned int *)(dst2+8) =
- ((y & 0x000001fe) >> 1) |
- ((y & 0x000ff000) >> 4) |
- ((y & 0x7f800000) >> 7);
- *(unsigned int *)(dst2+12) =
- ((z & 0x000003fc) >> 2) |
- ((z & 0x001fe000) >> 5) |
- ((z & 0xff000000) >> 8);
- }
- /* RGB24 version: */
- static void interpRGB24 (unsigned char *src1, unsigned char *src2,
- unsigned char *dst1, unsigned char *dst2, int width)
- {
- unsigned int a, b, c, d, e, f;
- unsigned int w, x, y, z;
- width >>= 1; /* two per pass */
- while (--width) { /* do all but last pair */
- /*
- * 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 *)(src1+0);
- b = *(unsigned int *)(src1+4);
- e = *(unsigned int *)(src1+8);
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)(dst1+0) =
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6) |
- ((x & 0x000001fe) << 23);
- *(unsigned int *)(dst1+4) =
- ((x & 0x000ff000) >> 12) |
- ((x & 0x7f800000) >> 15) |
- ((y & 0x000000ff) << 16) |
- ((y & 0x0007f800) << 13);
- *(unsigned int *)(dst1+8) =
- ((y & 0x3fc00000) >> 22) |
- ((z & 0x000001fe) << 7) |
- ((z & 0x000ff000) << 4) |
- ((z & 0x7f800000) << 1);
- /* bottom line */
- c = *(unsigned int *)(src2+0);
- d = *(unsigned int *)(src2+4);
- f = *(unsigned int *)(src2+8);
- 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 *)(dst2+0) =
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7) |
- ((x & 0x000003fc) << 22);
- *(unsigned int *)(dst2+4) =
- ((x & 0x001fe000) >> 13) |
- ((x & 0xff000000) >> 16) |
- ((y & 0x000001fe) << 15) |
- ((y & 0x000ff000) << 12);
- *(unsigned int *)(dst2+8) =
- ((y & 0x7f800000) >> 23) |
- ((z & 0x000003fc) << 6) |
- ((z & 0x001fe000) << 3) |
- ((z & 0xff000000) << 0);
- /* next 2x2 input block */
- src1 += 8; src2 += 8;
- dst1 += 12; dst2 += 12;
- }
- /*
- * For last 4 output pels, repeat the final input pel for
- * for missing input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)(src1+0);
- b = *(unsigned int *)(src1+4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b + ROUND888;
- y = b;
- z = b + e + ROUND888;
- /* pack and store */
- *(unsigned int *)(dst1+0) =
- ((w & 0x000000ff) >> 0) |
- ((w & 0x0007f800) >> 3) |
- ((w & 0x3fc00000) >> 6) |
- ((x & 0x000001fe) << 23);
- *(unsigned int *)(dst1+4) =
- ((x & 0x000ff000) >> 12) |
- ((x & 0x7f800000) >> 15) |
- ((y & 0x000000ff) << 16) |
- ((y & 0x0007f800) << 13);
- *(unsigned int *)(dst1+8) =
- ((y & 0x3fc00000) >> 22) |
- ((z & 0x000001fe) << 7) |
- ((z & 0x000ff000) << 4) |
- ((z & 0x7f800000) << 1);
- /* bottom line */
- c = *(unsigned int *)(src2+0);
- d = *(unsigned int *)(src2+4);
- 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 *)(dst2+0) =
- ((w & 0x000001fe) >> 1) |
- ((w & 0x000ff000) >> 4) |
- ((w & 0x7f800000) >> 7) |
- ((x & 0x000003fc) << 22);
- *(unsigned int *)(dst2+4) =
- ((x & 0x001fe000) >> 13) |
- ((x & 0xff000000) >> 16) |
- ((y & 0x000001fe) << 15) |
- ((y & 0x000ff000) << 12);
- *(unsigned int *)(dst2+8) =
- ((y & 0x7f800000) >> 23) |
- ((z & 0x000003fc) << 6) |
- ((z & 0x001fe000) << 3) |
- ((z & 0xff000000) << 0);
- }
- /* RGB565 version: */
- static void interpRGB565 (unsigned char *src1, unsigned char *src2,
- unsigned char *dst1, unsigned char *dst2, int width)
- {
- unsigned int a, b, c, d, e, f;
- unsigned int w, x, y, z;
- width >>= 1; /* two per pass */
- while (--width) { /* do all but last pair */
- /*
- * 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 *)(src1+0);
- b = *(unsigned int *)(src1+4);
- e = *(unsigned int *)(src1+8);
- w = a;
- x = a + b;
- y = b;
- z = b + e;
- /* pack and store */
- *(unsigned int *)(dst1+0) =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007e000) >> 8) |
- ((w & 0x3e000000) >> 14) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000fc000) << 7) |
- ((x & 0x7c000000) << 1);
- *(unsigned int *)(dst1+4) =
- ((y & 0x000000f8) >> 3) |
- ((y & 0x0007e000) >> 8) |
- ((y & 0x3e000000) >> 14) |
- ((z & 0x000001f0) << 12) |
- ((z & 0x000fc000) << 7) |
- ((z & 0x7c000000) << 1);
- /* bottom line */
- c = *(unsigned int *)(src2+0);
- d = *(unsigned int *)(src2+4);
- f = *(unsigned int *)(src2+8);
- w = a + c;
- x = a + b + c + d;
- y = b + d;
- z = b + e + d + f;
- /* pack and store */
- *(unsigned int *)(dst2+0) =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000fc000) >> 9) |
- ((w & 0x7c000000) >> 15) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f8000) << 6) |
- ((x & 0xf8000000) << 0);
- *(unsigned int *)(dst2+4) =
- ((y & 0x000001f0) >> 4) |
- ((y & 0x000fc000) >> 9) |
- ((y & 0x7c000000) >> 15) |
- ((z & 0x000003e0) << 11) |
- ((z & 0x001f8000) << 6) |
- ((z & 0xf8000000) << 0);
- /* next 2x2 input block */
- src1 += 8; src2 += 8;
- dst1 += 8; dst2 += 8;
- }
- /*
- * For last 4 output pels, repeat the final input pel for
- * for missing input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)(src1+0);
- b = *(unsigned int *)(src1+4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b;
- y = b;
- z = b + e;
- /* pack and store */
- *(unsigned int *)(dst1+0) =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007e000) >> 8) |
- ((w & 0x3e000000) >> 14) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000fc000) << 7) |
- ((x & 0x7c000000) << 1);
- *(unsigned int *)(dst1+4) =
- ((y & 0x000000f8) >> 3) |
- ((y & 0x0007e000) >> 8) |
- ((y & 0x3e000000) >> 14) |
- ((z & 0x000001f0) << 12) |
- ((z & 0x000fc000) << 7) |
- ((z & 0x7c000000) << 1);
- /* bottom line */
- c = *(unsigned int *)(src2+0);
- d = *(unsigned int *)(src2+4);
- 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 *)(dst2+0) =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000fc000) >> 9) |
- ((w & 0x7c000000) >> 15) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f8000) << 6) |
- ((x & 0xf8000000) << 0);
- *(unsigned int *)(dst2+4) =
- ((y & 0x000001f0) >> 4) |
- ((y & 0x000fc000) >> 9) |
- ((y & 0x7c000000) >> 15) |
- ((z & 0x000003e0) << 11) |
- ((z & 0x001f8000) << 6) |
- ((z & 0xf8000000) << 0);
- }
- /* RGB555 version: */
- static void interpRGB555 (unsigned char *src1, unsigned char *src2,
- unsigned char *dst1, unsigned char *dst2, int width)
- {
- unsigned int a, b, c, d, e, f;
- unsigned int w, x, y, z;
- width >>= 1; /* two per pass */
- while (--width) { /* do all but last pair */
- /*
- * 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 *)(src1+0);
- b = *(unsigned int *)(src1+4);
- e = *(unsigned int *)(src1+8);
- w = a;
- x = a + b;
- y = b;
- z = b + e;
- /* pack and store */
- *(unsigned int *)(dst1+0) =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007c000) >> 9) |
- ((w & 0x3e000000) >> 15) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000f8000) << 6) |
- ((x & 0x7c000000) << 0);
- *(unsigned int *)(dst1+4) =
- ((y & 0x000000f8) >> 3) |
- ((y & 0x0007c000) >> 9) |
- ((y & 0x3e000000) >> 15) |
- ((z & 0x000001f0) << 12) |
- ((z & 0x000f8000) << 6) |
- ((z & 0x7c000000) << 0);
- /* bottom line */
- c = *(unsigned int *)(src2+0);
- d = *(unsigned int *)(src2+4);
- f = *(unsigned int *)(src2+8);
- w = a + c;
- x = a + b + c + d;
- y = b + d;
- z = b + e + d + f;
- /* pack and store */
- *(unsigned int *)(dst2+0) =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000f8000) >> 10) |
- ((w & 0x7c000000) >> 16) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f0000) << 5) |
- ((x & 0xf8000000) >> 1);
- *(unsigned int *)(dst2+4) =
- ((y & 0x000001f0) >> 4) |
- ((y & 0x000f8000) >> 10) |
- ((y & 0x7c000000) >> 16) |
- ((z & 0x000003e0) << 11) |
- ((z & 0x001f0000) << 5) |
- ((z & 0xf8000000) >> 1);
- /* next 2x2 input block */
- src1 += 8; src2 += 8;
- dst1 += 8; dst2 += 8;
- }
- /*
- * For last 4 output pels, repeat the final input pel for
- * for missing input. Equivalent to pixel-doubling the
- * last output pel.
- */
- /* top line */
- a = *(unsigned int *)(src1+0);
- b = *(unsigned int *)(src1+4);
- e = b; /* repeat last input pel */
- w = a;
- x = a + b;
- y = b;
- z = b + e;
- /* pack and store */
- *(unsigned int *)(dst1+0) =
- ((w & 0x000000f8) >> 3) |
- ((w & 0x0007c000) >> 9) |
- ((w & 0x3e000000) >> 15) |
- ((x & 0x000001f0) << 12) |
- ((x & 0x000f8000) << 6) |
- ((x & 0x7c000000) << 0);
- *(unsigned int *)(dst1+4) =
- ((y & 0x000000f8) >> 3) |
- ((y & 0x0007c000) >> 9) |
- ((y & 0x3e000000) >> 15) |
- ((z & 0x000001f0) << 12) |
- ((z & 0x000f8000) << 6) |
- ((z & 0x7c000000) << 0);
- /* bottom line */
- c = *(unsigned int *)(src2+0);
- d = *(unsigned int *)(src2+4);
- 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 *)(dst2+0) =
- ((w & 0x000001f0) >> 4) |
- ((w & 0x000f8000) >> 10) |
- ((w & 0x7c000000) >> 16) |
- ((x & 0x000003e0) << 11) |
- ((x & 0x001f0000) << 5) |
- ((x & 0xf8000000) >> 1);
- *(unsigned int *)(dst2+4) =
- ((y & 0x000001f0) >> 4) |
- ((y & 0x000f8000) >> 10) |
- ((y & 0x7c000000) >> 16) |
- ((z & 0x000003e0) << 11) |
- ((z & 0x001f0000) << 5) |
- ((z & 0xf8000000) >> 1);
- }
- /* the driver function: */
- void oldI420toRGBx2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst, int bpp,
- void (* interp) (unsigned char *, unsigned char *, unsigned char *, unsigned char *, int))
- {
- /* Pointers to the three RGB linebuffers */
- unsigned char *buf[3]; /* Flawfinder: ignore */
- int ibuf = 0; /* circular buffer index */
- int dstinc = bpp * 2 * pitchDst; /* offset to next output line */
- unsigned char *dst2 = dst + bpp * pitchDst; /* second output line */
- buf[0] = linebuf;
- buf[1] = linebuf + 4 * width;
- buf[2] = linebuf + 8 * width;
- /* Bump dst to other end, if inverting ouput */
- if (pitchDst < 0) {
- dst += bpp * -pitchDst * (2*height - 1);
- dst2 += bpp * -pitchDst * (2*height - 1);
- }
- /* Special case for first 2 lines */
- convertI420toXRGB (ysrc, usrc, vsrc, buf[next[ibuf]], buf[next2[ibuf]], width, pitchSrc);
- ysrc += pitchSrc << 1; /* next 2 lines */
- usrc += pitchSrc >> 1; /* next line */
- vsrc += pitchSrc >> 1; /* next line */
- /* skip first interp */
- ibuf = next[ibuf]; /* shift buffers */
- (* interp) (buf[ibuf], buf[next[ibuf]], dst, dst2, width);
- dst += dstinc; /* next 2 lines */
- dst2 += dstinc;
- ibuf = next[ibuf]; /* shift buffers */
- height >>= 1; /* two rows per pass */
- while (--height) { /* do all but last pair */
- /* Convert 2 lines into bufs */
- convertI420toXRGB (ysrc, usrc, vsrc, buf[next[ibuf]], buf[next2[ibuf]], width, pitchSrc);
- ysrc += pitchSrc << 1; /* next 2 lines */
- usrc += pitchSrc >> 1; /* next line */
- vsrc += pitchSrc >> 1; /* next line */
- /* Interp 2 lines into dst */
- (* interp) (buf[ibuf], buf[next[ibuf]], dst, dst2, width);
- dst += dstinc; /* next 2 lines */
- dst2 += dstinc;
- ibuf = next[ibuf]; /* shift buffers */
- /* Interp 2 lines into dst */
- (* interp) (buf[ibuf], buf[next[ibuf]], dst, dst2, width);
- dst += dstinc; /* next 2 lines */
- dst2 += dstinc;
- ibuf = next[ibuf]; /* shift buffers */
- }
- /* Last 2 lines, repeating last input line */
- (* interp) (buf[ibuf], buf[ibuf], dst, dst2, width);
- }
- /* actual converters: */
- void oldI420toRGB32x2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
- {
- oldI420toRGBx2 (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 4, interpRGB32);
- }
- void oldI420toRGB24x2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
- {
- oldI420toRGBx2 (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 3, interpRGB24);
- }
- void oldI420toRGB565x2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
- {
- oldI420toRGBx2 (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 2, interpRGB565);
- }
- void oldI420toRGB555x2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
- int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
- {
- oldI420toRGBx2 (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 2, interpRGB555);
- }
- #if defined (_MACINTOSH) && defined (_DEBUG)
- #pragma global_optimizer off
- #endif
- /* colorcvt.c -- end of file */