home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / py2s152.zip / Modules / yuvconvert.c < prev    next >
C/C++ Source or Header  |  1999-06-27  |  5KB  |  149 lines

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI or Corporation for National Research Initiatives or
  13. CNRI not be used in advertising or publicity pertaining to
  14. distribution of the software without specific, written prior
  15. permission.
  16.  
  17. While CWI is the initial source for this software, a modified version
  18. is made available by the Corporation for National Research Initiatives
  19. (CNRI) at the Internet address ftp://ftp.python.org.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  22. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  23. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  24. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  25. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  26. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  27. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28. PERFORMANCE OF THIS SOFTWARE.
  29.  
  30. ******************************************************************/
  31.  
  32. #include "yuv.h"
  33.  
  34. void
  35. yuv_sv411_to_cl422dc(int invert, void *data, void *yuv, int width, int height)
  36. {
  37.     struct yuv411 *in = data;
  38.     struct yuv422 *out_even = yuv;
  39.     struct yuv422 *out_odd = out_even + width / 2;
  40.     int i, j;        /* counters */
  41.  
  42.     for (i = height / 2; i--; ) {
  43.         for (j = width / 4; j--; ) {
  44.             YUV422_Y0(*out_even) = YUV411_Y00(*in);
  45.             YUV422_U0(*out_even) = YUV411_U00(*in);
  46.             YUV422_V0(*out_even) = YUV411_V00(*in);
  47.             YUV422_Y1(*out_even) = YUV411_Y01(*in);
  48.             out_even++;
  49.             YUV422_Y0(*out_even) = YUV411_Y02(*in);
  50.             YUV422_U0(*out_even) = YUV411_U02(*in);
  51.             YUV422_V0(*out_even) = YUV411_V02(*in);
  52.             YUV422_Y1(*out_even) = YUV411_Y03(*in);
  53.             out_even++;
  54.             YUV422_Y0(*out_odd) = YUV411_Y10(*in);
  55.             YUV422_U0(*out_odd) = YUV411_U10(*in);
  56.             YUV422_V0(*out_odd) = YUV411_V10(*in);
  57.             YUV422_Y1(*out_odd) = YUV411_Y11(*in);
  58.             out_odd++;
  59.             YUV422_Y0(*out_odd) = YUV411_Y12(*in);
  60.             YUV422_U0(*out_odd) = YUV411_U12(*in);
  61.             YUV422_V0(*out_odd) = YUV411_V12(*in);
  62.             YUV422_Y1(*out_odd) = YUV411_Y13(*in);
  63.             out_odd++;
  64.             in++;
  65.         }
  66.         out_even += width / 2;
  67.         out_odd += width / 2;
  68.     }
  69. }
  70.  
  71. void
  72. yuv_sv411_to_cl422dc_quartersize(int invert, void *data, void *yuv,
  73.                  int width, int height)
  74. {
  75.     int w4 = width / 4;    /* quarter of width is used often */
  76.     struct yuv411 *in_even = data;
  77.     struct yuv411 *in_odd = in_even + w4;
  78.     struct yuv422 *out_even = yuv;
  79.     struct yuv422 *out_odd = out_even + w4;
  80.     int i, j;        /* counters */
  81.     int u, v;        /* U and V values */
  82.  
  83.     for (i = height / 4; i--; ) {
  84.         for (j = w4; j--; ) {
  85.             u = YUV411_U00(*in_even);
  86.             v = YUV411_V00(*in_even);
  87.  
  88.             YUV422_Y0(*out_even) = YUV411_Y00(*in_even);
  89.             YUV422_U0(*out_even) = u;
  90.             YUV422_V0(*out_even) = v;
  91.             YUV422_Y1(*out_even) = YUV411_Y02(*in_even);
  92.  
  93.             YUV422_Y0(*out_odd) = YUV411_Y10(*in_odd);
  94.             YUV422_U0(*out_odd) = u;
  95.             YUV422_V0(*out_odd) = v;
  96.             YUV422_Y1(*out_odd) = YUV411_Y12(*in_odd);
  97.  
  98.             in_even++;
  99.             in_odd++;
  100.             out_even++;
  101.             out_odd++;
  102.         }
  103.         in_even += w4;
  104.         in_odd += w4;
  105.         out_even += w4;
  106.         out_odd += w4;
  107.     }
  108. }
  109.  
  110. void
  111. yuv_sv411_to_cl422dc_sixteenthsize(int invert, void *data, void *yuv,
  112.                    int width, int height)
  113. {
  114.     int w4_3 = 3 * width / 4; /* three quarters of width is used often */
  115.     int w8 = width / 8;    /* and so is one eighth */
  116.     struct yuv411 *in_even = data;
  117.     struct yuv411 *in_odd = in_even + width / 2;
  118.     struct yuv422 *out_even = yuv;
  119.     struct yuv422 *out_odd = out_even + w8;
  120.     int i, j;        /* counters */
  121.     int u, v;        /* U and V values */
  122.  
  123.     for (i = height / 8; i--; ) {
  124.         for (j = w8; j--; ) {
  125.             u = YUV411_U00(in_even[0]);
  126.             v = YUV411_V00(in_even[0]);
  127.  
  128.             YUV422_Y0(*out_even) = YUV411_Y00(in_even[0]);
  129.             YUV422_U0(*out_even) = u;
  130.             YUV422_V0(*out_even) = v;
  131.             YUV422_Y1(*out_even) = YUV411_Y00(in_even[1]);
  132.  
  133.             YUV422_Y0(*out_odd) = YUV411_Y00(in_odd[0]);
  134.             YUV422_U0(*out_odd) = u;
  135.             YUV422_V0(*out_odd) = v;
  136.             YUV422_Y1(*out_odd) = YUV411_Y00(in_even[1]);
  137.  
  138.             in_even += 2;
  139.             in_odd += 2;
  140.             out_even++;
  141.             out_odd++;
  142.         }
  143.         in_even += w4_3;
  144.         in_odd += w4_3;
  145.         out_even += w8;
  146.         out_odd += w8;
  147.     }
  148. }
  149.