jdcolext.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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, 2015, D. R. Commander.
  8. * For conditions of distribution and use, see the accompanying README.ijg
  9. * file.
  10. *
  11. * This file contains output colorspace conversion routines.
  12. */
  13. /* This file is included by jdcolor.c */
  14. /*
  15. * Convert some rows of samples to the output colorspace.
  16. *
  17. * Note that we change from noninterleaved, one-plane-per-component format
  18. * to interleaved-pixel format. The output buffer is therefore three times
  19. * as wide as the input buffer.
  20. * A starting row offset is provided only for the input buffer. The caller
  21. * can easily adjust the passed output_buf value to accommodate any row
  22. * offset required on that side.
  23. */
  24. INLINE
  25. LOCAL(void)
  26. ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  27. JDIMENSION input_row, JSAMPARRAY output_buf,
  28. int num_rows)
  29. {
  30. my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
  31. register int y, cb, cr;
  32. register JSAMPROW outptr;
  33. register JSAMPROW inptr0, inptr1, inptr2;
  34. register JDIMENSION col;
  35. JDIMENSION num_cols = cinfo->output_width;
  36. /* copy these pointers into registers if possible */
  37. register JSAMPLE *range_limit = cinfo->sample_range_limit;
  38. register int *Crrtab = cconvert->Cr_r_tab;
  39. register int *Cbbtab = cconvert->Cb_b_tab;
  40. register JLONG *Crgtab = cconvert->Cr_g_tab;
  41. register JLONG *Cbgtab = cconvert->Cb_g_tab;
  42. SHIFT_TEMPS
  43. while (--num_rows >= 0) {
  44. inptr0 = input_buf[0][input_row];
  45. inptr1 = input_buf[1][input_row];
  46. inptr2 = input_buf[2][input_row];
  47. input_row++;
  48. outptr = *output_buf++;
  49. for (col = 0; col < num_cols; col++) {
  50. y = inptr0[col];
  51. cb = inptr1[col];
  52. cr = inptr2[col];
  53. /* Range-limiting is essential due to noise introduced by DCT losses. */
  54. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  55. outptr[RGB_GREEN] = range_limit[y +
  56. ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  57. SCALEBITS))];
  58. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  59. /* Set unused byte to 0xFF so it can be interpreted as an opaque */
  60. /* alpha channel value */
  61. #ifdef RGB_ALPHA
  62. outptr[RGB_ALPHA] = 0xFF;
  63. #endif
  64. outptr += RGB_PIXELSIZE;
  65. }
  66. }
  67. }
  68. /*
  69. * Convert grayscale to RGB: just duplicate the graylevel three times.
  70. * This is provided to support applications that don't want to cope
  71. * with grayscale as a separate case.
  72. */
  73. INLINE
  74. LOCAL(void)
  75. gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  76. JDIMENSION input_row, JSAMPARRAY output_buf,
  77. int num_rows)
  78. {
  79. register JSAMPROW inptr, outptr;
  80. register JDIMENSION col;
  81. JDIMENSION num_cols = cinfo->output_width;
  82. while (--num_rows >= 0) {
  83. inptr = input_buf[0][input_row++];
  84. outptr = *output_buf++;
  85. for (col = 0; col < num_cols; col++) {
  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, JSAMPIMAGE input_buf,
  102. JDIMENSION input_row, JSAMPARRAY output_buf,
  103. 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. outptr[RGB_RED] = inptr0[col];
  117. outptr[RGB_GREEN] = inptr1[col];
  118. outptr[RGB_BLUE] = inptr2[col];
  119. /* Set unused byte to 0xFF so it can be interpreted as an opaque */
  120. /* alpha channel value */
  121. #ifdef RGB_ALPHA
  122. outptr[RGB_ALPHA] = 0xFF;
  123. #endif
  124. outptr += RGB_PIXELSIZE;
  125. }
  126. }
  127. }