[kaffe] CVS kaffe (jserv): Commit last removal for Qt AWT backend.
Kaffe CVS
cvs-commits at kaffe.org
Fri Jul 9 23:50:52 PDT 2004
PatchSet 4922
Date: 2004/07/10 01:59:46
Author: jserv
Branch: HEAD
Tag: (none)
Log:
Commit last removal for Qt AWT backend.
Members:
libraries/clib/awt/qt/imggif.cc:1.2->1.3(DEAD)
libraries/clib/awt/qt/imgjpeg.cc:1.2->1.3(DEAD)
libraries/clib/awt/qt/imgpng.cc:1.2->1.3(DEAD)
===================================================================
Checking out kaffe/libraries/clib/awt/qt/imggif.cc
RCS: /home/cvs/kaffe/kaffe/libraries/clib/awt/qt/Attic/imggif.cc,v
VERS: 1.2
***************
--- kaffe/libraries/clib/awt/qt/imggif.cc Sat Jul 10 06:50:49 2004
+++ /dev/null Sun Aug 4 19:57:58 2002
@@ -1,328 +0,0 @@
-/**
- * imggif.c - interface for libgif input routines
- *
- * Copyright (c) 1998
- * Transvirtual Technologies, Inc. All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- */
-
-#include "defs.h"
-#include "toolkit.h"
-
-#include "qimage.h"
-
-#if defined(HAVE_GIF_LIB_H) && (defined(HAVE_LIBGIF) || defined(HAVE_LIBUNGIF))
-#define INCLUDE_GIF 1
-#endif
-
-#if defined(INCLUDE_GIF)
-BEGIN_C_DECLS
-
-#include "gif_lib.h"
-
-END_C_DECLS
-#endif
-
-
-#if defined(INCLUDE_GIF)
-static int iOffset[] = { 0, 4, 2, 1 };
-static int iJumps[] = { 8, 8, 4, 2 };
-#endif
-
-int colordepth;
-char *s;
-/**************************************************************************************
- * internal functions
- */
-
-#if defined(INCLUDE_GIF)
-static void
-writeRow ( Image* img, GifPixelType* rowBuf, GifColorType* cm, int row )
-{
- int idx, col;
- jint rgb;
- unsigned long pix;
- unsigned char *imgData;
- imgData = img->qImg->scanLine(row);
- //fprintf(stderr,"img w=%d h=%d imgData %p\n",img->qImg->width(),img->qImg->height(),imgData);
-// memset(imgData,(char *)rowBuf,img->width);
- for ( col=0; col < img->width; col++ ) {
- idx = rowBuf[col];
- if ( img->qImg_AlphaMask/*img->xMask*/ && (idx == img->trans) ) {
- pix = 0;
- //fprintf(stderr,"alpha %d %d\n",col,row);
- img->qImg_AlphaMask->setPixel((int)col,(int)row,(uint)0);
- //XPutPixel( img->xMask, col, row, 0);
- }
- else {
- rgb = (cm[idx].Red << 16) | (cm[idx].Green << 8) | (cm[idx].Blue);
-// pix = pixelValue( X, rgb);
- }
- //fprintf(stderr,"setting pixel %d %d %d\n",col,row,rgb);
- img->qImg->setPixel((int)col,(int)row,idx);
-// XPutPixel( img->xImg, col, row, pix);
- }
-}
-
-
-#define CHECK(gifOp) \
- if ( gifOp == GIF_ERROR ) { \
- if ( img ) Java_java_awt_Toolkit_imgFreeImage( 0, 0, img); \
- if ( rowBuf ) AWT_FREE( rowBuf); \
- return 0; \
- }
-
-
-static Image*
-readGif ( GifFileType *gf )
-{
- Image* firstImg = 0;
- Image* img = 0;
- int i, extCode, width, height, row, cmapSize;
- int trans = -1, nFrames = 0, delay = 0;
- GifRecordType rec;
- GifByteType *ext;
- ColorMapObject *cmap;
- GifColorType *clrs;
- GifPixelType *rowBuf = (GifPixelType*) AWT_MALLOC( gf->SWidth * sizeof( GifPixelType) );
-
- do {
- CHECK( DGifGetRecordType( gf, &rec));
-
- switch ( rec ) {
- case IMAGE_DESC_RECORD_TYPE:
- CHECK( DGifGetImageDesc( gf));
-
- width = gf->Image.Width;
- height = gf->Image.Height;
-
- cmap = (gf->Image.ColorMap) ? gf->Image.ColorMap : gf->SColorMap;
- clrs = cmap->Colors;
- cmapSize = cmap->ColorCount;
-
- /*
- * create our image objects and keep track of frames
- */
- if ( !firstImg ) { /* this is the first (maybe only) frame */
- firstImg = img = createImage( width, height);
- img->qImg = new QImage(width,height,colordepth);
- if(img->qImg->load(s)==FALSE) fprintf(stderr,"load image %s failed\n",s);
- }
- else { /* this is a subsequent gif-movie frame, link it in */
- img->next = createImage( width, height);
- img->next->qImg = new QImage(width,height,colordepth);
- if(img->next->qImg->load(s)==FALSE) fprintf(stderr,"load image %s failed\n",s);
- bool ok = FALSE;
- ok = reconvertImage(img);
- if (ok == FALSE) img->qpm->resize(0,0);
- img = img->next;
- }
-
- /*
- * The trans index might have been cached by a preceeding extension record. Now
- * that we have the Image object, it's time to store it in img and to create the
- * mask
- */
- if ( trans != -1 ) {
- img->trans = trans;
- createXMaskImage( X, img);
- img->qImg->setAlphaBuffer(TRUE);
- img->qImg_AlphaMask = new QImage();
- if(img->qImg && img->qImg->hasAlphaBuffer());
- *(img->qImg_AlphaMask) = img->qImg->createAlphaMask();
- trans = -1;
- }
-
- /*
- * Some browsers seem to assume minimal values, and some animations
- * seem to rely on this. But there's no safe guess, so we
- * skip it completely
- */
-/*
- if ( delay == 0 )
- delay = 1000;
- else if ( delay < 100 )
- delay = 100;
-*/
-
- img->latency = delay;
- img->left = gf->Image.Left;
- img->top = gf->Image.Top;
- img->frame = nFrames;
-
- nFrames++;
- createXImage( X, img);
- img->qImg = new QImage();
- if(img->qImg->load(s) == FALSE) fprintf(stderr,"load %s failed",s);
- /*
- * start reading in the image data
- */
- if ( gf->Image.Interlace ) {
- /* Need to perform 4 passes on the images: */
- for ( i = 0; i < 4; i++ ) {
- for (row = iOffset[i]; row < height; row += iJumps[i]) {
- memset( rowBuf, gf->SBackGroundColor, width);
- memset(img->qImg->scanLine(row),gf->SBackGroundColor,width);
- CHECK( DGifGetLine( gf, rowBuf, width));
- writeRow( img, rowBuf, clrs, row);
- }
- }
- }
- else {
- for ( row = 0; row < height; row++) {
- memset( rowBuf, gf->SBackGroundColor, width);
- CHECK( DGifGetLine(gf, rowBuf, width));
- memset (img->qImg->scanLine(row),gf->SBackGroundColor,width);
- writeRow( img, rowBuf, clrs, row);
- }
- }
- break;
-
- case EXTENSION_RECORD_TYPE:
- CHECK( DGifGetExtension( gf, &extCode, &ext));
-
- if ( extCode == 0xf9 ) { /* graphics extension */
- /*
- * extension record with transparency spec are preceeding description records
- * (which create new Images), so just cache the transp index, here
- */
- if ( ext[1] & 1 ) { /* transparent index following */
- trans = ext[4];
- }
- delay = ((ext[3] << 8) | ext[2]) * 10; /* delay in 1/100 secs */
- }
- else if ( extCode == 0xff ) { /* application extension block */
- }
-
- while ( ext != NULL ) {
- CHECK( DGifGetExtensionNext( gf, &ext));
- }
- break;
-
- case TERMINATE_RECORD_TYPE:
- break;
-
- default: /* Should be traps by DGifGetRecordType. */
- break;
- }
- } while ( rec != TERMINATE_RECORD_TYPE );
-
- if ( firstImg && (img != firstImg) ){
- img->next = firstImg; /* link it together (as a ring) */
- }
- //fprintf(stderr,"total frame = %d\n",nFrames);
- return firstImg;
-}
-
-/**************************************************************************************
- * memory buffer IO
- */
-
-typedef struct {
- unsigned char *buf;
- unsigned char *p;
- long remain;
-} BufferSource;
-
-static int
-readGifBuffer ( GifFileType *gf, GifByteType* buf, int length )
-{
- BufferSource *psource = (BufferSource*)gf->UserData;
-
- if ( psource && (psource->remain >= length) ) {
- memcpy( buf, psource->p, length);
- psource->p += length;
- psource->remain -= length;
-
- return length;
- }
- else {
- return 0;
- }
-}
-
-/*
- * intercept all file io and map it to AWT_xx file io maros
- * (in order to obtain thread safety)
- */
-typedef struct {
- int fd;
-} FileSource;
-
-static int
-readGifFileSource( GifFileType *gf, GifByteType* buf, int length )
-{
- FileSource *psource = (FileSource*)gf->UserData;
- int n = AWT_READ( psource->fd, buf, length);
-
- return (n < 0) ? 0 : n;
-}
-
-#endif /* INCLUDE_GIF */
-
-/**************************************************************************************
- * these are the "exported" production interface functions
- */
-
-Image*
-readGifFile ( int infile, char *fn )
-{
- Image *img = 0;
-
-#if defined(INCLUDE_GIF)
-
- /*
- * we don't use DGifOpenFile because file io might be intercepted
- * (because of threading)
- */
- FileSource fileSrc;
- GifFileType *gf;
- s=fn;
- QImage *tmp2 = new QImage(fn);
- colordepth = tmp2->depth();
- //fprintf(stderr,"colordepth %d %d %d\n",colordepth,tmp2->width(),tmp2->height());
- delete tmp2;
- fileSrc.fd = infile;
-
- if ( !(gf = DGifOpen( &fileSrc, readGifFileSource)) )
- {
- fprintf(stderr,"can't open gif file!!\n");
- return 0;
- }
- img = readGif( gf);
-
- DGifCloseFile( gf);
-#endif
-
- return img;
-}
-
-
-Image*
-readGifData ( unsigned char* buf, long len )
-{
- Image *img = 0;
-#if defined(INCLUDE_GIF)
- BufferSource bufSrc;
- GifFileType *gf;
- QByteArray a;
- a.setRawData((char *)buf,sizeof(buf));
- QImage *tmp2 = new QImage(a);
- colordepth = tmp2->depth();
- delete tmp2;
- bufSrc.buf = bufSrc.p = buf;
- bufSrc.remain = len;
-
- if ( !(gf = DGifOpen( &bufSrc, readGifBuffer)) )
- return 0;
-
- img = readGif( gf);
-
- DGifCloseFile( gf);
-
-#endif /* INCLUDE_GIF */
-
- return img;
-}
===================================================================
Checking out kaffe/libraries/clib/awt/qt/imgjpeg.cc
RCS: /home/cvs/kaffe/kaffe/libraries/clib/awt/qt/Attic/imgjpeg.cc,v
VERS: 1.2
***************
--- kaffe/libraries/clib/awt/qt/imgjpeg.cc Sat Jul 10 06:50:51 2004
+++ /dev/null Sun Aug 4 19:57:58 2002
@@ -1,388 +0,0 @@
-/**
- * imgjpeg.c - interface for libjpeg GIF input routines
- *
- * Copyright (c) 1998
- * Transvirtual Technologies, Inc. All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- */
-
-#include "defs.h"
-#include "toolkit.h"
-
-#if defined(HAVE_JPEGLIB_H) && defined(HAVE_LIBJPEG)
-#define INCLUDE_JPEG 1
-#endif
-
-#ifdef INCLUDE_JPEG
-BEGIN_C_DECLS
-
-#include "jpeglib.h"
-#include "jerror.h"
-
-END_C_DECLS
-#endif
-
-
-#define MAX_JPEG_COLORS 256
-
-/*
- * Hmmm, libjpeg uses explicit indices to access colormap components. We assume
- * the same values like in rdgif.h (which isn't part of jpeglib-6b anymore).
- * We should add a check for a RGB colormap / organization.
- */
-#define CM_RED 0
-#define CM_GREEN 1
-#define CM_BLUE 2
-
-/* references to img.c */
-Image* createImage ( int width, int height );
-void Java_java_awt_Toolkit_imgFreeImage( JNIEnv* env, jclass clazz, Image * img);
-void createXImage ( Toolkit* X, Image* img );
-
-
-#ifdef INCLUDE_JPEG
-
-/*******************************************************************************************
- * required typedefs and structs
- */
-
-struct error_mgr {
- struct jpeg_error_mgr pub;
- jmp_buf setjmp_buffer;
-};
-
-typedef struct error_mgr * error_ptr;
-
-METHODDEF(void)
-error_exit ( j_common_ptr cinfo)
-{
- error_ptr myerr = (error_ptr) cinfo->err;
- (*cinfo->err->output_message)(cinfo);
- longjmp(myerr->setjmp_buffer, 1);
-}
-
-
-typedef struct {
- struct jpeg_source_mgr pub; /* public fields */
-
- long buflen; /* length of external buffer */
- JOCTET * buffer; /* start of buffer */
-
- boolean start_of_file; /* have we gotten any data yet? */
-} bufsrc_mgr;
-
-typedef bufsrc_mgr * bufsrc_ptr;
-
-
-#define BUF_SIZE 2048
-
-typedef struct {
- struct jpeg_source_mgr pub; /* public fields */
-
- int fd;
- JOCTET *buffer;
-} filesrc_mgr;
-
-typedef filesrc_mgr * filesrc_ptr;
-
-
-/*******************************************************************************************
- * memory buffer extension for the standard jpeg lib input management (jdatasrc.c)
- */
-
-METHODDEF(void)
-init_buf_source (j_decompress_ptr cinfo)
-{
- bufsrc_ptr src = (bufsrc_ptr) cinfo->src;
-
- /* We reset the empty-input-file flag for each image,
- * but we don't clear the input buffer.
- * This is correct behavior for reading a series of images from one source.
- */
- src->start_of_file = TRUE;
-}
-
-
-static JOCTET end_marker[2] = { (JOCTET) 0xFF, (JOCTET) JPEG_EOI };
-
-METHODDEF(boolean)
-get_buf_source (j_decompress_ptr cinfo)
-{
- bufsrc_ptr src = (bufsrc_ptr) cinfo->src;
-
- if ( src->pub.next_input_byte && (src->start_of_file == FALSE) ) {
- WARNMS(cinfo, JWRN_JPEG_EOF);
- src->pub.next_input_byte = end_marker;
- src->pub.bytes_in_buffer = sizeof(end_marker);
- }
- else { /* we read in one seep (no need to use two buffers) */
- src->pub.next_input_byte = src->buffer;
- src->pub.bytes_in_buffer = src->buflen;
- src->start_of_file = FALSE;
- }
-
- return TRUE;
-}
-
-
-METHODDEF(void)
-skip_buf_source ( j_decompress_ptr cinfo, long num_bytes )
-{
- bufsrc_ptr src = (bufsrc_ptr) cinfo->src;
-
- if ( src->start_of_file == TRUE )
- get_buf_source( cinfo);
-
- src->pub.next_input_byte += (size_t) num_bytes;
- src->pub.bytes_in_buffer -= (size_t) num_bytes;
-}
-
-
-METHODDEF(void)
-term_buf_source (j_decompress_ptr cinfo)
-{
- bufsrc_ptr src = (bufsrc_ptr) cinfo->src;
-
- /*
- * Take care the (external) buffer isn't deleted by jpeg_destroy_decompress.
- * This shouldn't be necessary since jpeg_destroy cleans up by means of the
- * jpeg memory manager, but we better play it safe
- */
- src->buffer = 0;
-}
-
-
-GLOBAL(void)
-jpeg_buffer_src (j_decompress_ptr cinfo, unsigned char* buf, long len )
-{
- bufsrc_ptr src;
-
- if (cinfo->src == NULL) { /* first time for this JPEG object? */
- cinfo->src = (struct jpeg_source_mgr *)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
- sizeof(bufsrc_mgr));
- }
-
- src = (bufsrc_ptr) cinfo->src;
- src->pub.init_source = init_buf_source;
- src->pub.fill_input_buffer = get_buf_source;
- src->pub.skip_input_data = skip_buf_source;
- src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
- src->pub.term_source = term_buf_source;
-
- src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
- src->pub.next_input_byte = NULL; /* until buffer loaded */
-
- src->buffer = buf;
- src->buflen = len;
-}
-
-
-/*******************************************************************************************
- * file desriptor read extension for the standard jpeg lib input management (jdatasrc.c)
- */
-
-METHODDEF(void)
-init_file_source (j_decompress_ptr cinfo)
-{
- /* nothing to do */
-}
-
-METHODDEF(boolean)
-get_file_source (j_decompress_ptr cinfo)
-{
- filesrc_ptr src = (filesrc_ptr) cinfo->src;
- int n = AWT_READ( src->fd, src->buffer, BUF_SIZE);
-
- if ( n < 0 ) {
- WARNMS(cinfo, JWRN_JPEG_EOF);
- src->pub.next_input_byte = end_marker;
- src->pub.bytes_in_buffer = sizeof(end_marker);
- }
- else {
- src->pub.next_input_byte = src->buffer;
- src->pub.bytes_in_buffer = n;
- }
-
- return TRUE;
-}
-
-
-METHODDEF(void)
-skip_file_source ( j_decompress_ptr cinfo, long num_bytes )
-{
- filesrc_ptr src = (filesrc_ptr) cinfo->src;
-
- if ( num_bytes < src->pub.bytes_in_buffer ){
- src->pub.next_input_byte += num_bytes;
- src->pub.bytes_in_buffer -= num_bytes;
- }
- else {
- num_bytes -= src->pub.bytes_in_buffer;
-
- AWT_SETPOS( src->fd, num_bytes);
- get_file_source( cinfo);
- }
-}
-
-
-METHODDEF(void)
-term_file_source (j_decompress_ptr cinfo)
-{
- /* nothing to do, here
- * the file is closed by our caller, the buffer is allocated on the stack
- */
-}
-
-
-GLOBAL(void)
-jpeg_file_src (j_decompress_ptr cinfo, int fd )
-{
- filesrc_ptr src;
-
- if (cinfo->src == NULL) { /* first time for this JPEG object? */
- src = (filesrc_ptr)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
- sizeof(filesrc_mgr));
- src->buffer = (JOCTET *)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
- BUF_SIZE * sizeof(JOCTET));
- cinfo->src = (struct jpeg_source_mgr *) src;
- }
- else {
- src = (filesrc_ptr) cinfo->src;
- }
-
- src->pub.init_source = init_file_source;
- src->pub.fill_input_buffer = get_file_source;
- src->pub.skip_input_data = skip_file_source;
- src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
- src->pub.term_source = term_file_source;
-
- src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
- src->pub.next_input_byte = NULL; /* until buffer loaded */
-
- src->fd = fd;
-}
-
-
-/************************************************************************************
- * JPEG auxiliary funcs (production callbacks)
- */
-
-void
-jscan_to_img( Image * img, JSAMPROW buf, struct jpeg_decompress_struct * cinfo)
-{
- register int col, pix, rgb, idx;
- register JSAMPARRAY colormap = cinfo->colormap;
-
- for ( col = 0; col < cinfo->output_width; col++) {
- idx = *buf++;
- rgb = (colormap[CM_RED][idx] << 16) | (colormap[CM_GREEN][idx] << 8) | colormap[CM_BLUE][idx];
-// pix = pixelValue( X, rgb);
- XPutPixel( img->xImg, col, cinfo->output_scanline-1, pix);
- }
-}
-
-
-/************************************************************************************
- * Jpeg production
- */
-
-Image*
-readJpeg ( struct jpeg_decompress_struct* cinfo, volatile int colors )
-{
- struct error_mgr jerr;
- JSAMPARRAY buffer;
- Image* volatile img = 0;
- int row_stride;
-
- cinfo->err = jpeg_std_error(&jerr.pub);
- jerr.pub.error_exit = error_exit;
-
- if ( setjmp(jerr.setjmp_buffer)) {
- if ( img ) {
- Java_java_awt_Toolkit_imgFreeImage( 0, 0, img);
- }
- return 0;
- }
-
- jpeg_read_header( cinfo, TRUE);
-
- if ( colors < 8 ) {
- colors = 8;
- }
- else if ( colors > 256 ) {
- colors = 256;
- }
-
- cinfo->desired_number_of_colors = colors;
- cinfo->quantize_colors = TRUE;
- cinfo->out_color_space = JCS_RGB;
-
- jpeg_start_decompress( cinfo);
- row_stride = cinfo->output_width * cinfo->output_components;
-
- /* it's time to create the target image */
- img = createImage( cinfo->output_width, cinfo->output_height);
- createXImage( X, img);
-
- buffer = (*cinfo->mem->alloc_sarray)((j_common_ptr) cinfo, JPOOL_IMAGE, row_stride, 1);
-
- while (cinfo->output_scanline < cinfo->output_height) {
- jpeg_read_scanlines( cinfo, buffer, 1);
- jscan_to_img( img, buffer[0], cinfo);
- }
-
- jpeg_finish_decompress( cinfo);
-
- return img;
-}
-
-#endif /* INCLUDE_JPEG */
-
-
-/**************************************************************************************
- * these are the "exported" production interface functions
- */
-
-Image*
-readJpegFile ( int infile )
-{
- Image *img = 0;
-
-#ifdef INCLUDE_JPEG
- struct jpeg_decompress_struct cinfo;
-
- jpeg_create_decompress( &cinfo);
- jpeg_file_src( &cinfo, infile);
-
- img = readJpeg( &cinfo, MAX_JPEG_COLORS);
-
- jpeg_destroy_decompress( &cinfo);
-#endif /* INCLUDE_JPEG */
-
- return img;
-}
-
-
-Image*
-readJpegData ( unsigned char* buf, long len )
-{
- Image *img = 0;
-
-#ifdef INCLUDE_JPEG
- struct jpeg_decompress_struct cinfo;
-
- jpeg_create_decompress( &cinfo);
- jpeg_buffer_src( &cinfo, buf, len);
-
- img = readJpeg( &cinfo, MAX_JPEG_COLORS);
-
- jpeg_destroy_decompress( &cinfo);
-#endif /* INCLUDE_JPEG */
-
- return img;
-}
===================================================================
Checking out kaffe/libraries/clib/awt/qt/imgpng.cc
RCS: /home/cvs/kaffe/kaffe/libraries/clib/awt/qt/Attic/imgpng.cc,v
VERS: 1.2
***************
--- kaffe/libraries/clib/awt/qt/imgpng.cc Sat Jul 10 06:50:51 2004
+++ /dev/null Sun Aug 4 19:57:58 2002
@@ -1,369 +0,0 @@
-/**
- * imgpng.c - interface for libpng input routines
- *
- * Copyright (c) 1998
- * Transvirtual Technologies, Inc. All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- */
-
-#include "config.h"
-#include "defs.h"
-
-#if defined(HAVE_PNG_H) && defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
-#define INCLUDE_PNG 1
-#endif
-
-#if !defined(INCLUDE_PNG)
-#include "toolkit.h"
-#endif
-
-#if defined(INCLUDE_PNG)
-BEGIN_C_DECLS
-
-#include "png.h"
-
-END_C_DECLS
-#include "toolkit.h"
-
-
-/* references to img.cc */
-Image* createImage ( int width, int height );
-void Java_java_awt_Toolkit_imgFreeImage( JNIEnv* env, jclass clazz, Image * img);
-void createXImage ( Toolkit* X, Image* img );
-void createXMaskImage ( Toolkit* X, Image* img );
-void createAlphaImage ( Toolkit* X, Image* img );
-void reduceAlpha ( Toolkit* X, Image* img, int threshold );
-
-
-/**************************************************************************************
- * auxiliary funtions
- */
-
-static inline int
-hasAlpha ( png_structp png_ptr )
-{
- return (png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
- png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA);
-
-}
-
-static inline jint
-readARGB ( unsigned char** p, int hasAlpha )
-{
- jint argb;
-
- argb = *(*p)++;
- argb <<= 8;
- argb += *(*p)++;
- argb <<= 8;
- argb += *(*p)++;
-
- if ( hasAlpha ) {
- argb <<= 8;
- argb += *(*p)++;
- }
-
- return argb;
-}
-
-
-static inline void
-setPixel ( Image* img, unsigned long argb, int row, int col )
-{
- if ( img->alpha ){
- PutAlpha( img->alpha, col, row, argb >> 24);
- }
-
-// XPutPixel( img->xImg, col, row, pixelValue( X, argb));
-}
-
-
-static void
-readRowData ( png_structp png_ptr, png_infop info_ptr, png_bytep row, Image *img )
-{
- int i, j;
- jint argb;
- unsigned char *p;
-
- for ( i = 0; i < info_ptr->height; i++ ) {
- png_read_row( png_ptr, row, 0);
-
- for ( j=0, p=(unsigned char*)row; j<info_ptr->width; j++ ) {
- argb = readARGB( &p, (img->alpha != 0));
- setPixel( img, argb, i, j);
- }
- }
-}
-
-static void
-readImageData ( png_structp png_ptr, png_infop info_ptr, png_bytepp rows, Image *img )
-{
- int i, j;
- jint argb;
- unsigned char *p;
-
- png_read_image( png_ptr, rows);
-
- for ( i=0; i<info_ptr->height; i++ ) {
- for ( j=0, p=(unsigned char*)rows[i]; j<info_ptr->width; j++ ) {
- argb = readARGB( &p, (img->alpha != 0));
- setPixel( img, argb, i, j);
- }
- }
-}
-
-#if 0
-static void
-readbackRow ( Image *img, unsigned char* rowBuf, int row )
-{
- int i;
- unsigned char *p;
- int r, g, b, a;
- unsigned long pix;
-
- for ( i=0, p=rowBuf; i<img->width; i++ ) {
- pix = XGetPixel( img->xImg, i, row);
-// rgbValues( X, pix, &r, &g, &b);
-
- a = (img->alpha) ? GetAlpha( img->alpha, i, row) : 0xff;
-
- *p++ = a;
- *p++ = r;
- *p++ = g;
- *p++ = b;
- }
-}
-#endif
-
-#if 0
-/*
- * THIS DOESN'T WORK YET. The idea is to avoid allocating temporary
- * memory for the WHOLE image in ARGB pels (but ADAM7 seems to require
- * neighbor rows, too)
- */
-static void
-readInterlacedData ( png_structp png_ptr, png_infop info_ptr, png_bytep row, Image *img )
-{
- int i, j, pass;
- jint argb;
- unsigned char *p;
-
-
- for ( pass=0; pass<7; pass++ ) {
- for ( i = 0; i < info_ptr->height; i++ ) {
- if ( pass ) {
- readbackRow( img, row, i);
- }
- png_read_row( png_ptr, row, 0);
-
- for ( j=0, p=(unsigned char*)row; j<info_ptr->width; j++ ) {
- argb = readARGB( &p, (img->alpha != 0));
- setPixel( img, argb, i, j);
- }
- }
- }
-}
-#endif
-
-
-static Image*
-readPng ( png_structp png_ptr, png_infop info_ptr )
-{
- Image *volatile img = 0;
- double screen_gamma = 1.2, file_gamma;
- int i, number_passes;
- int row_bytes;
- png_bytepp volatile rows = 0;
- png_bytep volatile data = 0;
-
- if ( setjmp(png_ptr->jmpbuf) ) {
- if ( img )
- Java_java_awt_Toolkit_imgFreeImage( 0, 0, img);
- if ( rows )
- AWT_FREE( rows);
- if ( data )
- AWT_FREE( data);
- return 0;
- }
-
- png_read_info( png_ptr, info_ptr);
-
- /* handle gamma correction */
- {
-#if defined(PNG_READ_sRGB_SUPPORTED)
- int intent;
- if ( png_get_sRGB( png_ptr, info_ptr, &intent) ) {
- png_set_sRGB( png_ptr, info_ptr, intent);
- }
- else
-#endif
- if ( png_get_gAMA(png_ptr, info_ptr, &file_gamma) ) {
- png_set_gamma( png_ptr, screen_gamma, file_gamma);
- }
- else {
- png_set_gamma( png_ptr, screen_gamma, 0.50);
- }
- }
-
- png_set_strip_16( png_ptr);
- png_set_expand( png_ptr);
- png_set_gray_to_rgb( png_ptr);
- png_set_swap_alpha( png_ptr); /* we need ARGB instead of the standard RGBA */
-
- row_bytes = png_get_rowbytes( png_ptr, info_ptr);
- number_passes = png_set_interlace_handling( png_ptr);
-
- /* Optional call to gamma correct and add the background to the palette */
- png_read_update_info( png_ptr, info_ptr);
-
- /* time to create the image */
- img = createImage( info_ptr->width, info_ptr->height);
- if ( hasAlpha( png_ptr) )
- createAlphaImage( X, img);
- createXImage( X, img);
-
- if ( info_ptr->interlace_type != 0 ) {
-#ifndef OPTIMIZE_SPACE
- /*
- * This is bad: to read an interlaced image, we need enough space to (temporarily)
- * store the whole transformed data (passes need prev. results). Unfortunately,
- * interlacing is used for large images, and this might require a LOT of memory.
- */
- rows = AWT_MALLOC( sizeof(png_bytep) * info_ptr->height);
- data = AWT_MALLOC( row_bytes * info_ptr->height);
- for ( i=0; i<info_ptr->height; i++ )
- rows[i] = (data + i*row_bytes);
-
- readImageData( png_ptr, info_ptr, rows, img);
-
- AWT_FREE( rows);
- AWT_FREE( data);
-#else
- data = AWT_MALLOC( row_bytes);
- readInterlacedData( png_ptr, info_ptr, data, img);
- AWT_FREE( data);
-#endif
*** Patch too long, truncated ***
More information about the kaffe
mailing list