123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- /*
- * jdcol565.c
- *
- * This file was part of the Independent JPEG Group's software:
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * Modifications:
- * Copyright (C) 2013, Linaro Limited.
- * Copyright (C) 2014-2015, D. R. Commander.
- * For conditions of distribution and use, see the accompanying README.ijg
- * file.
- *
- * This file contains output colorspace conversion routines.
- */
- /* This file is included by jdcolor.c */
- INLINE
- LOCAL(void)
- ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
- JDIMENSION input_row, JSAMPARRAY output_buf,
- int num_rows)
- {
- my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
- register int y, cb, cr;
- register JSAMPROW outptr;
- register JSAMPROW inptr0, inptr1, inptr2;
- register JDIMENSION col;
- JDIMENSION num_cols = cinfo->output_width;
- /* copy these pointers into registers if possible */
- register JSAMPLE *range_limit = cinfo->sample_range_limit;
- register int *Crrtab = cconvert->Cr_r_tab;
- register int *Cbbtab = cconvert->Cb_b_tab;
- register JLONG *Crgtab = cconvert->Cr_g_tab;
- register JLONG *Cbgtab = cconvert->Cb_g_tab;
- SHIFT_TEMPS
- while (--num_rows >= 0) {
- JLONG rgb;
- unsigned int r, g, b;
- inptr0 = input_buf[0][input_row];
- inptr1 = input_buf[1][input_row];
- inptr2 = input_buf[2][input_row];
- input_row++;
- outptr = *output_buf++;
- if (PACK_NEED_ALIGNMENT(outptr)) {
- y = *inptr0++;
- cb = *inptr1++;
- cr = *inptr2++;
- r = range_limit[y + Crrtab[cr]];
- g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
- SCALEBITS))];
- b = range_limit[y + Cbbtab[cb]];
- rgb = PACK_SHORT_565(r, g, b);
- *(INT16 *)outptr = (INT16)rgb;
- outptr += 2;
- num_cols--;
- }
- for (col = 0; col < (num_cols >> 1); col++) {
- y = *inptr0++;
- cb = *inptr1++;
- cr = *inptr2++;
- r = range_limit[y + Crrtab[cr]];
- g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
- SCALEBITS))];
- b = range_limit[y + Cbbtab[cb]];
- rgb = PACK_SHORT_565(r, g, b);
- y = *inptr0++;
- cb = *inptr1++;
- cr = *inptr2++;
- r = range_limit[y + Crrtab[cr]];
- g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
- SCALEBITS))];
- b = range_limit[y + Cbbtab[cb]];
- rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
- WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
- outptr += 4;
- }
- if (num_cols & 1) {
- y = *inptr0;
- cb = *inptr1;
- cr = *inptr2;
- r = range_limit[y + Crrtab[cr]];
- g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
- SCALEBITS))];
- b = range_limit[y + Cbbtab[cb]];
- rgb = PACK_SHORT_565(r, g, b);
- *(INT16 *)outptr = (INT16)rgb;
- }
- }
- }
- INLINE
- LOCAL(void)
- ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
- JDIMENSION input_row, JSAMPARRAY output_buf,
- int num_rows)
- {
- my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
- register int y, cb, cr;
- register JSAMPROW outptr;
- register JSAMPROW inptr0, inptr1, inptr2;
- register JDIMENSION col;
- JDIMENSION num_cols = cinfo->output_width;
- /* copy these pointers into registers if possible */
- register JSAMPLE *range_limit = cinfo->sample_range_limit;
- register int *Crrtab = cconvert->Cr_r_tab;
- register int *Cbbtab = cconvert->Cb_b_tab;
- register JLONG *Crgtab = cconvert->Cr_g_tab;
- register JLONG *Cbgtab = cconvert->Cb_g_tab;
- JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
- SHIFT_TEMPS
- while (--num_rows >= 0) {
- JLONG rgb;
- unsigned int r, g, b;
- inptr0 = input_buf[0][input_row];
- inptr1 = input_buf[1][input_row];
- inptr2 = input_buf[2][input_row];
- input_row++;
- outptr = *output_buf++;
- if (PACK_NEED_ALIGNMENT(outptr)) {
- y = *inptr0++;
- cb = *inptr1++;
- cr = *inptr2++;
- r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
- g = range_limit[DITHER_565_G(y +
- ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
- SCALEBITS)), d0)];
- b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
- rgb = PACK_SHORT_565(r, g, b);
- *(INT16 *)outptr = (INT16)rgb;
- outptr += 2;
- num_cols--;
- }
- for (col = 0; col < (num_cols >> 1); col++) {
- y = *inptr0++;
- cb = *inptr1++;
- cr = *inptr2++;
- r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
- g = range_limit[DITHER_565_G(y +
- ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
- SCALEBITS)), d0)];
- b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
- d0 = DITHER_ROTATE(d0);
- rgb = PACK_SHORT_565(r, g, b);
- y = *inptr0++;
- cb = *inptr1++;
- cr = *inptr2++;
- r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
- g = range_limit[DITHER_565_G(y +
- ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
- SCALEBITS)), d0)];
- b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
- d0 = DITHER_ROTATE(d0);
- rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
- WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
- outptr += 4;
- }
- if (num_cols & 1) {
- y = *inptr0;
- cb = *inptr1;
- cr = *inptr2;
- r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
- g = range_limit[DITHER_565_G(y +
- ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
- SCALEBITS)), d0)];
- b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
- rgb = PACK_SHORT_565(r, g, b);
- *(INT16 *)outptr = (INT16)rgb;
- }
- }
- }
- INLINE
- LOCAL(void)
- rgb_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
- JDIMENSION input_row, JSAMPARRAY output_buf,
- int num_rows)
- {
- register JSAMPROW outptr;
- register JSAMPROW inptr0, inptr1, inptr2;
- register JDIMENSION col;
- JDIMENSION num_cols = cinfo->output_width;
- SHIFT_TEMPS
- while (--num_rows >= 0) {
- JLONG rgb;
- unsigned int r, g, b;
- inptr0 = input_buf[0][input_row];
- inptr1 = input_buf[1][input_row];
- inptr2 = input_buf[2][input_row];
- input_row++;
- outptr = *output_buf++;
- if (PACK_NEED_ALIGNMENT(outptr)) {
- r = *inptr0++;
- g = *inptr1++;
- b = *inptr2++;
- rgb = PACK_SHORT_565(r, g, b);
- *(INT16 *)outptr = (INT16)rgb;
- outptr += 2;
- num_cols--;
- }
- for (col = 0; col < (num_cols >> 1); col++) {
- r = *inptr0++;
- g = *inptr1++;
- b = *inptr2++;
- rgb = PACK_SHORT_565(r, g, b);
- r = *inptr0++;
- g = *inptr1++;
- b = *inptr2++;
- rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
- WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
- outptr += 4;
- }
- if (num_cols & 1) {
- r = *inptr0;
- g = *inptr1;
- b = *inptr2;
- rgb = PACK_SHORT_565(r, g, b);
- *(INT16 *)outptr = (INT16)rgb;
- }
- }
- }
- INLINE
- LOCAL(void)
- rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
- JDIMENSION input_row, JSAMPARRAY output_buf,
- int num_rows)
- {
- register JSAMPROW outptr;
- register JSAMPROW inptr0, inptr1, inptr2;
- register JDIMENSION col;
- register JSAMPLE *range_limit = cinfo->sample_range_limit;
- JDIMENSION num_cols = cinfo->output_width;
- JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
- SHIFT_TEMPS
- while (--num_rows >= 0) {
- JLONG rgb;
- unsigned int r, g, b;
- inptr0 = input_buf[0][input_row];
- inptr1 = input_buf[1][input_row];
- inptr2 = input_buf[2][input_row];
- input_row++;
- outptr = *output_buf++;
- if (PACK_NEED_ALIGNMENT(outptr)) {
- r = range_limit[DITHER_565_R(*inptr0++, d0)];
- g = range_limit[DITHER_565_G(*inptr1++, d0)];
- b = range_limit[DITHER_565_B(*inptr2++, d0)];
- rgb = PACK_SHORT_565(r, g, b);
- *(INT16 *)outptr = (INT16)rgb;
- outptr += 2;
- num_cols--;
- }
- for (col = 0; col < (num_cols >> 1); col++) {
- r = range_limit[DITHER_565_R(*inptr0++, d0)];
- g = range_limit[DITHER_565_G(*inptr1++, d0)];
- b = range_limit[DITHER_565_B(*inptr2++, d0)];
- d0 = DITHER_ROTATE(d0);
- rgb = PACK_SHORT_565(r, g, b);
- r = range_limit[DITHER_565_R(*inptr0++, d0)];
- g = range_limit[DITHER_565_G(*inptr1++, d0)];
- b = range_limit[DITHER_565_B(*inptr2++, d0)];
- d0 = DITHER_ROTATE(d0);
- rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
- WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
- outptr += 4;
- }
- if (num_cols & 1) {
- r = range_limit[DITHER_565_R(*inptr0, d0)];
- g = range_limit[DITHER_565_G(*inptr1, d0)];
- b = range_limit[DITHER_565_B(*inptr2, d0)];
- rgb = PACK_SHORT_565(r, g, b);
- *(INT16 *)outptr = (INT16)rgb;
- }
- }
- }
- INLINE
- LOCAL(void)
- gray_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
- JDIMENSION input_row, JSAMPARRAY output_buf,
- int num_rows)
- {
- register JSAMPROW inptr, outptr;
- register JDIMENSION col;
- JDIMENSION num_cols = cinfo->output_width;
- while (--num_rows >= 0) {
- JLONG rgb;
- unsigned int g;
- inptr = input_buf[0][input_row++];
- outptr = *output_buf++;
- if (PACK_NEED_ALIGNMENT(outptr)) {
- g = *inptr++;
- rgb = PACK_SHORT_565(g, g, g);
- *(INT16 *)outptr = (INT16)rgb;
- outptr += 2;
- num_cols--;
- }
- for (col = 0; col < (num_cols >> 1); col++) {
- g = *inptr++;
- rgb = PACK_SHORT_565(g, g, g);
- g = *inptr++;
- rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
- WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
- outptr += 4;
- }
- if (num_cols & 1) {
- g = *inptr;
- rgb = PACK_SHORT_565(g, g, g);
- *(INT16 *)outptr = (INT16)rgb;
- }
- }
- }
- INLINE
- LOCAL(void)
- gray_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
- JDIMENSION input_row, JSAMPARRAY output_buf,
- int num_rows)
- {
- register JSAMPROW inptr, outptr;
- register JDIMENSION col;
- register JSAMPLE *range_limit = cinfo->sample_range_limit;
- JDIMENSION num_cols = cinfo->output_width;
- JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
- while (--num_rows >= 0) {
- JLONG rgb;
- unsigned int g;
- inptr = input_buf[0][input_row++];
- outptr = *output_buf++;
- if (PACK_NEED_ALIGNMENT(outptr)) {
- g = *inptr++;
- g = range_limit[DITHER_565_R(g, d0)];
- rgb = PACK_SHORT_565(g, g, g);
- *(INT16 *)outptr = (INT16)rgb;
- outptr += 2;
- num_cols--;
- }
- for (col = 0; col < (num_cols >> 1); col++) {
- g = *inptr++;
- g = range_limit[DITHER_565_R(g, d0)];
- rgb = PACK_SHORT_565(g, g, g);
- d0 = DITHER_ROTATE(d0);
- g = *inptr++;
- g = range_limit[DITHER_565_R(g, d0)];
- rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
- d0 = DITHER_ROTATE(d0);
- WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
- outptr += 4;
- }
- if (num_cols & 1) {
- g = *inptr;
- g = range_limit[DITHER_565_R(g, d0)];
- rgb = PACK_SHORT_565(g, g, g);
- *(INT16 *)outptr = (INT16)rgb;
- }
- }
- }
|