jdcolext.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 = GETJSAMPLE(inptr0[col]);
  51. cb = GETJSAMPLE(inptr1[col]);
  52. cr = GETJSAMPLE(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. /* We can dispense with GETJSAMPLE() here */
  87. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  88. /* Set unused byte to 0xFF so it can be interpreted as an opaque */
  89. /* alpha channel value */
  90. #ifdef RGB_ALPHA
  91. outptr[RGB_ALPHA] = 0xFF;
  92. #endif
  93. outptr += RGB_PIXELSIZE;
  94. }
  95. }
  96. }
  97. /*
  98. * Convert RGB to extended RGB: just swap the order of source pixels
  99. */
  100. INLINE
  101. LOCAL(void)
  102. rgb_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  103. JDIMENSION input_row, JSAMPARRAY output_buf,
  104. int num_rows)
  105. {
  106. register JSAMPROW inptr0, inptr1, inptr2;
  107. register JSAMPROW outptr;
  108. register JDIMENSION col;
  109. JDIMENSION num_cols = cinfo->output_width;
  110. while (--num_rows >= 0) {
  111. inptr0 = input_buf[0][input_row];
  112. inptr1 = input_buf[1][input_row];
  113. inptr2 = input_buf[2][input_row];
  114. input_row++;
  115. outptr = *output_buf++;
  116. for (col = 0; col < num_cols; col++) {
  117. /* We can dispense with GETJSAMPLE() here */
  118. outptr[RGB_RED] = inptr0[col];
  119. outptr[RGB_GREEN] = inptr1[col];
  120. outptr[RGB_BLUE] = inptr2[col];
  121. /* Set unused byte to 0xFF so it can be interpreted as an opaque */
  122. /* alpha channel value */
  123. #ifdef RGB_ALPHA
  124. outptr[RGB_ALPHA] = 0xFF;
  125. #endif
  126. outptr += RGB_PIXELSIZE;
  127. }
  128. }
  129. }