jdcolext.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * jdcolext.c
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1991-1997, Thomas G. Lane.
  6. * libjpeg-turbo Modifications:
  7. * Copyright (C) 2009, 2011, D. R. Commander.
  8. * For conditions of distribution and use, see the accompanying README file.
  9. *
  10. * This file contains output colorspace conversion routines.
  11. */
  12. /* This file is included by jdcolor.c */
  13. /*
  14. * Convert some rows of samples to the output colorspace.
  15. *
  16. * Note that we change from noninterleaved, one-plane-per-component format
  17. * to interleaved-pixel format. The output buffer is therefore three times
  18. * as wide as the input buffer.
  19. * A starting row offset is provided only for the input buffer. The caller
  20. * can easily adjust the passed output_buf value to accommodate any row
  21. * offset required on that side.
  22. */
  23. INLINE
  24. LOCAL(void)
  25. ycc_rgb_convert_internal (j_decompress_ptr cinfo,
  26. JSAMPIMAGE input_buf, JDIMENSION input_row,
  27. JSAMPARRAY output_buf, int num_rows)
  28. {
  29. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  30. register int y, cb, cr;
  31. register JSAMPROW outptr;
  32. register JSAMPROW inptr0, inptr1, inptr2;
  33. register JDIMENSION col;
  34. JDIMENSION num_cols = cinfo->output_width;
  35. /* copy these pointers into registers if possible */
  36. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  37. register int * Crrtab = cconvert->Cr_r_tab;
  38. register int * Cbbtab = cconvert->Cb_b_tab;
  39. register INT32 * Crgtab = cconvert->Cr_g_tab;
  40. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  41. SHIFT_TEMPS
  42. while (--num_rows >= 0) {
  43. inptr0 = input_buf[0][input_row];
  44. inptr1 = input_buf[1][input_row];
  45. inptr2 = input_buf[2][input_row];
  46. input_row++;
  47. outptr = *output_buf++;
  48. for (col = 0; col < num_cols; col++) {
  49. y = GETJSAMPLE(inptr0[col]);
  50. cb = GETJSAMPLE(inptr1[col]);
  51. cr = GETJSAMPLE(inptr2[col]);
  52. /* Range-limiting is essential due to noise introduced by DCT losses. */
  53. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  54. outptr[RGB_GREEN] = range_limit[y +
  55. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  56. SCALEBITS))];
  57. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  58. /* Set unused byte to 0xFF so it can be interpreted as an opaque */
  59. /* alpha channel value */
  60. #ifdef RGB_ALPHA
  61. outptr[RGB_ALPHA] = 0xFF;
  62. #endif
  63. outptr += RGB_PIXELSIZE;
  64. }
  65. }
  66. }
  67. /*
  68. * Convert grayscale to RGB: just duplicate the graylevel three times.
  69. * This is provided to support applications that don't want to cope
  70. * with grayscale as a separate case.
  71. */
  72. INLINE
  73. LOCAL(void)
  74. gray_rgb_convert_internal (j_decompress_ptr cinfo,
  75. JSAMPIMAGE input_buf, JDIMENSION input_row,
  76. JSAMPARRAY output_buf, int num_rows)
  77. {
  78. register JSAMPROW inptr, outptr;
  79. register JDIMENSION col;
  80. JDIMENSION num_cols = cinfo->output_width;
  81. while (--num_rows >= 0) {
  82. inptr = input_buf[0][input_row++];
  83. outptr = *output_buf++;
  84. for (col = 0; col < num_cols; col++) {
  85. /* We can dispense with GETJSAMPLE() here */
  86. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  87. /* Set unused byte to 0xFF so it can be interpreted as an opaque */
  88. /* alpha channel value */
  89. #ifdef RGB_ALPHA
  90. outptr[RGB_ALPHA] = 0xFF;
  91. #endif
  92. outptr += RGB_PIXELSIZE;
  93. }
  94. }
  95. }
  96. /*
  97. * Convert RGB to extended RGB: just swap the order of source pixels
  98. */
  99. INLINE
  100. LOCAL(void)
  101. rgb_rgb_convert_internal (j_decompress_ptr cinfo,
  102. JSAMPIMAGE input_buf, JDIMENSION input_row,
  103. JSAMPARRAY output_buf, int num_rows)
  104. {
  105. register JSAMPROW inptr0, inptr1, inptr2;
  106. register JSAMPROW outptr;
  107. register JDIMENSION col;
  108. JDIMENSION num_cols = cinfo->output_width;
  109. while (--num_rows >= 0) {
  110. inptr0 = input_buf[0][input_row];
  111. inptr1 = input_buf[1][input_row];
  112. inptr2 = input_buf[2][input_row];
  113. input_row++;
  114. outptr = *output_buf++;
  115. for (col = 0; col < num_cols; col++) {
  116. /* We can dispense with GETJSAMPLE() here */
  117. outptr[RGB_RED] = inptr0[col];
  118. outptr[RGB_GREEN] = inptr1[col];
  119. outptr[RGB_BLUE] = inptr2[col];
  120. /* Set unused byte to 0xFF so it can be interpreted as an opaque */
  121. /* alpha channel value */
  122. #ifdef RGB_ALPHA
  123. outptr[RGB_ALPHA] = 0xFF;
  124. #endif
  125. outptr += RGB_PIXELSIZE;
  126. }
  127. }
  128. }