jdmrgext.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * jdmrgext.c
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1994-1996, Thomas G. Lane.
  6. * libjpeg-turbo Modifications:
  7. * Copyright (C) 2011, 2015, D. R. Commander.
  8. * For conditions of distribution and use, see the accompanying README.ijg
  9. * file.
  10. *
  11. * This file contains code for merged upsampling/color conversion.
  12. */
  13. /* This file is included by jdmerge.c */
  14. /*
  15. * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
  16. */
  17. INLINE
  18. LOCAL(void)
  19. h2v1_merged_upsample_internal (j_decompress_ptr cinfo,
  20. JSAMPIMAGE input_buf,
  21. JDIMENSION in_row_group_ctr,
  22. JSAMPARRAY output_buf)
  23. {
  24. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  25. register int y, cred, cgreen, cblue;
  26. int cb, cr;
  27. register JSAMPROW outptr;
  28. JSAMPROW inptr0, inptr1, inptr2;
  29. JDIMENSION col;
  30. /* copy these pointers into registers if possible */
  31. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  32. int * Crrtab = upsample->Cr_r_tab;
  33. int * Cbbtab = upsample->Cb_b_tab;
  34. JLONG * Crgtab = upsample->Cr_g_tab;
  35. JLONG * Cbgtab = upsample->Cb_g_tab;
  36. SHIFT_TEMPS
  37. inptr0 = input_buf[0][in_row_group_ctr];
  38. inptr1 = input_buf[1][in_row_group_ctr];
  39. inptr2 = input_buf[2][in_row_group_ctr];
  40. outptr = output_buf[0];
  41. /* Loop for each pair of output pixels */
  42. for (col = cinfo->output_width >> 1; col > 0; col--) {
  43. /* Do the chroma part of the calculation */
  44. cb = GETJSAMPLE(*inptr1++);
  45. cr = GETJSAMPLE(*inptr2++);
  46. cred = Crrtab[cr];
  47. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  48. cblue = Cbbtab[cb];
  49. /* Fetch 2 Y values and emit 2 pixels */
  50. y = GETJSAMPLE(*inptr0++);
  51. outptr[RGB_RED] = range_limit[y + cred];
  52. outptr[RGB_GREEN] = range_limit[y + cgreen];
  53. outptr[RGB_BLUE] = range_limit[y + cblue];
  54. #ifdef RGB_ALPHA
  55. outptr[RGB_ALPHA] = 0xFF;
  56. #endif
  57. outptr += RGB_PIXELSIZE;
  58. y = GETJSAMPLE(*inptr0++);
  59. outptr[RGB_RED] = range_limit[y + cred];
  60. outptr[RGB_GREEN] = range_limit[y + cgreen];
  61. outptr[RGB_BLUE] = range_limit[y + cblue];
  62. #ifdef RGB_ALPHA
  63. outptr[RGB_ALPHA] = 0xFF;
  64. #endif
  65. outptr += RGB_PIXELSIZE;
  66. }
  67. /* If image width is odd, do the last output column separately */
  68. if (cinfo->output_width & 1) {
  69. cb = GETJSAMPLE(*inptr1);
  70. cr = GETJSAMPLE(*inptr2);
  71. cred = Crrtab[cr];
  72. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  73. cblue = Cbbtab[cb];
  74. y = GETJSAMPLE(*inptr0);
  75. outptr[RGB_RED] = range_limit[y + cred];
  76. outptr[RGB_GREEN] = range_limit[y + cgreen];
  77. outptr[RGB_BLUE] = range_limit[y + cblue];
  78. #ifdef RGB_ALPHA
  79. outptr[RGB_ALPHA] = 0xFF;
  80. #endif
  81. }
  82. }
  83. /*
  84. * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
  85. */
  86. INLINE
  87. LOCAL(void)
  88. h2v2_merged_upsample_internal (j_decompress_ptr cinfo,
  89. JSAMPIMAGE input_buf,
  90. JDIMENSION in_row_group_ctr,
  91. JSAMPARRAY output_buf)
  92. {
  93. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  94. register int y, cred, cgreen, cblue;
  95. int cb, cr;
  96. register JSAMPROW outptr0, outptr1;
  97. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  98. JDIMENSION col;
  99. /* copy these pointers into registers if possible */
  100. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  101. int * Crrtab = upsample->Cr_r_tab;
  102. int * Cbbtab = upsample->Cb_b_tab;
  103. JLONG * Crgtab = upsample->Cr_g_tab;
  104. JLONG * Cbgtab = upsample->Cb_g_tab;
  105. SHIFT_TEMPS
  106. inptr00 = input_buf[0][in_row_group_ctr*2];
  107. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  108. inptr1 = input_buf[1][in_row_group_ctr];
  109. inptr2 = input_buf[2][in_row_group_ctr];
  110. outptr0 = output_buf[0];
  111. outptr1 = output_buf[1];
  112. /* Loop for each group of output pixels */
  113. for (col = cinfo->output_width >> 1; col > 0; col--) {
  114. /* Do the chroma part of the calculation */
  115. cb = GETJSAMPLE(*inptr1++);
  116. cr = GETJSAMPLE(*inptr2++);
  117. cred = Crrtab[cr];
  118. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  119. cblue = Cbbtab[cb];
  120. /* Fetch 4 Y values and emit 4 pixels */
  121. y = GETJSAMPLE(*inptr00++);
  122. outptr0[RGB_RED] = range_limit[y + cred];
  123. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  124. outptr0[RGB_BLUE] = range_limit[y + cblue];
  125. #ifdef RGB_ALPHA
  126. outptr0[RGB_ALPHA] = 0xFF;
  127. #endif
  128. outptr0 += RGB_PIXELSIZE;
  129. y = GETJSAMPLE(*inptr00++);
  130. outptr0[RGB_RED] = range_limit[y + cred];
  131. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  132. outptr0[RGB_BLUE] = range_limit[y + cblue];
  133. #ifdef RGB_ALPHA
  134. outptr0[RGB_ALPHA] = 0xFF;
  135. #endif
  136. outptr0 += RGB_PIXELSIZE;
  137. y = GETJSAMPLE(*inptr01++);
  138. outptr1[RGB_RED] = range_limit[y + cred];
  139. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  140. outptr1[RGB_BLUE] = range_limit[y + cblue];
  141. #ifdef RGB_ALPHA
  142. outptr1[RGB_ALPHA] = 0xFF;
  143. #endif
  144. outptr1 += RGB_PIXELSIZE;
  145. y = GETJSAMPLE(*inptr01++);
  146. outptr1[RGB_RED] = range_limit[y + cred];
  147. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  148. outptr1[RGB_BLUE] = range_limit[y + cblue];
  149. #ifdef RGB_ALPHA
  150. outptr1[RGB_ALPHA] = 0xFF;
  151. #endif
  152. outptr1 += RGB_PIXELSIZE;
  153. }
  154. /* If image width is odd, do the last output column separately */
  155. if (cinfo->output_width & 1) {
  156. cb = GETJSAMPLE(*inptr1);
  157. cr = GETJSAMPLE(*inptr2);
  158. cred = Crrtab[cr];
  159. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  160. cblue = Cbbtab[cb];
  161. y = GETJSAMPLE(*inptr00);
  162. outptr0[RGB_RED] = range_limit[y + cred];
  163. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  164. outptr0[RGB_BLUE] = range_limit[y + cblue];
  165. #ifdef RGB_ALPHA
  166. outptr0[RGB_ALPHA] = 0xFF;
  167. #endif
  168. y = GETJSAMPLE(*inptr01);
  169. outptr1[RGB_RED] = range_limit[y + cred];
  170. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  171. outptr1[RGB_BLUE] = range_limit[y + cblue];
  172. #ifdef RGB_ALPHA
  173. outptr1[RGB_ALPHA] = 0xFF;
  174. #endif
  175. }
  176. }