dslinux/user/pixil/packages/viewml/viewml/kimgio AUTHORS ChangeLog Makefile.am Makefile.in README eps.cpp eps.h jpeg.cpp jpeg.h kimgio.cpp kimgio.h netpbm.cpp netpbm.h pngr.cpp pngr.h tiffr.cpp tiffr.h xview.cpp xview.h
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:26:39 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/packages/viewml/viewml/kimgio
In directory antilope:/tmp/cvs-serv11916/packages/viewml/viewml/kimgio
Added Files:
AUTHORS ChangeLog Makefile.am Makefile.in README eps.cpp eps.h
jpeg.cpp jpeg.h kimgio.cpp kimgio.h netpbm.cpp netpbm.h
pngr.cpp pngr.h tiffr.cpp tiffr.h xview.cpp xview.h
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it
--- NEW FILE: eps.cpp ---
#include <unistd.h>
#include <stdio.h>
#include <qimage.h>
#include <qiodevice.h>
#include <qstring.h>
#include "eps.h"
#define BUFLEN 200
char buf[BUFLEN+1];
#define BBOX "%%BoundingBox:"
#define BBOX_LEN strlen(BBOX)
int bbox ( const char *fileName, int *x1, int *y1, int *x2, int *y2)
{
FILE * file;
int a, b, c, d;
int ret = FALSE;
file = fopen (fileName, "r");
do {
if (! fgets (buf, BUFLEN, file)) break;
if (strncmp (buf, BBOX, BBOX_LEN) == 0)
{
ret = sscanf (buf, "%s %d %d %d %d", buf,
&a, &b, &c, &d);
if (ret == 5) {
ret = TRUE;
break;
}
}
} while ( true );
*x1 = a;
*y1 = b;
*x2 = c;
*y2 = d;
fclose (file);
return ret;
}
void kimgio_epsf_read (QImageIO *image)
{
FILE * ghostfd, * imagefd;
char * tmpFileName;
int x1, y1, x2, y2;
QString cmdBuf;
QString tmp;
// find bounding box
if ( bbox (image->fileName(), &x1, &y1, &x2, &y2) == 0 ) {
return;
}
// temporary file name
tmpFileName = tmpnam(NULL);
if( tmpFileName == 0 ) {
return;
}
// x1, y1 -> translation
// x2, y2 -> new size
x2 -= x1;
y2 -= y1;
// create GS command line
cmdBuf = "gs -sOutputFile=";
cmdBuf += tmpFileName;
cmdBuf += " -q -g";
tmp.setNum( x2 );
cmdBuf += tmp;
tmp.setNum( y2 );
cmdBuf += "x";
cmdBuf += tmp;
cmdBuf += " -dNOPAUSE -sDEVICE=ppm -c "
"0 0 moveto "
"1000 0 lineto "
"1000 1000 lineto "
"0 1000 lineto "
"1 1 254 255 div setrgbcolor fill "
"0 0 0 setrgbcolor - -c showpage quit";
// run ghostview
ghostfd = popen (cmdBuf, "w");
if ( ghostfd == 0 ) {
return;
}
fprintf (ghostfd, "\n%d %d translate\n", -x1, -y1);
// write image to gs
imagefd = fopen( image->fileName(), "r" );
if ( imagefd != 0 )
{
while( fgets (buf, BUFLEN, imagefd) != 0 ) {
fputs (buf, ghostfd);
}
fclose (imagefd);
}
pclose ( ghostfd );
// load image
QImage myimage;
bool loadstat = myimage.load (tmpFileName);
if( loadstat ) {
myimage.createHeuristicMask();
image->setImage (myimage);
image->setStatus (0);
}
unlink (tmpFileName);
return;
}
void kimgio_epsf_write( QImageIO * )
{
// TODO: implement this
warning( "kimgio_epsf_write: not yet implemented" );
}
--- NEW FILE: eps.h ---
#ifndef _EPS_H
#define _EPS_H
void kimgio_epsf_read (QImageIO *image);
void kimgio_epsf_write (QImageIO *image);
#endif
--- NEW FILE: jpeg.cpp ---
////////////////////////////////////////////////////
//
// Transparent support for JPEG files in Qt Pixmaps,
// using IJG JPEG library.
//
// Sirtaj Kang, Oct 1996.
//
// $Id: jpeg.cpp,v 1.1 2006-10-03 11:26:37 dslinux_amadeus Exp $
#ifdef HAVE_CONFIG_H
#include"config.h"
#endif
#ifdef HAVE_LIBJPEG
#include<stdio.h>
#include<assert.h>
#include<sys/types.h>
#include"qimage.h"
#include"qdstream.h"
#include"qcolor.h"
#include"qpixmap.h"
#include"jpeg.h"
//
// Hack to fix INT16 redefinition problem
//
#define XMD_H
typedef short INT16;
extern "C" {
#include<jpeglib.h>
}
#undef XMD_H
//////
// Plug-in source manager for IJG JPEG compression/decompression library
//
//
// Source control structure.
//
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
QDataStream *infile; /* Pointer to QIODevice object */
JOCTET * buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */
} qimageio_jpeg_source_mgr;
void qimageio_jpeg_src(j_decompress_ptr cinfo, QDataStream *image);
//
// Source manager file request plug-in methods.
//
void qimageio_init_source(j_decompress_ptr cinfo);
boolean qimageio_fill_input_buffer(j_decompress_ptr cinfo);
void qimageio_skip_input_data(j_decompress_ptr cinfo, long num_bytes);
void qimageio_term_source(j_decompress_ptr cinfo);
// Buffer for file reads (max bytes)
// ?? Is this good enough? Bigger, perhaps?
#define INPUT_BUFFER_SIZE 4096
/////////////////////
//
// No JPEG save support yet
//
void kimgio_jpeg_write(QImageIO *)
{
fprintf(stderr, "JPEG saving unimplemented.\n");
return;
}
///////////
//
// Plug-in to read files from JPEG into QImage
//
void kimgio_jpeg_read(QImageIO * iio)
{
QIODevice *d = iio->ioDevice();
QImage image;
QDataStream s(d);
JSAMPROW buffer[1];
unsigned int *ui_row;
unsigned char *uc_row, *uc_row_index;
unsigned int depth, col;
unsigned char r,g,b;
// We need to know if the display can handle 32-bit images
depth = QPixmap::defaultDepth();
// Init jpeg decompression structures
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
qimageio_jpeg_src(&cinfo, &s);
if( jpeg_read_header(&cinfo, (boolean) FALSE )
!= JPEG_HEADER_OK ) {
return; // Header error
}
// If we're in an 8bit display, we want a colourmap.
if ((depth < 32) && (cinfo.out_color_space == JCS_RGB)) {
cinfo.quantize_colors = (boolean) TRUE;
cinfo.dither_mode = JDITHER_ORDERED;
}
jpeg_start_decompress(&cinfo);
if (cinfo.quantize_colors == TRUE) {
image.create(cinfo.output_width, cinfo.output_height,
8, cinfo.actual_number_of_colors,
QImage::LittleEndian);
// Read colourmap
for ( col = 0; col < (unsigned)cinfo.actual_number_of_colors;
col++ ) {
image.setColor(col, qRgb(cinfo.colormap[0][col],
cinfo.colormap[1][col],
cinfo.colormap[2][col]));
}
} else if (cinfo.out_color_space == JCS_GRAYSCALE) {
image.create(cinfo.output_width, cinfo.output_height,
8, 256, QImage::LittleEndian);
// Read colourmap
for (col = 0; col < 256; col++) {
image.setColor(col, qRgb(col, col, col));
}
} else {
image.create(cinfo.output_width, cinfo.output_height, 32);
}
// Alloc one-row buffer for scanline
buffer[0] = new JSAMPLE[cinfo.output_width * cinfo.output_components];
//
// Perform decompression
//
// Decompress with colormap
if (cinfo.quantize_colors == TRUE || cinfo.out_color_space != JCS_RGB) {
while (cinfo.output_scanline < cinfo.output_height) {
uc_row_index = image.scanLine(cinfo.output_scanline);
uc_row = buffer[0];
jpeg_read_scanlines(&cinfo, buffer, 1);
for (col = 0; col < cinfo.output_width; col++)
*uc_row_index++ = *uc_row++;
}
// Decompress 24-bit
} else {
while (cinfo.output_scanline < cinfo.output_height) {
ui_row = (unsigned int *)
image.scanLine(cinfo.output_scanline);
uc_row = buffer[0];
jpeg_read_scanlines(&cinfo, buffer, 1);
for (col = 0; col < cinfo.output_width; col++) {
r = *uc_row++;
g = *uc_row++;
b = *uc_row++;
*ui_row++ = qRgb(r, g, b);
}
}
}
// Clean up JPEG structs
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
// Bind new image to screen
iio->setImage(image);
iio->setStatus(0);
}
/////////
//
// JPEG plug in routines for QDataStream as input.
//
// Registers stream routines for use by IJG JPEG library
void qimageio_jpeg_src(j_decompress_ptr cinfo, QDataStream * image)
{
qimageio_jpeg_source_mgr *src;
// Set up buffer for the first time
if (cinfo->src == NULL) {
cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo,
JPOOL_PERMANENT,
sizeof(qimageio_jpeg_source_mgr));
src = (qimageio_jpeg_source_mgr *) cinfo->src;
src->buffer = (JOCTET *)
(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo,
JPOOL_PERMANENT,
INPUT_BUFFER_SIZE * sizeof(JOCTET));
}
// Register methods
src = (qimageio_jpeg_source_mgr *) cinfo->src;
src->pub.init_source = qimageio_init_source;
src->pub.fill_input_buffer = qimageio_fill_input_buffer;
src->pub.skip_input_data = qimageio_skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart;
src->pub.term_source = qimageio_term_source;
// This is potentially dangerous, as it has chance of being
// misinterpreted. Saves effort, tho!
src->infile = image;
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
src->pub.next_input_byte = NULL; /* until buffer loaded */
}
/////////
//
// Intializes data source
//
void qimageio_init_source(j_decompress_ptr cinfo)
{
qimageio_jpeg_source_mgr *ptr = (qimageio_jpeg_source_mgr *) cinfo->src;
ptr->start_of_file = (boolean) TRUE;
} /////////
//
// Reads data from stream into JPEG working buffer
//
boolean qimageio_fill_input_buffer(j_decompress_ptr cinfo)
{
qimageio_jpeg_source_mgr *ptr = (qimageio_jpeg_source_mgr *) cinfo->src;
size_t nbytes;
nbytes = ptr->infile->device()->readBlock((char *) (ptr->buffer),
INPUT_BUFFER_SIZE);
if (nbytes <= 0) {
if (ptr->start_of_file) {
fprintf(stderr, "error: file empty.\n");
return (boolean) FALSE;
}
fprintf(stderr, "warning: premature EOF in file.\n");
/* Insert a fake EOI marker */
ptr->buffer[0] = (JOCTET) 0xFF;
ptr->buffer[1] = (JOCTET) JPEG_EOI;
nbytes = 2;
}
ptr->pub.next_input_byte = ptr->buffer;
ptr->pub.bytes_in_buffer = nbytes;
ptr->start_of_file = (boolean) FALSE;
return (boolean) TRUE;
}
//////////
//
// Jumps over large chunks of data. Can probably be done quicker. (fseek()
// style).
void qimageio_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
{
qimageio_jpeg_source_mgr *ptr = (qimageio_jpeg_source_mgr *) cinfo->src;
if (num_bytes > 0) {
while (num_bytes > (long) ptr->pub.bytes_in_buffer) {
num_bytes -= (long) ptr->pub.bytes_in_buffer;
(void) qimageio_fill_input_buffer(cinfo);
} ptr->pub.next_input_byte += (size_t) num_bytes;
ptr->pub.bytes_in_buffer -= (size_t) num_bytes;
}
}
/////////
//
// Clean up. Doesn't really do anything, but required for compat.
//
void qimageio_term_source(j_decompress_ptr)
{
return;
}
#endif
--- NEW FILE: ChangeLog ---
1998-12-08 Alex Zepeda <garbanzo at hooked.net>
* pngr.cpp (kimgio_png_write): Removed text after #else and #endif. The
text should either be commented or made part of an #elif.
--- NEW FILE: pngr.cpp ---
/*
* PNGR.CPP -- QImageIO read/write handlers for
* the PNG graphic format using libpng.
*
* Copyright (c) October 1998, Sirtaj Singh Kang. Distributed under
* the LGPL.
*
* $Id: pngr.cpp,v 1.1 2006-10-03 11:26:37 dslinux_amadeus Exp $
*/
#ifdef HAVE_CONFIG_H
#include"config.h"
#endif
#ifdef HAVE_LIBPNG
#include<stdio.h>
#include<stdlib.h>
#include<qimage.h>
#include<qfile.h>
extern "C" {
#include<png.h>
}
void kimgio_png_read( QImageIO *io )
{
// open png file
QImage image;
FILE *fp = fopen ( io->fileName(), "r" );
int passes = 0;
if( fp == 0 ) {
debug( "Couldn't open %s for reading.", io->fileName() );
return;
}
// init png structures
png_structp png_ptr = png_create_read_struct( // image ptr
PNG_LIBPNG_VER_STRING, 0, 0, 0 );
if( png_ptr == 0 ) {
fclose( fp );
return;
}
png_infop png_info = png_create_info_struct( png_ptr ); // info ptr
if( png_info == 0 ) {
png_destroy_read_struct( &png_ptr, 0, 0 );
fclose( fp );
return;
}
png_infop png_end = png_create_info_struct( png_ptr );
if( !png_end ) {
png_destroy_read_struct( &png_ptr, &png_info, 0 );
fclose( fp );
return;
}
// error jump point
if( setjmp( png_ptr->jmpbuf ) ) {
png_destroy_read_struct( &png_ptr, &png_info, &png_end );
fclose( fp );
return;
}
// read header
png_init_io( png_ptr, fp );
png_read_info( png_ptr, png_info );
// transformations
png_set_packing( png_ptr );
png_set_strip_16( png_ptr );
if( !(png_ptr->color_type & PNG_COLOR_MASK_COLOR) ) {
png_set_gray_to_rgb( png_ptr );
}
else {
png_set_expand( png_ptr );
}
if( ! (png_info->color_type & PNG_COLOR_MASK_ALPHA) ) {
debug( "using filler" );
png_set_filler( png_ptr, 0, PNG_FILLER_BEFORE );
}
passes = png_set_interlace_handling ( png_ptr );
png_read_update_info( png_ptr, png_info );
if ( png_info->color_type != PNG_COLOR_TYPE_RGB_ALPHA ) {
debug( "Colortype %d is not rgb/alpha",
png_info->color_type );
}
if( png_info->bit_depth != 8 ) {
debug( "Depth %d is not 8", png_info->bit_depth );
}
// create image
if ( !image.create( png_info->width, png_info->height, 32 ) ) {
// out of memory
warning( "Out of memory creating QImage." );
png_destroy_read_struct( &png_ptr, &png_info, &png_end );
fclose( fp );
return;
}
// read image
for( ; passes; passes-- ) {
for( unsigned row = 0; row < png_info->height; row++ ) {
png_read_row( png_ptr, image.scanLine( row ), NULL );
}
}
if ( png_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ) {
debug( "Colortype %d is rgb/alpha",
png_info->color_type );
image.setAlphaBuffer(true);
}
else {
unsigned *pixels = (unsigned *) image.bits();
for( unsigned row = 0; row < png_info->height; row++ ) {
for( int i = 0; i < image.width(); i++ ) {
*pixels = *pixels >> 8;
pixels++;
}
}
}
png_read_end( png_ptr, png_info );
io->setImage( image );
io->setStatus( 0 );
// clean up
png_destroy_read_struct( &png_ptr, &png_info, &png_end );
fclose( fp );
return;
}
#if (defined PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 100)
void kimgio_png_write( QImageIO *iio )
{
QIODevice *f = ( iio->ioDevice() );
FILE *fp = 0;
png_structp png_ptr;
png_infop info_ptr;
int colortype = 0;
const QImage& image = iio->image();
int w = image.width(), h = image.height();
int numcolors = image.numColors();
int depth = image.depth() == 1 ? 1 : 8;
//debug("Size:\t%d X %d\n\tColors:\t%d\n\tDepth:\t%d",
// w, h, numcolors, image.depth());
if(numcolors > 0) {
//debug("PALETTE");
colortype = PNG_COLOR_TYPE_PALETTE;
}
else if(image.hasAlphaBuffer()) {
//debug("RGB_ALPHA");
colortype = PNG_COLOR_TYPE_RGB_ALPHA;
}
else {
//debug("RGB");
colortype = PNG_COLOR_TYPE_RGB;
}
// open the file
fp = fdopen(((QFile*)f)->handle(), "wb");
if (fp == 0) {
iio->setStatus( -1 );
return;
}
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also check that
* the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED.
*/
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if (png_ptr == 0) {
fclose(fp);
iio->setStatus( -2 );
return;
}
/* Allocate/initialize the image information data. REQUIRED */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == 0) {
fclose(fp);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
iio->setStatus( -3 );
return;
}
/* set up the output control if you are using standard C streams */
png_init_io(png_ptr, fp);
/* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
*/
png_set_IHDR(png_ptr, info_ptr, w, h, depth, colortype,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* set the palette if there is one. REQUIRED for indexed-color images */
if(numcolors > 0) {
info_ptr->palette = (png_colorp)png_malloc(png_ptr, numcolors * sizeof (png_color));
for(int i = 0; i < numcolors; i++) {
info_ptr->palette[i].red = qRed(image.color(i));
info_ptr->palette[i].blue = qBlue(image.color(i));
info_ptr->palette[i].green = qGreen(image.color(i));
}
png_set_PLTE(png_ptr, info_ptr, info_ptr->palette, numcolors);
}
//optional significant bit chunk
if(image.isGrayscale()) {
info_ptr->sig_bit.gray = 8;
}
else {
info_ptr->sig_bit.red = 8;
info_ptr->sig_bit.green = 8;
info_ptr->sig_bit.blue = 8;
}
if(image.hasAlphaBuffer())
info_ptr->sig_bit.alpha = 8;
// Optional gamma chunk is strongly suggested if you have any guess
// as to the correct gamma of the image.
//png_set_gAMA(png_ptr, info_ptr, gamma);
// Optionally write comments into the image
//text_ptr[0].key = "Title";
//text_ptr[0].text = "Mona Lisa";
//text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
//text_ptr[1].key = "Author";
//text_ptr[1].text = "Leonardo DaVinci";
//text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
//text_ptr[2].key = "Description";
//text_ptr[2].text = "<long text>";
//text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
//png_set_text(png_ptr, info_ptr, text_ptr, 2);
// Write the file header information. REQUIRED
png_write_info(png_ptr, info_ptr);
// Once we write out the header, the compression type on the text
// chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
// PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
// at the end.
// pack pixels into bytes
png_set_packing( png_ptr );
png_set_strip_16( png_ptr );
// swap location of alpha bytes from ARGB to RGBA
//png_set_swap_alpha(png_ptr);
// Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
// RGB (4 channels -> 3 channels). The second parameter is not used.
if ( depth == 8 && !image.hasAlphaBuffer() )
png_set_filler(png_ptr, 0,
QImage::systemByteOrder() == QImage::BigEndian ?
PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
// flip BGR pixels to RGB
//png_set_bgr(png_ptr);
// swap bytes of 16-bit files to most significant byte first
//png_set_swap(png_ptr);
// swap bits of 1, 2, 4 bit packed pixel formats
//png_set_packswap(png_ptr);
// The easiest way to write the image (you may have a different memory
// layout, however, so choose what fits your needs best). You need to
// use the first method if you aren't handling interlacing yourself.
#define entire
// One of the following output methods is REQUIRED
#ifdef entire // write out the entire image data in one call
png_byte **row_pointers = image.jumpTable();
png_write_image(png_ptr, row_pointers);
#else // (no_entire) write out the image data by one or more scanlines
// If you are only writing one row at a time, this works
for (int y = 0; y < h; y++) {
png_bytep row_pointer = image.scanLine(y);
png_write_rows(png_ptr, row_pointer, 1);
}
#endif // (no_entire) use only one output method
// You can write optional chunks like tEXt, zTXt, and tIME at the end as well.
// It is REQUIRED to call this to finish writing the rest of the file
png_write_end(png_ptr, info_ptr);
// if you malloced the palette, free it here
if(numcolors > 0)
free(info_ptr->palette);
// if you allocated any text comments, free them here
// clean up after the write, and free any memory allocated
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
// close the file
fclose(fp);
iio->setStatus( 0 );
return;
}
#else
// png library is too old
void kimgio_png_write( QImageIO *iio )
{
// TODO: implement this
warning("kimgio_png_write: not yet implemented for old PNG libraries");
}
#endif
#endif /* HAVE_LIBPNG */
--- NEW FILE: AUTHORS ---
Sirtaj Singh Kang <taj at kde.org> -- kimgio and jpeg, tiff, png readers
Dirk Schoenberger <> -- eps, netpbm readers
Torben Weis <weis at kde.org> -- XV format reader/writer
Thomas Tanghus <tanghus at kde.org> -- PNG writer
--- NEW FILE: pngr.h ---
/*
* PNGR.H -- Prototypes for QImageIO read/write handlers for
* the PNG graphic format using libpng.
*
* Copyright (c) October 1998, Sirtaj Singh Kang.
* Distributed under the LGPL.
*
* $Id: pngr.h,v 1.1 2006-10-03 11:26:37 dslinux_amadeus Exp $
*/
#ifndef _SSK_PNGR_H
#define _SSK_PNGR_H
class QImageIO;
void kimgio_png_read( QImageIO *io );
void kimgio_png_write(QImageIO *io );
#endif
--- NEW FILE: kimgio.cpp ---
/**
* kimgio.h -- Implementation of interface to the KDE Image IO library.
* Sirtaj Singh Kang <taj at kde.org>, 23 Sep 1998.
*
* $Id: kimgio.cpp,v 1.1 2006-10-03 11:26:37 dslinux_amadeus Exp $
*
* This library is distributed under the conditions of the GNU LGPL.
*/
static int registered = 0;
#include"jpeg.h"
#include"pngr.h"
#include"xview.h"
#include"eps.h"
#include"tiffr.h"
#ifdef HAVE_CONFIG_H
#include"config.h"
#endif
#include<qimage.h>
void kimgioRegister(void)
{
if( registered ) {
return;
}
registered = 1;
#ifdef HAVE_LIBJPEG
// JPEG
QImageIO::defineIOHandler( "JPEG", "^\377\330", 0,
kimgio_jpeg_read, kimgio_jpeg_write );
#endif
// XV thumbnails
QImageIO::defineIOHandler( "XV", "^P7 332", "T",
kimgio_xv_read, kimgio_xv_write );
QImageIO::defineIOHandler("EPS", "^%!PS-Adobe-[^\n]+\n"
"%%BoundingBox", "T", kimgio_epsf_read, kimgio_epsf_write );
#ifdef HAVE_LIBPNG
QImageIO::defineIOHandler( "PNG", "^.PNG", 0,
kimgio_png_read, kimgio_png_write );
#endif
#ifdef HAVE_LIBTIFF
QImageIO::defineIOHandler("TIFF","[MI][MI]", 0,
kimgio_tiff_read, kimgio_tiff_write );
#endif
}
--- NEW FILE: Makefile.in ---
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_alias = @build_alias@
build_triplet = @build@
host_alias = @host_alias@
host_triplet = @host@
target_alias = @target_alias@
target_triplet = @target@
AS = @AS@
CC = @CC@
CPP = @CPP@
CXX = @CXX@
CXXCPP = @CXXCPP@
DLLTOOL = @DLLTOOL@
GLINC = @GLINC@
GLLIB = @GLLIB@
GMSGFMT = @GMSGFMT@
IDL = @IDL@
KDE_EXTRA_RPATH = @KDE_EXTRA_RPATH@
KDE_INCLUDES = @KDE_INCLUDES@
KDE_LDFLAGS = @KDE_LDFLAGS@
KDE_RPATH = @KDE_RPATH@
LD = @LD@
LIBCOMPAT = @LIBCOMPAT@
LIBCRYPT = @LIBCRYPT@
LIBDL = @LIBDL@
LIBJPEG = @LIBJPEG@
LIBMICO = @LIBMICO@
LIBOBJS = @LIBOBJS@
LIBPNG = @LIBPNG@
LIBPTHREAD = @LIBPTHREAD@
LIBPYTHON = @LIBPYTHON@
LIBQIMGIO = @LIBQIMGIO@
LIBSOCKET = @LIBSOCKET@
LIBTIFF = @LIBTIFF@
LIBTOOL = @LIBTOOL@
LIBUCB = @LIBUCB@
LIBZ = @LIBZ@
LIB_KAB = @LIB_KAB@
LIB_KDECORE = @LIB_KDECORE@
LIB_KDEUI = @LIB_KDEUI@
LIB_KDEUTIL = @LIB_KDEUTIL@
LIB_KFILE = @LIB_KFILE@
LIB_KFM = @LIB_KFM@
LIB_KHTML = @LIB_KHTML@
LIB_KHTMLW = @LIB_KHTMLW@
LIB_KIMGIO = @LIB_KIMGIO@
LIB_KIO = @LIB_KIO@
LIB_MEDIATOOL = @LIB_MEDIATOOL@
LIB_QT = @LIB_QT@
LIB_X11 = @LIB_X11@
LN_S = @LN_S@
MAKEINFO = @MAKEINFO@
MICO_INCLUDES = @MICO_INCLUDES@
MICO_LDFLAGS = @MICO_LDFLAGS@
MOC = @MOC@
MSGFMT = @MSGFMT@
NM = @NM@
PACKAGE = @PACKAGE@
PAMINC = @PAMINC@
PAMLIBPATHS = @PAMLIBPATHS@
PAMLIBS = @PAMLIBS@
PYTHONINC = @PYTHONINC@
PYTHONLIB = @PYTHONLIB@
QKEYCODE_H = @QKEYCODE_H@
QT_INCLUDES = @QT_INCLUDES@
QT_LDFLAGS = @QT_LDFLAGS@
RANLIB = @RANLIB@
TOPSUBDIRS = @TOPSUBDIRS@
USE_NLS = @USE_NLS@
VERSION = @VERSION@
XGETTEXT = @XGETTEXT@
XPMINC = @XPMINC@
XPMLIB = @XPMLIB@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_INCLUDES = @X_INCLUDES@
X_LDFLAGS = @X_LDFLAGS@
all_includes = @all_includes@
all_libraries = @all_libraries@
install_root = @install_root@
kde_appsdir = @kde_appsdir@
kde_bindir = @kde_bindir@
kde_cgidir = @kde_cgidir@
kde_confdir = @kde_confdir@
kde_datadir = @kde_datadir@
kde_htmldir = @kde_htmldir@
kde_icondir = @kde_icondir@
kde_includes = @kde_includes@
kde_libraries = @kde_libraries@
kde_locale = @kde_locale@
kde_mimedir = @kde_mimedir@
kde_minidir = @kde_minidir@
kde_partsdir = @kde_partsdir@
kde_sounddir = @kde_sounddir@
kde_toolbardir = @kde_toolbardir@
kde_wallpaperdir = @kde_wallpaperdir@
qt_includes = @qt_includes@
qt_libraries = @qt_libraries@
topdir = @topdir@
x_includes = @x_includes@
x_libraries = @x_libraries@
lib_LTLIBRARIES = libkimgio.la
libkimgio_la_LDFLAGS = -version-info 2:0
libkimgio_la_SOURCES = jpeg.cpp xview.cpp kimgio.cpp kimgio.h eps.cpp tiffr.cpp pngr.cpp
include_HEADERS = kimgio.h
noinst_HEADERS = jpeg.h xview.h eps.h tiffr.h pngr.h
INCLUDES = $(all_includes)
EXTRA_DIST = netpbm.cpp netpbm.h
mkinstalldirs = $(SHELL) $(top_srcdir)/admin/mkinstalldirs
CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(lib_LTLIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libkimgio_la_LIBADD =
libkimgio_la_OBJECTS = jpeg.lo xview.lo kimgio.lo eps.lo tiffr.lo \
pngr.lo
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
HEADERS = $(include_HEADERS) $(noinst_HEADERS)
DIST_COMMON = README AUTHORS ChangeLog Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP_ENV = --best
SOURCES = $(libkimgio_la_SOURCES)
OBJECTS = $(libkimgio_la_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .cpp .lo .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps kimgio/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-libLTLIBRARIES:
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
distclean-libLTLIBRARIES:
maintainer-clean-libLTLIBRARIES:
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(libdir)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \
$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \
else :; fi; \
done
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
list='$(lib_LTLIBRARIES)'; for p in $$list; do \
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \
done
.c.o:
$(COMPILE) -c $<
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
.c.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
.s.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
.S.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
maintainer-clean-libtool:
libkimgio.la: $(libkimgio_la_OBJECTS) $(libkimgio_la_DEPENDENCIES)
$(CXXLINK) -rpath $(libdir) $(libkimgio_la_LDFLAGS) $(libkimgio_la_OBJECTS) $(libkimgio_la_LIBADD) $(LIBS)
.cpp.o:
$(CXXCOMPILE) -c $<
.cpp.lo:
$(LTCXXCOMPILE) -c $<
install-includeHEADERS: $(include_HEADERS)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(includedir)
@list='$(include_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p"; \
$(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p; \
done
uninstall-includeHEADERS:
@$(NORMAL_UNINSTALL)
list='$(include_HEADERS)'; for p in $$list; do \
rm -f $(DESTDIR)$(includedir)/$$p; \
done
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = kimgio
distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am: install-libLTLIBRARIES
install-exec: install-exec-am
install-data-am: install-includeHEADERS
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am: uninstall-libLTLIBRARIES uninstall-includeHEADERS
uninstall: uninstall-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
$(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir)
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-libLTLIBRARIES mostlyclean-compile \
mostlyclean-libtool mostlyclean-tags \
mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-libLTLIBRARIES clean-compile clean-libtool clean-tags \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-libLTLIBRARIES distclean-compile \
distclean-libtool distclean-tags distclean-generic \
clean-am
-rm -f libtool
distclean: distclean-am
maintainer-clean-am: maintainer-clean-libLTLIBRARIES \
maintainer-clean-compile maintainer-clean-libtool \
maintainer-clean-tags maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \
clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \
uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \
distclean-compile clean-compile maintainer-clean-compile \
mostlyclean-libtool distclean-libtool clean-libtool \
maintainer-clean-libtool uninstall-includeHEADERS \
install-includeHEADERS tags mostlyclean-tags distclean-tags clean-tags \
maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \
installcheck-am installcheck install-exec-am install-exec \
install-data-am install-data install-am install uninstall-am uninstall \
all-redirect all-am all installdirs mostlyclean-generic \
distclean-generic clean-generic maintainer-clean-generic clean \
mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
--- NEW FILE: Makefile.am ---
lib_LTLIBRARIES= libkimgio.la
libkimgio_la_LDFLAGS = -version-info 2:0
libkimgio_la_SOURCES = jpeg.cpp xview.cpp kimgio.cpp kimgio.h eps.cpp \
tiffr.cpp pngr.cpp
include_HEADERS = kimgio.h
noinst_HEADERS= jpeg.h xview.h eps.h tiffr.h pngr.h
INCLUDES = $(all_includes)
EXTRA_DIST = netpbm.cpp netpbm.h
--- NEW FILE: kimgio.h ---
/**
* kimgio.h -- Declaration of interface to the KDE Image IO library.
* Sirtaj Singh Kang <taj at kde.org>, 23 Sep 1998.
*
* $Id: kimgio.h,v 1.1 2006-10-03 11:26:37 dslinux_amadeus Exp $
*
* This library is distributed under the conditions of the GNU LGPL.
*/
#ifndef SSK_KIMGIO_H
#define SSK_KIMGIO_H
/**
* Registers all available image format encoders and decoders.
*/
void kimgioRegister(void);
#endif
--- NEW FILE: netpbm.h ---
////////////////
//
// netpbm.h -- QImage IO handler declaration for several graphics formats using
// using the NetPBM tools.
//
//////
// PCX IO handlers for QImage.
//
void read_pcx (QImageIO *image);
//////
// IFF IO handlers for QImage.
//
void read_ilbm (QImageIO *image);
//////
// TGA IO handlers for QImage.
//
void read_tga (QImageIO *image);
--- NEW FILE: netpbm.cpp ---
////////////////////////////////////////////////////
//
// Transparent support for several files formats in Qt Pixmaps,
// using the NetPBM tools.
//
// Dirk Schoenberger, Jul 1997.
//
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <qimage.h>
#define CMDBUFLEN 4096
//////
// the real filter.
//
void import_graphic (char *filter, QImageIO *image)
{
char * tmpFileName;
QImage myimage;
char cmdBuf [CMDBUFLEN];
tmpFileName = tmpnam(NULL);
sprintf (cmdBuf, "%s %s > %s", filter, image->fileName(), tmpFileName);
// printf (cmdBuf);
// fflush (stdout);
system (cmdBuf);
myimage.load (tmpFileName);
unlink (tmpFileName);
image->setImage (myimage);
image->setStatus (0);
}
//////
// PCX IO handlers for QImage.
//
void read_pcx (QImageIO *image)
{
import_graphic ("pcxtoppm", image);
}
//////
// IFF IO handlers for QImage.
//
void read_ilbm (QImageIO *image)
{
import_graphic ("ilbmtoppm", image);
}
//////
// TGA IO handlers for QImage.
//
void read_tga (QImageIO *image)
{
import_graphic ("tgatoppm", image);
}
--- NEW FILE: README ---
KDE Image I/O library.
This library allows applications that use the Qt library to read and
write images in extra formats. Current formats include:
JPEG <read>
XV <read> <write>
EPS <read>
NETPBM <incomplete>
PNG <read>
TIFF <read>
To use these formats, you must
1. link the application with the libkimgio library
2. Include the <kimgio.h> header
3. call kimgioRegister() once, somewhere in your code
before you load an image.
Writing handlers
----------------
Please read the documentation for the QImageIO class in the Qt
documentation.
1. When writing handlers, there is a function naming convention;
suppose, for example, we were writing PNG read and write handlers,
we would name them
void kimgio_png_read ( QImageIO * );
void kimgio_png_write( QImageIO * );
ie
kimgio_<format>_<read/write>
This should reduce the chance of identifier clashes with other code.
2. If you only have either a reader or the writer for a particular
format, don't use NULL in QImageIO::defineIOHandler. Instead, write
a stub function for the unimplemented handler which displays a message
on standard output. This prevents kimgio-using programs dumping core
when attempting to call the unimplemented handler.
Yours in good faith and pedantry,
Sirtaj Singh Kang <taj at kde.org>, 23 September 1998.
$Id: README,v 1.1 2006-10-03 11:26:37 dslinux_amadeus Exp $
--- NEW FILE: tiffr.cpp ---
#ifdef HAVE_CONFIG_H
#include"config.h"
#endif
#ifdef HAVE_LIBTIFF
#include<tiffio.h>
#include<qimage.h>
#include"tiffr.h"
void kimgio_tiff_read( QImageIO *io )
{
TIFF *tiff;
uint32 width, height;
uint32 *data;
// FIXME: use qdatastream
// open file
tiff = TIFFOpen( io->fileName(), "r" );
if( tiff == 0 ) {
return;
}
// create image with loaded dimensions
TIFFGetField( tiff, TIFFTAG_IMAGEWIDTH, &width );
TIFFGetField( tiff, TIFFTAG_IMAGELENGTH, &height );
QImage image( width, height, 32 );
data = (uint32 *)image.bits();
//Sven: changed to %ld for 64bit machines
debug( "unsigned size: %ld, uint32 size: %ld",
(long)sizeof(unsigned), (long)sizeof(uint32) );
// read data
bool stat =TIFFReadRGBAImage( tiff, width, height, data );
if( stat == 0 ) {
TIFFClose( tiff );
return;
}
// reverse image (it's upside down)
for( unsigned ctr = 0; ctr < (height>>1); ) {
unsigned *line1 = (unsigned *)image.scanLine( ctr );
unsigned *line2 = (unsigned *)image.scanLine( height
- ( ++ctr ) );
for( unsigned x = 0; x < width; x++ ) {
int temp = *line1;
*line1 = *line2;
*line2 = temp;
line1++;
line2++;
}
// swap rows
}
// set channel order to Qt order
// FIXME: Right now they are the same, but will it change?
// for( int ctr = (image.numBytes() / sizeof(uint32))+1; ctr ; ctr-- ) {
// // TODO: manage alpha with TIFFGetA
// *data = qRgb( TIFFGetR( *data ),
// TIFFGetG( *data ), TIFFGetB( *data ) );
// data++;
// }
TIFFClose( tiff );
io->setImage( image );
io->setStatus ( 0 );
}
void kimgio_tiff_write( QImageIO * )
{
// TODO: stub
}
#endif
--- NEW FILE: xview.h ---
#ifndef XVIEW_H
#define XVIEW_H
#include <qimage.h>
#include <qpixmap.h>
void kimgio_xv_read( QImageIO * );
void kimgio_xv_write( QImageIO * );
#endif
--- NEW FILE: xview.cpp ---
#include <stdio.h>
#include <string.h>
#include <qiodev.h>
#include <qcolor.h>
#include <qfile.h>
#include <qwmatrix.h>
#include "xview.h"
#define BUFSIZE 1024
void kimgio_xv_read( QImageIO *_imageio )
{
int x=-1;
int y=-1;
int maxval=-1;
QIODevice *iodev = _imageio->ioDevice();
char str[ BUFSIZE ];
// magic number must be "P7 332"
iodev->readLine( str, BUFSIZE );
if (strncmp(str,"P7 332",6)) return;
// next line #XVVERSION
iodev->readLine( str, BUFSIZE );
if (strncmp(str, "#XVVERSION", 10))
return;
// now it gets interesting, #BUILTIN means we are out.
// if IMGINFO comes, we are happy!
iodev->readLine( str, BUFSIZE );
if (strncmp(str, "#IMGINFO:", 9))
return;
// after this an #END_OF_COMMENTS signals everything to be ok!
iodev->readLine( str, BUFSIZE );
if (strncmp(str, "#END_OF", 7))
return;
// now a last line with width, height, maxval which is
// supposed to be 255
iodev->readLine( str, BUFSIZE );
sscanf(str, "%d %d %d", &x, &y, &maxval);
if (maxval != 255) return;
// now follows a binary block of x*y bytes.
int blocksize = x*y;
char *block = new char[ blocksize ];
if (iodev->readBlock(block, blocksize) != blocksize )
{
return;
}
// Create the image
QImage image( x, y, 8, maxval + 1, QImage::BigEndian );
// how do the color handling? they are absolute 24bpp
// or at least can be calculated as such.
int r,g,b;
for ( int j = 0; j < 256; j++ )
{
r = ((int) ((j >> 5) & 0x07)) << 5;
g = ((int) ((j >> 2) & 0x07)) << 5;
b = ((int) ((j >> 0) & 0x03)) << 6;
image.setColor( j, qRgb( r, g, b ) );
}
for ( int py = 0; py < y; py++ )
{
uchar *data = image.scanLine( py );
memcpy( data, block + py * x, x );
}
_imageio->setImage( image );
_imageio->setStatus( 0 );
delete [] block;
return;
}
void kimgio_xv_write( QImageIO *imageio )
{
QIODevice& f = *( imageio->ioDevice() );
// Removed "f.open(...)" and "f.close()" (tanghus)
const QImage& image = imageio->image();
int w = image.width(), h = image.height();
char str[ 1024 ];
// magic number must be "P7 332"
f.writeBlock( "P7 332\n", 7 );
// next line #XVVERSION
f.writeBlock( "#XVVERSION:\n", 12 );
// now it gets interesting, #BUILTIN means we are out.
// if IMGINFO comes, we are happy!
f.writeBlock( "#IMGINFO:\n", 10 );
// after this an #END_OF_COMMENTS signals everything to be ok!
f.writeBlock( "#END_OF_COMMENTS:\n", 18 );
// now a last line with width, height, maxval which is supposed to be 255
sprintf( str, "%i %i 255\n", w, h );
f.writeBlock( str, strlen( str ) );
if ( image.depth() == 1 )
{
image.convertDepth( 8 );
}
uchar buffer[ 128 ];
for ( int py = 0; py < h; py++ )
{
uchar *data = image.scanLine( py );
for ( int px = 0; px < w; px++ )
{
int r, g, b;
if ( image.depth() == 32 )
{
QRgb *data32 = (QRgb*) data;
r = qRed( *data32 ) >> 5;
g = qGreen( *data32 ) >> 5;
b = qBlue( *data32 ) >> 6;
data += sizeof( QRgb );
}
else
{
QRgb color = image.color( *data );
r = qRed( color ) >> 5;
g = qGreen( color ) >> 5;
b = qBlue( color ) >> 6;
data++;
}
buffer[ px ] = ( r << 5 ) | ( g << 2 ) | b;
}
f.writeBlock( (const char*)buffer, w );
}
imageio->setStatus( 0 );
}
--- NEW FILE: tiffr.h ---
/**
* QImageIO Routines to read/write TIFF images.
* Sirtaj Singh Kang, Oct 1998.
*
* $Id: tiffr.h,v 1.1 2006-10-03 11:26:37 dslinux_amadeus Exp $
*/
#ifndef KIMG_TIFFR_H
#define KIMG_TIFFR_H
class QImageIO;
void kimgio_tiff_read( QImageIO *io );
void kimgio_tiff_write( QImageIO *io );
#endif
--- NEW FILE: jpeg.h ---
////////////////
//
// jpeg.h -- QImage IO handler declaration for JFIF JPEG graphic format,
// SirtaJ Singh Kang <taj at kde.org>, December 1996.
// using IJG JPEG library.
//
// $Id: jpeg.h,v 1.1 2006-10-03 11:26:37 dslinux_amadeus Exp $
#ifndef _SSK_JPEG_QHANDLERS_H
#define _SSK_JPEG_QHANDLERS_H
class QImageIO;
//////
// JPEG IO handlers for QImage.
//
void kimgio_jpeg_read(QImageIO *image);
void kimgio_jpeg_write(QImageIO *image);
#endif
More information about the dslinux-commit
mailing list