⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrsprite.c

📁 这是从一款商业嵌入式浏览器中节选出来的代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * wrsprite.c * * Copyright (C) 1995, ANT Limited. * Author Nick Smith <nas@ant.co.uk>, 1995 * * This file contains routines to write output images in RISC OS Sprite format. * 'New format' 16bpp, and 'Old format' 8bpp fixed palette formats are supported. * Greyscale output is provided by 8bpp true palette and 4bpp fixed palette formats. */#include "layers.h"#include "../../webimage.h"#include "../../image.h"#include "layers_assert.h"#include "layers_util.h"#include "layers_bmp.h"#include "layers_endian.h"#include "layers_dbg.h"#ifdef DYNAMIC_LIBJPEG    #include <jconfig.h>#include <jpeglib.h>    #include <jerror.h>    #else    #include "../jconfig.h"#include "../jpeglib.h"    #include "../jerror.h"    #endif#include "sprinternal.h"#include "wrsprite.h"/* * For 12-bit JPEG data, we give an error as unsupported. * (When the core library supports data precision reduction, a cleaner * implementation will be to ask for that instead.) */#if BITS_IN_JSAMPLE == 8#define PUTSPRITESAMPLE(ptr,v)  *ptr++ = (char) (v)#ifdef WIN32#define PUTSPRITESAMPLE4BPP(ptr,a,b) *ptr++ = (char) ((b) | (a<<4)) /* Win32 nibble order */#else#define PUTSPRITESAMPLE4BPP(ptr,a,b) *ptr++ = (char) ((a) | (b<<4)) /* RiscOS nibble order */#endif#define SPRITE_MAXVAL 255#elseSorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */#endif/* * When JSAMPLE is the same size as char, we can just fwrite() the * decompressed data to the SPRITE file. *//* * Write some pixel data. * In this module rows_supplied will always be 1. * * put_pixel_rows handles the "normal" 8-bit case where the decompressor * output buffer is physically the same as the fwrite buffer. */static voidput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,		JDIMENSION rows_supplied){  sprite_dest_ptr dest = (sprite_dest_ptr) dinfo;  register JSAMPROW ptr;  register char *bufferptr;  register JDIMENSION col;  ptr = dest->pub.buffer[0];#if CHAR_BIT==32  bufferptr = dest->iobuffer;  for (col = 0; col < dest->samples_per_row; col += 4)  {    *bufferptr++ = GETJSAMPLE(ptr[0]) | (GETJSAMPLE(ptr[2]) << 8) | (GETJSAMPLE(ptr[2]) << 16) | (GETJSAMPLE(ptr[2]) << 24);    ptr += 4;  }  /* set ptr to start of new output buffer */  ptr = (JSAMPROW)dest->iobuffer;#else  bufferptr = dest->iobuffer;  for (col = 0; col < dest->samples_per_row; col ++ )  {    *bufferptr++ = GETJSAMPLE(ptr[0]);    ptr ++;  }  /* set ptr to start of new output buffer */  ptr = (JSAMPROW)dest->iobuffer;#endif  ASSERT( dest->outfile );    if (dest->outfile)  {    dest->putdst(ptr, dest->buffer_width, dest->outfile);  }  else  {    (void) JFWRITE(dest->pub.output_file, (char *) ptr, dest->buffer_width);  }  NOT_USED(cinfo);  NOT_USED(rows_supplied);}static voidput_pixel_rows_rotate_left_90 (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,		JDIMENSION rows_supplied){    sprite_dest_ptr const dest = (sprite_dest_ptr) dinfo;    register JDIMENSION col = cinfo->output_width;    unsigned int offset;        /* calculate offset for writing */    offset  = dest->image_offset;    offset += (cinfo->output_scanline - rows_supplied);    if ( col < JPEG_MAX_DIMENSION )    {        /* work across the columns */        while(col--)        {            unsigned int row;            register unsigned char *bufferptr = (unsigned char *)dest->iobuffer;            /* seek to the start of the row */            if (dest->outfile)            {                ASSERT(offset>=dest->image_offset);                dest->seekdst(offset, dest->outfile);            }            else            {                ASSERT(0);            }            for (row = 0; row < rows_supplied; row++)            {                register const JSAMPLE FAR *ptr = dest->pub.buffer[row];                unsigned int pix;                ptr += col;                                pix = GETJSAMPLE( ptr[0] );                *bufferptr++ = pix;            }            if (dest->outfile)            {                dest->putdst((unsigned char *)dest->iobuffer, rows_supplied, dest->outfile);            }            else            {                (void) JFWRITE(dest->pub.output_file,rows_supplied, dest->buffer_width);            }            offset += dest->stride;        }    }    }static voidput_pixel_rows_rotate_left_180 (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;    unsigned int offset;    offset = dest->image_offset;    offset += (cinfo->output_height-cinfo->output_scanline)*(dest->stride);    if (dest->outfile)    {        ASSERT(offset>=dest->image_offset);        /* seek to the start of the block of rows we're doing */        dest->seekdst(offset, dest->outfile);    }    else    {        ASSERT(0);  /* no seek function supplied */    }    if ( col < JPEG_MAX_DIMENSION)    {        for ( ; rows_supplied; rows_supplied-- )        {            register const JSAMPLE FAR * ptr = dest->pub.buffer[rows_supplied - 1];            register unsigned char *bufferptr = (unsigned char *)dest->iobuffer;            col = dest->samples_per_row;            ptr += (col - 1);            for ( ; col >= 1; col -= 1)            {                unsigned int pix;                                pix = GETJSAMPLE( ptr[0]);                *bufferptr++ = pix;                ptr--;            }        }    }    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);    }}static voidput_pixel_rows_rotate_left_270 (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,		JDIMENSION rows_supplied){    sprite_dest_ptr const dest = (sprite_dest_ptr) dinfo;    JDIMENSION col = cinfo->output_width;    unsigned int offset;    /* calculate offset for writing */    offset  = dest->image_offset;    offset += (cinfo->output_height-cinfo->output_scanline);    offset += dest->stride * (col - 1);    if ( col < JPEG_MAX_DIMENSION )    {        /* work across the columns */        while(col--)        {            unsigned int row;            register unsigned char *bufferptr = (unsigned char *)dest->iobuffer + rows_supplied;            if (dest->outfile)            {                ASSERT(offset>=dest->image_offset);                dest->seekdst(offset, dest->outfile);            }            else            {                ASSERT(0);            }            for (row = 0; row < rows_supplied; row++)            {                register const JSAMPLE FAR *ptr = dest->pub.buffer[row];                unsigned int pix;                ptr += col;                                pix = GETJSAMPLE( ptr[0] );                *--bufferptr = pix;            }            if (dest->outfile)            {                dest->putdst((unsigned char *)dest->iobuffer, rows_supplied, dest->outfile);            }            else            {                (void) JFWRITE(dest->pub.output_file, rows_supplied, dest->buffer_width);            }            offset -= dest->stride;        }    }}#if LAYERS_FB_32BITSstatic voidput_pixel32bpp_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;    ASSERT(rows_supplied == 1);    if ( col < JPEG_MAX_DIMENSION)    {        register const JSAMPLE FAR * ptr = dest->pub.buffer[0];        register unsigned int *bufferptr = (unsigned int *)dest->iobuffer;        for ( ; col >= 3; col -= 3)        {            unsigned int pix;            pix = layers_fb_PACK32( GETJSAMPLE( ptr[0] ),                                    GETJSAMPLE( ptr[1] ),                                    GETJSAMPLE( ptr[2] ),                                    layers_OPAQUE );            *bufferptr++ = pix;            ptr += 3;        }    }    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(cinfo);    NOT_USED(rows_supplied);}/*  * Write out data rotated by 180 degrees.  This is pretty easy.  Seek to the start * of the block, write the block out in reverse order, reversing the data in each * line as well. */static void put_pixel32bpp_rows_rotate_left_180 (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;    unsigned int offset;    offset = dest->image_offset;    offset += (cinfo->output_height-cinfo->output_scanline)*sizeof(unsigned int)*(dest->samples_per_row/3);    if (dest->outfile)    {        ASSERT(offset>=dest->image_offset);        /* seek to the start of the block of rows we're doing */        dest->seekdst(offset, dest->outfile);    }    else    {        ASSERT(0);  /* no seek function supplied */    }    if ( col < JPEG_MAX_DIMENSION)    {        for ( ; rows_supplied; rows_supplied-- )        {            register const JSAMPLE FAR * ptr = dest->pub.buffer[rows_supplied - 1];            register unsigned int *bufferptr = (unsigned int *)dest->iobuffer;            col = dest->samples_per_row;            ptr += (col - 3);            for ( ; col >= 3; col -= 3)            {                unsigned int pix;                                pix = layers_fb_PACK32( GETJSAMPLE( ptr[0] ),                                        GETJSAMPLE( ptr[1] ),                                        GETJSAMPLE( ptr[2] ),                                        layers_OPAQUE );                *bufferptr++ = pix;                ptr -= 3;            }        }    }    if (dest->outfile)    {        dest->putdst((unsigned char *)dest->iobuffer, dest->buffer_width, dest->outfile);    }    else    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -