📄 wrsprite16.c
字号:
/* JPEG decoder 16bit output code * Copyright (C) ANT Limited 1999 -- All Rights Reserved -- Confidential * $Header: /cvs/repos/src/webimage/dll_jpeg/layers/wrsprite16.c,v 1.1.4.5 2004/08/03 10:34:07 michael Exp $ */#include "layers.h"#include "../../webimage.h"#include "../../image.h"#include "layers_util.h"#include "layers_bmp.h"#include "layers_endian.h"#include "layers_dbg.h"#include "layers_assert.h"#include "sprinternal.h"#ifdef DYNAMIC_LIBJPEG #include <jpeglib.h> #include <jerror.h> #else #include "../jpeglib.h" #include "../jerror.h" #endif#include "wrsprite.h"#if BITS_IN_JSAMPLE == 8#define CLIP( _v, _l, _h) \ if ( _v > (_l)) { if ( _v < (_h)) _v &= (_h); else _v = (_h); } else _v = (_l)#if !RISCOS/* R,G,B in the other order (they're just trying to make it tricky) */#if LAYERS_FB_ARGB4444/* This macro performs the dithering calculation and must be set up to * match the frame buffer format. */#define PUTSPRITESAMPLE16BPP(ptr,r,g,b,rd,gd,bd) do \ { register int rr,gg,bb; \\ gg = g + gd + 8; \ CLIP( gg, 0, 0xf0);\ gd = (g - gg)/2; \\ rr = r + rd + 8; \ CLIP( rr, 0, 0xf0);\ rd = (r - rr)/2; \\ bb = b + bd + 8; \ CLIP( bb, 0, 0xf0);\ bd = (b - bb)/2; \\ PUTRGB16( ptr, rr, gg, bb);\ } while(0)#else#define PUTSPRITESAMPLE16BPP(ptr,r,g,b,rd,gd,bd) do \ { register int rr,gg,bb; \\ gg = g + gd + 4; \ CLIP( gg, 0, 0xf8);\ gd = (g - gg)/2; \\ rr = r + rd + 4; \ CLIP( rr, 0, 0xf8);\ rd = (r - rr)/2; \\ bb = b + bd + 4; \ CLIP( bb, 0, 0xf8);\ bd = (b - bb)/2; \\ PUTRGB16( ptr, rr, gg, bb);\ } while(0)#endif#if CHAR_BIT==32#define PUTRGB16( _ptr, _r, _g, _b) \ _ptr = (((_b)>>3) | ((_g)<<2) | ((_r)<<7))#else /* CHAR_BIT!=32 */#if FLAVOUR_BIG_ENDIAN#define PUTRGB16( _ptr, _r, _g, _b) do \{ \ unsigned short temp = layers_fb_PACK16(_r, _g, _b, 0); \ *((unsigned short*)_ptr) = ((temp << 8) & 0xff00) + ((temp >> 8) & 0xff); \} while(0)#else /* !FLAVOUR_BIG_ENDIAN */#define PUTRGB16( _ptr, _r, _g, _b) \ *((unsigned short*)_ptr) = layers_fb_PACK16(_r, _g, _b, 0)#endif /* !FLAVOUR_BIG_ENDIAN */#endif /* CHAR_BIT!=32 */#else /* RISCOS *//* Acorn R,G,B order */#define PUTSPRITESAMPLE16BPP(ptr,r,g,b,rd,gd,bd) \ { register int rr,gg,bb; \\ gg = g + gd + 4; \ CLIP( gg, 0, 0xf8);\ gd = (g - gg)/2; \\ rr = r + rd + 4; \ CLIP( rr, 0, 0xf8);\ rd = (r - rr)/2; \\ bb = b + bd + 4; \ CLIP( bb, 0, 0xf8);\ bd = (b - bb)/2; \\ ptr[0] = (char) ((rr>>3) + (gg<<2)); \ ptr[1] = (char) ((gg>>6) + (bb>>1)); \ }#endif#elseSorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */#endif/* * Write some pixel data. * In this module rows_supplied will always be 1. * * put_pixel16bpp_rows handles the "normal" 16-bit case, packing 3 bytes of R,G,B * into 5 bits R,G,B. We apply simple truncation of precision, with no attempt to * error diffuse, etc. */OVERLAY_SEGMENT("code_jeg")voidput_pixel16bpp_rows( j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, JDIMENSION rows_supplied ){ sprite_dest_ptr const dest = (sprite_dest_ptr) dinfo; register JDIMENSION col = dest->samples_per_row; /* fprintf(stderr, "put_pixel16bpp_rows: ptr %x buf %x samples %x\n", (int) ptr, (int) bufferptr, dest->samples_per_row); */ if ( col < JPEG_MAX_DIMENSION) { int rd = 0, gd = 0, bd = 0; register const JSAMPLE FAR * ptr = dest->pub.buffer[0]; register char *bufferptr = dest->iobuffer;#if CHAR_BIT==32 if ( cinfo->output_scanline & 1) { bufferptr += cinfo->output_width/2; ptr += dest->samples_per_row; /* if odd width then process the end pixel first */ if ( cinfo->output_width & 1 ) { ptr -= 3; col -= 3; PUTSPRITESAMPLE16BPP( *bufferptr, GETJSAMPLE( ptr[0] ), GETJSAMPLE( ptr[1]), GETJSAMPLE( ptr[2]), rd, gd, bd); } /* we must have an even number of pixels left by now */ ASSERT( (col%6) == 0); for ( ; col > 0; col -= 6) { unsigned int tmp, tmp2; ptr -= 6; PUTSPRITESAMPLE16BPP( tmp2, GETJSAMPLE( ptr[3]), GETJSAMPLE( ptr[4]), GETJSAMPLE( ptr[5]), rd, gd, bd); PUTSPRITESAMPLE16BPP( tmp, GETJSAMPLE( ptr[0]), GETJSAMPLE( ptr[1]), GETJSAMPLE( ptr[2]), rd, gd, bd); *--bufferptr = tmp | (tmp2 << 16); } } else { /* if this image is an odd width then there will be one pixel left over (3 components so col==3) which we must not process in the loop but must leave to the special case following */ for ( ; col > 3; col -= 6) { unsigned int tmp, tmp2; PUTSPRITESAMPLE16BPP( tmp, GETJSAMPLE( ptr[0]), GETJSAMPLE( ptr[1]), GETJSAMPLE( ptr[2]), rd, gd, bd); PUTSPRITESAMPLE16BPP( tmp2, GETJSAMPLE( ptr[3]), GETJSAMPLE( ptr[4]), GETJSAMPLE( ptr[5]), rd, gd, bd); *bufferptr++ = tmp | (tmp2 << 16); ptr += 6; } /* process last pixel if necessary */ if ( col > 0) { ASSERT(col==3); PUTSPRITESAMPLE16BPP( *bufferptr, GETJSAMPLE( ptr[0]), GETJSAMPLE( ptr[1]), GETJSAMPLE( ptr[2]), rd, gd, bd); } }#else if ( cinfo->output_scanline & 1) { bufferptr += 2 * cinfo->output_width; ptr += dest->samples_per_row; for ( ; col >= 3; col -= 3) { bufferptr -= 2; ptr -= 3; PUTSPRITESAMPLE16BPP( bufferptr, GETJSAMPLE( ptr[0]), GETJSAMPLE( ptr[1]), GETJSAMPLE( ptr[2]), rd, gd, bd); } } else { for ( ; col >= 3; col -= 3) { PUTSPRITESAMPLE16BPP( bufferptr, GETJSAMPLE( ptr[0]), GETJSAMPLE( ptr[1]), GETJSAMPLE( ptr[2]), rd, gd, bd); ptr += 3; bufferptr += 2; } }#endif } /* fprintf(stderr, "put_pixel16bpp_rows: out %x io %x len %x\n", (int) dest->pub.output_file, (int) dest->iobuffer, dest->buffer_width); */ if (dest->outfile) { dest->putdst((unsigned char *)dest->iobuffer, dest->buffer_width, dest->outfile); } else { (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); } NOT_USED(rows_supplied);}/* eof wrsprite16.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -