Path: blob/master/3rdparty/libjpeg-turbo/src/jdcol565.c
16337 views
/*1* jdcol565.c2*3* This file was part of the Independent JPEG Group's software:4* Copyright (C) 1991-1997, Thomas G. Lane.5* Modifications:6* Copyright (C) 2013, Linaro Limited.7* Copyright (C) 2014-2015, D. R. Commander.8* For conditions of distribution and use, see the accompanying README.ijg9* file.10*11* This file contains output colorspace conversion routines.12*/1314/* This file is included by jdcolor.c */151617INLINE18LOCAL(void)19ycc_rgb565_convert_internal (j_decompress_ptr cinfo,20JSAMPIMAGE input_buf, JDIMENSION input_row,21JSAMPARRAY output_buf, int num_rows)22{23my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;24register int y, cb, cr;25register JSAMPROW outptr;26register JSAMPROW inptr0, inptr1, inptr2;27register JDIMENSION col;28JDIMENSION num_cols = cinfo->output_width;29/* copy these pointers into registers if possible */30register JSAMPLE * range_limit = cinfo->sample_range_limit;31register int * Crrtab = cconvert->Cr_r_tab;32register int * Cbbtab = cconvert->Cb_b_tab;33register JLONG * Crgtab = cconvert->Cr_g_tab;34register JLONG * Cbgtab = cconvert->Cb_g_tab;35SHIFT_TEMPS3637while (--num_rows >= 0) {38JLONG rgb;39unsigned int r, g, b;40inptr0 = input_buf[0][input_row];41inptr1 = input_buf[1][input_row];42inptr2 = input_buf[2][input_row];43input_row++;44outptr = *output_buf++;4546if (PACK_NEED_ALIGNMENT(outptr)) {47y = GETJSAMPLE(*inptr0++);48cb = GETJSAMPLE(*inptr1++);49cr = GETJSAMPLE(*inptr2++);50r = range_limit[y + Crrtab[cr]];51g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],52SCALEBITS))];53b = range_limit[y + Cbbtab[cb]];54rgb = PACK_SHORT_565(r, g, b);55*(INT16*)outptr = (INT16)rgb;56outptr += 2;57num_cols--;58}59for (col = 0; col < (num_cols >> 1); col++) {60y = GETJSAMPLE(*inptr0++);61cb = GETJSAMPLE(*inptr1++);62cr = GETJSAMPLE(*inptr2++);63r = range_limit[y + Crrtab[cr]];64g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],65SCALEBITS))];66b = range_limit[y + Cbbtab[cb]];67rgb = PACK_SHORT_565(r, g, b);6869y = GETJSAMPLE(*inptr0++);70cb = GETJSAMPLE(*inptr1++);71cr = GETJSAMPLE(*inptr2++);72r = range_limit[y + Crrtab[cr]];73g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],74SCALEBITS))];75b = range_limit[y + Cbbtab[cb]];76rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));7778WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);79outptr += 4;80}81if (num_cols & 1) {82y = GETJSAMPLE(*inptr0);83cb = GETJSAMPLE(*inptr1);84cr = GETJSAMPLE(*inptr2);85r = range_limit[y + Crrtab[cr]];86g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],87SCALEBITS))];88b = range_limit[y + Cbbtab[cb]];89rgb = PACK_SHORT_565(r, g, b);90*(INT16*)outptr = (INT16)rgb;91}92}93}949596INLINE97LOCAL(void)98ycc_rgb565D_convert_internal (j_decompress_ptr cinfo,99JSAMPIMAGE input_buf, JDIMENSION input_row,100JSAMPARRAY output_buf, int num_rows)101{102my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;103register int y, cb, cr;104register JSAMPROW outptr;105register JSAMPROW inptr0, inptr1, inptr2;106register JDIMENSION col;107JDIMENSION num_cols = cinfo->output_width;108/* copy these pointers into registers if possible */109register JSAMPLE * range_limit = cinfo->sample_range_limit;110register int * Crrtab = cconvert->Cr_r_tab;111register int * Cbbtab = cconvert->Cb_b_tab;112register JLONG * Crgtab = cconvert->Cr_g_tab;113register JLONG * Cbgtab = cconvert->Cb_g_tab;114JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];115SHIFT_TEMPS116117while (--num_rows >= 0) {118JLONG rgb;119unsigned int r, g, b;120121inptr0 = input_buf[0][input_row];122inptr1 = input_buf[1][input_row];123inptr2 = input_buf[2][input_row];124input_row++;125outptr = *output_buf++;126if (PACK_NEED_ALIGNMENT(outptr)) {127y = GETJSAMPLE(*inptr0++);128cb = GETJSAMPLE(*inptr1++);129cr = GETJSAMPLE(*inptr2++);130r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];131g = range_limit[DITHER_565_G(y +132((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],133SCALEBITS)), d0)];134b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];135rgb = PACK_SHORT_565(r, g, b);136*(INT16*)outptr = (INT16)rgb;137outptr += 2;138num_cols--;139}140for (col = 0; col < (num_cols >> 1); col++) {141y = GETJSAMPLE(*inptr0++);142cb = GETJSAMPLE(*inptr1++);143cr = GETJSAMPLE(*inptr2++);144r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];145g = range_limit[DITHER_565_G(y +146((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],147SCALEBITS)), d0)];148b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];149d0 = DITHER_ROTATE(d0);150rgb = PACK_SHORT_565(r, g, b);151152y = GETJSAMPLE(*inptr0++);153cb = GETJSAMPLE(*inptr1++);154cr = GETJSAMPLE(*inptr2++);155r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];156g = range_limit[DITHER_565_G(y +157((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],158SCALEBITS)), d0)];159b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];160d0 = DITHER_ROTATE(d0);161rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));162163WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);164outptr += 4;165}166if (num_cols & 1) {167y = GETJSAMPLE(*inptr0);168cb = GETJSAMPLE(*inptr1);169cr = GETJSAMPLE(*inptr2);170r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];171g = range_limit[DITHER_565_G(y +172((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],173SCALEBITS)), d0)];174b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];175rgb = PACK_SHORT_565(r, g, b);176*(INT16*)outptr = (INT16)rgb;177}178}179}180181182INLINE183LOCAL(void)184rgb_rgb565_convert_internal (j_decompress_ptr cinfo,185JSAMPIMAGE input_buf, JDIMENSION input_row,186JSAMPARRAY output_buf, int num_rows)187{188register JSAMPROW outptr;189register JSAMPROW inptr0, inptr1, inptr2;190register JDIMENSION col;191JDIMENSION num_cols = cinfo->output_width;192SHIFT_TEMPS193194while (--num_rows >= 0) {195JLONG rgb;196unsigned int r, g, b;197198inptr0 = input_buf[0][input_row];199inptr1 = input_buf[1][input_row];200inptr2 = input_buf[2][input_row];201input_row++;202outptr = *output_buf++;203if (PACK_NEED_ALIGNMENT(outptr)) {204r = GETJSAMPLE(*inptr0++);205g = GETJSAMPLE(*inptr1++);206b = GETJSAMPLE(*inptr2++);207rgb = PACK_SHORT_565(r, g, b);208*(INT16*)outptr = (INT16)rgb;209outptr += 2;210num_cols--;211}212for (col = 0; col < (num_cols >> 1); col++) {213r = GETJSAMPLE(*inptr0++);214g = GETJSAMPLE(*inptr1++);215b = GETJSAMPLE(*inptr2++);216rgb = PACK_SHORT_565(r, g, b);217218r = GETJSAMPLE(*inptr0++);219g = GETJSAMPLE(*inptr1++);220b = GETJSAMPLE(*inptr2++);221rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));222223WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);224outptr += 4;225}226if (num_cols & 1) {227r = GETJSAMPLE(*inptr0);228g = GETJSAMPLE(*inptr1);229b = GETJSAMPLE(*inptr2);230rgb = PACK_SHORT_565(r, g, b);231*(INT16*)outptr = (INT16)rgb;232}233}234}235236237INLINE238LOCAL(void)239rgb_rgb565D_convert_internal (j_decompress_ptr cinfo,240JSAMPIMAGE input_buf, JDIMENSION input_row,241JSAMPARRAY output_buf, int num_rows)242{243register JSAMPROW outptr;244register JSAMPROW inptr0, inptr1, inptr2;245register JDIMENSION col;246register JSAMPLE * range_limit = cinfo->sample_range_limit;247JDIMENSION num_cols = cinfo->output_width;248JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];249SHIFT_TEMPS250251while (--num_rows >= 0) {252JLONG rgb;253unsigned int r, g, b;254255inptr0 = input_buf[0][input_row];256inptr1 = input_buf[1][input_row];257inptr2 = input_buf[2][input_row];258input_row++;259outptr = *output_buf++;260if (PACK_NEED_ALIGNMENT(outptr)) {261r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];262g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];263b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];264rgb = PACK_SHORT_565(r, g, b);265*(INT16*)outptr = (INT16)rgb;266outptr += 2;267num_cols--;268}269for (col = 0; col < (num_cols >> 1); col++) {270r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];271g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];272b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];273d0 = DITHER_ROTATE(d0);274rgb = PACK_SHORT_565(r, g, b);275276r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];277g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];278b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];279d0 = DITHER_ROTATE(d0);280rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));281282WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);283outptr += 4;284}285if (num_cols & 1) {286r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0), d0)];287g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1), d0)];288b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2), d0)];289rgb = PACK_SHORT_565(r, g, b);290*(INT16*)outptr = (INT16)rgb;291}292}293}294295296INLINE297LOCAL(void)298gray_rgb565_convert_internal (j_decompress_ptr cinfo,299JSAMPIMAGE input_buf, JDIMENSION input_row,300JSAMPARRAY output_buf, int num_rows)301{302register JSAMPROW inptr, outptr;303register JDIMENSION col;304JDIMENSION num_cols = cinfo->output_width;305306while (--num_rows >= 0) {307JLONG rgb;308unsigned int g;309310inptr = input_buf[0][input_row++];311outptr = *output_buf++;312if (PACK_NEED_ALIGNMENT(outptr)) {313g = *inptr++;314rgb = PACK_SHORT_565(g, g, g);315*(INT16*)outptr = (INT16)rgb;316outptr += 2;317num_cols--;318}319for (col = 0; col < (num_cols >> 1); col++) {320g = *inptr++;321rgb = PACK_SHORT_565(g, g, g);322g = *inptr++;323rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));324WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);325outptr += 4;326}327if (num_cols & 1) {328g = *inptr;329rgb = PACK_SHORT_565(g, g, g);330*(INT16*)outptr = (INT16)rgb;331}332}333}334335336INLINE337LOCAL(void)338gray_rgb565D_convert_internal (j_decompress_ptr cinfo,339JSAMPIMAGE input_buf, JDIMENSION input_row,340JSAMPARRAY output_buf, int num_rows)341{342register JSAMPROW inptr, outptr;343register JDIMENSION col;344register JSAMPLE * range_limit = cinfo->sample_range_limit;345JDIMENSION num_cols = cinfo->output_width;346JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];347348while (--num_rows >= 0) {349JLONG rgb;350unsigned int g;351352inptr = input_buf[0][input_row++];353outptr = *output_buf++;354if (PACK_NEED_ALIGNMENT(outptr)) {355g = *inptr++;356g = range_limit[DITHER_565_R(g, d0)];357rgb = PACK_SHORT_565(g, g, g);358*(INT16*)outptr = (INT16)rgb;359outptr += 2;360num_cols--;361}362for (col = 0; col < (num_cols >> 1); col++) {363g = *inptr++;364g = range_limit[DITHER_565_R(g, d0)];365rgb = PACK_SHORT_565(g, g, g);366d0 = DITHER_ROTATE(d0);367368g = *inptr++;369g = range_limit[DITHER_565_R(g, d0)];370rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));371d0 = DITHER_ROTATE(d0);372373WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);374outptr += 4;375}376if (num_cols & 1) {377g = *inptr;378g = range_limit[DITHER_565_R(g, d0)];379rgb = PACK_SHORT_565(g, g, g);380*(INT16*)outptr = (INT16)rgb;381}382}383}384385386