colorcvt.c
Upload User: zhongxx05
Upload Date: 2007-06-06
Package Size: 33641k
Code Size: 288k
Category:

Symbian

Development Platform:

C/C++

  1.         for (i = 0; i < dest_dy; i ++) {
  2.             /* convert a line: */
  3.             register int ddx = dest_dx;
  4.             while (ddx) {
  5.                 /* RGB -> 0BGR: */
  6.                 *(unsigned int *)d = (unsigned int)
  7.                     (s[0] << 16) | (s[1] << 8) | s[2];
  8.                 d += BPP4; s += BPP3;
  9.                 ddx --;
  10.             }
  11.             s += src_pitch - dest_dx * BPP3;
  12.             d += dest_pitch - dest_dx * BPP4;
  13.         }
  14.         return 0;
  15.     }
  16.     /* check if 2:1 scale: */
  17.     if (scale_x == 2 && scale_y == 2) {
  18.         /* local variables: */
  19.         unsigned char *s, *d;
  20.         register int i;
  21.         /* get pointers: */
  22.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  23.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  24.         /* convert & stretch image: */
  25.         for (i = 0; i < src_dy; i ++) {
  26.             /* convert & stretch a line: */
  27.             register int sdx = src_dx;
  28.             while (sdx) {
  29.                 /* RGB -> 0BGR: */
  30.                 register unsigned int a;
  31.                 a = (unsigned int)
  32.                     (s[0] << 16) | (s[1] << 8) | s[2];
  33.                 *(unsigned int *)d = a;
  34.                 *(unsigned int *)(d+BPP4) = a;
  35.                 d += 2*BPP4; s += BPP3;
  36.                 sdx --;
  37.             }
  38.             s -= src_dx * BPP3;
  39.             d -= src_dx * 2*BPP4;
  40.             /* replicate a line (vertical stretching): */
  41.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP4); /* Flawfinder: ignore */
  42.             /* bump pointers to the next row: */
  43.             s += src_pitch;
  44.             d += dest_pitch * 2;
  45.         }
  46.         return 0;
  47.     }
  48.     /* conversion is not supported */
  49.     return -1;
  50. }
  51. int RGB565toBGR32 (unsigned char *dest_ptr, int dest_width, int dest_height,
  52.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  53.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  54.     int src_x, int src_y, int src_dx, int src_dy)
  55. {
  56.     /* scale factors: */
  57.     int scale_x, scale_y;
  58.     /* check arguments: */
  59.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  60.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  61.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  62.         return -1;
  63.     /* check if bottom-up bitmaps: */
  64.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  65.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  66.     /* check if 1:1 scale: */
  67.     if (scale_x == 1 && scale_y == 1) {
  68.         /* local variables: */
  69.         unsigned char *s, *d;
  70.         register int i;
  71.         /* get pointers: */
  72.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  73.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  74.         /* convert image: */
  75.         for (i = 0; i < dest_dy; i ++) {
  76.             /* convert a line: */
  77.             register int ddx = dest_dx;
  78.             while (ddx) {
  79.                 /* rrrr,rggg,gggb,bbbb -> 0BGR: */
  80.                 register unsigned short a;
  81.                 a = *(unsigned short *)s;
  82.                 *(unsigned int *)d = (unsigned int)
  83.                     ((a & 0x001F) << 19)|
  84.                     ((a & 0x07E0) << 5) |
  85.                     ((a & 0xF800) >> 8);
  86.                 d += BPP4; s += BPP2;
  87.                 ddx --;
  88.             }
  89.             s += src_pitch - dest_dx * BPP2;
  90.             d += dest_pitch - dest_dx * BPP4;
  91.         }
  92.         return 0;
  93.     }
  94.     /* check if 2:1 scale: */
  95.     if (scale_x == 2 && scale_y == 2) {
  96.         /* local variables: */
  97.         unsigned char *s, *d;
  98.         register int i;
  99.         /* get pointers: */
  100.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  101.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  102.         /* convert & stretch image: */
  103.         for (i = 0; i < src_dy; i ++) {
  104.             /* convert & stretch a line: */
  105.             register int sdx = src_dx;
  106.             while (sdx) {
  107.                 register unsigned short a;
  108.                 register unsigned int c;
  109.                 a = *(unsigned short *)s;
  110.                 c = ((a & 0x001F) << 19)|
  111.                     ((a & 0x07E0) << 5) |
  112.                     ((a & 0xF800) >> 8);
  113.                 *(unsigned int *)d = c;
  114.                 *(unsigned int *)(d+BPP4) = c;
  115.                 d += 2*BPP4; s += BPP2;
  116.                 sdx --;
  117.             }
  118.             s -= src_dx * BPP2;
  119.             d -= src_dx * 2*BPP4;
  120.             /* replicate a line (vertical stretching): */
  121.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP4); /* Flawfinder: ignore */
  122.             /* bump pointers to the next row: */
  123.             s += src_pitch;
  124.             d += dest_pitch * 2;
  125.         }
  126.         return 0;
  127.     }
  128.     /* conversion is not supported */
  129.     return -1;
  130. }
  131. int RGB555toBGR32 (unsigned char *dest_ptr, int dest_width, int dest_height,
  132.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  133.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  134.     int src_x, int src_y, int src_dx, int src_dy)
  135. {
  136.     /* scale factors: */
  137.     int scale_x, scale_y;
  138.     /* check arguments: */
  139.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  140.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  141.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  142.         return -1;
  143.     /* check if bottom-up bitmaps: */
  144.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  145.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  146.     /* check if 1:1 scale: */
  147.     if (scale_x == 1 && scale_y == 1) {
  148.         /* local variables: */
  149.         unsigned char *s, *d;
  150.         register int i;
  151.         /* get pointers: */
  152.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  153.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  154.         /* convert image: */
  155.         for (i = 0; i < dest_dy; i ++) {
  156.             /* convert a line: */
  157.             register int ddx = dest_dx;
  158.             while (ddx) {
  159.                 /* 0rrrr,rgg,gggb,bbbb -> 0BGR: */
  160.                 register unsigned short a;
  161.                 a = *(unsigned short *)s;
  162.                 *(unsigned int *)d = (unsigned int)
  163.                     ((a & 0x001F) << 19)|
  164.                     ((a & 0x03E0) << 6) |
  165.                     ((a & 0x7C00) >> 7);
  166.                 d += BPP4; s += BPP2;
  167.                 ddx --;
  168.             }
  169.             s += src_pitch - dest_dx * BPP2;
  170.             d += dest_pitch - dest_dx * BPP4;
  171.         }
  172.         return 0;
  173.     }
  174.     /* check if 2:1 scale: */
  175.     if (scale_x == 2 && scale_y == 2) {
  176.         /* local variables: */
  177.         unsigned char *s, *d;
  178.         register int i;
  179.         /* get pointers: */
  180.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  181.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  182.         /* convert & stretch image: */
  183.         for (i = 0; i < src_dy; i ++) {
  184.             /* convert & stretch a line: */
  185.             register int sdx = src_dx;
  186.             while (sdx) {
  187.                 register unsigned short a;
  188.                 register unsigned int c;
  189.                 a = *(unsigned short *)s;
  190.                 c = ((a & 0x001F) << 19)|
  191.                     ((a & 0x03E0) << 6) |
  192.                     ((a & 0x7C00) >> 7);
  193.                 *(unsigned int *)d = c;
  194.                 *(unsigned int *)(d+BPP4) = c;
  195.                 d += 2*BPP4; s += BPP2;
  196.                 sdx --;
  197.             }
  198.             s -= src_dx * BPP2;
  199.             d -= src_dx * 2*BPP4;
  200.             /* replicate a line (vertical stretching): */
  201.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP4); /* Flawfinder: ignore */
  202.             /* bump pointers to the next row: */
  203.             s += src_pitch;
  204.             d += dest_pitch * 2;
  205.         }
  206.         return 0;
  207.     }
  208.     /* conversion is not supported */
  209.     return -1;
  210. }
  211. int RGB8toBGR32 (unsigned char *dest_ptr, int dest_width, int dest_height,
  212.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  213.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  214.     int src_x, int src_y, int src_dx, int src_dy)
  215. {
  216.     return -1;   /* not implemented yet... */
  217. }
  218. /********************************
  219.  *
  220.  * "RGBx to RGBy" converters.
  221.  *
  222.  ********************************/
  223. /*
  224.  * RGB32toRGB32() converter:
  225.  *  1:1, 2:1
  226.  */
  227. int RGB32toRGB32 (unsigned char *dest_ptr, int dest_width, int dest_height,
  228.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  229.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  230.     int src_x, int src_y, int src_dx, int src_dy)
  231. {
  232.     /* scale factors: */
  233.     int scale_x, scale_y;
  234.     /* check arguments: */
  235.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  236.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  237.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  238.         return -1;
  239.     /* check if bottom-up bitmaps: */
  240.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  241.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  242.     /* check if 1:1 scale: */
  243.     if (scale_x == 1 && scale_y == 1) {
  244.         /* local variables: */
  245.         unsigned char *s, *d;
  246.         register int i;
  247.         /* get pointers: */
  248.         s = src_ptr + src_x * BPP4 + src_y * src_pitch;
  249.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  250.         /* copy image: */
  251.         for (i = 0; i < dest_dy; i ++) {
  252.             memcpy (d, s, dest_dx * BPP4);  /* copy dest_dx pixels */ /* Flawfinder: ignore */
  253.             s += src_pitch;
  254.             d += dest_pitch;
  255.         }
  256.         return 0;
  257.     }
  258.     /* check if 2:1 scale: */
  259.     if (scale_x == 2 && scale_y == 2) {
  260.         /* local variables: */
  261.         unsigned char *s, *d;
  262.         register int i;
  263.         /* get pointers: */
  264.         s = src_ptr + src_x * BPP4 + src_y * src_pitch;
  265.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  266.         /* stretch image: */
  267.         for (i = 0; i < src_dy; i ++) {
  268.             /* stretch a line: */
  269.             register int sdx = src_dx;
  270.             while (sdx) {
  271.                 register unsigned int a;
  272.                 a = *(unsigned int *)s;
  273.                 *(unsigned int *)d = a;
  274.                 *(unsigned int *)(d+BPP4) = a;
  275.                 d += 2*BPP4; s += BPP4;
  276.                 sdx --;
  277.             }
  278.             s -= src_dx * BPP4;
  279.             d -= src_dx * 2*BPP4;
  280.             /* replicate a line (vertical stretching): */
  281.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP4); /* Flawfinder: ignore */
  282.             /* bump pointers to the next row: */
  283.             s += src_pitch;
  284.             d += dest_pitch * 2;
  285.         }
  286.         return 0;
  287.     }
  288.     /* conversion is not supported */
  289.     return -1;
  290. }
  291. int RGB32toRGB24 (unsigned char *dest_ptr, int dest_width, int dest_height,
  292.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  293.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  294.     int src_x, int src_y, int src_dx, int src_dy)
  295. {
  296.     return -1;   /* not implemented yet... */
  297. }
  298. int RGB32toRGB565 (unsigned char *dest_ptr, int dest_width, int dest_height,
  299.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  300.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  301.     int src_x, int src_y, int src_dx, int src_dy)
  302. {
  303.     return -1;   /* not implemented yet... */
  304. }
  305. int RGB32toRGB555 (unsigned char *dest_ptr, int dest_width, int dest_height,
  306.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  307.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  308.     int src_x, int src_y, int src_dx, int src_dy)
  309. {
  310.     return -1;   /* not implemented yet... */
  311. }
  312. /*
  313.  * No dithering yet.
  314.  */
  315. int RGB32toRGB8 (unsigned char *dest_ptr, int dest_width, int dest_height,
  316.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  317.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  318.     int src_x, int src_y, int src_dx, int src_dy)
  319. {
  320.     /* scale factors: */
  321.     int scale_x, scale_y;
  322.     /* check arguments: */
  323.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  324.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  325.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  326.         return -1;
  327.     /* check if bottom-up bitmaps: */
  328.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  329.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  330.     /* check if 1:1 scale: */
  331.     if (scale_x == 1 && scale_y == 1) {
  332.         /* local variables: */
  333.         unsigned char *s, *d;
  334.         register int i;
  335.         /* get pointers: */
  336.         s = src_ptr + src_x * BPP4 + src_y * src_pitch;
  337.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  338.         /* copy rows: */
  339.         for (i = 0; i < dest_dy; i ++) {
  340.             /* convert a line: */
  341.             register int ddx = dest_dx;
  342.             while (ddx) {
  343.                 register unsigned int a;
  344.                 a = *(unsigned int *)s;             /* BGR0 */
  345.                 *d = pmap[
  346.                     ((a & 0x000000f0) >>  4) |
  347.                     ((a & 0x0000f000) >>  8) |
  348.                     ((a & 0x00f00000) >> 12)];
  349.                 d += BPP1; s += BPP4;
  350.                 ddx --;
  351.             }
  352.             /* bump pointers to the next row: */
  353.             s += src_pitch - dest_dx * BPP4;
  354.             d += dest_pitch - dest_dx * BPP1;
  355.         }
  356.         return 0;
  357.     }
  358.     /* check if 2:1 scale: */
  359.     if (scale_x == 2 && scale_y == 2) {
  360.         /* local variables: */
  361.         unsigned char *s, *d;
  362.         register int i;
  363.         /* get pointers: */
  364.         s = src_ptr + src_x * BPP4 + src_y * src_pitch;
  365.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  366.         /* stretch image: */
  367.         for (i = 0; i < src_dy; i ++) {
  368.             /* stretch a line: */
  369.             register int sdx = src_dx;
  370.             while (sdx) {
  371.                 register unsigned int a;
  372.                 register unsigned char c;
  373.                 a = *(unsigned int *)s;             /* BRG0 */
  374.                 c = pmap[
  375.                     ((a & 0x000000f0) >>  4) |
  376.                     ((a & 0x0000f000) >>  8) |
  377.                     ((a & 0x00f00000) >> 12)];
  378.                 *(d+0) = c;
  379.                 *(d+BPP1) = c;
  380.                 d += 2*BPP1; s += BPP4;
  381.                 sdx --;
  382.             }
  383.             s -= src_dx * BPP4;
  384.             d -= src_dx * 2*BPP1;
  385.             /* replicate a line (vertical stretching): */
  386.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
  387.             /* bump pointers to the next row: */
  388.             s += src_pitch;
  389.             d += dest_pitch * 2;
  390.         }
  391.         return 0;
  392.     }
  393.     /* conversion is not supported */
  394.     return -1;
  395. }
  396. /*
  397.  * RGB24toRGB32() converter:
  398.  *  1:1, 2:1
  399.  */
  400. int RGB24toRGB32 (unsigned char *dest_ptr, int dest_width, int dest_height,
  401.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  402.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  403.     int src_x, int src_y, int src_dx, int src_dy)
  404. {
  405.     /* scale factors: */
  406.     int scale_x, scale_y;
  407.     /* check arguments: */
  408.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  409.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  410.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  411.         return -1;
  412.     /* check if bottom-up bitmaps: */
  413.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  414.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  415.     /* check if 1:1 scale: */
  416.     if (scale_x == 1 && scale_y == 1) {
  417.         /* local variables: */
  418.         unsigned char *s, *d;
  419.         register int i;
  420.         /* get pointers: */
  421.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  422.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  423.         /* copy rows: */
  424.         for (i = 0; i < dest_dy; i ++) {
  425.             register int sx = src_x, ddx = dest_dx;
  426.             /* process misaligned pixels first: */
  427.             while ((sx & 3) && ddx) {
  428.                 /* BGR -> BGR0: */
  429.                 *(unsigned int *)d = (unsigned int)s[0] | (s[1] << 8) | (s[2] << 16);
  430.                 d += BPP4; s += BPP3;
  431.                 sx ++; ddx --;
  432.             }
  433.             /* main loop: process 4 pixels a time: */
  434.             while (ddx >= 4) {
  435.                 register unsigned int a, b;
  436.                 a = *(unsigned int *)s;             /* BGR.B */
  437.                 b = *(unsigned int *)(s+4);         /* GR.BG */
  438.                 *(unsigned int *)d      = a & 0x00FFFFFF;
  439.                 *(unsigned int *)(d+4)  = ((a >> 24) | (b << 8)) & 0x00FFFFFF;
  440.                 a = *(unsigned int *)(s+8);         /* R.BGR */
  441.                 *(unsigned int *)(d+8)  = ((b >> 16) | (a << 16)) & 0x00FFFFFF;
  442.                 *(unsigned int *)(d+12) = a >> 8;
  443.                 d += BPP4*4; s += BPP3*4;
  444.                 ddx -= 4;
  445.             }
  446.             /* process the remaining 1..3 pixels: */
  447.             while (ddx) {
  448.                 /* RGB -> RGB0: */
  449.                 *(unsigned int *)d = (unsigned int)s[0] | (s[1] << 8) | (s[2] << 16);
  450.                 d += BPP4; s += BPP3;
  451.                 ddx --;
  452.             }
  453.             /* bump pointers to the next row: */
  454.             s += src_pitch - dest_dx * BPP3;
  455.             d += dest_pitch - dest_dx * BPP4;
  456.         }
  457.         return 0;
  458.     }
  459.     /* check if 2:1 scale: */
  460.     if (scale_x == 2 && scale_y == 2) {
  461.         /* local variables: */
  462.         unsigned char *s, *d;
  463.         register int i;
  464.         /* get pointers: */
  465.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  466.         d = dest_ptr + dest_x * BPP4 + dest_y * dest_pitch;
  467.         /* stretch image: */
  468.         for (i = 0; i < src_dy; i ++) {
  469.             /* stretch a line: */
  470.             register int sx = src_x, sdx = src_dx;
  471.             /* misaligned pixels first: */
  472.             while ((sx & 3) && sdx) {
  473.                 /* BGR -> BGR0: */
  474.                 register unsigned int a;
  475.                 a = (unsigned int)s[0] | (s[1] << 8) | (s[2] << 16);
  476.                 *(unsigned int *)d = a;
  477.                 *(unsigned int *)(d+BPP4) = a;
  478.                 d += 2*BPP4; s += BPP3;
  479.                 sx ++; sdx --;
  480.             }
  481.             /* main bulk of data: */
  482.             while (sdx >= 4) {
  483.                 register unsigned int a, b, c;
  484.                 a = *(unsigned int *)s;             /* bgrB */
  485.                 b = *(unsigned int *)(s+4);         /* GRbg */
  486.                 c = a & 0x00FFFFFF;
  487.                 *(unsigned int *)(d) = c;
  488.                 *(unsigned int *)(d+BPP4) = c;
  489.                 c = ((a >> 24) | (b << 8)) & 0x00FFFFFF;
  490.                 *(unsigned int *)(d+2*BPP4) = c;
  491.                 *(unsigned int *)(d+3*BPP4) = c;
  492.                 a = *(unsigned int *)(s+8);         /* rBGR */
  493.                 c = ((b >> 16) | (a << 16)) & 0x00FFFFFF;
  494.                 *(unsigned int *)(d+4*BPP4) = c;
  495.                 *(unsigned int *)(d+5*BPP4) = c;
  496.                 c = a >> 8;
  497.                 *(unsigned int *)(d+6*BPP4) = c;
  498.                 *(unsigned int *)(d+7*BPP4) = c;
  499.                 d += 4*2*BPP4; s += 4*BPP3;
  500.                 sdx -= 4;
  501.             }
  502.             /* the remaining 1..3 pixels: */
  503.             while (sdx) {
  504.                 /* BGR -> BGR0: */
  505.                 register unsigned int a;
  506.                 a = (unsigned int)s[0] | (s[1] << 8) | (s[2] << 16);
  507.                 *(unsigned int *)d = a;
  508.                 *(unsigned int *)(d+BPP4) = a;
  509.                 d += 2*BPP4; s += BPP3;
  510.                 sdx --;
  511.             }
  512.             s -= src_dx * BPP3;
  513.             d -= src_dx * 2*BPP4;
  514.             /* replicate a line (vertical stretching): */
  515.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP4); /* Flawfinder: ignore */
  516.             /* bump pointers to the next row: */
  517.             s += src_pitch;
  518.             d += dest_pitch * 2;
  519.         }
  520.         return 0;
  521.     }
  522.     /* conversion is not supported */
  523.     return -1;
  524. }
  525. /*
  526.  * RGB24toRGB24() converter:
  527.  *  1:1, 2:1
  528.  */
  529. int RGB24toRGB24 (unsigned char *dest_ptr, int dest_width, int dest_height,
  530.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  531.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  532.     int src_x, int src_y, int src_dx, int src_dy)
  533. {
  534.     /* scale factors: */
  535.     int scale_x, scale_y;
  536.     /* check arguments: */
  537.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  538.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  539.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  540.         return -1;
  541.     /* check if bottom-up bitmaps: */
  542.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  543.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  544.     /* check if 1:1 scale: */
  545.     if (scale_x == 1 && scale_y == 1) {
  546.         /* local variables: */
  547.         unsigned char *s, *d;
  548.         register int i;
  549.         /* get pointers: */
  550.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  551.         d = dest_ptr + dest_x * BPP3 + dest_y * dest_pitch;
  552.         /* copy image: */
  553.         for (i = 0; i < dest_dy; i ++) {
  554.             memcpy (d, s, dest_dx * BPP3);  /* copy dest_dx pixels */ /* Flawfinder: ignore */
  555.             s += src_pitch;
  556.             d += dest_pitch;
  557.         }
  558.         return 0;
  559.     }
  560.     /* check if 2:1 scale: */
  561.     if (scale_x == 2 && scale_y == 2) {
  562.         /* local variables: */
  563.         unsigned char *s, *d;
  564.         register int i;
  565.         /* get pointers: */
  566.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  567.         d = dest_ptr + dest_x * BPP3 + dest_y * dest_pitch;
  568.         /* stretch image: */
  569.         for (i = 0; i < src_dy; i ++) {
  570.             /* stretch a line: */
  571.             register int sx = src_x, sdx = src_dx;
  572.             /* misaligned pixels first: */
  573.             while ((sx & 3) && sdx) {
  574.                 register unsigned char a;
  575.                 a = *s; *d = a; *(d+BPP3) = a;
  576.                 a = *(s+1); *(d+1) = a; *(d+1+BPP3) = a;
  577.                 a = *(s+2); *(d+2) = a; *(d+2+BPP3) = a;
  578.                 d += 2*BPP3; s += BPP3;
  579.                 sx ++; sdx --;
  580.             }
  581.             /* main bulk of data: */
  582.             while (sdx >= 4) {
  583.                 register unsigned int a, b;
  584.                 a = *(unsigned int *)s;             /* bgrB */
  585.                 b = *(unsigned int *)(s+4);         /* GRbg */
  586.                 *(unsigned int *)(d) = (a & 0x00FFFFFF) | (a << 24);    /* bgrb */
  587.                 *(unsigned int *)(d+4) = (a >> 8) | (b << 24);          /* grBG */
  588.                 *(unsigned int *)(d+2*4) = ((b & 0xFF00) >> 8) |        /* RBGR */
  589.                                            ((a & 0xFF000000) >> 16) | (b << 16);
  590.                 a = *(unsigned int *)(s+8);         /* rBGR */
  591.                 *(unsigned int *)(d+3*4) = (b >> 16) |                  /* bgrb */
  592.                                            ((a & 0xFF) << 16) | ((b & 0xFF0000) << 8);
  593.                 *(unsigned int *)(d+4*4) = (b >> 24) | (a << 8);        /* grBG */
  594.                 *(unsigned int *)(d+5*4) = (a >> 24) | (a & 0xFFFFFF00);/* RBGR */
  595.                 d += 4*2*BPP3; s += 4*BPP3;
  596.                 sdx -= 4;
  597.             }
  598.             /* the remaining 1..3 pixels: */
  599.             while (sdx) {
  600.                 register unsigned char a;
  601.                 a = *s; *d = a; *(d+BPP3) = a;
  602.                 a = *(s+1); *(d+1) = a; *(d+1+BPP3) = a;
  603.                 a = *(s+2); *(d+2) = a; *(d+2+BPP3) = a;
  604.                 d += 2*BPP3; s += BPP3;
  605.                 sdx --;
  606.             }
  607.             s -= src_dx * BPP3;
  608.             d -= src_dx * 2*BPP3;
  609.             /* replicate a line (vertical stretching): */
  610.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP3); /* Flawfinder: ignore */
  611.             /* bump pointers to the next row: */
  612.             s += src_pitch;
  613.             d += dest_pitch * 2;
  614.         }
  615.         return 0;
  616.     }
  617.     /* conversion is not supported */
  618.     return -1;
  619. }
  620. /*
  621.  * RGB24toRGB565() converter:
  622.  *  1:1, 2:1
  623.  */
  624. int RGB24toRGB565 (unsigned char *dest_ptr, int dest_width, int dest_height,
  625.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  626.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  627.     int src_x, int src_y, int src_dx, int src_dy)
  628. {
  629.     /* scale factors: */
  630.     int scale_x, scale_y;
  631.     /* check arguments: */
  632.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  633.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  634.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  635.         return -1;
  636.     /* check if bottom-up bitmaps: */
  637.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  638.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  639.     /* check if 1:1 scale: */
  640.     if (scale_x == 1 && scale_y == 1) {
  641.         /* local variables: */
  642.         unsigned char *s, *d;
  643.         register int i;
  644.         /* get pointers: */
  645.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  646.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  647.         /* copy rows: */
  648.         for (i = 0; i < dest_dy; i ++) {
  649.             register int sx = src_x, ddx = dest_dx;
  650.             /* process misaligned pixels first: */
  651.             while ((sx & 3) && ddx) {
  652.                 /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.rrrrrggg: */
  653.                 *(unsigned short *)d =
  654.                     (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
  655.                 d += BPP2;  s += BPP3;
  656.                 sx ++; ddx --;
  657.             }
  658.             /* main loop: process 4 pixels a time: */
  659.             while (ddx >= 4) {
  660.                 register unsigned int a, b;
  661.                 a = *(unsigned int *)s;             /* BGR.B */
  662.                 b = *(unsigned int *)(s+4);         /* GR.BG */
  663.                 *(unsigned int *)d =
  664.                     ((a & 0xF8) >> 3) | ((a & 0xFC00) >> 5) | ((a & 0xF80000) >> 8) |
  665.                     ((a & 0xF8000000) >> 11) | ((b & 0xFC) << 19) | ((b & 0xF800) << 16);
  666.                 a = *(unsigned int *)(s+8);         /* R.BGR */
  667.                 *(unsigned int *)(d+4) =
  668.                     ((b & 0xF80000) >> 19) | ((b & 0xFC000000) >> 21) | ((a & 0xF8) << 8) |
  669.                     ((a & 0xF800) << 5) | ((a & 0xFC0000) << 3) | (a & 0xF8000000);
  670.                 d += BPP2*4; s += BPP3*4; ddx -= 4;
  671.             }
  672.             /* process the remaining 1..3 pixels: */
  673.             while (ddx) {
  674.                 /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.rrrrrggg: */
  675.                 *(unsigned short *)d =
  676.                     (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
  677.                 d += BPP2;  s += BPP3;
  678.                 ddx --;
  679.             }
  680.             /* bump pointers to the next row: */
  681.             s += src_pitch - dest_dx * BPP3;
  682.             d += dest_pitch - dest_dx * BPP2;
  683.         }
  684.         return 0;
  685.     }
  686.     /* check if 2:1 scale: */
  687.     if (scale_x == 2 && scale_y == 2) {
  688.         /* local variables: */
  689.         unsigned char *s, *d;
  690.         register int i;
  691.         /* get pointers: */
  692.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  693.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  694.         /* stretch image: */
  695.         for (i = 0; i < src_dy; i ++) {
  696.             /* stretch a line: */
  697.             register int sx = src_x, sdx = src_dx;
  698.             /* misaligned pixels first: */
  699.             while ((sx & 3) && sdx) {
  700.                 /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
  701.                 register unsigned short a;
  702.                 a = (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
  703.                 *(unsigned short *)d = a;
  704.                 *(unsigned short *)(d+BPP2) = a;
  705.                 d += 2*BPP2;  s += BPP3;
  706.                 sx ++; sdx --;
  707.             }
  708.             /* main bulk of data: */
  709.             while (sdx >= 4) {
  710.                 register unsigned int a, b, c;
  711.                 a = *(unsigned int *)s;             /* bgrB */
  712.                 b = *(unsigned int *)(s+4);         /* GRbg */
  713.                 c = ((a & 0xF8) >> 3) | ((a & 0xFC00) >> 5) | ((a & 0xF80000) >> 8);
  714.                 *(unsigned int *)d = c | (c << 16);
  715.                 c = ((a & 0xF8000000) >> 11) | ((b & 0xFC) << 19) | ((b & 0xF800) << 16);
  716.                 *(unsigned int *)(d+2*BPP2) = c | (c >> 16);
  717.                 a = *(unsigned int *)(s+8);         /* rBGR */
  718.                 c = ((b & 0xF80000) >> 19) | ((b & 0xFC000000) >> 21) | ((a & 0xF8) << 8);
  719.                 *(unsigned int *)(d+2*2*BPP2) = c | (c << 16);
  720.                 c = ((a & 0xF800) << 5) | ((a & 0xFC0000) << 3) | (a & 0xF8000000);
  721.                 *(unsigned int *)(d+3*2*BPP2) = c | (c >> 16);
  722.                 d += 2*4*BPP2; s += 4*BPP3;
  723.                 sdx -= 4;
  724.             }
  725.             /* the remaining pixels: */
  726.             while (sdx) {
  727.                 /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
  728.                 register unsigned short a;
  729.                 a = (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
  730.                 *(unsigned short *)d = a;
  731.                 *(unsigned short *)(d+BPP2) = a;
  732.                 d += 2*BPP2;  s += BPP3;
  733.                 sdx --;
  734.             }
  735.             s -= src_dx * BPP3;
  736.             d -= src_dx * 2*BPP2;
  737.             /* replicate a line (vertical stretching): */
  738.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
  739.             /* bump pointers to the next row: */
  740.             s += src_pitch;
  741.             d += dest_pitch * 2;
  742.         }
  743.         return 0;
  744.     }
  745.     /* conversion is not supported */
  746.     return -1;
  747. }
  748. /*
  749.  * RGB24toRGB555() converter:
  750.  *  1:1, 2:1
  751.  */
  752. int RGB24toRGB555 (unsigned char *dest_ptr, int dest_width, int dest_height,
  753.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  754.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  755.     int src_x, int src_y, int src_dx, int src_dy)
  756. {
  757.     /* scale factors: */
  758.     int scale_x, scale_y;
  759.     /* check arguments: */
  760.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  761.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  762.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  763.         return -1;
  764.     /* check if bottom-up bitmaps: */
  765.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  766.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  767.     /* check if 1:1 scale: */
  768.     if (scale_x == 1 && scale_y == 1) {
  769.         /* local variables: */
  770.         unsigned char *s, *d;
  771.         register int i;
  772.         /* get pointers: */
  773.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  774.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  775.         /* copy rows: */
  776.         for (i = 0; i < dest_dy; i ++) {
  777.             register int sx = src_x, ddx = dest_dx;
  778.             /* process misaligned pixels first: */
  779.             while ((sx & 3) && ddx) {
  780.                 /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
  781.                 *(unsigned short *)d =
  782.                     (s[0] >> 3) | ((s[1] & 0xF8) << 2) | ((s[2] & 0xF8) << 7);
  783.                 d += BPP2;  s += BPP3;
  784.                 sx ++; ddx --;
  785.             }
  786.             /* main loop: process 4 pixels a time: */
  787.             while (ddx >= 4) {
  788.                 register unsigned int a, b;
  789.                 a = *(unsigned int *)s;             /* bgrB */
  790.                 b = *(unsigned int *)(s+4);         /* GRbg */
  791.                 *(unsigned int *)d =
  792.                     ((a & 0xF8) >> 3) | ((a & 0xF800) >> 6) | ((a & 0xF80000) >> 9) |
  793.                     ((a & 0xF8000000) >> 11) | ((b & 0xF8) << 18) | ((b & 0xF800) << 15);
  794.                 a = *(unsigned int *)(s+8);         /* rBGR */
  795.                 *(unsigned int *)(d+4) =
  796.                     ((b & 0xF80000) >> 19) | ((b & 0xF8000000) >> 22) | ((a & 0xF8) << 7) |
  797.                     ((a & 0xF800) << 5) | ((a & 0xF80000) << 2) | ((a & 0xF8000000) >> 1);
  798.                 d += BPP2*4; s += BPP3*4; ddx -= 4;
  799.             }
  800.             /* process the remaining 1..3 pixels: */
  801.             while (ddx) {
  802.                 /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.rrrrrggg: */
  803.                 *(unsigned short *)d =
  804.                     (s[0] >> 3) | ((s[1] & 0xF8) << 2) | ((s[2] & 0xF8) << 7);
  805.                 d += BPP2;  s += BPP3;
  806.                 ddx --;
  807.             }
  808.             /* bump pointers to the next row: */
  809.             s += src_pitch - dest_dx * BPP3;
  810.             d += dest_pitch - dest_dx * BPP2;
  811.         }
  812.         return 0;
  813.     }
  814.     /* check if 2:1 scale: */
  815.     if (scale_x == 2 && scale_y == 2) {
  816.         /* local variables: */
  817.         unsigned char *s, *d;
  818.         register int i;
  819.         /* get pointers: */
  820.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  821.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  822.         /* stretch image: */
  823.         for (i = 0; i < src_dy; i ++) {
  824.             /* stretch a line: */
  825.             register int sx = src_x, sdx = src_dx;
  826.             /* misaligned pixels first: */
  827.             while ((sx & 3) && sdx) {
  828.                 /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
  829.                 register unsigned short a;
  830.                 a = (s[0] >> 3) | ((s[1] & 0xF8) << 2) | ((s[2] & 0xF8) << 7);
  831.                 *(unsigned short *)d = a;
  832.                 *(unsigned short *)(d+BPP2) = a;
  833.                 d += 2*BPP2;  s += BPP3;
  834.                 sx ++; sdx --;
  835.             }
  836.             /* main bulk of data: */
  837.             while (sdx >= 4) {
  838.                 register unsigned int a, b, c;
  839.                 a = *(unsigned int *)s;             /* bgrB */
  840.                 b = *(unsigned int *)(s+4);         /* GRbg */
  841.                 c = ((a & 0xF8) >> 3) | ((a & 0xF800) >> 6) | ((a & 0xF80000) >> 9);
  842.                 *(unsigned int *)d = c | (c << 16);
  843.                 c = ((a & 0xF8000000) >> 11) | ((b & 0xF8) << 18) | ((b & 0xF800) << 15);
  844.                 *(unsigned int *)(d+2*BPP2) = c | (c >> 16);
  845.                 a = *(unsigned int *)(s+8);         /* rBGR */
  846.                 c = ((b & 0xF80000) >> 19) | ((b & 0xF8000000) >> 22) | ((a & 0xF8) << 7);
  847.                 *(unsigned int *)(d+2*2*BPP2) = c | (c << 16);
  848.                 c = ((a & 0xF800) << 5) | ((a & 0xF80000) << 2) | ((a & 0xF8000000) >> 1);
  849.                 *(unsigned int *)(d+3*2*BPP2) = c | (c >> 16);
  850.                 d += 2*4*BPP2; s += 4*BPP3;
  851.                 sdx -= 4;
  852.             }
  853.             /* the remaining pixels: */
  854.             while (sdx) {
  855.                 /* bbbbbbbb.gggggggg.rrrrrrrr -> gggbbbbb.0rrrrrgg: */
  856.                 register unsigned short a;
  857.                 a = (s[0] >> 3) | ((s[1] & 0xF8) << 2) | ((s[2] & 0xF8) << 7);
  858.                 *(unsigned short *)d = a;
  859.                 *(unsigned short *)(d+BPP2) = a;
  860.                 d += 2*BPP2;  s += BPP3;
  861.                 sdx --;
  862.             }
  863.             s -= src_dx * BPP3;
  864.             d -= src_dx * 2*BPP2;
  865.             /* replicate a line (vertical stretching): */
  866.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
  867.             /* bump pointers to the next row: */
  868.             s += src_pitch;
  869.             d += dest_pitch * 2;
  870.         }
  871.         return 0;
  872.     }
  873.     /* conversion is not supported */
  874.     return -1;
  875. }
  876. /*
  877.  * No dithering yet.
  878.  */
  879. int RGB24toRGB8 (unsigned char *dest_ptr, int dest_width, int dest_height,
  880.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  881.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  882.     int src_x, int src_y, int src_dx, int src_dy)
  883. {
  884.     /* scale factors: */
  885.     int scale_x, scale_y;
  886.     /* check arguments: */
  887.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  888.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  889.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  890.         return -1;
  891.     /* check if bottom-up bitmaps: */
  892.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  893.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  894.     /* check if 1:1 scale: */
  895.     if (scale_x == 1 && scale_y == 1) {
  896.         /* local variables: */
  897.         unsigned char *s, *d;
  898.         register int i;
  899.         /* get pointers: */
  900.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  901.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  902.         /* copy rows: */
  903.         for (i = 0; i < dest_dy; i ++) {
  904.             register int sx = src_x, ddx = dest_dx;
  905.             /* process misaligned pixels first: */
  906.             while ((sx & 3) && ddx) {
  907.                 /* BGR -> palette index: */
  908.                 *d = pmap[(unsigned int)
  909.                     ((s[0] & 0xf0) >> 4) |
  910.                     ((s[1] & 0xf0)     ) |
  911.                     ((s[2] & 0xf0) << 4)];
  912.                 d += BPP1; s += BPP3;
  913.                 sx ++; ddx --;
  914.             }
  915.             /* main loop: process 4 pixels a time: */
  916.             while (ddx >= 4) {
  917.                 register unsigned int a, b;
  918.                 a = *(unsigned int *)s;             /* BGR.B */
  919.                 b = *(unsigned int *)(s+4);         /* GR.BG */
  920.                 *d = pmap[(unsigned int)
  921.                     ((a & 0x000000f0) >>  4) |
  922.                     ((a & 0x0000f000) >>  8) |
  923.                     ((a & 0x00f00000) >> 12)];
  924.                 *(d+BPP1) = pmap[(unsigned int)
  925.                     ((a & 0xf0000000) >> 28) |
  926.                     ((b & 0x000000f0)      ) |
  927.                     ((b & 0x0000f000) >>  4)];
  928.                 a = *(unsigned int *)(s+8);         /* R.BGR */
  929.                 *(d+2*BPP1) = pmap[(unsigned int)
  930.                     ((b & 0x00f00000) >> 20) |
  931.                     ((b & 0xf0000000) >> 24) |
  932.                     ((a & 0x000000f0) <<  4)];
  933.                 *(d+3*BPP1) = pmap[(unsigned int)
  934.                     ((a & 0x0000f000) >> 12) |
  935.                     ((a & 0x00f00000) >> 16) |
  936.                     ((a & 0xf0000000) >> 20)];
  937.                 d += BPP1*4; s += BPP3*4;
  938.                 ddx -= 4;
  939.             }
  940.             /* process the remaining 1..3 pixels: */
  941.             while (ddx) {
  942.                 /* RGB -> palette index: */
  943.                 *d = pmap[(unsigned int)
  944.                     ((s[0] & 0xf0) >> 4) |
  945.                     ((s[1] & 0xf0)     ) |
  946.                     ((s[2] & 0xf0) << 4)];
  947.                 d += BPP1; s += BPP3;
  948.                 ddx --;
  949.             }
  950.             /* bump pointers to the next row: */
  951.             s += src_pitch - dest_dx * BPP3;
  952.             d += dest_pitch - dest_dx * BPP1;
  953.         }
  954.         return 0;
  955.     }
  956.     /* check if 2:1 scale: */
  957.     if (scale_x == 2 && scale_y == 2) {
  958.         /* local variables: */
  959.         unsigned char *s, *d;
  960.         register int i;
  961.         /* get pointers: */
  962.         s = src_ptr + src_x * BPP3 + src_y * src_pitch;
  963.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  964.         /* stretch image: */
  965.         for (i = 0; i < src_dy; i ++) {
  966.             /* stretch a line: */
  967.             register int sx = src_x, sdx = src_dx;
  968.             /* misaligned pixels first: */
  969.             while ((sx & 3) && sdx) {
  970.                 /* BGR -> palette index: */
  971.                 register unsigned char c;
  972.                 c = pmap[(unsigned int)
  973.                     ((s[0] & 0xf0) >> 4) |
  974.                     ((s[1] & 0xf0)     ) |
  975.                     ((s[2] & 0xf0) << 4)];
  976.                 *d = c;
  977.                 *(d+BPP1) = c;
  978.                 d += 2*BPP1; s += BPP3;
  979.                 sx ++; sdx --;
  980.             }
  981.             /* main bulk of data: */
  982.             while (sdx >= 4) {
  983.                 register unsigned int a, b;
  984.                 register unsigned char c;
  985.                 a = *(unsigned int *)s;             /* bgrB */
  986.                 b = *(unsigned int *)(s+4);         /* GRbg */
  987.                 c = pmap[(unsigned int)
  988.                     ((a & 0x000000f0) >>  4) |
  989.                     ((a & 0x0000f000) >>  8) |
  990.                     ((a & 0x00f00000) >> 12)];
  991.                 *(d+0) = c;
  992.                 *(d+BPP1) = c;
  993.                 c = pmap[(unsigned int)
  994.                     ((a & 0xf0000000) >> 28) |
  995.                     ((b & 0x000000f0)      ) |
  996.                     ((b & 0x0000f000) >>  4)];
  997.                 *(d+2*BPP1) = c;
  998.                 *(d+3*BPP1) = c;
  999.                 a = *(unsigned int *)(s+8);         /* rBGR */
  1000.                 c = pmap[(unsigned int)
  1001.                     ((b & 0x00f00000) >> 20) |
  1002.                     ((b & 0xf0000000) >> 24) |
  1003.                     ((a & 0x000000f0) <<  4)];
  1004.                 *(d+4*BPP1) = c;
  1005.                 *(d+5*BPP1) = c;
  1006.                 c = pmap[(unsigned int)
  1007.                     ((a & 0x0000f000) >> 12) |
  1008.                     ((a & 0x00f00000) >> 16) |
  1009.                     ((a & 0xf0000000) >> 20)];
  1010.                 *(d+6*BPP1) = c;
  1011.                 *(d+7*BPP1) = c;
  1012.                 d += 4*2*BPP1; s += 4*BPP3;
  1013.                 sdx -= 4;
  1014.             }
  1015.             /* the remaining 1..3 pixels: */
  1016.             while (sdx) {
  1017.                 /* BGR -> palette index: */
  1018.                 register unsigned char c;
  1019.                 c = pmap[(unsigned int)
  1020.                     ((s[0] & 0xf0) >> 4) |
  1021.                     ((s[1] & 0xf0)     ) |
  1022.                     ((s[2] & 0xf0) << 4)];
  1023.                 *d = c;
  1024.                 *(d+BPP1) = c;
  1025.                 d += 2*BPP1; s += BPP3;
  1026.                 sdx --;
  1027.             }
  1028.             s -= src_dx * BPP3;
  1029.             d -= src_dx * 2*BPP1;
  1030.             /* replicate a line (vertical stretching): */
  1031.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
  1032.             /* bump pointers to the next row: */
  1033.             s += src_pitch;
  1034.             d += dest_pitch * 2;
  1035.         }
  1036.         return 0;
  1037.     }
  1038.     /* conversion is not supported */
  1039.     return -1;
  1040. }
  1041. int RGB565toRGB32 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1042.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1043.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1044.     int src_x, int src_y, int src_dx, int src_dy)
  1045. {
  1046.     return -1;   /* not implemented yet... */
  1047. }
  1048. int RGB565toRGB24 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1049.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1050.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1051.     int src_x, int src_y, int src_dx, int src_dy)
  1052. {
  1053.     return -1;   /* not implemented yet... */
  1054. }
  1055. /*
  1056.  * RGB565toRGB565() converter:
  1057.  *  1:1, 2:1
  1058.  */
  1059. int RGB565toRGB565 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1060.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1061.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1062.     int src_x, int src_y, int src_dx, int src_dy)
  1063. {
  1064.     /* scale factors: */
  1065.     int scale_x, scale_y;
  1066.     /* check arguments: */
  1067.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  1068.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  1069.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  1070.         return -1;
  1071.     /* check if bottom-up bitmaps: */
  1072.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  1073.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  1074.     /* check if 1:1 scale: */
  1075.     if (scale_x == 1 && scale_y == 1) {
  1076.         /* local variables: */
  1077.         unsigned char *s, *d;
  1078.         register int i;
  1079.         /* get pointers: */
  1080.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1081.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  1082.         /* copy image: */
  1083.         for (i = 0; i < dest_dy; i ++) {
  1084.             memcpy (d, s, dest_dx * BPP2);  /* copy dest_dx pixels */ /* Flawfinder: ignore */
  1085.             s += src_pitch;
  1086.             d += dest_pitch;
  1087.         }
  1088.         return 0;
  1089.     }
  1090.     /* check if 2:1 scale: */
  1091.     if (scale_x == 2 && scale_y == 2) {
  1092.         /* local variables: */
  1093.         unsigned char *s, *d;
  1094.         register int i;
  1095.         /* get pointers: */
  1096.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1097.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  1098.         /* stretch image: */
  1099.         for (i = 0; i < src_dy; i ++) {
  1100.             /* stretch a line: */
  1101.             register int sdx = src_dx;
  1102.             /* misaligned pixel first: */
  1103.             if (src_x & 1) {
  1104.                 register unsigned short a;
  1105.                 a = *(unsigned short *)s;
  1106.                 *(unsigned short *)d = a;
  1107.                 *(unsigned short *)(d+BPP2) = a;
  1108.                 d += 2*BPP2; s += BPP2;
  1109.                 sdx --;
  1110.             }
  1111.             /* main bulk of data: */
  1112.             while (sdx >= 2) {
  1113.                 register unsigned int a;
  1114.                 a = *(unsigned int *)s;
  1115.                 *(unsigned int *)d = (a & 0xFFFF) | (a << 16);
  1116.                 *(unsigned int *)(d+2*BPP2) = (a & 0xFFFF0000) | (a >> 16);
  1117.                 d += 2*2*BPP2; s += 2*BPP2;
  1118.                 sdx -= 2;
  1119.             }
  1120.             /* the remaining odd pixel: */
  1121.             if (sdx) {
  1122.                 register unsigned short a;
  1123.                 a = *(unsigned short *)s;
  1124.                 *(unsigned short *)d = a;
  1125.                 *(unsigned short *)(d+BPP2) = a;
  1126.                 d += 2*BPP2; s += BPP2;
  1127.             }
  1128.             s -= src_dx * BPP2;
  1129.             d -= src_dx * 2*BPP2;
  1130.             /* replicate a line (vertical stretching): */
  1131.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
  1132.             /* bump pointers to the next row: */
  1133.             s += src_pitch;
  1134.             d += dest_pitch * 2;
  1135.         }
  1136.         return 0;
  1137.     }
  1138.     /* conversion is not supported */
  1139.     return -1;
  1140. }
  1141. int RGB565toRGB555 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1142.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1143.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1144.     int src_x, int src_y, int src_dx, int src_dy)
  1145. {
  1146.     return -1;   /* not implemented yet... */
  1147. }
  1148. /*
  1149.  * No dithering yet.
  1150.  */
  1151. int RGB565toRGB8 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1152.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1153.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1154.     int src_x, int src_y, int src_dx, int src_dy)
  1155. {
  1156.     /* scale factors: */
  1157.     int scale_x, scale_y;
  1158.     /* check arguments: */
  1159.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  1160.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  1161.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  1162.         return -1;
  1163.     /* check if bottom-up bitmaps: */
  1164.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  1165.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  1166.     /* check if 1:1 scale: */
  1167.     if (scale_x == 1 && scale_y == 1) {
  1168.         /* local variables: */
  1169.         unsigned char *s, *d;
  1170.         register int i;
  1171.         /* get pointers: */
  1172.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1173.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  1174.         /* copy rows: */
  1175.         for (i = 0; i < dest_dy; i ++) {
  1176.             register int ddx = dest_dx;
  1177.             /* first odd pixel: */
  1178.             if (src_x & 1) {
  1179.                 /* gggbbbbb.rrrrrggg -> palette index: */
  1180.                 unsigned short a = *(unsigned short *)s;
  1181.                 *d = pmap[
  1182.                     ((a & 0x001E) >> 1) |
  1183.                     ((a & 0x0780) >> 3) |
  1184.                     ((a & 0xf000) >> 4)];
  1185.                 d += BPP1; s += BPP2;
  1186.                 ddx --;
  1187.             }
  1188.             /* main loop: process 2 pixels a time: */
  1189.             while (ddx >= 2) {
  1190.                 /* gggbbbbb.rrrrrggg.gggbbbbb.rrrrrggg -> 2 palette indices */
  1191.                 register unsigned int a;
  1192.                 a = *(unsigned int *)s;
  1193.                 *d = pmap[
  1194.                     ((a & 0x001e) >> 1) |
  1195.                     ((a & 0x0780) >> 3) |
  1196.                     ((a & 0xf000) >> 4)];
  1197.                 *(d+BPP1) = pmap[
  1198.                     ((a & 0x001e0000) >> 17) |
  1199.                     ((a & 0x07800000) >> 19) |
  1200.                     ((a & 0xf0000000) >> 20)];
  1201.                 d += BPP1*2; s += BPP2*2;
  1202.                 ddx -= 2;
  1203.             }
  1204.             /* the remaining odd pixel: */
  1205.             if (ddx) {
  1206.                 /* gggbbbbb.rrrrrggg -> palette index: */
  1207.                 unsigned short a = *(unsigned short *)s;
  1208.                 *d = pmap[
  1209.                     ((a & 0x001e) >> 1) |
  1210.                     ((a & 0x0780) >> 3) |
  1211.                     ((a & 0xf000) >> 4)];
  1212.                 d += BPP1; s += BPP2;
  1213.                 ddx --;
  1214.             }
  1215.             /* bump pointers to the next row: */
  1216.             s += src_pitch - dest_dx * BPP2;
  1217.             d += dest_pitch - dest_dx * BPP1;
  1218.         }
  1219.         return 0;
  1220.     }
  1221.     /* check if 2:1 scale: */
  1222.     if (scale_x == 2 && scale_y == 2) {
  1223.         /* local variables: */
  1224.         unsigned char *s, *d;
  1225.         register int i;
  1226.         /* get pointers: */
  1227.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1228.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  1229.         /* stretch image: */
  1230.         for (i = 0; i < src_dy; i ++) {
  1231.             /* stretch a line: */
  1232.             register int sdx = src_dx;
  1233.             /* first odd pixel: */
  1234.             if (src_x & 1) {
  1235.                 /* gggbbbbb.rrrrrggg -> palette index: */
  1236.                 unsigned short a = *(unsigned short *)s;
  1237.                 register unsigned char c;
  1238.                 c = pmap[
  1239.                     ((a & 0x001e) >> 1) |
  1240.                     ((a & 0x0780) >> 3) |
  1241.                     ((a & 0xf000) >> 4)];
  1242.                 *d = c;
  1243.                 *(d+BPP1) = c;
  1244.                 d += 2*BPP1; s += BPP2;
  1245.                 sdx --;
  1246.             }
  1247.             /* main bulk of data: */
  1248.             while (sdx >= 2) {
  1249.                 /* gggbbbbb.rrrrrggg.gggbbbbb.rrrrrggg -> 2 palette indices */
  1250.                 register unsigned int a;
  1251.                 register unsigned char c;
  1252.                 a = *(unsigned int *)s;
  1253.                 c = pmap[
  1254.                     ((a & 0x001e) >> 1) |
  1255.                     ((a & 0x0780) >> 3) |
  1256.                     ((a & 0xf000) >> 4)];
  1257.                 *(d+0) = c;
  1258.                 *(d+BPP1) = c;
  1259.                 c = pmap[
  1260.                     ((a & 0x001e0000) >> 17) |
  1261.                     ((a & 0x07800000) >> 19) |
  1262.                     ((a & 0xf0000000) >> 20)];
  1263.                 *(d+2*BPP1) = c;
  1264.                 *(d+3*BPP1) = c;
  1265.                 d += 2*2*BPP1; s += 2*BPP2;
  1266.                 sdx -= 2;
  1267.             }
  1268.             /* the remaining odd pixel: */
  1269.             if (sdx) {
  1270.                 /* gggbbbbb.rrrrrggg -> palette index: */
  1271.                 unsigned short a = *(unsigned short *)s;
  1272.                 register unsigned char c;
  1273.                 c = pmap[
  1274.                     ((a & 0x001e) >> 1) |
  1275.                     ((a & 0x0780) >> 3) |
  1276.                     ((a & 0xf000) >> 4)];
  1277.                 *d = c;
  1278.                 *(d+BPP1) = c;
  1279.                 d += 2*BPP1; s += BPP2;
  1280.             }
  1281.             s -= src_dx * BPP2;
  1282.             d -= src_dx * 2*BPP1;
  1283.             /* replicate a line (vertical stretching): */
  1284.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
  1285.             /* bump pointers to the next row: */
  1286.             s += src_pitch;
  1287.             d += dest_pitch * 2;
  1288.         }
  1289.         return 0;
  1290.     }
  1291.     /* conversion is not supported */
  1292.     return -1;
  1293. }
  1294. int RGB555toRGB32 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1295.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1296.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1297.     int src_x, int src_y, int src_dx, int src_dy)
  1298. {
  1299.     return -1;   /* not implemented yet... */
  1300. }
  1301. int RGB555toRGB24 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1302.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1303.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1304.     int src_x, int src_y, int src_dx, int src_dy)
  1305. {
  1306.     return -1;   /* not implemented yet... */
  1307. }
  1308. /*
  1309.  * RGB555toRGB565() converter:
  1310.  *  1:1, 2:1
  1311.  */
  1312. int RGB555toRGB565 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1313.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1314.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1315.     int src_x, int src_y, int src_dx, int src_dy)
  1316. {
  1317.     /* scale factors: */
  1318.     int scale_x, scale_y;
  1319.     /* check arguments: */
  1320.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  1321.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  1322.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  1323.         return -1;
  1324.     /* check if bottom-up bitmaps: */
  1325.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  1326.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  1327.     /* check if 1:1 scale: */
  1328.     if (scale_x == 1 && scale_y == 1) {
  1329.         /* local variables: */
  1330.         unsigned char *s, *d;
  1331.         register int i;
  1332.         /* get pointers: */
  1333.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1334.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  1335.         /* copy rows: */
  1336.         for (i = 0; i < dest_dy; i ++) {
  1337.             register int sx = src_x, ddx = dest_dx;
  1338.             /* process misaligned pixels first: */
  1339.             while ((sx & 3) && ddx) {
  1340.                 /* gggbbbbb.0rrrrrgg -> gg0bbbbb.rrrrrggg : */
  1341.                 register unsigned short c = *(unsigned short *)s;
  1342.                 *(unsigned short *)d = (c & 0x1F) | ((c & 0x7FE0) << 1);
  1343.                 d += BPP2;  s += BPP2;
  1344.                 sx ++; ddx --;
  1345.             }
  1346.             /* main loop: process 4 pixels a time: */
  1347.             while (ddx >= 4) {
  1348.                 register unsigned int a, b;
  1349.                 a = *(unsigned int *)s;     /* gggbbbbb.0rrrrrgg.gggbbbbb.0rrrrrgg */
  1350.                 b = *(unsigned int *)(s+4);
  1351.                 *(unsigned int *)d = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
  1352.                 *(unsigned int *)(d+4) = (b & 0x1F001F) | ((b & 0x7FE07FE0) << 1);
  1353.                 d += BPP2*4; s += BPP2*4; ddx -= 4;
  1354.             }
  1355.             /* process the remaining 1..3 pixels: */
  1356.             while (ddx) {
  1357.                 /* gggbbbbb.0rrrrrgg -> gg0bbbbb.rrrrrggg : */
  1358.                 register unsigned short c = *(unsigned short *)s;
  1359.                 *(unsigned short *)d = (c & 0x1F) | ((c & 0x7FE0) << 1);
  1360.                 d += BPP2;  s += BPP2;
  1361.                 ddx --;
  1362.             }
  1363.             /* bump pointers to the next row: */
  1364.             s += src_pitch - dest_dx * BPP2;
  1365.             d += dest_pitch - dest_dx * BPP2;
  1366.         }
  1367.         return 0;
  1368.     }
  1369.     /* check if 2:1 scale: */
  1370.     if (scale_x == 2 && scale_y == 2) {
  1371.         /* local variables: */
  1372.         unsigned char *s, *d;
  1373.         register int i;
  1374.         /* get pointers: */
  1375.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1376.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  1377.         /* stretch image: */
  1378.         for (i = 0; i < src_dy; i ++) {
  1379.             /* stretch a line: */
  1380.             register int sx = src_x, sdx = src_dx;
  1381.             /* misaligned pixels first: */
  1382.             while ((sx & 3) && sdx) {
  1383.                 /* gggbbbbb.0rrrrrgg -> gg0bbbbb.rrrrrggg : */
  1384.                 register unsigned short a, b;
  1385.                 a = *(unsigned short *)s;
  1386.                 b = (a & 0x1F) | ((a & 0x7FE0) << 1);
  1387.                 *(unsigned short *)d = b;
  1388.                 *(unsigned short *)(d+BPP2) = b;
  1389.                 d += 2*BPP2; s += BPP2;
  1390.                 sx ++; sdx --;
  1391.             }
  1392.             /* main bulk of data: */
  1393.             while (sdx >= 4) {
  1394.                 register unsigned int a, b;
  1395.                 a = *(unsigned int *)s;     /* gggbbbbb.0rrrrrgg.gggbbbbb.0rrrrrgg */
  1396.                 b = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
  1397.                 *(unsigned int *)d = (b & 0xFFFF) | (b << 16);
  1398.                 *(unsigned int *)(d+2*BPP2) = (b & 0xFFFF0000) | (b >> 16);
  1399.                 a = *(unsigned int *)(s+2*BPP2);
  1400.                 b = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
  1401.                 *(unsigned int *)(d+2*2*BPP2) = (b & 0xFFFF) | (b << 16);
  1402.                 *(unsigned int *)(d+3*2*BPP2) = (b & 0xFFFF0000) | (b >> 16);
  1403.                 d += 2*4*BPP2; s += 4*BPP2;
  1404.                 sdx -= 4;
  1405.             }
  1406.             /* the remaining pixels: */
  1407.             while (sdx) {
  1408.                 /* gggbbbbb.0rrrrrgg -> gg0bbbbb.rrrrrggg : */
  1409.                 register unsigned short a, b;
  1410.                 a = *(unsigned short *)s;
  1411.                 b = (a & 0x1F) | ((a & 0x7FE0) << 1);
  1412.                 *(unsigned short *)d = b;
  1413.                 *(unsigned short *)(d+BPP2) = b;
  1414.                 d += 2*BPP2; s += BPP2;
  1415.                 sdx --;
  1416.             }
  1417.             s -= src_dx * BPP2;
  1418.             d -= src_dx * 2*BPP2;
  1419.             /* replicate a line (vertical stretching): */
  1420.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
  1421.             /* bump pointers to the next row: */
  1422.             s += src_pitch;
  1423.             d += dest_pitch * 2;
  1424.         }
  1425.         return 0;
  1426.     }
  1427.     /* conversion is not supported */
  1428.     return -1;
  1429. }
  1430. /*
  1431.  * RGB555toRGB555() converter:
  1432.  *  1:1, 2:1
  1433.  */
  1434. int RGB555toRGB555 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1435.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1436.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1437.     int src_x, int src_y, int src_dx, int src_dy)
  1438. {
  1439.     /* scale factors: */
  1440.     int scale_x, scale_y;
  1441.     /* check arguments: */
  1442.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  1443.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  1444.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  1445.         return -1;
  1446.     /* check if bottom-up bitmaps: */
  1447.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  1448.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  1449.     /* check if 1:1 scale: */
  1450.     if (scale_x == 1 && scale_y == 1) {
  1451.         /* local variables: */
  1452.         unsigned char *s, *d;
  1453.         register int i;
  1454.         /* get pointers: */
  1455.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1456.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  1457.         /* copy image: */
  1458.         for (i = 0; i < dest_dy; i ++) {
  1459.             memcpy (d, s, dest_dx * BPP2);  /* copy dest_dx pixels */ /* Flawfinder: ignore */
  1460.             s += src_pitch;
  1461.             d += dest_pitch;
  1462.         }
  1463.         return 0;
  1464.     }
  1465.     /* check if 2:1 scale: */
  1466.     if (scale_x == 2 && scale_y == 2) {
  1467.         /* local variables: */
  1468.         unsigned char *s, *d;
  1469.         register int i;
  1470.         /* get pointers: */
  1471.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1472.         d = dest_ptr + dest_x * BPP2 + dest_y * dest_pitch;
  1473.         /* stretch image: */
  1474.         for (i = 0; i < src_dy; i ++) {
  1475.             /* stretch a line: */
  1476.             register int sdx = src_dx;
  1477.             /* misaligned pixel first: */
  1478.             if (src_x & 1) {
  1479.                 register unsigned short a;
  1480.                 a = *(unsigned short *)s;
  1481.                 *(unsigned short *)d = a;
  1482.                 *(unsigned short *)(d+BPP2) = a;
  1483.                 d += 2*BPP2; s += BPP2;
  1484.                 sdx --;
  1485.             }
  1486.             /* main bulk of data: */
  1487.             while (sdx >= 2) {
  1488.                 register unsigned int a;
  1489.                 a = *(unsigned int *)s;
  1490.                 *(unsigned int *)d = (a & 0xFFFF) | (a << 16);
  1491.                 *(unsigned int *)(d+2*BPP2) = (a & 0xFFFF0000) | (a >> 16);
  1492.                 d += 2*2*BPP2; s += 2*BPP2;
  1493.                 sdx -= 2;
  1494.             }
  1495.             /* the remaining odd pixel: */
  1496.             if (sdx) {
  1497.                 register unsigned short a;
  1498.                 a = *(unsigned short *)s;
  1499.                 *(unsigned short *)d = a;
  1500.                 *(unsigned short *)(d+BPP2) = a;
  1501.                 d += 2*BPP2; s += BPP2;
  1502.             }
  1503.             s -= src_dx * BPP2;
  1504.             d -= src_dx * 2*BPP2;
  1505.             /* replicate a line (vertical stretching): */
  1506.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP2); /* Flawfinder: ignore */
  1507.             /* bump pointers to the next row: */
  1508.             s += src_pitch;
  1509.             d += dest_pitch * 2;
  1510.         }
  1511.         return 0;
  1512.     }
  1513.     /* conversion is not supported */
  1514.     return -1;
  1515. }
  1516. /*
  1517.  * No dithering yet.
  1518.  */
  1519. int RGB555toRGB8 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1520.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1521.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1522.     int src_x, int src_y, int src_dx, int src_dy)
  1523. {
  1524.     /* scale factors: */
  1525.     int scale_x, scale_y;
  1526.     /* check arguments: */
  1527.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  1528.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  1529.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  1530.         return -1;
  1531.     /* check if bottom-up bitmaps: */
  1532.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  1533.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  1534.     /* check if 1:1 scale: */
  1535.     if (scale_x == 1 && scale_y == 1) {
  1536.         /* local variables: */
  1537.         unsigned char *s, *d;
  1538.         register int i;
  1539.         /* get pointers: */
  1540.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1541.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  1542.         /* copy rows: */
  1543.         for (i = 0; i < dest_dy; i ++) {
  1544.             register int ddx = dest_dx;
  1545.             /* first odd pixel: */
  1546.             if (src_x & 1) {
  1547.                 /* gggbbbbb.0rrrrrgg -> palette index: */
  1548.                 unsigned short a = *(unsigned short *)s;
  1549.                 *d = pmap[
  1550.                     ((a & 0x001e) >> 1) |
  1551.                     ((a & 0x03c0) >> 2) |
  1552.                     ((a & 0x7800) >> 3)];
  1553.                 d += BPP1; s += BPP2;
  1554.                 ddx --;
  1555.             }
  1556.             /* main loop: process 2 pixels a time: */
  1557.             while (ddx >= 2) {
  1558.                 /* gggbbbbb.0rrrrrgg.gggbbbbb.0rrrrrgg -> 2 palette indices */
  1559.                 register unsigned int a;
  1560.                 a = *(unsigned int *)s;
  1561.                 *d = pmap[
  1562.                     ((a & 0x001e) >> 1) |
  1563.                     ((a & 0x03c0) >> 2) |
  1564.                     ((a & 0x7800) >> 3)];
  1565.                 *(d+BPP1) = pmap[
  1566.                     ((a & 0x001e0000) >> 17) |
  1567.                     ((a & 0x03c00000) >> 18) |
  1568.                     ((a & 0x78000000) >> 19)];
  1569.                 d += BPP1*2; s += BPP2*2;
  1570.                 ddx -= 2;
  1571.             }
  1572.             /* the remaining odd pixel: */
  1573.             if (ddx) {
  1574.                 /* gggbbbbb.0rrrrrgg -> palette index: */
  1575.                 unsigned short a = *(unsigned short *)s;
  1576.                 *d = pmap[
  1577.                     ((a & 0x001e) >> 1) |
  1578.                     ((a & 0x03c0) >> 2) |
  1579.                     ((a & 0x7800) >> 3)];
  1580.                 d += BPP1; s += BPP2;
  1581.                 ddx --;
  1582.             }
  1583.             /* bump pointers to the next row: */
  1584.             s += src_pitch - dest_dx * BPP2;
  1585.             d += dest_pitch - dest_dx * BPP1;
  1586.         }
  1587.         return 0;
  1588.     }
  1589.     /* check if 2:1 scale: */
  1590.     if (scale_x == 2 && scale_y == 2) {
  1591.         /* local variables: */
  1592.         unsigned char *s, *d;
  1593.         register int i;
  1594.         /* get pointers: */
  1595.         s = src_ptr + src_x * BPP2 + src_y * src_pitch;
  1596.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  1597.         /* stretch image: */
  1598.         for (i = 0; i < src_dy; i ++) {
  1599.             /* stretch a line: */
  1600.             register int sdx = src_dx;
  1601.             /* first odd pixel: */
  1602.             if (src_x & 1) {
  1603.                 /* gggbbbbb.0rrrrrgg -> palette index: */
  1604.                 unsigned short a = *(unsigned short *)s;
  1605.                 register unsigned char c;
  1606.                 c = pmap[
  1607.                     ((a & 0x001e) >> 1) |
  1608.                     ((a & 0x03c0) >> 2) |
  1609.                     ((a & 0x7800) >> 3)];
  1610.                 *d = c;
  1611.                 *(d+BPP1) = c;
  1612.                 d += 2*BPP1; s += BPP2;
  1613.                 sdx --;
  1614.             }
  1615.             /* main bulk of data: */
  1616.             while (sdx >= 2) {
  1617.                 /* gggbbbbb.0rrrrrgg.gggbbbbb.0rrrrrgg -> 2 palette indices */
  1618.                 register unsigned int a;
  1619.                 register unsigned char c;
  1620.                 a = *(unsigned int *)s;
  1621.                 c = pmap[
  1622.                     ((a & 0x001e) >> 1) |
  1623.                     ((a & 0x03c0) >> 2) |
  1624.                     ((a & 0x7800) >> 3)];
  1625.                 *(d+0) = c;
  1626.                 *(d+BPP1) = c;
  1627.                 c = pmap[
  1628.                     ((a & 0x001e0000) >> 17) |
  1629.                     ((a & 0x03c00000) >> 18) |
  1630.                     ((a & 0x78000000) >> 19)];
  1631.                 *(d+2*BPP1) = c;
  1632.                 *(d+3*BPP1) = c;
  1633.                 d += 2*2*BPP1; s += 2*BPP2;
  1634.                 sdx -= 2;
  1635.             }
  1636.             /* the remaining odd pixel: */
  1637.             if (sdx) {
  1638.                 /* gggbbbbb.0rrrrrgg -> palette index: */
  1639.                 unsigned short a = *(unsigned short *)s;
  1640.                 register unsigned char c;
  1641.                 c = pmap[
  1642.                     ((a & 0x001e) >> 1) |
  1643.                     ((a & 0x03c0) >> 2) |
  1644.                     ((a & 0x7800) >> 3)];
  1645.                 *d = c;
  1646.                 *(d+BPP1) = c;
  1647.                 d += 2*BPP1; s += BPP2;
  1648.             }
  1649.             s -= src_dx * BPP2;
  1650.             d -= src_dx * 2*BPP1;
  1651.             /* replicate a line (vertical stretching): */
  1652.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
  1653.             /* bump pointers to the next row: */
  1654.             s += src_pitch;
  1655.             d += dest_pitch * 2;
  1656.         }
  1657.         return 0;
  1658.     }
  1659.     /* conversion is not supported */
  1660.     return -1;
  1661. }
  1662. int RGB8toRGB32 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1663.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1664.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1665.     int src_x, int src_y, int src_dx, int src_dy)
  1666. {
  1667.     return -1;   /* not implemented yet... */
  1668. }
  1669. int RGB8toRGB24 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1670.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1671.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1672.     int src_x, int src_y, int src_dx, int src_dy)
  1673. {
  1674.     return -1;   /* not implemented yet... */
  1675. }
  1676. int RGB8toRGB565 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1677.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1678.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1679.     int src_x, int src_y, int src_dx, int src_dy)
  1680. {
  1681.     return -1;   /* not implemented yet... */
  1682. }
  1683. int RGB8toRGB555 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1684.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1685.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1686.     int src_x, int src_y, int src_dx, int src_dy)
  1687. {
  1688.     return -1;   /* not implemented yet... */
  1689. }
  1690. /*
  1691.  * RGB8toRGB8() converter:
  1692.  *  1:1, 2:1
  1693.  */
  1694. int RGB8toRGB8 (unsigned char *dest_ptr, int dest_width, int dest_height,
  1695.     int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
  1696.     unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
  1697.     int src_x, int src_y, int src_dx, int src_dy)
  1698. {
  1699.     /* scale factors: */
  1700.     int scale_x, scale_y;
  1701.     /* check arguments: */
  1702.     if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
  1703.         dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
  1704.         src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
  1705.         return -1;
  1706.     /* check if bottom-up bitmaps: */
  1707.     if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;
  1708.     if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
  1709.     /* check if 1:1 scale: */
  1710.     if (scale_x == 1 && scale_y == 1) {
  1711.         /* local variables: */
  1712.         unsigned char *s, *d;
  1713.         register int i;
  1714.         /* get pointers: */
  1715.         s = src_ptr + src_x * BPP1 + src_y * src_pitch;
  1716.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  1717.         /* copy image: */
  1718.         for (i = 0; i < dest_dy; i ++) {
  1719.             memcpy (d, s, dest_dx * BPP1);  /* copy dest_dx pixels */ /* Flawfinder: ignore */
  1720.             s += src_pitch;
  1721.             d += dest_pitch;
  1722.         }
  1723.         return 0;
  1724.     }
  1725.     /* check if 2:1 scale: */
  1726.     if (scale_x == 2 && scale_y == 2) {
  1727.         /* local variables: */
  1728.         unsigned char *s, *d;
  1729.         register int i;
  1730.         /* get pointers: */
  1731.         s = src_ptr + src_x * BPP1 + src_y * src_pitch;
  1732.         d = dest_ptr + dest_x * BPP1 + dest_y * dest_pitch;
  1733.         /* stretch image: */
  1734.         for (i = 0; i < src_dy; i ++) {
  1735.             /* stretch a line: */
  1736.             register int sx = src_x, sdx = src_dx;
  1737.             /* misaligned pixels first: */
  1738.             while ((sx & 3) && sdx) {
  1739.                 register unsigned char a;
  1740.                 a = *s; *d = a; *(d+BPP1) = a;
  1741.                 d += 2*BPP1; s += BPP1;
  1742.                 sx ++; sdx --;
  1743.             }
  1744.             /* main bulk of data: */
  1745.             while (sdx >= 4) {
  1746.                 register unsigned int a;
  1747.                 a = *(unsigned int *)s;
  1748.                 *(unsigned int *)d = (a & 0xFF) | ((a & 0xFFFF) << 8) | ((a & 0xFF00) << 16);
  1749.                 *(unsigned int *)(d+4*BPP1) = (a & 0xFF000000) | ((a & 0xFFFF0000) >> 8) | ((a & 0xFF0000) >> 16);
  1750.                 d += 2*4*BPP1; s += 4*BPP1;
  1751.                 sdx -= 4;
  1752.             }
  1753.             /* the remaining 1..3 pixels: */
  1754.             while (sdx) {
  1755.                 register unsigned char a;
  1756.                 a = *s; *d = a; *(d+BPP1) = a;
  1757.                 d += 2*BPP1; s += BPP1;
  1758.                 sdx --;
  1759.             }
  1760.             s -= src_dx * BPP1;
  1761.             d -= src_dx * 2*BPP1;
  1762.             /* replicate a line (vertical stretching): */
  1763.             memcpy (d + dest_pitch, d, src_dx * 2 * BPP1); /* Flawfinder: ignore */
  1764.             /* bump pointers to the next row: */
  1765.             s += src_pitch;
  1766.             d += dest_pitch * 2;
  1767.         }
  1768.         return 0;
  1769.     }
  1770.     /* conversion is not supported */
  1771.     return -1;
  1772. }
  1773. /*
  1774.  * Old I420->RGB converters:
  1775.  * Use:
  1776.  *  void oldI420toRGBXXX (unsigned char *ysrc, unsigned char *usrc,
  1777.  *          unsigned char *vsrc, int pitchSrc, unsigned char *dst,
  1778.  *          int width, int height, int pitchDst);
  1779.  * Input:
  1780.  *  ysrc, usrc, vsrc - pointers to Y, Cr, and Cb components of the frame
  1781.  *  pitchSrc - pitch of the input frame (luminance)
  1782.  *  dst - pointer to an output buffer
  1783.  *  width, height - the size of frame to convert
  1784.  *  pitchDst - pitch of the output buffer (in RGB pixels!!!)
  1785.  * Returns:
  1786.  *  none.
  1787.  */
  1788. /* the driver function: */
  1789. static int oldI420toRGB (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  1790.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst, int bpp,
  1791.     void (* dbline) (unsigned char *d1, unsigned char *d2, int dest_x,
  1792.     unsigned char *sy1, unsigned char *sy2, unsigned char *su, unsigned char *sv,
  1793.     int src_x, int dx))
  1794. {
  1795.     unsigned char *sy1, *sy2, *sv, *su, *d1, *d2;
  1796.     register int j, pitch = pitchDst * bpp;
  1797.     /* bump dest to other end, if bottom-up output: */
  1798.     if (pitch < 0)
  1799.         dst += -pitch * (height-1);                     /* start of last line */
  1800.     /* get pointers: */
  1801.     sy1 = ysrc;                                         /* luma offset */
  1802.     sy2 = sy1  + pitchSrc;
  1803.     su  = usrc;                                         /* chroma offset */
  1804.     sv  = vsrc;
  1805.     d1  = dst;                                          /* RGB offset */
  1806.     d2  = d1 + pitch;
  1807.     /* convert aligned portion of the image: */
  1808.     for (j = 0; j < height/2; j ++) {
  1809.         /* convert two lines a time: */
  1810.         (* dbline) (d1, d2, 0, sy1, sy2, su, sv, 0, width);
  1811.         sy1 += pitchSrc*2; sy2 += pitchSrc*2;
  1812.         su  += pitchSrc/2; sv  += pitchSrc/2;
  1813.         d1  += pitch*2; d2  += pitch*2;
  1814.     }
  1815.     return 0;
  1816. }
  1817. /* actual converters: */
  1818. void oldI420toRGB32 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  1819.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
  1820. {
  1821.     oldI420toRGB (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 4,
  1822.         is_alpha? dblineI420toRGB32alpha: dblineI420toRGB32);
  1823. }
  1824. void oldI420toRGB24 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  1825.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
  1826. {
  1827.     oldI420toRGB (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 3,
  1828.         is_alpha? dblineI420toRGB24alpha: dblineI420toRGB24);
  1829. }
  1830. void oldI420toRGB565 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  1831.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
  1832. {
  1833.     oldI420toRGB (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 2,
  1834.         is_alpha? dblineI420toRGB565alpha: dblineI420toRGB565);
  1835. }
  1836. void oldI420toRGB555 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  1837.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
  1838. {
  1839.     oldI420toRGB (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 2,
  1840.         is_alpha? dblineI420toRGB555alpha: dblineI420toRGB555);
  1841. }
  1842. /*
  1843.  * Convert two YUV lines into RGB linebufs.
  1844.  * Produces two RGB lines per call.
  1845.  * Output in padded RGB format, needed for SIMD interpolation.
  1846.  */
  1847. static void convertI420toXRGB (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  1848.     unsigned char *buf1, unsigned char *buf2, int width, int pitchSrc)
  1849. {
  1850.     unsigned char * ysrc2 = ysrc + pitchSrc;
  1851.     if (is_alpha) {
  1852.         /* use full matrix: */
  1853.         for (; width; width -= 2) {
  1854.             int ruv, guv, buv, y;
  1855.             buv = butab[usrc[0]] + bvtab[vsrc[0]];
  1856.             guv = gutab[usrc[0]] + gvtab[vsrc[0]];
  1857.             ruv = rutab[usrc[0]] + rvtab[vsrc[0]];
  1858.             /* store as |00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB| */
  1859.             y = ytab[ysrc[0]];
  1860.             *(int *)(buf1+0) =
  1861.                 (CLIP8[y + buv] << 0) |
  1862.                 (CLIP8[y + guv] << 11) |
  1863.                 (CLIP8[y + ruv] << 22);
  1864.             y = ytab[ysrc[1]];
  1865.             *(int *)(buf1+4) =
  1866.                 (CLIP8[y + buv] << 0) |
  1867.                 (CLIP8[y + guv] << 11) |
  1868.                 (CLIP8[y + ruv] << 22);
  1869.             y = ytab[ysrc2[0]];
  1870.             *(int *)(buf2+0) =
  1871.                 (CLIP8[y + buv] << 0) |
  1872.                 (CLIP8[y + guv] << 11) |
  1873.                 (CLIP8[y + ruv] << 22);
  1874.             y = ytab[ysrc2[1]];
  1875.             *(int *)(buf2+4) =
  1876.                 (CLIP8[y + buv] << 0) |
  1877.                 (CLIP8[y + guv] << 11) |
  1878.                 (CLIP8[y + ruv] << 22);
  1879.             /* next 2x2 block */
  1880.             ysrc += 2; ysrc2 += 2;
  1881.             usrc += 1; vsrc += 1;
  1882.             buf1 += 8; buf2 += 8;
  1883.         }
  1884.     } else {
  1885.         /* no chroma rotation: */
  1886.         for (; width; width -= 2) {
  1887.             int rv, guv, bu, y;
  1888.             bu = butab[usrc[0]];
  1889.             guv = gutab[usrc[0]] + gvtab[vsrc[0]];
  1890.             rv = rvtab[vsrc[0]];
  1891.             /* store as |00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB| */
  1892.             y = ytab[ysrc[0]];
  1893.             *(int *)(buf1+0) =
  1894.                 (CLIP8[y + bu] << 0) |
  1895.                 (CLIP8[y + guv] << 11) |
  1896.                 (CLIP8[y + rv] << 22);
  1897.             y = ytab[ysrc[1]];
  1898.             *(int *)(buf1+4) =
  1899.                 (CLIP8[y + bu] << 0) |
  1900.                 (CLIP8[y + guv] << 11) |
  1901.                 (CLIP8[y + rv] << 22);
  1902.             y = ytab[ysrc2[0]];
  1903.             *(int *)(buf2+0) =
  1904.                 (CLIP8[y + bu] << 0) |
  1905.                 (CLIP8[y + guv] << 11) |
  1906.                 (CLIP8[y + rv] << 22);
  1907.             y = ytab[ysrc2[1]];
  1908.             *(int *)(buf2+4) =
  1909.                 (CLIP8[y + bu] << 0) |
  1910.                 (CLIP8[y + guv] << 11) |
  1911.                 (CLIP8[y + rv] << 22);
  1912.             /* next 2x2 block */
  1913.             ysrc += 2; ysrc2 += 2;
  1914.             usrc += 1; vsrc += 1;
  1915.             buf1 += 8; buf2 += 8;
  1916.         }
  1917.     }
  1918. }
  1919. /*
  1920.  * Interpolate and pack RGB lines into final output
  1921.  * Produces two output lines per call.
  1922.  * Requires padded RGB for SIMD interpolation.
  1923.  */
  1924. #define ROUND888 0x00400801
  1925. /* RGB32 version: */
  1926. static void interpRGB32 (unsigned char *src1, unsigned char *src2,
  1927.     unsigned char *dst1, unsigned char *dst2, int width)
  1928. {
  1929.     unsigned int a, b, c, d, e, f;
  1930.     unsigned int w, x, y, z;
  1931.     width >>= 1;                /* two per pass */
  1932.     while (--width) {           /* do all but last pair */
  1933.     /*
  1934.      * Input pels       Output pels
  1935.      *  a b e           w  x  y  z
  1936.      *  c d f           w' x' y' z'
  1937.      *
  1938.      * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
  1939.      */
  1940.         /* top line */
  1941.         a = *(unsigned int *)(src1+0);
  1942.         b = *(unsigned int *)(src1+4);
  1943.         e = *(unsigned int *)(src1+8);
  1944.         w = a;
  1945.         x = a + b + ROUND888;
  1946.         y = b;
  1947.         z = b + e + ROUND888;
  1948.         /* pack and store */
  1949.         *(unsigned int *)(dst1+0) =
  1950.             ((w & 0x000000ff) >> 0) |
  1951.             ((w & 0x0007f800) >> 3) |
  1952.             ((w & 0x3fc00000) >> 6);
  1953.         *(unsigned int *)(dst1+4) =
  1954.             ((x & 0x000001fe) >> 1) |
  1955.             ((x & 0x000ff000) >> 4) |
  1956.             ((x & 0x7f800000) >> 7);
  1957.         *(unsigned int *)(dst1+8) =
  1958.             ((y & 0x000000ff) >> 0) |
  1959.             ((y & 0x0007f800) >> 3) |
  1960.             ((y & 0x3fc00000) >> 6);
  1961.         *(unsigned int *)(dst1+12) =
  1962.             ((z & 0x000001fe) >> 1) |
  1963.             ((z & 0x000ff000) >> 4) |
  1964.             ((z & 0x7f800000) >> 7);
  1965.         /* bottom line */
  1966.         c = *(unsigned int *)(src2+0);
  1967.         d = *(unsigned int *)(src2+4);
  1968.         f = *(unsigned int *)(src2+8);
  1969.         w = a + c + ROUND888;
  1970.         x = a + b + c + d + (ROUND888<<1);
  1971.         y = b + d + ROUND888;
  1972.         z = b + e + d + f + (ROUND888<<1);
  1973.         /* pack and store */
  1974.         *(unsigned int *)(dst2+0) =
  1975.             ((w & 0x000001fe) >> 1) |
  1976.             ((w & 0x000ff000) >> 4) |
  1977.             ((w & 0x7f800000) >> 7);
  1978.         *(unsigned int *)(dst2+4) =
  1979.             ((x & 0x000003fc) >> 2) |
  1980.             ((x & 0x001fe000) >> 5) |
  1981.             ((x & 0xff000000) >> 8);
  1982.         *(unsigned int *)(dst2+8) =
  1983.             ((y & 0x000001fe) >> 1) |
  1984.             ((y & 0x000ff000) >> 4) |
  1985.             ((y & 0x7f800000) >> 7);
  1986.         *(unsigned int *)(dst2+12) =
  1987.             ((z & 0x000003fc) >> 2) |
  1988.             ((z & 0x001fe000) >> 5) |
  1989.             ((z & 0xff000000) >> 8);
  1990.         /* bump pointers to next 2x2 input */
  1991.         src1 += 8; src2 += 8;
  1992.         dst1 += 16; dst2 += 16;
  1993.     }
  1994.     /*
  1995.      * For last 4 output pels, repeat final input pel
  1996.      * for offscreen input.  Equivalent to pixel-doubling the
  1997.      * last output pel.
  1998.      */
  1999.     /* top line */
  2000.     a = *(unsigned int *)(src1+0);
  2001.     b = *(unsigned int *)(src1+4);
  2002.     e = b;      /* repeat last input pel */
  2003.     w = a;
  2004.     x = a + b + ROUND888;
  2005.     y = b;
  2006.     z = b + e + ROUND888;
  2007.     /* pack and store */
  2008.     *(unsigned int *)(dst1+0) =
  2009.         ((w & 0x000000ff) >> 0) |
  2010.         ((w & 0x0007f800) >> 3) |
  2011.         ((w & 0x3fc00000) >> 6);
  2012.     *(unsigned int *)(dst1+4) =
  2013.         ((x & 0x000001fe) >> 1) |
  2014.         ((x & 0x000ff000) >> 4) |
  2015.         ((x & 0x7f800000) >> 7);
  2016.     *(unsigned int *)(dst1+8) =
  2017.         ((y & 0x000000ff) >> 0) |
  2018.         ((y & 0x0007f800) >> 3) |
  2019.         ((y & 0x3fc00000) >> 6);
  2020.     *(unsigned int *)(dst1+12) =
  2021.         ((z & 0x000001fe) >> 1) |
  2022.         ((z & 0x000ff000) >> 4) |
  2023.         ((z & 0x7f800000) >> 7);
  2024.     /* bottom line */
  2025.     c = *(unsigned int *)(src2+0);
  2026.     d = *(unsigned int *)(src2+4);
  2027.     f = d;      /* repeat last input pel */
  2028.     w = a + c + ROUND888;
  2029.     x = a + b + c + d + (ROUND888<<1);
  2030.     y = b + d + ROUND888;
  2031.     z = b + e + d + f + (ROUND888<<1);
  2032.     /* pack and store */
  2033.     *(unsigned int *)(dst2+0) =
  2034.         ((w & 0x000001fe) >> 1) |
  2035.         ((w & 0x000ff000) >> 4) |
  2036.         ((w & 0x7f800000) >> 7);
  2037.     *(unsigned int *)(dst2+4) =
  2038.         ((x & 0x000003fc) >> 2) |
  2039.         ((x & 0x001fe000) >> 5) |
  2040.         ((x & 0xff000000) >> 8);
  2041.     *(unsigned int *)(dst2+8) =
  2042.         ((y & 0x000001fe) >> 1) |
  2043.         ((y & 0x000ff000) >> 4) |
  2044.         ((y & 0x7f800000) >> 7);
  2045.     *(unsigned int *)(dst2+12) =
  2046.         ((z & 0x000003fc) >> 2) |
  2047.         ((z & 0x001fe000) >> 5) |
  2048.         ((z & 0xff000000) >> 8);
  2049. }
  2050. /* RGB24 version: */
  2051. static void interpRGB24 (unsigned char *src1, unsigned char *src2,
  2052.     unsigned char *dst1, unsigned char *dst2, int width)
  2053. {
  2054.     unsigned int a, b, c, d, e, f;
  2055.     unsigned int w, x, y, z;
  2056.     width >>= 1;        /* two per pass */
  2057.     while (--width) {   /* do all but last pair */
  2058.     /*
  2059.      * Input pels       Output pels
  2060.      *  a b e           w  x  y  z
  2061.      *  c d f           w' x' y' z'
  2062.      *
  2063.      * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
  2064.      */
  2065.         /* top line */
  2066.         a = *(unsigned int *)(src1+0);
  2067.         b = *(unsigned int *)(src1+4);
  2068.         e = *(unsigned int *)(src1+8);
  2069.         w = a;
  2070.         x = a + b + ROUND888;
  2071.         y = b;
  2072.         z = b + e + ROUND888;
  2073.         /* pack and store */
  2074.         *(unsigned int *)(dst1+0) =
  2075.             ((w & 0x000000ff) >> 0) |
  2076.             ((w & 0x0007f800) >> 3) |
  2077.             ((w & 0x3fc00000) >> 6) |
  2078.             ((x & 0x000001fe) << 23);
  2079.         *(unsigned int *)(dst1+4) =
  2080.             ((x & 0x000ff000) >> 12) |
  2081.             ((x & 0x7f800000) >> 15) |
  2082.             ((y & 0x000000ff) << 16) |
  2083.             ((y & 0x0007f800) << 13);
  2084.         *(unsigned int *)(dst1+8) =
  2085.             ((y & 0x3fc00000) >> 22) |
  2086.             ((z & 0x000001fe) << 7) |
  2087.             ((z & 0x000ff000) << 4) |
  2088.             ((z & 0x7f800000) << 1);
  2089.         /* bottom line */
  2090.         c = *(unsigned int *)(src2+0);
  2091.         d = *(unsigned int *)(src2+4);
  2092.         f = *(unsigned int *)(src2+8);
  2093.         w = a + c + ROUND888;
  2094.         x = a + b + c + d + (ROUND888<<1);
  2095.         y = b + d + ROUND888;
  2096.         z = b + e + d + f + (ROUND888<<1);
  2097.         /* pack and store */
  2098.         *(unsigned int *)(dst2+0) =
  2099.             ((w & 0x000001fe) >> 1) |
  2100.             ((w & 0x000ff000) >> 4) |
  2101.             ((w & 0x7f800000) >> 7) |
  2102.             ((x & 0x000003fc) << 22);
  2103.         *(unsigned int *)(dst2+4) =
  2104.             ((x & 0x001fe000) >> 13) |
  2105.             ((x & 0xff000000) >> 16) |
  2106.             ((y & 0x000001fe) << 15) |
  2107.             ((y & 0x000ff000) << 12);
  2108.         *(unsigned int *)(dst2+8) =
  2109.             ((y & 0x7f800000) >> 23) |
  2110.             ((z & 0x000003fc) << 6) |
  2111.             ((z & 0x001fe000) << 3) |
  2112.             ((z & 0xff000000) << 0);
  2113.         /* next 2x2 input block */
  2114.         src1 += 8; src2 += 8;
  2115.         dst1 += 12; dst2 += 12;
  2116.     }
  2117.     /*
  2118.      * For last 4 output pels, repeat the final input pel for
  2119.      * for missing input.  Equivalent to pixel-doubling the
  2120.      * last output pel.
  2121.      */
  2122.     /* top line */
  2123.     a = *(unsigned int *)(src1+0);
  2124.     b = *(unsigned int *)(src1+4);
  2125.     e = b;      /* repeat last input pel */
  2126.     w = a;
  2127.     x = a + b + ROUND888;
  2128.     y = b;
  2129.     z = b + e + ROUND888;
  2130.     /* pack and store */
  2131.     *(unsigned int *)(dst1+0) =
  2132.         ((w & 0x000000ff) >> 0) |
  2133.         ((w & 0x0007f800) >> 3) |
  2134.         ((w & 0x3fc00000) >> 6) |
  2135.         ((x & 0x000001fe) << 23);
  2136.     *(unsigned int *)(dst1+4) =
  2137.         ((x & 0x000ff000) >> 12) |
  2138.         ((x & 0x7f800000) >> 15) |
  2139.         ((y & 0x000000ff) << 16) |
  2140.         ((y & 0x0007f800) << 13);
  2141.     *(unsigned int *)(dst1+8) =
  2142.         ((y & 0x3fc00000) >> 22) |
  2143.         ((z & 0x000001fe) << 7) |
  2144.         ((z & 0x000ff000) << 4) |
  2145.         ((z & 0x7f800000) << 1);
  2146.     /* bottom line */
  2147.     c = *(unsigned int *)(src2+0);
  2148.     d = *(unsigned int *)(src2+4);
  2149.     f = d;      /* repeat last input pel */
  2150.     w = a + c + ROUND888;
  2151.     x = a + b + c + d + (ROUND888<<1);
  2152.     y = b + d + ROUND888;
  2153.     z = b + e + d + f + (ROUND888<<1);
  2154.     /* pack and store */
  2155.     *(unsigned int *)(dst2+0) =
  2156.         ((w & 0x000001fe) >> 1) |
  2157.         ((w & 0x000ff000) >> 4) |
  2158.         ((w & 0x7f800000) >> 7) |
  2159.         ((x & 0x000003fc) << 22);
  2160.     *(unsigned int *)(dst2+4) =
  2161.         ((x & 0x001fe000) >> 13) |
  2162.         ((x & 0xff000000) >> 16) |
  2163.         ((y & 0x000001fe) << 15) |
  2164.         ((y & 0x000ff000) << 12);
  2165.     *(unsigned int *)(dst2+8) =
  2166.         ((y & 0x7f800000) >> 23) |
  2167.         ((z & 0x000003fc) << 6) |
  2168.         ((z & 0x001fe000) << 3) |
  2169.         ((z & 0xff000000) << 0);
  2170. }
  2171. /* RGB565 version: */
  2172. static void interpRGB565 (unsigned char *src1, unsigned char *src2,
  2173.     unsigned char *dst1, unsigned char *dst2, int width)
  2174. {
  2175.     unsigned int a, b, c, d, e, f;
  2176.     unsigned int w, x, y, z;
  2177.     width >>= 1;        /* two per pass */
  2178.     while (--width) {   /* do all but last pair */
  2179.     /*
  2180.      * Input pels       Output pels
  2181.      *  a b e           w  x  y  z
  2182.      *  c d f           w' x' y' z'
  2183.      *
  2184.      * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
  2185.      */
  2186.         /* top line */
  2187.         a = *(unsigned int *)(src1+0);
  2188.         b = *(unsigned int *)(src1+4);
  2189.         e = *(unsigned int *)(src1+8);
  2190.         w = a;
  2191.         x = a + b;
  2192.         y = b;
  2193.         z = b + e;
  2194.         /* pack and store */
  2195.         *(unsigned int *)(dst1+0) =
  2196.             ((w & 0x000000f8) >> 3) |
  2197.             ((w & 0x0007e000) >> 8) |
  2198.             ((w & 0x3e000000) >> 14) |
  2199.             ((x & 0x000001f0) << 12) |
  2200.             ((x & 0x000fc000) << 7) |
  2201.             ((x & 0x7c000000) << 1);
  2202.         *(unsigned int *)(dst1+4) =
  2203.             ((y & 0x000000f8) >> 3) |
  2204.             ((y & 0x0007e000) >> 8) |
  2205.             ((y & 0x3e000000) >> 14) |
  2206.             ((z & 0x000001f0) << 12) |
  2207.             ((z & 0x000fc000) << 7) |
  2208.             ((z & 0x7c000000) << 1);
  2209.         /* bottom line */
  2210.         c = *(unsigned int *)(src2+0);
  2211.         d = *(unsigned int *)(src2+4);
  2212.         f = *(unsigned int *)(src2+8);
  2213.         w = a + c;
  2214.         x = a + b + c + d;
  2215.         y = b + d;
  2216.         z = b + e + d + f;
  2217.         /* pack and store */
  2218.         *(unsigned int *)(dst2+0) =
  2219.             ((w & 0x000001f0) >> 4) |
  2220.             ((w & 0x000fc000) >> 9) |
  2221.             ((w & 0x7c000000) >> 15) |
  2222.             ((x & 0x000003e0) << 11) |
  2223.             ((x & 0x001f8000) << 6) |
  2224.             ((x & 0xf8000000) << 0);
  2225.         *(unsigned int *)(dst2+4) =
  2226.             ((y & 0x000001f0) >> 4) |
  2227.             ((y & 0x000fc000) >> 9) |
  2228.             ((y & 0x7c000000) >> 15) |
  2229.             ((z & 0x000003e0) << 11) |
  2230.             ((z & 0x001f8000) << 6) |
  2231.             ((z & 0xf8000000) << 0);
  2232.         /* next 2x2 input block */
  2233.         src1 += 8; src2 += 8;
  2234.         dst1 += 8; dst2 += 8;
  2235.     }
  2236.     /*
  2237.      * For last 4 output pels, repeat the final input pel for
  2238.      * for missing input.  Equivalent to pixel-doubling the
  2239.      * last output pel.
  2240.      */
  2241.     /* top line */
  2242.     a = *(unsigned int *)(src1+0);
  2243.     b = *(unsigned int *)(src1+4);
  2244.     e = b;      /* repeat last input pel */
  2245.     w = a;
  2246.     x = a + b;
  2247.     y = b;
  2248.     z = b + e;
  2249.     /* pack and store */
  2250.     *(unsigned int *)(dst1+0) =
  2251.         ((w & 0x000000f8) >> 3) |
  2252.         ((w & 0x0007e000) >> 8) |
  2253.         ((w & 0x3e000000) >> 14) |
  2254.         ((x & 0x000001f0) << 12) |
  2255.         ((x & 0x000fc000) << 7) |
  2256.         ((x & 0x7c000000) << 1);
  2257.     *(unsigned int *)(dst1+4) =
  2258.         ((y & 0x000000f8) >> 3) |
  2259.         ((y & 0x0007e000) >> 8) |
  2260.         ((y & 0x3e000000) >> 14) |
  2261.         ((z & 0x000001f0) << 12) |
  2262.         ((z & 0x000fc000) << 7) |
  2263.         ((z & 0x7c000000) << 1);
  2264.     /* bottom line */
  2265.     c = *(unsigned int *)(src2+0);
  2266.     d = *(unsigned int *)(src2+4);
  2267.     f = d;      /* repeat last input pel */
  2268.     w = a + c;
  2269.     x = a + b + c + d;
  2270.     y = b + d;
  2271.     z = b + e + d + f;
  2272.     /* pack and store */
  2273.     *(unsigned int *)(dst2+0) =
  2274.         ((w & 0x000001f0) >> 4) |
  2275.         ((w & 0x000fc000) >> 9) |
  2276.         ((w & 0x7c000000) >> 15) |
  2277.         ((x & 0x000003e0) << 11) |
  2278.         ((x & 0x001f8000) << 6) |
  2279.         ((x & 0xf8000000) << 0);
  2280.     *(unsigned int *)(dst2+4) =
  2281.         ((y & 0x000001f0) >> 4) |
  2282.         ((y & 0x000fc000) >> 9) |
  2283.         ((y & 0x7c000000) >> 15) |
  2284.         ((z & 0x000003e0) << 11) |
  2285.         ((z & 0x001f8000) << 6) |
  2286.         ((z & 0xf8000000) << 0);
  2287. }
  2288. /* RGB555 version: */
  2289. static void interpRGB555 (unsigned char *src1, unsigned char *src2,
  2290.     unsigned char *dst1, unsigned char *dst2, int width)
  2291. {
  2292.     unsigned int a, b, c, d, e, f;
  2293.     unsigned int w, x, y, z;
  2294.     width >>= 1;        /* two per pass */
  2295.     while (--width) {   /* do all but last pair */
  2296.     /*
  2297.      * Input pels       Output pels
  2298.      *  a b e           w  x  y  z
  2299.      *  c d f           w' x' y' z'
  2300.      *
  2301.      * Input stored as 00 RRRRRRRR 000 GGGGGGGG 000 BBBBBBBB
  2302.      */
  2303.         /* top line */
  2304.         a = *(unsigned int *)(src1+0);
  2305.         b = *(unsigned int *)(src1+4);
  2306.         e = *(unsigned int *)(src1+8);
  2307.         w = a;
  2308.         x = a + b;
  2309.         y = b;
  2310.         z = b + e;
  2311.         /* pack and store */
  2312.         *(unsigned int *)(dst1+0) =
  2313.             ((w & 0x000000f8) >> 3) |
  2314.             ((w & 0x0007c000) >> 9) |
  2315.             ((w & 0x3e000000) >> 15) |
  2316.             ((x & 0x000001f0) << 12) |
  2317.             ((x & 0x000f8000) << 6) |
  2318.             ((x & 0x7c000000) << 0);
  2319.         *(unsigned int *)(dst1+4) =
  2320.             ((y & 0x000000f8) >> 3) |
  2321.             ((y & 0x0007c000) >> 9) |
  2322.             ((y & 0x3e000000) >> 15) |
  2323.             ((z & 0x000001f0) << 12) |
  2324.             ((z & 0x000f8000) << 6) |
  2325.             ((z & 0x7c000000) << 0);
  2326.         /* bottom line */
  2327.         c = *(unsigned int *)(src2+0);
  2328.         d = *(unsigned int *)(src2+4);
  2329.         f = *(unsigned int *)(src2+8);
  2330.         w = a + c;
  2331.         x = a + b + c + d;
  2332.         y = b + d;
  2333.         z = b + e + d + f;
  2334.         /* pack and store */
  2335.         *(unsigned int *)(dst2+0) =
  2336.             ((w & 0x000001f0) >> 4) |
  2337.             ((w & 0x000f8000) >> 10) |
  2338.             ((w & 0x7c000000) >> 16) |
  2339.             ((x & 0x000003e0) << 11) |
  2340.             ((x & 0x001f0000) << 5) |
  2341.             ((x & 0xf8000000) >> 1);
  2342.         *(unsigned int *)(dst2+4) =
  2343.             ((y & 0x000001f0) >> 4) |
  2344.             ((y & 0x000f8000) >> 10) |
  2345.             ((y & 0x7c000000) >> 16) |
  2346.             ((z & 0x000003e0) << 11) |
  2347.             ((z & 0x001f0000) << 5) |
  2348.             ((z & 0xf8000000) >> 1);
  2349.         /* next 2x2 input block */
  2350.         src1 += 8; src2 += 8;
  2351.         dst1 += 8; dst2 += 8;
  2352.     }
  2353.     /*
  2354.      * For last 4 output pels, repeat the final input pel for
  2355.      * for missing input.  Equivalent to pixel-doubling the
  2356.      * last output pel.
  2357.      */
  2358.     /* top line */
  2359.     a = *(unsigned int *)(src1+0);
  2360.     b = *(unsigned int *)(src1+4);
  2361.     e = b;      /* repeat last input pel */
  2362.     w = a;
  2363.     x = a + b;
  2364.     y = b;
  2365.     z = b + e;
  2366.     /* pack and store */
  2367.     *(unsigned int *)(dst1+0) =
  2368.         ((w & 0x000000f8) >> 3) |
  2369.         ((w & 0x0007c000) >> 9) |
  2370.         ((w & 0x3e000000) >> 15) |
  2371.         ((x & 0x000001f0) << 12) |
  2372.         ((x & 0x000f8000) << 6) |
  2373.         ((x & 0x7c000000) << 0);
  2374.     *(unsigned int *)(dst1+4) =
  2375.         ((y & 0x000000f8) >> 3) |
  2376.         ((y & 0x0007c000) >> 9) |
  2377.         ((y & 0x3e000000) >> 15) |
  2378.         ((z & 0x000001f0) << 12) |
  2379.         ((z & 0x000f8000) << 6) |
  2380.         ((z & 0x7c000000) << 0);
  2381.     /* bottom line */
  2382.     c = *(unsigned int *)(src2+0);
  2383.     d = *(unsigned int *)(src2+4);
  2384.     f = d;      /* repeat last input pel */
  2385.     w = a + c;
  2386.     x = a + b + c + d;
  2387.     y = b + d;
  2388.     z = b + e + d + f;
  2389.     /* pack and store */
  2390.     *(unsigned int *)(dst2+0) =
  2391.         ((w & 0x000001f0) >> 4) |
  2392.         ((w & 0x000f8000) >> 10) |
  2393.         ((w & 0x7c000000) >> 16) |
  2394.         ((x & 0x000003e0) << 11) |
  2395.         ((x & 0x001f0000) << 5) |
  2396.         ((x & 0xf8000000) >> 1);
  2397.     *(unsigned int *)(dst2+4) =
  2398.         ((y & 0x000001f0) >> 4) |
  2399.         ((y & 0x000f8000) >> 10) |
  2400.         ((y & 0x7c000000) >> 16) |
  2401.         ((z & 0x000003e0) << 11) |
  2402.         ((z & 0x001f0000) << 5) |
  2403.         ((z & 0xf8000000) >> 1);
  2404. }
  2405. /* the driver function: */
  2406. void oldI420toRGBx2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  2407.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst, int bpp,
  2408.     void (* interp) (unsigned char *, unsigned char *, unsigned char *, unsigned char *, int))
  2409. {
  2410.     /* Pointers to the three RGB linebuffers */
  2411.     unsigned char *buf[3]; /* Flawfinder: ignore */
  2412.     int ibuf = 0;                           /* circular buffer index */
  2413.     int dstinc = bpp * 2 * pitchDst;        /* offset to next output line */
  2414.     unsigned char *dst2 = dst + bpp * pitchDst;    /* second output line */
  2415.     buf[0] = linebuf;
  2416.     buf[1] = linebuf + 4 * width;
  2417.     buf[2] = linebuf + 8 * width;
  2418.     /* Bump dst to other end, if inverting ouput */
  2419.     if (pitchDst < 0) {
  2420.         dst += bpp * -pitchDst * (2*height - 1);
  2421.         dst2 += bpp * -pitchDst * (2*height - 1);
  2422.     }
  2423.     /* Special case for first 2 lines */
  2424.     convertI420toXRGB (ysrc, usrc, vsrc, buf[next[ibuf]], buf[next2[ibuf]], width, pitchSrc);
  2425.     ysrc += pitchSrc << 1;                  /* next 2 lines */
  2426.     usrc += pitchSrc >> 1;                  /* next line */
  2427.     vsrc += pitchSrc >> 1;                  /* next line */
  2428.     /* skip first interp */
  2429.     ibuf = next[ibuf];                      /* shift buffers */
  2430.     (* interp) (buf[ibuf], buf[next[ibuf]], dst, dst2, width);
  2431.     dst += dstinc;                          /* next 2 lines */
  2432.     dst2 += dstinc;
  2433.     ibuf = next[ibuf];                      /* shift buffers */
  2434.     height >>= 1;       /* two rows per pass */
  2435.     while (--height) {  /* do all but last pair */
  2436.         /* Convert 2 lines into bufs */
  2437.         convertI420toXRGB (ysrc, usrc, vsrc, buf[next[ibuf]], buf[next2[ibuf]], width, pitchSrc);
  2438.         ysrc += pitchSrc << 1;              /* next 2 lines */
  2439.         usrc += pitchSrc >> 1;              /* next line */
  2440.         vsrc += pitchSrc >> 1;              /* next line */
  2441.         /* Interp 2 lines into dst */
  2442.         (* interp) (buf[ibuf], buf[next[ibuf]], dst, dst2, width);
  2443.         dst += dstinc;                      /* next 2 lines */
  2444.         dst2 += dstinc;
  2445.         ibuf = next[ibuf];                  /* shift buffers */
  2446.         /* Interp 2 lines into dst */
  2447.         (* interp) (buf[ibuf], buf[next[ibuf]], dst, dst2, width);
  2448.         dst += dstinc;                      /* next 2 lines */
  2449.         dst2 += dstinc;
  2450.         ibuf = next[ibuf];                  /* shift buffers */
  2451.     }
  2452.     /* Last 2 lines, repeating last input line */
  2453.     (* interp) (buf[ibuf], buf[ibuf], dst, dst2, width);
  2454. }
  2455. /* actual converters: */
  2456. void oldI420toRGB32x2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  2457.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
  2458. {
  2459.     oldI420toRGBx2 (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 4, interpRGB32);
  2460. }
  2461. void oldI420toRGB24x2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  2462.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
  2463. {
  2464.     oldI420toRGBx2 (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 3, interpRGB24);
  2465. }
  2466. void oldI420toRGB565x2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  2467.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
  2468. {
  2469.     oldI420toRGBx2 (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 2, interpRGB565);
  2470. }
  2471. void oldI420toRGB555x2 (unsigned char *ysrc, unsigned char *usrc, unsigned char *vsrc,
  2472.     int pitchSrc, unsigned char *dst, int width, int height, int pitchDst)
  2473. {
  2474.     oldI420toRGBx2 (ysrc, usrc, vsrc, pitchSrc, dst, width, height, pitchDst, 2, interpRGB555);
  2475. }
  2476. #if defined (_MACINTOSH) && defined (_DEBUG)
  2477. #pragma global_optimizer off
  2478. #endif
  2479. /* colorcvt.c -- end of file */