jdmrgext.c 5.9 KB

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