eliminate pnm
This commit is contained in:
parent
8f506cb1ed
commit
70ab5d89b4
|
|
@ -1,23 +0,0 @@
|
|||
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
|
||||
dtoolutil:c dtoolbase:c dtool:m
|
||||
#define LOCAL_LIBS pandabase
|
||||
|
||||
#if $[or $[eq $[USE_COMPILER],MSVC],$[eq $[USE_COMPILER],INTEL]]
|
||||
#define CFLAGS /D__STDC__
|
||||
#endif
|
||||
|
||||
#begin lib_target
|
||||
#define TARGET pnm
|
||||
|
||||
#define SOURCES \
|
||||
bitio.c bitio.h compile.h libpbm.h libpbm1.c libpbm2.c libpbm3.c \
|
||||
libpbm4.c libpbm5.c libpgm.h libpgm1.c libpgm2.c libpnm1.c \
|
||||
libpnm2.c libpnm3.c libpnm4.c libppm.h libppm1.c libppm2.c \
|
||||
libppm3.c libppm4.c libppm5.c pbm.h pbmfont.h pbmplus.h pgm.h \
|
||||
pnm.h ppm.h ppmcmap.h ppmdraw.h rast.h version.h
|
||||
|
||||
#define INSTALL_HEADERS \
|
||||
pbm.h pbmplus.h pgm.h pnm.h ppm.h
|
||||
|
||||
#end lib_target
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
/* compile_time.h This file tells the package when it was compiled */
|
||||
/* DO NOT EDIT - THIS FILE IS MAINTAINED AUTOMATICALLY */
|
||||
#define COMPILE_TIME "Tue Mar 19 19:03:20 PST 1996"
|
||||
#define COMPILED_BY "drose"
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/* libpbm.h - internal header file for libpbm portable bitmap library
|
||||
*/
|
||||
|
||||
#ifndef _LIBPBM_H_
|
||||
#define _LIBPBM_H_
|
||||
|
||||
/* Here are some routines internal to the pbm library. */
|
||||
|
||||
char pbm_getc ARGS(( FILE* file ));
|
||||
unsigned char pbm_getrawbyte ARGS(( FILE* file ));
|
||||
int pbm_getint ARGS(( FILE* file ));
|
||||
|
||||
int pbm_readmagicnumber ARGS(( FILE* file ));
|
||||
|
||||
EXPCL_PANDA void pbm_readpbminitrest( FILE* file, int* colsP, int* rowsP );
|
||||
|
||||
#endif /*_LIBPBM_H_*/
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,134 +0,0 @@
|
|||
/* libpbm2.c - pbm utility library part 2
|
||||
**
|
||||
** Copyright (C) 1988 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pbm.h"
|
||||
#include "libpbm.h"
|
||||
|
||||
static bit pbm_getbit ARGS((FILE *));
|
||||
static bit
|
||||
pbm_getbit( file )
|
||||
FILE* file;
|
||||
{
|
||||
register char ch;
|
||||
|
||||
do
|
||||
{
|
||||
ch = pbm_getc( file );
|
||||
}
|
||||
while ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' );
|
||||
|
||||
if ( ch != '0' && ch != '1' )
|
||||
pm_error( "junk in file where bits should be" );
|
||||
|
||||
return ( ch == '1' ) ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
pbm_readmagicnumber( file )
|
||||
FILE* file;
|
||||
{
|
||||
int ich1, ich2;
|
||||
|
||||
ich1 = getc( file );
|
||||
if ( ich1 == EOF )
|
||||
pm_error( "EOF / read error reading magic number" );
|
||||
ich2 = getc( file );
|
||||
if ( ich2 == EOF )
|
||||
pm_error( "EOF / read error reading magic number" );
|
||||
return ich1 * 256 + ich2;
|
||||
}
|
||||
|
||||
void
|
||||
pbm_readpbminitrest( file, colsP, rowsP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
{
|
||||
/* Read size. */
|
||||
*colsP = pbm_getint( file );
|
||||
*rowsP = pbm_getint( file );
|
||||
}
|
||||
|
||||
void
|
||||
pbm_readpbminit( file, colsP, rowsP, formatP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
int* formatP;
|
||||
{
|
||||
/* Check magic number. */
|
||||
*formatP = pbm_readmagicnumber( file );
|
||||
switch ( PBM_FORMAT_TYPE(*formatP) )
|
||||
{
|
||||
case PBM_TYPE:
|
||||
pbm_readpbminitrest( file, colsP, rowsP );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "bad magic number - not a pbm file" );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pbm_readpbmrow( file, bitrow, cols, format )
|
||||
FILE* file;
|
||||
bit* bitrow;
|
||||
int cols, format;
|
||||
{
|
||||
register int col, bitshift;
|
||||
register unsigned char item;
|
||||
register bit* bP;
|
||||
|
||||
switch ( format )
|
||||
{
|
||||
case PBM_FORMAT:
|
||||
for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
|
||||
*bP = pbm_getbit( file );
|
||||
break;
|
||||
|
||||
case RPBM_FORMAT:
|
||||
bitshift = -1;
|
||||
for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
|
||||
{
|
||||
if ( bitshift == -1 )
|
||||
{
|
||||
item = pbm_getrawbyte( file );
|
||||
bitshift = 7;
|
||||
}
|
||||
*bP = ( item >> bitshift ) & 1;
|
||||
--bitshift;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
bit**
|
||||
pbm_readpbm( file, colsP, rowsP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
{
|
||||
register bit** bits;
|
||||
int format, row;
|
||||
|
||||
pbm_readpbminit( file, colsP, rowsP, &format );
|
||||
|
||||
bits = pbm_allocarray( *colsP, *rowsP );
|
||||
|
||||
for ( row = 0; row < *rowsP; ++row )
|
||||
pbm_readpbmrow( file, bits[row], *colsP, format );
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
/* libpbm3.c - pbm utility library part 3
|
||||
**
|
||||
** Copyright (C) 1988 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pbm.h"
|
||||
#include "libpbm.h"
|
||||
|
||||
static void pbm_writepbmrowplain ARGS((FILE* file, bit* bitrow, int cols));
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
static void pbm_writepbmrowraw ARGS((FILE* file, bit* bitrow, int cols));
|
||||
#endif /* PBMPLUS_RAWBITS */
|
||||
void
|
||||
pbm_writepbminit( file, cols, rows, forceplain )
|
||||
FILE* file;
|
||||
int cols, rows;
|
||||
int forceplain;
|
||||
{
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
if ( ! forceplain ) {
|
||||
fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, RPBM_MAGIC2, cols, rows );
|
||||
#ifdef VMS
|
||||
set_outfile_binary();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, PBM_MAGIC2, cols, rows );
|
||||
#else /*PBMPLUS_RAWBITS*/
|
||||
fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, PBM_MAGIC2, cols, rows );
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
}
|
||||
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
static void
|
||||
pbm_writepbmrowraw( file, bitrow, cols )
|
||||
FILE* file;
|
||||
bit* bitrow;
|
||||
int cols;
|
||||
{
|
||||
register int col, bitshift;
|
||||
register unsigned char item;
|
||||
register bit* bP;
|
||||
|
||||
bitshift = 7;
|
||||
item = 0;
|
||||
for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
|
||||
{
|
||||
if ( *bP )
|
||||
item += 1 << bitshift;
|
||||
--bitshift;
|
||||
if ( bitshift == -1 )
|
||||
{
|
||||
(void) putc( item, file );
|
||||
bitshift = 7;
|
||||
item = 0;
|
||||
}
|
||||
}
|
||||
if ( bitshift != 7 )
|
||||
(void) putc( item, file );
|
||||
}
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
|
||||
static void
|
||||
pbm_writepbmrowplain( file, bitrow, cols )
|
||||
FILE* file;
|
||||
bit* bitrow;
|
||||
int cols;
|
||||
{
|
||||
register int col, charcount;
|
||||
register bit* bP;
|
||||
|
||||
charcount = 0;
|
||||
for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
|
||||
{
|
||||
if ( charcount >= 70 )
|
||||
{
|
||||
(void) putc( '\n', file );
|
||||
charcount = 0;
|
||||
}
|
||||
(void) putc( *bP ? '1' : '0', file );
|
||||
++charcount;
|
||||
}
|
||||
(void) putc( '\n', file );
|
||||
}
|
||||
|
||||
void
|
||||
pbm_writepbmrow( file, bitrow, cols, forceplain )
|
||||
FILE* file;
|
||||
bit* bitrow;
|
||||
int cols;
|
||||
int forceplain;
|
||||
{
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
if ( ! forceplain )
|
||||
pbm_writepbmrowraw( file, bitrow, cols );
|
||||
else
|
||||
pbm_writepbmrowplain( file, bitrow, cols );
|
||||
#else /*PBMPLUS_RAWBITS*/
|
||||
pbm_writepbmrowplain( file, bitrow, cols );
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
}
|
||||
|
||||
void
|
||||
pbm_writepbm( file, bits, cols, rows, forceplain )
|
||||
FILE* file;
|
||||
bit** bits;
|
||||
int cols, rows;
|
||||
int forceplain;
|
||||
{
|
||||
int row;
|
||||
|
||||
pbm_writepbminit( file, cols, rows, forceplain );
|
||||
|
||||
for ( row = 0; row < rows; ++row )
|
||||
pbm_writepbmrow( file, bits[row], cols, forceplain );
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/* libpbm4.c - pbm utility library part 4
|
||||
**
|
||||
** Copyright (C) 1988 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pbm.h"
|
||||
#include "libpbm.h"
|
||||
|
||||
char
|
||||
pbm_getc( file )
|
||||
FILE* file;
|
||||
{
|
||||
register int ich;
|
||||
register char ch;
|
||||
|
||||
ich = getc( file );
|
||||
if ( ich == EOF )
|
||||
pm_error( "EOF / read error" );
|
||||
ch = (char) ich;
|
||||
|
||||
if ( ch == '#' )
|
||||
{
|
||||
do
|
||||
{
|
||||
ich = getc( file );
|
||||
if ( ich == EOF )
|
||||
pm_error( "EOF / read error" );
|
||||
ch = (char) ich;
|
||||
}
|
||||
while ( ch != '\n' && ch != '\r' );
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
unsigned char
|
||||
pbm_getrawbyte( file )
|
||||
FILE* file;
|
||||
{
|
||||
register int iby;
|
||||
|
||||
iby = getc( file );
|
||||
if ( iby == EOF )
|
||||
pm_error( "EOF / read error" );
|
||||
return (unsigned char) iby;
|
||||
}
|
||||
|
||||
int
|
||||
pbm_getint( file )
|
||||
FILE* file;
|
||||
{
|
||||
register char ch;
|
||||
register int i;
|
||||
|
||||
do
|
||||
{
|
||||
ch = pbm_getc( file );
|
||||
}
|
||||
while ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' );
|
||||
|
||||
if ( ch < '0' || ch > '9' )
|
||||
pm_error( "junk in file where an integer should be" );
|
||||
|
||||
i = 0;
|
||||
do
|
||||
{
|
||||
i = i * 10 + ch - '0';
|
||||
ch = pbm_getc( file );
|
||||
}
|
||||
while ( ch >= '0' && ch <= '9' );
|
||||
|
||||
return i;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,11 +0,0 @@
|
|||
/* libpgm.h - internal header file for libpgm portable graymap library
|
||||
*/
|
||||
|
||||
#ifndef _LIBPGM_H_
|
||||
#define _LIBPGM_H_
|
||||
|
||||
/* Here are some routines internal to the pgm library. */
|
||||
|
||||
EXPCL_PANDA void pgm_readpgminitrest( FILE* file, int* colsP, int* rowsP, gray* maxvalP );
|
||||
|
||||
#endif /*_LIBPGM_H_*/
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
/* libpgm1.c - pgm utility library part 1
|
||||
**
|
||||
** Copyright (C) 1989 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pgm.h"
|
||||
#include "libpgm.h"
|
||||
#include "pbm.h"
|
||||
#include "libpbm.h"
|
||||
|
||||
void
|
||||
pgm_init( argcP, argv )
|
||||
int* argcP;
|
||||
char* argv[];
|
||||
{
|
||||
pbm_init( argcP, argv );
|
||||
}
|
||||
|
||||
void
|
||||
pgm_readpgminitrest( file, colsP, rowsP, maxvalP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
gray* maxvalP;
|
||||
{
|
||||
int maxval;
|
||||
|
||||
/* Read size. */
|
||||
*colsP = pbm_getint( file );
|
||||
*rowsP = pbm_getint( file );
|
||||
|
||||
/* Read maxval. */
|
||||
maxval = pbm_getint( file );
|
||||
if ( maxval > PGM_MAXMAXVAL )
|
||||
pm_error( "maxval is too large - try reconfiguring with PGM_BIGGRAYS" );
|
||||
*maxvalP = maxval;
|
||||
}
|
||||
|
||||
gray pgm_pbmmaxval = 1;
|
||||
|
||||
void
|
||||
pgm_readpgminit( file, colsP, rowsP, maxvalP, formatP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
int* formatP;
|
||||
gray* maxvalP;
|
||||
{
|
||||
/* Check magic number. */
|
||||
*formatP = pbm_readmagicnumber( file );
|
||||
switch ( PGM_FORMAT_TYPE(*formatP) )
|
||||
{
|
||||
case PGM_TYPE:
|
||||
pgm_readpgminitrest( file, colsP, rowsP, maxvalP );
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
pbm_readpbminitrest( file, colsP, rowsP );
|
||||
*maxvalP = pgm_pbmmaxval;
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "bad magic number - not a pgm or pbm file" );
|
||||
}
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
pgm_readpgmrow( FILE* file, gray* grayrow, int cols, gray maxval, int format )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pgm_readpgmrow( file, grayrow, cols, maxval, format )
|
||||
FILE* file;
|
||||
gray* grayrow;
|
||||
int cols;
|
||||
gray maxval;
|
||||
int format;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int col;
|
||||
register gray* gP;
|
||||
bit* bitrow;
|
||||
register bit* bP;
|
||||
|
||||
switch ( format )
|
||||
{
|
||||
case PGM_FORMAT:
|
||||
for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
|
||||
{
|
||||
*gP = pbm_getint( file );
|
||||
#ifdef DEBUG
|
||||
if ( *gP > maxval )
|
||||
pm_error( "value out of bounds (%u > %u)", *gP, maxval );
|
||||
#endif /*DEBUG*/
|
||||
}
|
||||
break;
|
||||
|
||||
case RPGM_FORMAT:
|
||||
for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
|
||||
{
|
||||
*gP = pbm_getrawbyte( file );
|
||||
#ifdef DEBUG
|
||||
if ( *gP > maxval )
|
||||
pm_error( "value out of bounds (%u > %u)", *gP, maxval );
|
||||
#endif /*DEBUG*/
|
||||
}
|
||||
break;
|
||||
|
||||
case PBM_FORMAT:
|
||||
case RPBM_FORMAT:
|
||||
bitrow = pbm_allocrow( cols );
|
||||
pbm_readpbmrow( file, bitrow, cols, format );
|
||||
for ( col = 0, gP = grayrow, bP = bitrow; col < cols; ++col, ++gP, ++bP )
|
||||
*gP = ( *bP == PBM_WHITE ) ? maxval : 0;
|
||||
pbm_freerow( bitrow );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
gray**
|
||||
pgm_readpgm( file, colsP, rowsP, maxvalP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
gray* maxvalP;
|
||||
{
|
||||
gray** grays;
|
||||
int row;
|
||||
int format;
|
||||
|
||||
pgm_readpgminit( file, colsP, rowsP, maxvalP, &format );
|
||||
|
||||
grays = pgm_allocarray( *colsP, *rowsP );
|
||||
|
||||
for ( row = 0; row < *rowsP; ++row )
|
||||
pgm_readpgmrow( file, grays[row], *colsP, *maxvalP, format );
|
||||
|
||||
return grays;
|
||||
}
|
||||
|
|
@ -1,154 +0,0 @@
|
|||
/* libpgm2.c - pgm utility library part 2
|
||||
**
|
||||
** Copyright (C) 1989 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pgm.h"
|
||||
#include "libpgm.h"
|
||||
|
||||
static void putus1 ARGS((unsigned short n, FILE* file));
|
||||
static void pgm_writepgmrowplain ARGS((FILE* file, gray* grayrow, int cols, gray maxval));
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
static void pgm_writepgmrowraw ARGS((FILE* file, gray* grayrow, int cols, gray maxval));
|
||||
#endif /* PBMPLUS_RAWBITS */
|
||||
#if __STDC__
|
||||
void
|
||||
pgm_writepgminit( FILE* file, int cols, int rows, gray maxval, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pgm_writepgminit( file, cols, rows, maxval, forceplain )
|
||||
FILE* file;
|
||||
int cols, rows;
|
||||
gray maxval;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
if ( maxval <= 255 && ! forceplain ) {
|
||||
fprintf(
|
||||
file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, RPGM_MAGIC2,
|
||||
cols, rows, maxval );
|
||||
#ifdef VMS
|
||||
set_outfile_binary();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
fprintf(
|
||||
file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, PGM_MAGIC2,
|
||||
cols, rows, maxval );
|
||||
#else /*PBMPLUS_RAWBITS*/
|
||||
fprintf(
|
||||
file, "%c%c\n%d %d\n%d\n", PGM_MAGIC1, PGM_MAGIC2,
|
||||
cols, rows, maxval );
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
}
|
||||
|
||||
static void
|
||||
putus1( n, file )
|
||||
unsigned short n;
|
||||
FILE* file;
|
||||
{
|
||||
if ( n >= 10 )
|
||||
putus1((unsigned short)( n / 10), file );
|
||||
(void) putc( n % 10 + '0', file );
|
||||
}
|
||||
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
static void
|
||||
pgm_writepgmrowraw(FILE* file,gray* grayrow,int cols,gray maxval)
|
||||
{
|
||||
register int col;
|
||||
register gray* gP;
|
||||
|
||||
for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if ( *gP > maxval )
|
||||
pm_error( "value out of bounds (%u > %u)", *gP, maxval );
|
||||
#endif /*DEBUG*/
|
||||
(void) putc( *gP, file );
|
||||
}
|
||||
}
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
|
||||
static void
|
||||
pgm_writepgmrowplain(FILE* file,gray* grayrow,int cols,gray maxval)
|
||||
{
|
||||
register int col, charcount;
|
||||
register gray* gP;
|
||||
|
||||
charcount = 0;
|
||||
for ( col = 0, gP = grayrow; col < cols; ++col, ++gP )
|
||||
{
|
||||
if ( charcount >= 65 )
|
||||
{
|
||||
(void) putc( '\n', file );
|
||||
charcount = 0;
|
||||
}
|
||||
else if ( charcount > 0 )
|
||||
{
|
||||
(void) putc( ' ', file );
|
||||
++charcount;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if ( *gP > maxval )
|
||||
pm_error( "value out of bounds (%u > %u)", *gP, maxval );
|
||||
#endif /*DEBUG*/
|
||||
/* putus1( (unsigned long) *gP, file ); */
|
||||
putus1( (unsigned short) *gP, file );
|
||||
charcount += 3;
|
||||
}
|
||||
if ( charcount > 0 )
|
||||
(void) putc( '\n', file );
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
pgm_writepgmrow( FILE* file, gray* grayrow, int cols, gray maxval, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pgm_writepgmrow( file, grayrow, cols, maxval, forceplain )
|
||||
FILE* file;
|
||||
gray* grayrow;
|
||||
int cols;
|
||||
gray maxval;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
if ( maxval <= 255 && ! forceplain )
|
||||
pgm_writepgmrowraw( file, grayrow, cols, maxval );
|
||||
else
|
||||
pgm_writepgmrowplain( file, grayrow, cols, maxval );
|
||||
#else /*PBMPLUS_RAWBITS*/
|
||||
pgm_writepgmrowplain( file, grayrow, cols, maxval );
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
pgm_writepgm( FILE* file, gray** grays, int cols, int rows, gray maxval, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pgm_writepgm( file, grays, cols, rows, maxval, forceplain )
|
||||
FILE* file;
|
||||
gray** grays;
|
||||
int cols, rows;
|
||||
gray maxval;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
int row;
|
||||
|
||||
pgm_writepgminit( file, cols, rows, maxval, forceplain );
|
||||
|
||||
for ( row = 0; row < rows; ++row )
|
||||
pgm_writepgmrow( file, grays[row], cols, maxval, forceplain );
|
||||
}
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
/* libpnm1.c - pnm utility library part 1
|
||||
**
|
||||
** Copyright (C) 1989 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pnm.h"
|
||||
|
||||
#include "ppm.h"
|
||||
#include "libppm.h"
|
||||
|
||||
#include "pgm.h"
|
||||
#include "libpgm.h"
|
||||
|
||||
#include "pbm.h"
|
||||
#include "libpbm.h"
|
||||
|
||||
void
|
||||
pnm_init( argcP, argv )
|
||||
int* argcP;
|
||||
char* argv[];
|
||||
{
|
||||
ppm_init( argcP, argv );
|
||||
}
|
||||
|
||||
EXPCL_PANDA xelval pnm_pbmmaxval = 1;
|
||||
|
||||
void
|
||||
pnm_readpnminit( file, colsP, rowsP, maxvalP, formatP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
int* formatP;
|
||||
xelval* maxvalP;
|
||||
{
|
||||
gray gmaxval;
|
||||
|
||||
/* Check magic number. */
|
||||
*formatP = pbm_readmagicnumber( file );
|
||||
switch ( PNM_FORMAT_TYPE(*formatP) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
ppm_readppminitrest( file, colsP, rowsP, (pixval*) maxvalP );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
pgm_readpgminitrest( file, colsP, rowsP, &gmaxval );
|
||||
*maxvalP = (xelval) gmaxval;
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
pbm_readpbminitrest( file, colsP, rowsP );
|
||||
*maxvalP = pnm_pbmmaxval;
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "bad magic number - not a ppm, pgm, or pbm file" );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__STDC__) || defined(WIN32_VC)
|
||||
void
|
||||
EXPCL_PANDA pnm_readpnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format )
|
||||
#else /*__STDC__*/
|
||||
void pnm_readpnmrow( file, xelrow, cols, maxval, format )
|
||||
FILE* file;
|
||||
xel* xelrow;
|
||||
xelval maxval;
|
||||
int cols, format;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int col;
|
||||
register xel* xP;
|
||||
gray* grayrow;
|
||||
register gray* gP;
|
||||
bit* bitrow;
|
||||
register bit* bP;
|
||||
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
ppm_readppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, format );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
grayrow = pgm_allocrow( cols );
|
||||
pgm_readpgmrow( file, grayrow, cols, (gray) maxval, format );
|
||||
for ( col = 0, xP = xelrow, gP = grayrow; col < cols; ++col, ++xP, ++gP )
|
||||
PNM_ASSIGN1( *xP, *gP );
|
||||
pgm_freerow( grayrow );
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
bitrow = pbm_allocrow( cols );
|
||||
pbm_readpbmrow( file, bitrow, cols, format );
|
||||
for ( col = 0, xP = xelrow, bP = bitrow; col < cols; ++col, ++xP, ++bP )
|
||||
PNM_ASSIGN1( *xP, *bP == PBM_BLACK ? 0: pnm_pbmmaxval );
|
||||
pbm_freerow( bitrow );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
xel**
|
||||
pnm_readpnm( file, colsP, rowsP, maxvalP, formatP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
int* formatP;
|
||||
xelval* maxvalP;
|
||||
{
|
||||
xel** xels;
|
||||
int row;
|
||||
|
||||
pnm_readpnminit( file, colsP, rowsP, maxvalP, formatP );
|
||||
|
||||
xels = pnm_allocarray( *colsP, *rowsP );
|
||||
|
||||
for ( row = 0; row < *rowsP; ++row )
|
||||
pnm_readpnmrow( file, xels[row], *colsP, *maxvalP, *formatP );
|
||||
|
||||
return xels;
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/* libpnm2.c - pnm utility library part 2
|
||||
**
|
||||
** Copyright (C) 1989 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pnm.h"
|
||||
|
||||
#include "ppm.h"
|
||||
#include "libppm.h"
|
||||
|
||||
#include "pgm.h"
|
||||
#include "libpgm.h"
|
||||
|
||||
#include "pbm.h"
|
||||
#include "libpbm.h"
|
||||
|
||||
#if defined(__STDC__) || defined(WIN32_VC)
|
||||
void
|
||||
EXPCL_PANDA pnm_writepnminit( FILE* file, int cols, int rows, xelval maxval, int format, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pnm_writepnminit( file, cols, rows, maxval, format, forceplain )
|
||||
FILE* file;
|
||||
int cols, rows, format;
|
||||
xelval maxval;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
ppm_writeppminit( file, cols, rows, (pixval) maxval, forceplain );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
pgm_writepgminit( file, cols, rows, (gray) maxval, forceplain );
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
pbm_writepbminit( file, cols, rows, forceplain );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__STDC__) || defined(WIN32_VC)
|
||||
EXPCL_PANDA void pnm_writepnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pnm_writepnmrow( file, xelrow, cols, maxval, format, forceplain )
|
||||
FILE* file;
|
||||
xel* xelrow;
|
||||
int cols, format;
|
||||
xelval maxval;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int col;
|
||||
register xel* xP;
|
||||
gray* grayrow;
|
||||
register gray* gP;
|
||||
bit* bitrow;
|
||||
register bit* bP;
|
||||
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
ppm_writeppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, forceplain );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
grayrow = pgm_allocrow( cols );
|
||||
for ( col = 0, gP = grayrow, xP = xelrow; col < cols; ++col, ++gP, ++xP )
|
||||
*gP = PNM_GET1( *xP );
|
||||
pgm_writepgmrow( file, grayrow, cols, (gray) maxval, forceplain );
|
||||
pgm_freerow( grayrow );
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
bitrow = pbm_allocrow( cols );
|
||||
for ( col = 0, bP = bitrow, xP = xelrow; col < cols; ++col, ++bP, ++xP )
|
||||
*bP = PNM_GET1( *xP ) == 0 ? PBM_BLACK : PBM_WHITE;
|
||||
pbm_writepbmrow( file, bitrow, cols, forceplain );
|
||||
pbm_freerow( bitrow );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
pnm_writepnm( FILE* file, xel** xels, int cols, int rows, xelval maxval, int format, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pnm_writepnm( file, xels, cols, rows, maxval, format, forceplain )
|
||||
FILE* file;
|
||||
xel** xels;
|
||||
xelval maxval;
|
||||
int cols, rows, format;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
int row;
|
||||
|
||||
pnm_writepnminit( file, cols, rows, maxval, format, forceplain );
|
||||
|
||||
for ( row = 0; row < rows; ++row )
|
||||
pnm_writepnmrow( file, xels[row], cols, maxval, format, forceplain );
|
||||
}
|
||||
|
|
@ -1,386 +0,0 @@
|
|||
/* libpnm3.c - pnm utility library part 3
|
||||
**
|
||||
** Copyright (C) 1989, 1991 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pnm.h"
|
||||
|
||||
#include "ppm.h"
|
||||
#include "libppm.h"
|
||||
|
||||
#include "pgm.h"
|
||||
#include "libpgm.h"
|
||||
|
||||
#include "pbm.h"
|
||||
#include "libpbm.h"
|
||||
|
||||
#if __STDC__
|
||||
xel
|
||||
pnm_backgroundxel( xel** xels, int cols, int rows, xelval maxval, int format )
|
||||
#else /*__STDC__*/
|
||||
xel
|
||||
pnm_backgroundxel( xels, cols, rows, maxval, format )
|
||||
xel** xels;
|
||||
int cols, rows, format;
|
||||
xelval maxval;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
xel bgxel, ul, ur, ll, lr;
|
||||
|
||||
/* Guess a good background value. */
|
||||
ul = xels[0][0];
|
||||
ur = xels[0][cols-1];
|
||||
ll = xels[rows-1][0];
|
||||
lr = xels[rows-1][cols-1];
|
||||
|
||||
/* First check for three corners equal. */
|
||||
if ( PNM_EQUAL( ul, ur ) && PNM_EQUAL( ur, ll ) )
|
||||
bgxel = ul;
|
||||
else if ( PNM_EQUAL( ul, ur ) && PNM_EQUAL( ur, lr ) )
|
||||
bgxel = ul;
|
||||
else if ( PNM_EQUAL( ul, ll ) && PNM_EQUAL( ll, lr ) )
|
||||
bgxel = ul;
|
||||
else if ( PNM_EQUAL( ur, ll ) && PNM_EQUAL( ll, lr ) )
|
||||
bgxel = ur;
|
||||
/* Nope, check for two corners equal. */
|
||||
else if ( PNM_EQUAL( ul, ur ) || PNM_EQUAL( ul, ll ) ||
|
||||
PNM_EQUAL( ul, lr ) )
|
||||
bgxel = ul;
|
||||
else if ( PNM_EQUAL( ur, ll ) || PNM_EQUAL( ur, lr ) )
|
||||
bgxel = ur;
|
||||
else if ( PNM_EQUAL( ll, lr ) )
|
||||
bgxel = ll;
|
||||
else
|
||||
{
|
||||
/* Nope, we have to average the four corners. This breaks the
|
||||
** rules of pnm, but oh well. Let's try to do it portably. */
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
PPM_ASSIGN( bgxel,
|
||||
PPM_GETR(ul) + PPM_GETR(ur) + PPM_GETR(ll) + PPM_GETR(lr) / 4,
|
||||
PPM_GETG(ul) + PPM_GETG(ur) + PPM_GETG(ll) + PPM_GETG(lr) / 4,
|
||||
PPM_GETB(ul) + PPM_GETB(ur) + PPM_GETB(ll) + PPM_GETB(lr) / 4 );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
{
|
||||
gray gul, gur, gll, glr;
|
||||
gul = (gray) PNM_GET1( ul );
|
||||
gur = (gray) PNM_GET1( ur );
|
||||
gll = (gray) PNM_GET1( ll );
|
||||
glr = (gray) PNM_GET1( lr );
|
||||
PNM_ASSIGN1( bgxel, ( ( gul + gur + gll + glr ) / 4 ) );
|
||||
break;
|
||||
}
|
||||
|
||||
case PBM_TYPE:
|
||||
pm_error(
|
||||
"pnm_backgroundxel: four bits no two of which equal each other??" );
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
return bgxel;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
xel
|
||||
pnm_backgroundxelrow( xel* xelrow, int cols, xelval maxval, int format )
|
||||
#else /*__STDC__*/
|
||||
xel
|
||||
pnm_backgroundxelrow( xelrow, cols, maxval, format )
|
||||
xel* xelrow;
|
||||
int cols, format;
|
||||
xelval maxval;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
xel bgxel, l, r;
|
||||
|
||||
/* Guess a good background value. */
|
||||
l = xelrow[0];
|
||||
r = xelrow[cols-1];
|
||||
|
||||
/* First check for both corners equal. */
|
||||
if ( PNM_EQUAL( l, r ) )
|
||||
bgxel = l;
|
||||
else
|
||||
{
|
||||
/* Nope, we have to average the two corners. This breaks the
|
||||
** rules of pnm, but oh well. Let's try to do it portably. */
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
PPM_ASSIGN( bgxel, PPM_GETR(l) + PPM_GETR(r) / 2,
|
||||
PPM_GETG(l) + PPM_GETG(r) / 2, PPM_GETB(l) + PPM_GETB(r) / 2 );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
{
|
||||
gray gl, gr;
|
||||
gl = (gray) PNM_GET1( l );
|
||||
gr = (gray) PNM_GET1( r );
|
||||
PNM_ASSIGN1( bgxel, ( ( gl + gr ) / 2 ) );
|
||||
break;
|
||||
}
|
||||
|
||||
case PBM_TYPE:
|
||||
{
|
||||
int col, blacks;
|
||||
|
||||
/* One black, one white. Gotta count. */
|
||||
for ( col = 0, blacks = 0; col < cols; ++col )
|
||||
{
|
||||
if ( PNM_GET1( xelrow[col] ) == 0 )
|
||||
++blacks;
|
||||
}
|
||||
if ( blacks >= cols / 2 )
|
||||
PNM_ASSIGN1( bgxel, 0 );
|
||||
else
|
||||
PNM_ASSIGN1( bgxel, pnm_pbmmaxval );
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
return bgxel;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
xel
|
||||
pnm_whitexel( xelval maxval, int format )
|
||||
#else /*__STDC__*/
|
||||
xel
|
||||
pnm_whitexel( maxval, format )
|
||||
xelval maxval;
|
||||
int format;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
xel x;
|
||||
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
PPM_ASSIGN( x, maxval, maxval, maxval );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
PNM_ASSIGN1( x, maxval );
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
PNM_ASSIGN1( x, pnm_pbmmaxval );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
xel
|
||||
pnm_blackxel( xelval maxval, int format )
|
||||
#else /*__STDC__*/
|
||||
xel
|
||||
pnm_blackxel( maxval, format )
|
||||
xelval maxval;
|
||||
int format;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
xel x;
|
||||
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
PPM_ASSIGN( x, 0, 0, 0 );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
PNM_ASSIGN1( x, (xelval) 0 );
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
PNM_ASSIGN1( x, (xelval) 0 );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
pnm_invertxel( xel* xP, xelval maxval, int format )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pnm_invertxel( xP, maxval, format )
|
||||
xel* xP;
|
||||
xelval maxval;
|
||||
int format;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
PPM_ASSIGN(
|
||||
*xP, maxval - PPM_GETR( *xP ),
|
||||
maxval - PPM_GETG( *xP ), maxval - PPM_GETB( *xP ) );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
PNM_ASSIGN1( *xP, (gray) maxval - (gray) PNM_GET1( *xP ) );
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
PNM_ASSIGN1( *xP, ( PNM_GET1( *xP ) == 0 ) ? pnm_pbmmaxval : 0 );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
pnm_promoteformat( xel** xels, int cols, int rows, xelval maxval, int format, xelval newmaxval, int newformat )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pnm_promoteformat( xels, cols, rows, maxval, format, newmaxval, newformat )
|
||||
xel** xels;
|
||||
xelval maxval, newmaxval;
|
||||
int cols, rows, format, newformat;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
int row;
|
||||
|
||||
for ( row = 0; row < rows; ++row )
|
||||
pnm_promoteformatrow(
|
||||
xels[row], cols, maxval, format, newmaxval, newformat );
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
pnm_promoteformatrow( xel* xelrow, int cols, xelval maxval, int format, xelval newmaxval, int newformat )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
pnm_promoteformatrow( xelrow, cols, maxval, format, newmaxval, newformat )
|
||||
xel* xelrow;
|
||||
xelval maxval, newmaxval;
|
||||
int cols, format, newformat;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int col;
|
||||
register xel* xP;
|
||||
|
||||
if ( ( PNM_FORMAT_TYPE(format) == PPM_TYPE &&
|
||||
( PNM_FORMAT_TYPE(newformat) == PGM_TYPE ||
|
||||
PNM_FORMAT_TYPE(newformat) == PBM_TYPE ) ) ||
|
||||
( PNM_FORMAT_TYPE(format) == PGM_TYPE &&
|
||||
PNM_FORMAT_TYPE(newformat) == PBM_TYPE ) )
|
||||
pm_error( "pnm_promoteformatrow: can't promote downwards!" );
|
||||
|
||||
/* Are we promoting to the same type? */
|
||||
if ( PNM_FORMAT_TYPE(format) == PNM_FORMAT_TYPE(newformat) )
|
||||
{
|
||||
if ( PNM_FORMAT_TYPE(format) == PBM_TYPE )
|
||||
return;
|
||||
if ( newmaxval < maxval )
|
||||
pm_error(
|
||||
"pnm_promoteformatrow: can't decrease maxval - try using pnmdepth" );
|
||||
if ( newmaxval == maxval )
|
||||
return;
|
||||
/* Increase maxval. */
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PGM_TYPE:
|
||||
for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
|
||||
PNM_ASSIGN1(
|
||||
*xP, (int) PNM_GET1(*xP) * newmaxval / maxval );
|
||||
break;
|
||||
|
||||
case PPM_TYPE:
|
||||
for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
|
||||
PPM_DEPTH( *xP, *xP, maxval, newmaxval );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "shouldn't happen" );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* We must be promoting to a higher type. */
|
||||
switch ( PNM_FORMAT_TYPE(format) )
|
||||
{
|
||||
case PBM_TYPE:
|
||||
switch ( PNM_FORMAT_TYPE(newformat) )
|
||||
{
|
||||
case PGM_TYPE:
|
||||
for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
|
||||
if ( PNM_GET1(*xP) == 0 )
|
||||
PNM_ASSIGN1( *xP, 0 );
|
||||
else
|
||||
PNM_ASSIGN1( *xP, newmaxval );
|
||||
break;
|
||||
|
||||
case PPM_TYPE:
|
||||
for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
|
||||
if ( PNM_GET1(*xP) == 0 )
|
||||
PPM_ASSIGN( *xP, 0, 0, 0 );
|
||||
else
|
||||
PPM_ASSIGN( *xP, newmaxval, newmaxval, newmaxval );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
switch ( PNM_FORMAT_TYPE(newformat) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
if ( newmaxval < maxval )
|
||||
pm_error(
|
||||
"pnm_promoteformatrow: can't decrease maxval - try using pnmdepth" );
|
||||
if ( newmaxval == maxval )
|
||||
{
|
||||
for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
|
||||
PPM_ASSIGN(
|
||||
*xP, PNM_GET1(*xP), PNM_GET1(*xP), PNM_GET1(*xP) );
|
||||
}
|
||||
else
|
||||
{ /* Increase maxval. */
|
||||
for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
|
||||
PPM_ASSIGN(
|
||||
*xP, (int) PNM_GET1(*xP) * newmaxval / maxval,
|
||||
(int) PNM_GET1(*xP) * newmaxval / maxval,
|
||||
(int) PNM_GET1(*xP) * newmaxval / maxval );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,453 +0,0 @@
|
|||
/* libpnm4.c - pnm utility library part 4
|
||||
**
|
||||
** Copyright (C) 1988 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "pnm.h"
|
||||
#include "rast.h"
|
||||
|
||||
/*
|
||||
** Semi-work-alike versions of some Sun pixrect routines. Just enough
|
||||
** for rasterfile reading and writing to work.
|
||||
*/
|
||||
|
||||
struct pixrect*
|
||||
mem_create( w, h, depth )
|
||||
int w, h, depth;
|
||||
{
|
||||
struct pixrect* p;
|
||||
struct mpr_data* m;
|
||||
|
||||
p = (struct pixrect*) malloc( sizeof(struct pixrect) );
|
||||
if ( p == NULL )
|
||||
return NULL;
|
||||
p->pr_ops = NULL;
|
||||
p->pr_size.x = w;
|
||||
p->pr_size.y = h;
|
||||
p->pr_depth = depth;
|
||||
m = p->pr_data = (struct mpr_data*) malloc( sizeof(struct mpr_data) );
|
||||
if ( m == NULL )
|
||||
{
|
||||
free( p );
|
||||
return NULL;
|
||||
}
|
||||
/* According to the documentation, linebytes is supposed to be rounded
|
||||
** up to a longword (except on 386 boxes). However, this turns out
|
||||
** not to be the case. In reality, all of Sun's code rounds up to
|
||||
** a short, not a long.
|
||||
*/
|
||||
m->md_linebytes = ( w * depth + 15 ) / 16 * 2;
|
||||
m->md_offset.x = 0;
|
||||
m->md_offset.y = 0;
|
||||
m->md_flags = 0;
|
||||
m->md_image = (unsigned char*) malloc( m->md_linebytes * h );
|
||||
if ( m->md_image == NULL )
|
||||
{
|
||||
free( m );
|
||||
free( p );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
mem_free( p )
|
||||
struct pixrect* p;
|
||||
{
|
||||
free( p->pr_data->md_image );
|
||||
free( p->pr_data );
|
||||
free( p );
|
||||
}
|
||||
|
||||
int
|
||||
pr_dump( p, out, colormap, type, copy_flag )
|
||||
struct pixrect* p;
|
||||
FILE* out;
|
||||
colormap_t* colormap;
|
||||
int type, copy_flag;
|
||||
{
|
||||
struct rasterfile h;
|
||||
int size, besize, count;
|
||||
unsigned char* beimage;
|
||||
unsigned char* bp;
|
||||
unsigned char c, pc;
|
||||
int i, j;
|
||||
|
||||
h.ras_magic = RAS_MAGIC;
|
||||
h.ras_width = p->pr_size.x;
|
||||
h.ras_height = p->pr_size.y;
|
||||
h.ras_depth = p->pr_depth;
|
||||
|
||||
h.ras_type = type;
|
||||
switch ( type )
|
||||
{
|
||||
case RT_OLD:
|
||||
pm_error( "old rasterfile type is not supported" );
|
||||
|
||||
case RT_FORMAT_TIFF:
|
||||
pm_error( "tiff rasterfile type is not supported" );
|
||||
|
||||
case RT_FORMAT_IFF:
|
||||
pm_error( "iff rasterfile type is not supported" );
|
||||
|
||||
case RT_EXPERIMENTAL:
|
||||
pm_error( "experimental rasterfile type is not supported" );
|
||||
|
||||
case RT_STANDARD:
|
||||
case RT_FORMAT_RGB:
|
||||
/* Ignore hP->ras_length. */
|
||||
h.ras_length = p->pr_size.y * p->pr_data->md_linebytes;
|
||||
break;
|
||||
|
||||
case RT_BYTE_ENCODED:
|
||||
size = p->pr_size.y * p->pr_data->md_linebytes;
|
||||
bp = p->pr_data->md_image;
|
||||
beimage = (unsigned char*) malloc( size * 3 / 2 ); /* worst case */
|
||||
if ( beimage == NULL )
|
||||
return PIX_ERR;
|
||||
besize = 0;
|
||||
count = 0;
|
||||
for ( i = 0; i < size; ++i )
|
||||
{
|
||||
c = *bp++;
|
||||
if ( count > 0 )
|
||||
{
|
||||
if ( pc != c )
|
||||
{
|
||||
if ( count == 1 && pc == 128 )
|
||||
{
|
||||
beimage[besize++] = 128;
|
||||
beimage[besize++] = 0;
|
||||
count = 0;
|
||||
}
|
||||
else if ( count > 2 || pc == 128 )
|
||||
{
|
||||
beimage[besize++] = 128;
|
||||
beimage[besize++] = count - 1;
|
||||
beimage[besize++] = pc;
|
||||
count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( j = 0; j < count; ++j )
|
||||
beimage[besize++] = pc;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
pc = c;
|
||||
++count;
|
||||
if ( count == 256 )
|
||||
{
|
||||
beimage[besize++] = 128;
|
||||
beimage[besize++] = count - 1;
|
||||
beimage[besize++] = c;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
if ( count > 0 )
|
||||
{
|
||||
if ( count == 1 && c == 128 )
|
||||
{
|
||||
beimage[besize++] = 128;
|
||||
beimage[besize++] = 0;
|
||||
}
|
||||
if ( count > 2 || c == 128 )
|
||||
{
|
||||
beimage[besize++] = 128;
|
||||
beimage[besize++] = count - 1;
|
||||
beimage[besize++] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( j = 0; j < count; ++j )
|
||||
beimage[besize++] = c;
|
||||
}
|
||||
}
|
||||
h.ras_length = besize;
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "unknown rasterfile type" );
|
||||
}
|
||||
|
||||
if ( colormap == NULL )
|
||||
{
|
||||
h.ras_maptype = RMT_NONE;
|
||||
h.ras_maplength = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
h.ras_maptype = colormap->type;
|
||||
switch ( colormap->type )
|
||||
{
|
||||
case RMT_EQUAL_RGB:
|
||||
h.ras_maplength = colormap->length * 3;
|
||||
break;
|
||||
|
||||
case RMT_RAW:
|
||||
h.ras_maplength = colormap->length;
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "unknown colormap type" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( pm_writebiglong( out, h.ras_magic ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_writebiglong( out, h.ras_width ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_writebiglong( out, h.ras_height ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_writebiglong( out, h.ras_depth ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_writebiglong( out, h.ras_length ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_writebiglong( out, h.ras_type ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_writebiglong( out, h.ras_maptype ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_writebiglong( out, h.ras_maplength ) == -1 )
|
||||
return PIX_ERR;
|
||||
|
||||
if ( colormap != NULL )
|
||||
{
|
||||
switch ( colormap->type )
|
||||
{
|
||||
case RMT_EQUAL_RGB:
|
||||
if ( fwrite( colormap->map[0], 1, colormap->length, out ) != (size_t)
|
||||
colormap->length )
|
||||
return PIX_ERR;
|
||||
if ( fwrite( colormap->map[1], 1, colormap->length, out ) != (size_t)
|
||||
colormap->length )
|
||||
return PIX_ERR;
|
||||
if ( fwrite( colormap->map[2], 1, colormap->length, out ) != (size_t)
|
||||
colormap->length )
|
||||
return PIX_ERR;
|
||||
break;
|
||||
|
||||
case RMT_RAW:
|
||||
if ( fwrite( colormap->map[0], 1, colormap->length, out ) != (size_t)
|
||||
colormap->length )
|
||||
return PIX_ERR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case RT_STANDARD:
|
||||
case RT_FORMAT_RGB:
|
||||
if ( fwrite( p->pr_data->md_image, 1, h.ras_length, out ) != (size_t)
|
||||
h.ras_length )
|
||||
return PIX_ERR;
|
||||
break;
|
||||
|
||||
case RT_BYTE_ENCODED:
|
||||
if ( fwrite( beimage, 1, besize, out ) != (size_t) besize )
|
||||
{
|
||||
free( beimage );
|
||||
return PIX_ERR;
|
||||
}
|
||||
free( beimage );
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pr_load_header( in, hP )
|
||||
FILE* in;
|
||||
struct rasterfile* hP;
|
||||
{
|
||||
if ( pm_readbiglong( in, &(hP->ras_magic) ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( hP->ras_magic != RAS_MAGIC )
|
||||
return PIX_ERR;
|
||||
if ( pm_readbiglong( in, &(hP->ras_width) ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_readbiglong( in, &(hP->ras_height) ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_readbiglong( in, &(hP->ras_depth) ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_readbiglong( in, &(hP->ras_length) ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_readbiglong( in, &(hP->ras_type) ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_readbiglong( in, &(hP->ras_maptype) ) == -1 )
|
||||
return PIX_ERR;
|
||||
if ( pm_readbiglong( in, &(hP->ras_maplength) ) == -1 )
|
||||
return PIX_ERR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pr_load_colormap( in, hP, colormap )
|
||||
FILE* in;
|
||||
struct rasterfile* hP;
|
||||
colormap_t* colormap;
|
||||
{
|
||||
if ( colormap == NULL || hP->ras_maptype == RMT_NONE )
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < hP->ras_maplength; ++i )
|
||||
if ( getc( in ) == EOF )
|
||||
return PIX_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
colormap->type = hP->ras_maptype;
|
||||
switch ( hP->ras_maptype )
|
||||
{
|
||||
case RMT_EQUAL_RGB:
|
||||
colormap->length = hP->ras_maplength / 3;
|
||||
colormap->map[0] = (unsigned char*) malloc( colormap->length );
|
||||
if ( colormap->map[0] == NULL )
|
||||
return PIX_ERR;
|
||||
colormap->map[1] = (unsigned char*) malloc( colormap->length );
|
||||
if ( colormap->map[1] == NULL )
|
||||
{
|
||||
free( colormap->map[0] );
|
||||
return PIX_ERR;
|
||||
}
|
||||
colormap->map[2] = (unsigned char*) malloc( colormap->length );
|
||||
if ( colormap->map[2] == NULL )
|
||||
{
|
||||
free( colormap->map[0] );
|
||||
free( colormap->map[1] );
|
||||
return PIX_ERR;
|
||||
}
|
||||
if ( fread( colormap->map[0], 1, colormap->length, in ) != (size_t) colormap->length ||
|
||||
fread( colormap->map[1], 1, colormap->length, in ) != (size_t) colormap->length ||
|
||||
fread( colormap->map[2], 1, colormap->length, in ) != (size_t) colormap->length )
|
||||
{
|
||||
free( colormap->map[0] );
|
||||
free( colormap->map[1] );
|
||||
free( colormap->map[2] );
|
||||
return PIX_ERR;
|
||||
}
|
||||
break;
|
||||
|
||||
case RMT_RAW:
|
||||
colormap->length = hP->ras_maplength;
|
||||
colormap->map[0] = (unsigned char*) malloc( colormap->length );
|
||||
if ( colormap->map[0] == NULL )
|
||||
return PIX_ERR;
|
||||
colormap->map[2] = colormap->map[1] = colormap->map[0];
|
||||
if ( fread( colormap->map[0], 1, hP->ras_maplength, in ) != (size_t) hP->ras_maplength )
|
||||
{
|
||||
free( colormap->map[0] );
|
||||
return PIX_ERR;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "unknown colormap type" );
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct pixrect*
|
||||
pr_load_image( in, hP, colormap )
|
||||
FILE* in;
|
||||
struct rasterfile* hP;
|
||||
colormap_t* colormap;
|
||||
{
|
||||
struct pixrect* p;
|
||||
unsigned char* beimage;
|
||||
register unsigned char* bep;
|
||||
register unsigned char* bp;
|
||||
register unsigned char c;
|
||||
int i;
|
||||
register int j, count;
|
||||
|
||||
p = mem_create( hP->ras_width, hP->ras_height, hP->ras_depth );
|
||||
if ( p == NULL )
|
||||
return NULL;
|
||||
|
||||
switch ( hP->ras_type )
|
||||
{
|
||||
case RT_OLD:
|
||||
pm_error( "old rasterfile type is not supported" );
|
||||
|
||||
case RT_FORMAT_TIFF:
|
||||
pm_error( "tiff rasterfile type is not supported" );
|
||||
|
||||
case RT_FORMAT_IFF:
|
||||
pm_error( "iff rasterfile type is not supported" );
|
||||
|
||||
case RT_EXPERIMENTAL:
|
||||
pm_error( "experimental rasterfile type is not supported" );
|
||||
|
||||
case RT_STANDARD:
|
||||
case RT_FORMAT_RGB:
|
||||
/* Ignore hP->ras_length. */
|
||||
i = p->pr_size.y * p->pr_data->md_linebytes;
|
||||
if ( fread( p->pr_data->md_image, 1, i, in ) != (size_t) i )
|
||||
{
|
||||
mem_free( p );
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case RT_BYTE_ENCODED:
|
||||
beimage = (unsigned char*) malloc( hP->ras_length );
|
||||
if ( beimage == NULL )
|
||||
{
|
||||
mem_free( p );
|
||||
return NULL;
|
||||
}
|
||||
if ( fread( beimage, 1, hP->ras_length, in ) != (size_t) hP->ras_length )
|
||||
{
|
||||
mem_free( p );
|
||||
free( beimage );
|
||||
return NULL;
|
||||
}
|
||||
bep = beimage;
|
||||
bp = p->pr_data->md_image;
|
||||
for ( i = 0; i < hP->ras_length; )
|
||||
{
|
||||
c = *bep++;
|
||||
if ( c == 128 )
|
||||
{
|
||||
count = ( *bep++ ) + 1;
|
||||
if ( count == 1 )
|
||||
{
|
||||
*bp++ = 128;
|
||||
i += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
c = *bep++;
|
||||
for ( j = 0; j < count; ++j )
|
||||
*bp++ = c;
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*bp++ = c;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
free( beimage );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "unknown rasterfile type" );
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/* libppm.h - internal header file for libppm portable pixmap library
|
||||
*/
|
||||
|
||||
#ifndef _LIBPPM_H_
|
||||
#define _LIBPPM_H_
|
||||
|
||||
/* Here are some routines internal to the ppm library. */
|
||||
|
||||
EXPCL_PANDA void ppm_readppminitrest( FILE* file, int* colsP, int* rowsP, pixval* maxvalP );
|
||||
|
||||
#endif /*_LIBPPM_H_*/
|
||||
|
|
@ -1,195 +0,0 @@
|
|||
/* libppm1.c - ppm utility library part 1
|
||||
**
|
||||
** Copyright (C) 1989 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "ppm.h"
|
||||
#include "libppm.h"
|
||||
#include "pgm.h"
|
||||
#include "libpgm.h"
|
||||
#include "pbm.h"
|
||||
#include "libpbm.h"
|
||||
|
||||
void
|
||||
ppm_init( argcP, argv )
|
||||
int* argcP;
|
||||
char* argv[];
|
||||
{
|
||||
pgm_init( argcP, argv );
|
||||
}
|
||||
|
||||
void
|
||||
ppm_readppminitrest( file, colsP, rowsP, maxvalP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
pixval* maxvalP;
|
||||
{
|
||||
int maxval;
|
||||
|
||||
/* Read size. */
|
||||
*colsP = pbm_getint( file );
|
||||
*rowsP = pbm_getint( file );
|
||||
|
||||
/* Read maxval. */
|
||||
maxval = pbm_getint( file );
|
||||
if ( maxval > PPM_MAXMAXVAL )
|
||||
pm_error(
|
||||
"maxval is too large - try reconfiguring with PGM_BIGGRAYS\n or without PPM_PACKCOLORS" );
|
||||
*maxvalP = maxval;
|
||||
}
|
||||
|
||||
pixval ppm_pbmmaxval = 1;
|
||||
|
||||
void
|
||||
ppm_readppminit( file, colsP, rowsP, maxvalP, formatP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
int* formatP;
|
||||
pixval* maxvalP;
|
||||
{
|
||||
/* Check magic number. */
|
||||
*formatP = pbm_readmagicnumber( file );
|
||||
switch ( PPM_FORMAT_TYPE(*formatP) )
|
||||
{
|
||||
case PPM_TYPE:
|
||||
ppm_readppminitrest( file, colsP, rowsP, maxvalP );
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
pgm_readpgminitrest( file, colsP, rowsP, maxvalP );
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
pbm_readpbminitrest( file, colsP, rowsP );
|
||||
*maxvalP = ppm_pbmmaxval;
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "bad magic number - not a ppm, pgm, or pbm file" );
|
||||
}
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppm_readppmrow( FILE* file, pixel* pixelrow, int cols, pixval maxval, int format )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppm_readppmrow( file, pixelrow, cols, maxval, format )
|
||||
FILE* file;
|
||||
pixel* pixelrow;
|
||||
int cols, format;
|
||||
pixval maxval;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int col;
|
||||
register pixel* pP;
|
||||
register pixval r, g, b;
|
||||
gray* grayrow;
|
||||
register gray* gP;
|
||||
bit* bitrow;
|
||||
register bit* bP;
|
||||
|
||||
switch ( format )
|
||||
{
|
||||
case PPM_FORMAT:
|
||||
for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
|
||||
{
|
||||
r = pbm_getint( file );
|
||||
#ifdef DEBUG
|
||||
if ( r > maxval )
|
||||
pm_error( "r value out of bounds (%u > %u)", r, maxval );
|
||||
#endif /*DEBUG*/
|
||||
g = pbm_getint( file );
|
||||
#ifdef DEBUG
|
||||
if ( g > maxval )
|
||||
pm_error( "g value out of bounds (%u > %u)", g, maxval );
|
||||
#endif /*DEBUG*/
|
||||
b = pbm_getint( file );
|
||||
#ifdef DEBUG
|
||||
if ( b > maxval )
|
||||
pm_error( "b value out of bounds (%u > %u)", b, maxval );
|
||||
#endif /*DEBUG*/
|
||||
PPM_ASSIGN( *pP, r, g, b );
|
||||
}
|
||||
break;
|
||||
|
||||
case RPPM_FORMAT:
|
||||
for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
|
||||
{
|
||||
r = pbm_getrawbyte( file );
|
||||
#ifdef DEBUG
|
||||
if ( r > maxval )
|
||||
pm_error( "r value out of bounds (%u > %u)", r, maxval );
|
||||
#endif /*DEBUG*/
|
||||
g = pbm_getrawbyte( file );
|
||||
#ifdef DEBUG
|
||||
if ( g > maxval )
|
||||
pm_error( "g value out of bounds (%u > %u)", g, maxval );
|
||||
#endif /*DEBUG*/
|
||||
b = pbm_getrawbyte( file );
|
||||
#ifdef DEBUG
|
||||
if ( b > maxval )
|
||||
pm_error( "b value out of bounds (%u > %u)", b, maxval );
|
||||
#endif /*DEBUG*/
|
||||
PPM_ASSIGN( *pP, r, g, b );
|
||||
}
|
||||
break;
|
||||
|
||||
case PGM_FORMAT:
|
||||
case RPGM_FORMAT:
|
||||
grayrow = pgm_allocrow( cols );
|
||||
pgm_readpgmrow( file, grayrow, cols, maxval, format );
|
||||
for ( col = 0, gP = grayrow, pP = pixelrow; col < cols; ++col, ++gP, ++pP )
|
||||
{
|
||||
r = *gP;
|
||||
PPM_ASSIGN( *pP, r, r, r );
|
||||
}
|
||||
pgm_freerow( grayrow );
|
||||
break;
|
||||
|
||||
case PBM_FORMAT:
|
||||
case RPBM_FORMAT:
|
||||
bitrow = pbm_allocrow( cols );
|
||||
pbm_readpbmrow( file, bitrow, cols, format );
|
||||
for ( col = 0, bP = bitrow, pP = pixelrow; col < cols; ++col, ++bP, ++pP )
|
||||
{
|
||||
r = ( *bP == PBM_WHITE ) ? maxval : 0;
|
||||
PPM_ASSIGN( *pP, r, r, r );
|
||||
}
|
||||
pbm_freerow( bitrow );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( "can't happen" );
|
||||
}
|
||||
}
|
||||
|
||||
pixel**
|
||||
ppm_readppm( file, colsP, rowsP, maxvalP )
|
||||
FILE* file;
|
||||
int* colsP;
|
||||
int* rowsP;
|
||||
pixval* maxvalP;
|
||||
{
|
||||
pixel** pixels;
|
||||
int row;
|
||||
int format;
|
||||
|
||||
ppm_readppminit( file, colsP, rowsP, maxvalP, &format );
|
||||
|
||||
pixels = ppm_allocarray( *colsP, *rowsP );
|
||||
|
||||
for ( row = 0; row < *rowsP; ++row )
|
||||
ppm_readppmrow( file, pixels[row], *colsP, *maxvalP, format );
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
/* libppm2.c - ppm utility library part 2
|
||||
**
|
||||
** Copyright (C) 1989 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "ppm.h"
|
||||
#include "libppm.h"
|
||||
|
||||
static void putus ARGS((unsigned short n, FILE* file));
|
||||
|
||||
static void ppm_writeppmrowplain ARGS((FILE* file, pixel* pixelrow, int cols, pixval maxval));
|
||||
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
static void ppm_writeppmrowraw(FILE* file, pixel* pixelrow, int cols, pixval maxval);
|
||||
#endif /* PBMPLUS_RAWBITS */
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppm_writeppminit( FILE* file, int cols, int rows, pixval maxval, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppm_writeppminit( file, cols, rows, maxval, forceplain )
|
||||
FILE* file;
|
||||
int cols, rows;
|
||||
pixval maxval;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
if ( maxval <= 255 && ! forceplain ) {
|
||||
fprintf(
|
||||
file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, RPPM_MAGIC2,
|
||||
cols, rows, maxval );
|
||||
#ifdef VMS
|
||||
set_outfile_binary();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
fprintf(
|
||||
file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, PPM_MAGIC2,
|
||||
cols, rows, maxval );
|
||||
#else /*PBMPLUS_RAWBITS*/
|
||||
fprintf(
|
||||
file, "%c%c\n%d %d\n%d\n", PPM_MAGIC1, PPM_MAGIC2,
|
||||
cols, rows, maxval );
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
}
|
||||
|
||||
static void
|
||||
putus(unsigned short n, FILE* file)
|
||||
{
|
||||
if ( n >= 10 )
|
||||
putus( (unsigned short)(n / 10), file );
|
||||
(void) putc( n % 10 + '0', file );
|
||||
}
|
||||
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
static void
|
||||
ppm_writeppmrowraw (FILE* file,pixel* pixelrow,int cols,pixval maxval)
|
||||
{
|
||||
register int col;
|
||||
register pixel* pP;
|
||||
register pixval val;
|
||||
|
||||
for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
|
||||
{
|
||||
val = PPM_GETR( *pP );
|
||||
#ifdef DEBUG
|
||||
if ( val > maxval )
|
||||
pm_error( "r value out of bounds (%u > %u)", val, maxval );
|
||||
#endif /*DEBUG*/
|
||||
(void) putc( val, file );
|
||||
val = PPM_GETG( *pP );
|
||||
#ifdef DEBUG
|
||||
if ( val > maxval )
|
||||
pm_error( "g value out of bounds (%u > %u)", val, maxval );
|
||||
#endif /*DEBUG*/
|
||||
(void) putc( val, file );
|
||||
val = PPM_GETB( *pP );
|
||||
#ifdef DEBUG
|
||||
if ( val > maxval )
|
||||
pm_error( "b value out of bounds (%u > %u)", val, maxval );
|
||||
#endif /*DEBUG*/
|
||||
(void) putc( val, file );
|
||||
}
|
||||
}
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
|
||||
static void
|
||||
ppm_writeppmrowplain(FILE* file,pixel* pixelrow,int cols,pixval maxval)
|
||||
{
|
||||
register int col, charcount;
|
||||
register pixel* pP;
|
||||
register pixval val;
|
||||
|
||||
charcount = 0;
|
||||
for ( col = 0, pP = pixelrow; col < cols; ++col, ++pP )
|
||||
{
|
||||
if ( charcount >= 65 )
|
||||
{
|
||||
(void) putc( '\n', file );
|
||||
charcount = 0;
|
||||
}
|
||||
else if ( charcount > 0 )
|
||||
{
|
||||
(void) putc( ' ', file );
|
||||
(void) putc( ' ', file );
|
||||
charcount += 2;
|
||||
}
|
||||
val = PPM_GETR( *pP );
|
||||
#ifdef DEBUG
|
||||
if ( val > maxval )
|
||||
pm_error( "r value out of bounds (%u > %u)", val, maxval );
|
||||
#endif /*DEBUG*/
|
||||
putus( val, file );
|
||||
(void) putc( ' ', file );
|
||||
val = PPM_GETG( *pP );
|
||||
#ifdef DEBUG
|
||||
if ( val > maxval )
|
||||
pm_error( "g value out of bounds (%u > %u)", val, maxval );
|
||||
#endif /*DEBUG*/
|
||||
putus( val, file );
|
||||
(void) putc( ' ', file );
|
||||
val = PPM_GETB( *pP );
|
||||
#ifdef DEBUG
|
||||
if ( val > maxval )
|
||||
pm_error( "b value out of bounds (%u > %u)", val, maxval );
|
||||
#endif /*DEBUG*/
|
||||
putus( val, file );
|
||||
charcount += 11;
|
||||
}
|
||||
if ( charcount > 0 )
|
||||
(void) putc( '\n', file );
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppm_writeppmrow( FILE* file, pixel* pixelrow, int cols, pixval maxval, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppm_writeppmrow( file, pixelrow, cols, maxval, forceplain )
|
||||
FILE* file;
|
||||
pixel* pixelrow;
|
||||
int cols;
|
||||
pixval maxval;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
#ifdef PBMPLUS_RAWBITS
|
||||
if ( maxval <= 255 && ! forceplain )
|
||||
ppm_writeppmrowraw( file, pixelrow, cols, maxval );
|
||||
else
|
||||
ppm_writeppmrowplain( file, pixelrow, cols, maxval );
|
||||
#else /*PBMPLUS_RAWBITS*/
|
||||
ppm_writeppmrowplain( file, pixelrow, cols, maxval );
|
||||
#endif /*PBMPLUS_RAWBITS*/
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppm_writeppm( FILE* file, pixel** pixels, int cols, int rows, pixval maxval, int forceplain )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppm_writeppm( file, pixels, cols, rows, maxval, forceplain )
|
||||
FILE* file;
|
||||
pixel** pixels;
|
||||
int cols, rows;
|
||||
pixval maxval;
|
||||
int forceplain;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
int row;
|
||||
|
||||
ppm_writeppminit( file, cols, rows, maxval, forceplain );
|
||||
|
||||
for ( row = 0; row < rows; ++row )
|
||||
ppm_writeppmrow( file, pixels[row], cols, maxval, forceplain );
|
||||
}
|
||||
|
|
@ -1,330 +0,0 @@
|
|||
/* libppm4.c - ppm utility library part 4
|
||||
**
|
||||
** Copyright (C) 1989 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "ppm.h"
|
||||
|
||||
static void canonstr ARGS((char* str));
|
||||
static long rgbnorm ARGS((long rgb, long lmaxval, int n, char* colorname));
|
||||
static void
|
||||
canonstr( str )
|
||||
char* str;
|
||||
{
|
||||
while ( *str != '\0' )
|
||||
{
|
||||
if ( *str == ' ' )
|
||||
{
|
||||
(void) strcpy( str, &(str[1]) );
|
||||
continue;
|
||||
}
|
||||
if ( isupper( *str ) )
|
||||
*str = tolower( *str );
|
||||
++str;
|
||||
}
|
||||
}
|
||||
|
||||
static long
|
||||
rgbnorm( rgb, lmaxval, n, colorname )
|
||||
long rgb, lmaxval;
|
||||
int n;
|
||||
char* colorname;
|
||||
{
|
||||
switch ( n )
|
||||
{
|
||||
case 1:
|
||||
if ( lmaxval != 15 )
|
||||
rgb = rgb * lmaxval / 15;
|
||||
break;
|
||||
case 2:
|
||||
if ( lmaxval != 255 )
|
||||
rgb = rgb * lmaxval / 255;
|
||||
break;
|
||||
case 3:
|
||||
if ( lmaxval != 4095 )
|
||||
rgb = rgb * lmaxval / 4095;
|
||||
break;
|
||||
case 4:
|
||||
if ( lmaxval != 65535L )
|
||||
rgb = rgb * lmaxval / 65535L;
|
||||
break;
|
||||
default:
|
||||
pm_error( "invalid color specifier - \"%s\"", colorname );
|
||||
}
|
||||
return rgb;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
pixel
|
||||
ppm_parsecolor( char* colorname, pixval maxval )
|
||||
#else /*__STDC__*/
|
||||
pixel
|
||||
ppm_parsecolor( colorname, maxval )
|
||||
char* colorname;
|
||||
pixval maxval;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
int hexit[256], i;
|
||||
pixel p;
|
||||
long lmaxval, r, g, b;
|
||||
char* inval = "invalid color specifier - \"%s\"";
|
||||
|
||||
for ( i = 0; i < 256; ++i )
|
||||
hexit[i] = 1234567890;
|
||||
hexit['0'] = 0;
|
||||
hexit['1'] = 1;
|
||||
hexit['2'] = 2;
|
||||
hexit['3'] = 3;
|
||||
hexit['4'] = 4;
|
||||
hexit['5'] = 5;
|
||||
hexit['6'] = 6;
|
||||
hexit['7'] = 7;
|
||||
hexit['8'] = 8;
|
||||
hexit['9'] = 9;
|
||||
hexit['a'] = hexit['A'] = 10;
|
||||
hexit['b'] = hexit['B'] = 11;
|
||||
hexit['c'] = hexit['C'] = 12;
|
||||
hexit['d'] = hexit['D'] = 13;
|
||||
hexit['e'] = hexit['E'] = 14;
|
||||
hexit['f'] = hexit['F'] = 15;
|
||||
|
||||
lmaxval = maxval;
|
||||
if ( strncmp( colorname, "rgb:", 4 ) == 0 )
|
||||
{
|
||||
/* It's a new-X11-style hexadecimal rgb specifier. */
|
||||
char* cp;
|
||||
|
||||
cp = colorname + 4;
|
||||
r = g = b = 0;
|
||||
for ( i = 0; *cp != '/'; ++i, ++cp )
|
||||
r = r * 16 + hexit[*cp];
|
||||
r = rgbnorm( r, lmaxval, i, colorname );
|
||||
for ( i = 0, ++cp; *cp != '/'; ++i, ++cp )
|
||||
g = g * 16 + hexit[*cp];
|
||||
g = rgbnorm( g, lmaxval, i, colorname );
|
||||
for ( i = 0, ++cp; *cp != '\0'; ++i, ++cp )
|
||||
b = b * 16 + hexit[*cp];
|
||||
b = rgbnorm( b, lmaxval, i, colorname );
|
||||
if ( r < 0 || r > lmaxval || g < 0 || g > lmaxval || b < 0 || b > lmaxval )
|
||||
pm_error( inval, colorname );
|
||||
}
|
||||
else if ( strncmp( colorname, "rgbi:", 5 ) == 0 )
|
||||
{
|
||||
/* It's a new-X11-style decimal/float rgb specifier. */
|
||||
float fr, fg, fb;
|
||||
|
||||
if ( sscanf( colorname, "rgbi:%f/%f/%f", &fr, &fg, &fb ) != 3 )
|
||||
pm_error( inval, colorname );
|
||||
if ( fr < 0.0 || fr > 1.0 || fg < 0.0 || fg > 1.0 || fb < 0.0 || fb > 1.0 )
|
||||
pm_error( "invalid color specifier - \"%s\" - values must be between 0.0 and 1.0", colorname );
|
||||
r = fr * lmaxval;
|
||||
g = fg * lmaxval;
|
||||
b = fb * lmaxval;
|
||||
}
|
||||
else if ( colorname[0] == '#' )
|
||||
{
|
||||
/* It's an old-X11-style hexadecimal rgb specifier. */
|
||||
switch ( strlen( colorname ) )
|
||||
{
|
||||
case 4:
|
||||
r = hexit[colorname[1]];
|
||||
g = hexit[colorname[2]];
|
||||
b = hexit[colorname[3]];
|
||||
r = rgbnorm( r, lmaxval, 1, colorname );
|
||||
g = rgbnorm( g, lmaxval, 1, colorname );
|
||||
b = rgbnorm( b, lmaxval, 1, colorname );
|
||||
break;
|
||||
|
||||
case 7:
|
||||
r = ( hexit[colorname[1]] << 4 ) + hexit[colorname[2]];
|
||||
g = ( hexit[colorname[3]] << 4 ) + hexit[colorname[4]];
|
||||
b = ( hexit[colorname[5]] << 4 ) + hexit[colorname[6]];
|
||||
r = rgbnorm( r, lmaxval, 2, colorname );
|
||||
g = rgbnorm( g, lmaxval, 2, colorname );
|
||||
b = rgbnorm( b, lmaxval, 2, colorname );
|
||||
break;
|
||||
|
||||
case 10:
|
||||
r = ( hexit[colorname[1]] << 8 ) + ( hexit[colorname[2]] << 4 ) +
|
||||
hexit[colorname[3]];
|
||||
g = ( hexit[colorname[4]] << 8 ) + ( hexit[colorname[5]] << 4 ) +
|
||||
hexit[colorname[6]];
|
||||
b = ( hexit[colorname[7]] << 8 ) + ( hexit[colorname[8]] << 4 ) +
|
||||
hexit[colorname[9]];
|
||||
r = rgbnorm( r, lmaxval, 3, colorname );
|
||||
g = rgbnorm( g, lmaxval, 3, colorname );
|
||||
b = rgbnorm( b, lmaxval, 3, colorname );
|
||||
break;
|
||||
|
||||
case 13:
|
||||
r = ( hexit[colorname[1]] << 12 ) + ( hexit[colorname[2]] << 8 ) +
|
||||
( hexit[colorname[3]] << 4 ) + hexit[colorname[4]];
|
||||
g = ( hexit[colorname[5]] << 12 ) + ( hexit[colorname[6]] << 8 ) +
|
||||
( hexit[colorname[7]] << 4 ) + hexit[colorname[8]];
|
||||
b = ( hexit[colorname[9]] << 12 ) + ( hexit[colorname[10]] << 8 ) +
|
||||
( hexit[colorname[11]] << 4 ) + hexit[colorname[12]];
|
||||
r = rgbnorm( r, lmaxval, 4, colorname );
|
||||
g = rgbnorm( g, lmaxval, 4, colorname );
|
||||
b = rgbnorm( b, lmaxval, 4, colorname );
|
||||
break;
|
||||
|
||||
default:
|
||||
pm_error( inval, colorname );
|
||||
}
|
||||
if ( r < 0 || r > lmaxval || g < 0 || g > lmaxval || b < 0 || b > lmaxval )
|
||||
pm_error( inval, colorname );
|
||||
}
|
||||
else if ( ( colorname[0] >= '0' && colorname[0] <= '9' ) ||
|
||||
colorname[0] == '.' )
|
||||
{
|
||||
/* It's an old-style decimal/float rgb specifier. */
|
||||
float fr, fg, fb;
|
||||
|
||||
if ( sscanf( colorname, "%f,%f,%f", &fr, &fg, &fb ) != 3 )
|
||||
pm_error( inval, colorname );
|
||||
if ( fr < 0.0 || fr > 1.0 || fg < 0.0 || fg > 1.0 || fb < 0.0 || fb > 1.0 )
|
||||
pm_error( "invalid color specifier - \"%s\" - values must be between 0.0 and 1.0", colorname );
|
||||
r = fr * lmaxval;
|
||||
g = fg * lmaxval;
|
||||
b = fb * lmaxval;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Must be a name from the X-style rgb file. */
|
||||
#ifndef RGB_DB
|
||||
pm_error( "color names database required - please reconfigure with RGBDEF" );
|
||||
#else /*RGB_DB*/
|
||||
FILE* f;
|
||||
char buf1[200], buf2[200];
|
||||
|
||||
#ifndef A_RGBENV
|
||||
(void) sprintf( buf1, "%s.txt", RGB_DB );
|
||||
if ( ( f = fopen( buf1, "r" ) ) == NULL )
|
||||
pm_error( "can't open color names database - reconfigure with correct RGBDEF" );
|
||||
#else /* A_RGBENV */
|
||||
char *rgbdef;
|
||||
if( (rgbdef = getenv(RGB_DB))==NULL )
|
||||
pm_error( "can't get path to color names database - %s not set", RGB_DB );
|
||||
if ( ( f = fopen( rgbdef, "r" ) ) == NULL )
|
||||
pm_error( "can't open color names database - set %s to correct path", RGB_DB );
|
||||
#endif /* A_RGBENV */
|
||||
canonstr( colorname );
|
||||
while ( fgets( buf1, sizeof(buf1), f ) != NULL )
|
||||
{
|
||||
if ( sscanf( buf1, "%ld %ld %ld %[^\n]", &r, &g, &b, buf2 ) != 4 )
|
||||
{
|
||||
pm_message(
|
||||
"can't parse color names database line - \"%s\"", buf1 );
|
||||
continue;
|
||||
}
|
||||
canonstr( buf2 );
|
||||
if ( strcmp( colorname, buf2 ) == 0 )
|
||||
goto gotit;
|
||||
}
|
||||
(void) fclose( f );
|
||||
pm_error( "unknown color - \"%s\"", colorname );
|
||||
|
||||
gotit:
|
||||
(void) fclose( f );
|
||||
/* Rescale from [0..255] if necessary. */
|
||||
if ( lmaxval != 255 )
|
||||
{
|
||||
r = r * lmaxval / 255;
|
||||
g = g * lmaxval / 255;
|
||||
b = b * lmaxval / 255;
|
||||
}
|
||||
#endif /*RGB_DB*/
|
||||
}
|
||||
|
||||
PPM_ASSIGN( p, r, g, b );
|
||||
return p;
|
||||
}
|
||||
|
||||
static char colorname[200];
|
||||
|
||||
#if __STDC__
|
||||
char*
|
||||
ppm_colorname( pixel* colorP, pixval maxval, int hexok )
|
||||
#else /*__STDC__*/
|
||||
char*
|
||||
ppm_colorname( colorP, maxval, hexok )
|
||||
pixel* colorP;
|
||||
pixval maxval;
|
||||
int hexok;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
int r, g, b;
|
||||
#ifdef RGB_DB
|
||||
FILE* f;
|
||||
char buf[200];
|
||||
int this_r, this_g, this_b;
|
||||
int best_diff, this_diff;
|
||||
char this_colorname[200];
|
||||
#ifdef A_RGBENV
|
||||
char *rgbdef;
|
||||
#endif /* A_RGBENV */
|
||||
#endif /*RGB_DB*/
|
||||
|
||||
if ( maxval == 255 )
|
||||
{
|
||||
r = PPM_GETR( *colorP );
|
||||
g = PPM_GETG( *colorP );
|
||||
b = PPM_GETB( *colorP );
|
||||
}
|
||||
else
|
||||
{
|
||||
r = (int) PPM_GETR( *colorP ) * 255 / (int) maxval;
|
||||
g = (int) PPM_GETG( *colorP ) * 255 / (int) maxval;
|
||||
b = (int) PPM_GETB( *colorP ) * 255 / (int) maxval;
|
||||
}
|
||||
|
||||
#ifdef RGB_DB
|
||||
#ifndef A_RGBENV
|
||||
(void) sprintf( buf, "%s.txt", RGB_DB );
|
||||
if ( ( f = fopen( buf, "r" ) ) == NULL )
|
||||
pm_error( "can't open color names database - reconfigure with correct RGBDEF" );
|
||||
#else /* A_RGBENV */
|
||||
if( (rgbdef = getenv(RGB_DB))==NULL )
|
||||
pm_error( "can't get path to color names database - %s not set", RGB_DB );
|
||||
if ( ( f = fopen( rgbdef, "r" ) ) == NULL )
|
||||
pm_error( "can't open color names database - set %s to correct path", RGB_DB );
|
||||
#endif /* A_RGBENV */
|
||||
best_diff = 32767;
|
||||
while ( fgets( buf, sizeof(buf), f ) != NULL )
|
||||
{
|
||||
if ( sscanf( buf, "%d %d %d %[^\n]", &this_r, &this_g, &this_b,
|
||||
this_colorname ) != 4 )
|
||||
{
|
||||
pm_message(
|
||||
"can't parse color names database line - \"%s\"",
|
||||
buf );
|
||||
continue;
|
||||
}
|
||||
this_diff = abs( r - this_r ) + abs( g - this_g ) + abs( b - this_b );
|
||||
if ( this_diff < best_diff )
|
||||
{
|
||||
best_diff = this_diff;
|
||||
(void) strcpy( colorname, this_colorname );
|
||||
}
|
||||
}
|
||||
(void) fclose( f );
|
||||
if ( best_diff != 32767 && ( best_diff == 0 || ! hexok ) )
|
||||
return colorname;
|
||||
#endif /*RGB_DB*/
|
||||
|
||||
/* Color lookup failed; generate an X11-style hex specifier. */
|
||||
if ( ! hexok )
|
||||
pm_error(
|
||||
"color names database required - please reconfigure with RGBDEF" );
|
||||
sprintf( colorname, "#%02x%02x%02x", r, g, b );
|
||||
return colorname;
|
||||
}
|
||||
|
|
@ -1,697 +0,0 @@
|
|||
/* libppm5.c - ppm utility library part 5
|
||||
**
|
||||
** This library module contains the ppmdraw routines.
|
||||
**
|
||||
** Copyright (C) 1989, 1991 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "ppm.h"
|
||||
#include "ppmdraw.h"
|
||||
|
||||
#define DDA_SCALE 8192
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppmd_point_drawproc( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, char* clientdata )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppmd_point_drawproc( pixels, cols, rows, maxval, x, y, clientdata )
|
||||
pixel** pixels;
|
||||
int cols, rows, x, y;
|
||||
pixval maxval;
|
||||
char* clientdata;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
if ( x >= 0 && x < cols && y >= 0 && y < rows )
|
||||
pixels[y][x] = *( (pixel*) clientdata );
|
||||
}
|
||||
|
||||
|
||||
/* Simple fill routine. */
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppmd_filledrectangle( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, int width, int height, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppmd_filledrectangle( pixels, cols, rows, maxval, x, y, width, height, drawprocP, clientdata )
|
||||
pixel** pixels;
|
||||
int cols, rows, x, y, width, height;
|
||||
pixval maxval;
|
||||
void (*drawprocP)();
|
||||
char* clientdata;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int cx, cy, cwidth, cheight, col, row;
|
||||
|
||||
/* Clip. */
|
||||
cx = x;
|
||||
cy = y;
|
||||
cwidth = width;
|
||||
cheight = height;
|
||||
if ( cx < 0 )
|
||||
{
|
||||
cx = 0;
|
||||
cwidth += x;
|
||||
}
|
||||
if ( cy < 0 )
|
||||
{
|
||||
cy = 0;
|
||||
cheight += y;
|
||||
}
|
||||
if ( cx + cwidth > cols )
|
||||
cwidth = cols - cx;
|
||||
if ( cy + cheight > rows )
|
||||
cheight = rows - cy;
|
||||
|
||||
/* Draw. */
|
||||
for ( row = cy; row < cy + cheight; ++row )
|
||||
for ( col = cx; col < cx + cwidth; ++col )
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
pixels[row][col] = *( (pixel*) clientdata );
|
||||
else
|
||||
(*drawprocP)(
|
||||
pixels, cols, rows, maxval, col, row, clientdata );
|
||||
}
|
||||
|
||||
|
||||
/* Outline drawing stuff. */
|
||||
|
||||
static int ppmd_linetype = PPMD_LINETYPE_NORMAL;
|
||||
|
||||
int
|
||||
ppmd_setlinetype( type )
|
||||
int type;
|
||||
{
|
||||
int old;
|
||||
|
||||
old = ppmd_linetype;
|
||||
ppmd_linetype = type;
|
||||
return old;
|
||||
}
|
||||
|
||||
static int ppmd_lineclip = 1;
|
||||
|
||||
int
|
||||
ppmd_setlineclip( clip )
|
||||
int clip;
|
||||
{
|
||||
int old;
|
||||
|
||||
old = ppmd_lineclip;
|
||||
ppmd_lineclip = clip;
|
||||
return old;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppmd_line( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int x1, int y1, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppmd_line( pixels, cols, rows, maxval, x0, y0, x1, y1, drawprocP, clientdata )
|
||||
pixel** pixels;
|
||||
int cols, rows, x0, y0, x1, y1;
|
||||
pixval maxval;
|
||||
void (*drawprocP)();
|
||||
char* clientdata;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int cx0, cy0, cx1, cy1;
|
||||
|
||||
/* Special case zero-length lines. */
|
||||
if ( x0 == x1 && y0 == y1 )
|
||||
{
|
||||
if ( ( ! ppmd_lineclip ) ||
|
||||
( x0 >= 0 && x0 < cols && y0 >= 0 && y0 < rows ) )
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
ppmd_point_drawproc(
|
||||
pixels, cols, rows, maxval, x0, y0, clientdata );
|
||||
else
|
||||
(*drawprocP)( pixels, cols, rows, maxval, x0, y0, clientdata );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Clip. */
|
||||
cx0 = x0;
|
||||
cy0 = y0;
|
||||
cx1 = x1;
|
||||
cy1 = y1;
|
||||
if ( ppmd_lineclip )
|
||||
{
|
||||
if ( cx0 < 0 )
|
||||
{
|
||||
if ( cx1 < 0 ) return;
|
||||
cy0 = cy0 + ( cy1 - cy0 ) * ( -cx0 ) / ( cx1 - cx0 );
|
||||
cx0 = 0;
|
||||
}
|
||||
else if ( cx0 >= cols )
|
||||
{
|
||||
if ( cx1 >= cols ) return;
|
||||
cy0 = cy0 + ( cy1 - cy0 ) * ( cols - 1 - cx0 ) / ( cx1 - cx0 );
|
||||
cx0 = cols - 1;
|
||||
}
|
||||
if ( cy0 < 0 )
|
||||
{
|
||||
if ( cy1 < 0 ) return;
|
||||
cx0 = cx0 + ( cx1 - cx0 ) * ( -cy0 ) / ( cy1 - cy0 );
|
||||
cy0 = 0;
|
||||
}
|
||||
else if ( cy0 >= rows )
|
||||
{
|
||||
if ( cy1 >= rows ) return;
|
||||
cx0 = cx0 + ( cx1 - cx0 ) * ( rows - 1 - cy0 ) / ( cy1 - cy0 );
|
||||
cy0 = rows - 1;
|
||||
}
|
||||
if ( cx1 < 0 )
|
||||
{
|
||||
cy1 = cy1 + ( cy0 - cy1 ) * ( -cx1 ) / ( cx0 - cx1 );
|
||||
cx1 = 0;
|
||||
}
|
||||
else if ( cx1 >= cols )
|
||||
{
|
||||
cy1 = cy1 + ( cy0 - cy1 ) * ( cols - 1 - cx1 ) / ( cx0 - cx1 );
|
||||
cx1 = cols - 1;
|
||||
}
|
||||
if ( cy1 < 0 )
|
||||
{
|
||||
cx1 = cx1 + ( cx0 - cx1 ) * ( -cy1 ) / ( cy0 - cy1 );
|
||||
cy1 = 0;
|
||||
}
|
||||
else if ( cy1 >= rows )
|
||||
{
|
||||
cx1 = cx1 + ( cx0 - cx1 ) * ( rows - 1 - cy1 ) / ( cy0 - cy1 );
|
||||
cy1 = rows - 1;
|
||||
}
|
||||
|
||||
/* Check again for zero-length lines. */
|
||||
if ( cx0 == cx1 && cy0 == cy1 )
|
||||
{
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
ppmd_point_drawproc(
|
||||
pixels, cols, rows, maxval, cx0, cy0, clientdata );
|
||||
else
|
||||
(*drawprocP)(
|
||||
pixels, cols, rows, maxval, cx0, cy0, clientdata );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw, using a simple DDA. */
|
||||
if ( abs( cx1 - cx0 ) > abs( cy1 - cy0 ) )
|
||||
{ /* Loop over X domain. */
|
||||
register long dy, srow;
|
||||
register int dx, col, row, prevrow;
|
||||
|
||||
if ( cx1 > cx0 )
|
||||
dx = 1;
|
||||
else
|
||||
dx = -1;
|
||||
dy = ( cy1 - cy0 ) * DDA_SCALE / abs( cx1 - cx0 );
|
||||
prevrow = row = cy0;
|
||||
srow = row * DDA_SCALE + DDA_SCALE / 2;
|
||||
col = cx0;
|
||||
for ( ; ; )
|
||||
{
|
||||
if ( ppmd_linetype == PPMD_LINETYPE_NODIAGS && row != prevrow )
|
||||
{
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
pixels[prevrow][col] = *( (pixel*) clientdata );
|
||||
else
|
||||
(*drawprocP)(
|
||||
pixels, cols, rows, maxval, col, prevrow, clientdata );
|
||||
prevrow = row;
|
||||
}
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
pixels[row][col] = *( (pixel*) clientdata );
|
||||
else
|
||||
(*drawprocP)(
|
||||
pixels, cols, rows, maxval, col, row, clientdata );
|
||||
if ( col == cx1 )
|
||||
break;
|
||||
srow += dy;
|
||||
row = srow / DDA_SCALE;
|
||||
col += dx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* Loop over Y domain. */
|
||||
register long dx, scol;
|
||||
register int dy, col, row, prevcol;
|
||||
|
||||
if ( cy1 > cy0 )
|
||||
dy = 1;
|
||||
else
|
||||
dy = -1;
|
||||
dx = ( cx1 - cx0 ) * DDA_SCALE / abs( cy1 - cy0 );
|
||||
row = cy0;
|
||||
prevcol = col = cx0;
|
||||
scol = col * DDA_SCALE + DDA_SCALE / 2;
|
||||
for ( ; ; )
|
||||
{
|
||||
if ( ppmd_linetype == PPMD_LINETYPE_NODIAGS && col != prevcol )
|
||||
{
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
pixels[row][prevcol] = *( (pixel*) clientdata );
|
||||
else
|
||||
(*drawprocP)(
|
||||
pixels, cols, rows, maxval, prevcol, row, clientdata );
|
||||
prevcol = col;
|
||||
}
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
pixels[row][col] = *( (pixel*) clientdata );
|
||||
else
|
||||
(*drawprocP)(
|
||||
pixels, cols, rows, maxval, col, row, clientdata );
|
||||
if ( row == cy1 )
|
||||
break;
|
||||
row += dy;
|
||||
scol += dx;
|
||||
col = scol / DDA_SCALE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define SPLINE_THRESH 3
|
||||
#if __STDC__
|
||||
void
|
||||
ppmd_spline3( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int x1, int y1, int x2, int y2, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppmd_spline3( pixels, cols, rows, maxval, x0, y0, x1, y1, x2, y2, drawprocP, clientdata )
|
||||
pixel** pixels;
|
||||
int cols, rows, x0, y0, x1, y1, x2, y2;
|
||||
pixval maxval;
|
||||
void (*drawprocP)();
|
||||
char* clientdata;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int xa, ya, xb, yb, xc, yc, xp, yp;
|
||||
|
||||
xa = ( x0 + x1 ) / 2;
|
||||
ya = ( y0 + y1 ) / 2;
|
||||
xc = ( x1 + x2 ) / 2;
|
||||
yc = ( y1 + y2 ) / 2;
|
||||
xb = ( xa + xc ) / 2;
|
||||
yb = ( ya + yc ) / 2;
|
||||
|
||||
xp = ( x0 + xb ) / 2;
|
||||
yp = ( y0 + yb ) / 2;
|
||||
if ( abs( xa - xp ) + abs( ya - yp ) > SPLINE_THRESH )
|
||||
ppmd_spline3(
|
||||
pixels, cols, rows, maxval, x0, y0, xa, ya, xb, yb, drawprocP,
|
||||
clientdata );
|
||||
else
|
||||
ppmd_line(
|
||||
pixels, cols, rows, maxval, x0, y0, xb, yb, drawprocP, clientdata );
|
||||
|
||||
xp = ( x2 + xb ) / 2;
|
||||
yp = ( y2 + yb ) / 2;
|
||||
if ( abs( xc - xp ) + abs( yc - yp ) > SPLINE_THRESH )
|
||||
ppmd_spline3(
|
||||
pixels, cols, rows, maxval, xb, yb, xc, yc, x2, y2, drawprocP,
|
||||
clientdata );
|
||||
else
|
||||
ppmd_line(
|
||||
pixels, cols, rows, maxval, xb, yb, x2, y2, drawprocP, clientdata );
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppmd_polyspline( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int nc, int* xc, int* yc, int x1, int y1, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppmd_polyspline( pixels, cols, rows, maxval, x0, y0, nc, xc, yc, x1, y1, drawprocP, clientdata )
|
||||
pixel** pixels;
|
||||
int cols, rows, x0, y0, nc, x1, y1;
|
||||
int* xc;
|
||||
int* yc;
|
||||
pixval maxval;
|
||||
void (*drawprocP)();
|
||||
char* clientdata;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int i, x, y, xn, yn;
|
||||
|
||||
x = x0;
|
||||
y = y0;
|
||||
for ( i = 0; i < nc - 1; ++i )
|
||||
{
|
||||
xn = ( xc[i] + xc[i + 1] ) / 2;
|
||||
yn = ( yc[i] + yc[i + 1] ) / 2;
|
||||
ppmd_spline3(
|
||||
pixels, cols, rows, maxval, x, y, xc[i], yc[i], xn, yn, drawprocP,
|
||||
clientdata );
|
||||
x = xn;
|
||||
y = yn;
|
||||
}
|
||||
ppmd_spline3(
|
||||
pixels, cols, rows, maxval, x, y, xc[nc - 1], yc[nc - 1], x1, y1,
|
||||
drawprocP, clientdata );
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppmd_circle( pixel** pixels, int cols, int rows, pixval maxval, int cx, int cy, int radius, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppmd_circle( pixels, cols, rows, maxval, cx, cy, radius, drawprocP, clientdata )
|
||||
pixel** pixels;
|
||||
int cols, rows, cx, cy, radius;
|
||||
pixval maxval;
|
||||
void (*drawprocP)();
|
||||
char* clientdata;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register int x0, y0, x, y, prevx, prevy, nopointsyet;
|
||||
register long sx, sy, e;
|
||||
|
||||
x0 = x = radius;
|
||||
y0 = y = 0;
|
||||
sx = x * DDA_SCALE + DDA_SCALE / 2;
|
||||
sy = y * DDA_SCALE + DDA_SCALE / 2;
|
||||
e = DDA_SCALE / radius;
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
pixels[y + cy][x + cx] = *( (pixel*) clientdata );
|
||||
else
|
||||
(*drawprocP)( pixels, cols, rows, maxval, x + cx, y + cy, clientdata );
|
||||
nopointsyet = 1;
|
||||
do
|
||||
{
|
||||
prevx = x;
|
||||
prevy = y;
|
||||
sx += e * sy / DDA_SCALE;
|
||||
sy -= e * sx / DDA_SCALE;
|
||||
x = sx / DDA_SCALE;
|
||||
y = sy / DDA_SCALE;
|
||||
if ( x != prevx || y != prevy )
|
||||
{
|
||||
nopointsyet = 0;
|
||||
if ( drawprocP == PPMD_NULLDRAWPROC )
|
||||
pixels[y + cy][x + cx] = *( (pixel*) clientdata );
|
||||
else
|
||||
(*drawprocP)(
|
||||
pixels, cols, rows, maxval, x + cx, y + cy, clientdata );
|
||||
}
|
||||
}
|
||||
while ( nopointsyet || x != x0 || y != y0 );
|
||||
}
|
||||
|
||||
|
||||
/* Arbitrary fill stuff. */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short x;
|
||||
short y;
|
||||
short edge;
|
||||
} coord;
|
||||
typedef struct
|
||||
{
|
||||
int n;
|
||||
int size;
|
||||
int curedge;
|
||||
int segstart;
|
||||
int ydir;
|
||||
int startydir;
|
||||
coord* coords;
|
||||
} fillobj;
|
||||
|
||||
#define SOME 1000
|
||||
|
||||
static int oldclip;
|
||||
|
||||
char*
|
||||
ppmd_fill_init( )
|
||||
{
|
||||
fillobj* fh;
|
||||
|
||||
fh = (fillobj*) malloc( sizeof(fillobj) );
|
||||
if ( fh == 0 )
|
||||
pm_error( "out of memory allocating a fillhandle" );
|
||||
fh->n = 0;
|
||||
fh->coords = (coord*) malloc( SOME * sizeof(coord) );
|
||||
if ( fh->coords == 0 )
|
||||
pm_error( "out of memory allocating a fillhandle" );
|
||||
fh->size = SOME;
|
||||
fh->curedge = 0;
|
||||
|
||||
/* Turn off line clipping. */
|
||||
oldclip = ppmd_setlineclip( 0 );
|
||||
|
||||
return (char*) fh;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppmd_fill_drawproc( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, char* clientdata )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppmd_fill_drawproc( pixels, cols, rows, maxval, x, y, clientdata )
|
||||
pixel** pixels;
|
||||
int cols, rows, x, y;
|
||||
pixval maxval;
|
||||
char* clientdata;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register fillobj* fh;
|
||||
register coord* cp;
|
||||
register coord* ocp;
|
||||
|
||||
fh = (fillobj*) clientdata;
|
||||
|
||||
if ( fh->n > 0 )
|
||||
{
|
||||
/* If these are the same coords we saved last time, don't bother. */
|
||||
ocp = &(fh->coords[fh->n - 1]);
|
||||
if ( x == ocp->x && y == ocp->y )
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ok, these are new; check if there's room for two more coords. */
|
||||
if ( fh->n + 1 >= fh->size )
|
||||
{
|
||||
fh->size += SOME;
|
||||
fh->coords = (coord*) realloc(
|
||||
(char*) fh->coords, fh->size * sizeof(coord) );
|
||||
if ( fh->coords == 0 )
|
||||
pm_error( "out of memory enlarging a fillhandle" );
|
||||
}
|
||||
|
||||
/* Check for extremum and set the edge number. */
|
||||
if ( fh->n == 0 )
|
||||
{ /* Start first segment. */
|
||||
fh->segstart = fh->n;
|
||||
fh->ydir = 0;
|
||||
fh->startydir = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
register int dx, dy;
|
||||
|
||||
dx = x - ocp->x;
|
||||
dy = y - ocp->y;
|
||||
if ( dx < -1 || dx > 1 || dy < -1 || dy > 1 )
|
||||
{ /* Segment break. Close off old one. */
|
||||
if ( fh->startydir != 0 && fh->ydir != 0 )
|
||||
if ( fh->startydir == fh->ydir )
|
||||
{ /* Oops, first edge and last edge are the same.
|
||||
** Renumber the first edge in the old segment. */
|
||||
register coord* fcp;
|
||||
int oldedge;
|
||||
|
||||
fcp = &(fh->coords[fh->segstart]);
|
||||
oldedge = fcp->edge;
|
||||
for ( ; fcp->edge == oldedge; ++fcp )
|
||||
fcp->edge = ocp->edge;
|
||||
}
|
||||
/* And start new segment. */
|
||||
++(fh->curedge);
|
||||
fh->segstart = fh->n;
|
||||
fh->ydir = 0;
|
||||
fh->startydir = 0;
|
||||
}
|
||||
else
|
||||
{ /* Segment continues. */
|
||||
if ( dy != 0 )
|
||||
{
|
||||
if ( fh->ydir != 0 && fh->ydir != dy )
|
||||
{ /* Direction changed. Insert a fake coord, old
|
||||
** position but new edge number. */
|
||||
++(fh->curedge);
|
||||
cp = &(fh->coords[fh->n]);
|
||||
cp->x = ocp->x;
|
||||
cp->y = ocp->y;
|
||||
cp->edge = fh->curedge;
|
||||
++(fh->n);
|
||||
}
|
||||
fh->ydir = dy;
|
||||
if ( fh->startydir == 0 )
|
||||
fh->startydir = dy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Save this coord. */
|
||||
cp = &(fh->coords[fh->n]);
|
||||
cp->x = x;
|
||||
cp->y = y;
|
||||
cp->edge = fh->curedge;
|
||||
++(fh->n);
|
||||
}
|
||||
|
||||
static int
|
||||
yx_compare(const void* v1,const void* v2) {
|
||||
coord* c1 = (coord *)v1;
|
||||
coord* c2 = (coord *)v2;
|
||||
|
||||
if ( c1->y > c2->y )
|
||||
return 1;
|
||||
if ( c1->y < c2->y )
|
||||
return -1;
|
||||
if ( c1->x > c2->x )
|
||||
return 1;
|
||||
if ( c1->x < c2->x )
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
void
|
||||
ppmd_fill( pixel** pixels, int cols, int rows, pixval maxval, char* fillhandle, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata )
|
||||
#else /*__STDC__*/
|
||||
void
|
||||
ppmd_fill( pixels, cols, rows, maxval, fillhandle, drawprocP, clientdata )
|
||||
pixel** pixels;
|
||||
int cols, rows;
|
||||
pixval maxval;
|
||||
char* fillhandle;
|
||||
void (*drawprocP)();
|
||||
char* clientdata;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
register fillobj* fh;
|
||||
int pedge, eq;
|
||||
register int i, leftside, edge, lx, rx, py;
|
||||
register coord* cp;
|
||||
|
||||
fh = (fillobj*) fillhandle;
|
||||
|
||||
/* Close off final segment. */
|
||||
if ( fh->n > 0 && fh->startydir != 0 && fh->ydir != 0 )
|
||||
if ( fh->startydir == fh->ydir )
|
||||
{ /* Oops, first edge and last edge are the same. */
|
||||
register coord* fcp;
|
||||
int lastedge, oldedge;
|
||||
|
||||
lastedge = fh->coords[fh->n - 1].edge;
|
||||
fcp = &(fh->coords[fh->segstart]);
|
||||
oldedge = fcp->edge;
|
||||
for ( ; fcp->edge == oldedge; ++fcp )
|
||||
fcp->edge = lastedge;
|
||||
}
|
||||
|
||||
/* Restore clipping now. */
|
||||
(void) ppmd_setlineclip( oldclip );
|
||||
|
||||
/* Sort the coords by Y, secondarily by X. */
|
||||
qsort( (char*) fh->coords, fh->n, sizeof(coord), yx_compare );
|
||||
|
||||
/* Find equal coords with different edge numbers, and swap if necessary. */
|
||||
edge = -1;
|
||||
for ( i = 0; i < fh->n; ++i )
|
||||
{
|
||||
cp = &(fh->coords[i]);
|
||||
if ( i > 1 && eq && cp->edge != edge && cp->edge == pedge )
|
||||
{ /* Swap .-1 and .-2. */
|
||||
coord t;
|
||||
|
||||
t = fh->coords[i-1];
|
||||
fh->coords[i-1] = fh->coords[i-2];
|
||||
fh->coords[i-2] = t;
|
||||
}
|
||||
if ( i > 0 )
|
||||
{
|
||||
if ( cp->x == lx && cp->y == py )
|
||||
{
|
||||
eq = 1;
|
||||
if ( cp->edge != edge && cp->edge == pedge )
|
||||
{ /* Swap . and .-1. */
|
||||
coord t;
|
||||
|
||||
t = *cp;
|
||||
*cp = fh->coords[i-1];
|
||||
fh->coords[i-1] = t;
|
||||
}
|
||||
}
|
||||
else
|
||||
eq = 0;
|
||||
}
|
||||
lx = cp->x;
|
||||
py = cp->y;
|
||||
pedge = edge;
|
||||
edge = cp->edge;
|
||||
}
|
||||
|
||||
/* Ok, now run through the coords filling spans. */
|
||||
for ( i = 0; i < fh->n; ++i )
|
||||
{
|
||||
cp = &(fh->coords[i]);
|
||||
if ( i == 0 )
|
||||
{
|
||||
lx = rx = cp->x;
|
||||
py = cp->y;
|
||||
edge = cp->edge;
|
||||
leftside = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( cp->y != py )
|
||||
{ /* Row changed. Emit old span and start a new one. */
|
||||
ppmd_filledrectangle(
|
||||
pixels, cols, rows, maxval, lx, py, rx - lx + 1, 1,
|
||||
drawprocP, clientdata);
|
||||
lx = rx = cp->x;
|
||||
py = cp->y;
|
||||
edge = cp->edge;
|
||||
leftside = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( cp->edge == edge )
|
||||
{ /* Continuation of side. */
|
||||
rx = cp->x;
|
||||
}
|
||||
else
|
||||
{ /* Edge changed. Is it a span? */
|
||||
if ( leftside )
|
||||
{
|
||||
rx = cp->x;
|
||||
leftside = 0;
|
||||
}
|
||||
else
|
||||
{ /* Got a span to fill. */
|
||||
ppmd_filledrectangle(
|
||||
pixels, cols, rows, maxval, lx, py, rx - lx + 1,
|
||||
1, drawprocP, clientdata);
|
||||
lx = rx = cp->x;
|
||||
leftside = 1;
|
||||
}
|
||||
edge = cp->edge;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* All done. Free up the fillhandle and leave. */
|
||||
free( fh->coords );
|
||||
free( fh );
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/* pbm.h - header file for libpbm portable bitmap library
|
||||
*/
|
||||
|
||||
#ifndef _PBM_H_
|
||||
#define _PBM_H_
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#include "pbmplus.h"
|
||||
|
||||
typedef unsigned char bit;
|
||||
#define PBM_WHITE 0
|
||||
#define PBM_BLACK 1
|
||||
|
||||
|
||||
/* Magic constants. */
|
||||
|
||||
#define PBM_MAGIC1 'P'
|
||||
#define PBM_MAGIC2 '1'
|
||||
#define RPBM_MAGIC2 '4'
|
||||
#define PBM_FORMAT (PBM_MAGIC1 * 256 + PBM_MAGIC2)
|
||||
#define RPBM_FORMAT (PBM_MAGIC1 * 256 + RPBM_MAGIC2)
|
||||
#define PBM_TYPE PBM_FORMAT
|
||||
|
||||
|
||||
/* Macro for turning a format number into a type number. */
|
||||
|
||||
#define PBM_FORMAT_TYPE(f) ((f) == PBM_FORMAT || (f) == RPBM_FORMAT ? PBM_TYPE : -1)
|
||||
|
||||
|
||||
/* Declarations of routines. */
|
||||
|
||||
void pbm_init ARGS(( int* argcP, char* argv[] ));
|
||||
|
||||
#define pbm_allocarray( cols, rows ) ((bit**) pm_allocarray( cols, rows, sizeof(bit) ))
|
||||
#define pbm_allocrow( cols ) ((bit*) pm_allocrow( cols, sizeof(bit) ))
|
||||
#define pbm_freearray( bits, rows ) pm_freearray( (char**) bits, rows )
|
||||
#define pbm_freerow( bitrow ) pm_freerow( (char*) bitrow )
|
||||
|
||||
bit** pbm_readpbm ARGS(( FILE* file, int* colsP, int* rowsP ));
|
||||
void pbm_readpbminit ARGS(( FILE* file, int* colsP, int* rowsP, int* formatP ));
|
||||
void pbm_readpbmrow ARGS(( FILE* file, bit* bitrow, int cols, int format ));
|
||||
char* pm_read_unknown_size ARGS(( FILE* file, long* buf ));
|
||||
|
||||
void pbm_writepbm ARGS(( FILE* file, bit** bits, int cols, int rows, int forceplain ));
|
||||
void pbm_writepbminit ARGS(( FILE* file, int cols, int rows, int forceplain ));
|
||||
void pbm_writepbmrow ARGS(( FILE* file, bit* bitrow, int cols, int forceplain ));
|
||||
|
||||
#endif /*_PBM_H_*/
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* pbmfont.h - header file for font routines in libpbm
|
||||
*/
|
||||
|
||||
struct glyph {
|
||||
int width, height;
|
||||
int x, y;
|
||||
int xadd;
|
||||
char* bmap;
|
||||
};
|
||||
|
||||
struct font {
|
||||
int maxwidth, maxheight;
|
||||
int x, y;
|
||||
struct glyph* glyph[256];
|
||||
/* for compatibility with old pbmtext routines */
|
||||
/* oldfont is 0 if the font is BDF derived */
|
||||
bit** oldfont;
|
||||
int fcols, frows;
|
||||
};
|
||||
|
||||
struct font* pbm_defaultfont ARGS(( char* which ));
|
||||
struct font* pbm_dissectfont ARGS(( bit** font, int frows, int fcols ));
|
||||
struct font* pbm_loadfont ARGS(( char* filename ));
|
||||
struct font* pbm_loadpbmfont ARGS(( char* filename ));
|
||||
struct font* pbm_loadbdffont ARGS(( char* filename ));
|
||||
void pbm_dumpfont ARGS(( struct font* fn ));
|
||||
int mk_argvn ARGS(( char* s, char* vec[], int max ));
|
||||
|
|
@ -1,291 +0,0 @@
|
|||
/* pbmplus.h - header file for PBM, PGM, PPM, and PNM
|
||||
**
|
||||
** Copyright (C) 1988, 1989, 1991 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
#ifndef _PBMPLUS_H_
|
||||
#define _PBMPLUS_H_
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#ifdef WIN32_VC
|
||||
#define MSDOS
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#ifdef VMS
|
||||
#include <perror.h>
|
||||
#endif
|
||||
|
||||
#if defined(USG) || defined(SVR4) || defined(VMS)
|
||||
#define SYSV
|
||||
#endif
|
||||
#if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS) || defined(AMIGA) )
|
||||
/* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
|
||||
** System V site, set the SYSV option; if you're IBM-compatible, set MSDOS;
|
||||
** and if you run on an Amiga, set AMIGA. If your compiler is ANSI C, you're
|
||||
** probably better off setting SYSV - all it affects is string handling.
|
||||
*/
|
||||
/*#define BSD*/
|
||||
#define SYSV
|
||||
/* #define MSDOS */
|
||||
/* #define AMIGA */
|
||||
#endif
|
||||
|
||||
/* CONFIGURE: If you have an X11-style rgb color names file, define its
|
||||
** path here. This is used by PPM to parse color names into rgb values.
|
||||
** If you don't have such a file, comment this out and use the alternative
|
||||
** hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).
|
||||
*/
|
||||
#ifndef RGB_DB
|
||||
#define RGB_DB "/usr/lib/X11/rgb.txt"
|
||||
/*#define RGB_DB "/usr/openwin/lib/rgb.txt"*/
|
||||
#ifdef VMS
|
||||
#define RGB_DB "PBMplus_Dir:RGB.TXT"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* CONFIGURE: If you want to enable writing "raw" files, set this option.
|
||||
** "Raw" files are smaller, and much faster to read and write, but you
|
||||
** must have a filesystem that allows all 256 ASCII characters to be read
|
||||
** and written. You will no longer be able to mail P?M files without
|
||||
** using uuencode or the equivalent, or running the files through pnmnoraw.
|
||||
** Note that reading "raw" files works whether writing is enabled or not.
|
||||
*/
|
||||
#define PBMPLUS_RAWBITS
|
||||
|
||||
/* CONFIGURE: PGM can store gray values as either bytes or shorts. For most
|
||||
** applications, bytes will be big enough, and the memory savings can be
|
||||
** substantial. However, if you need more than 8 bits of grayscale resolution,
|
||||
** then define this symbol. Unless your computer is very slow or you are short
|
||||
** of memory, there is no reason why you should not set this symbol.
|
||||
*/
|
||||
#define PGM_BIGGRAYS
|
||||
|
||||
/* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
|
||||
** If grays are stored in bytes, that's 24 bits per color pixel; if
|
||||
** grays are stored as shorts, that's 48 bits per color pixel. PPM
|
||||
** can also be configured to pack the three grays into a single longword,
|
||||
** 10 bits each, 30 bits per pixel.
|
||||
**
|
||||
** If you have configured PGM with the PGM_BIGGRAYS option, AND you don't
|
||||
** need more than 10 bits for each color component, AND you care more about
|
||||
** memory use than speed, then this option might be a win. Under these
|
||||
** circumstances it will make some of the programs use 1.5 times less space,
|
||||
** but all of the programs will run about 1.4 times slower.
|
||||
**
|
||||
** If you are not using PGM_BIGGRAYS, then this option is useless -- it
|
||||
** doesn't save any space, but it still slows things down.
|
||||
*/
|
||||
/* #define PPM_PACKCOLORS */
|
||||
|
||||
/* CONFIGURE: uncomment this to enable debugging checks. */
|
||||
/* #define DEBUG */
|
||||
|
||||
#if ( defined(SYSV) || defined(AMIGA) )
|
||||
|
||||
#include <string.h>
|
||||
#define random rand
|
||||
#define srandom(s) srand(s)
|
||||
#ifndef __SASC
|
||||
#define index(s,c) strchr(s,c)
|
||||
#define rindex(s,c) strrchr(s,c)
|
||||
#ifndef _DCC /* Amiga DICE Compiler */
|
||||
#define bzero(dst,len) memset(dst,0,len)
|
||||
#define bcopy(src,dst,len) memcpy(dst,src,len)
|
||||
#define bcmp memcmp
|
||||
#ifndef __cplusplus
|
||||
extern void srand();
|
||||
extern int rand();
|
||||
#endif
|
||||
#endif /* _DCC */
|
||||
#endif /* __SASC */
|
||||
|
||||
#else /* SYSV or AMIGA */
|
||||
|
||||
#ifndef WIN32_VC
|
||||
#include <strings.h>
|
||||
extern void srandom();
|
||||
extern long random();
|
||||
#endif
|
||||
|
||||
#endif /*SYSV or AMIGA*/
|
||||
|
||||
#if (defined(MSDOS) || defined(AMIGA) )
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#define index(s,c) strchr(s,c)
|
||||
#define rindex(s,c) strrchr(s,c)
|
||||
#else
|
||||
#ifndef __cplusplus
|
||||
extern int atoi();
|
||||
extern void exit();
|
||||
extern long time();
|
||||
extern int write();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* CONFIGURE: On most BSD systems, malloc() gets declared in stdlib.h, on
|
||||
** system V, it gets declared in malloc.h. On some systems, malloc.h
|
||||
** doesn't declare these, so we have to do it here. On other systems,
|
||||
** for example HP/UX, it declares them incompatibly. And some systems,
|
||||
** for example Dynix, don't have a malloc.h at all. A sad situation.
|
||||
** If you have compilation problems that point here, feel free to tweak
|
||||
** or remove these declarations.
|
||||
*/
|
||||
#ifdef BSD
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#if (defined(SYSV) && !defined(VMS))
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
/* extern char* malloc(); */
|
||||
/* extern char* realloc(); */
|
||||
/* extern char* calloc(); */
|
||||
|
||||
/* CONFIGURE: Some systems don't have vfprintf(), which we need for the
|
||||
** error-reporting routines. If you compile and get a link error about
|
||||
** this routine, uncomment the first define, which gives you a vfprintf
|
||||
** that uses the theoretically non-portable but fairly common routine
|
||||
** _doprnt(). If you then get a link error about _doprnt, or
|
||||
** message-printing doesn't look like it's working, try the second
|
||||
** define instead.
|
||||
*/
|
||||
/* #define NEED_VFPRINTF1 */
|
||||
/* #define NEED_VFPRINTF2 */
|
||||
|
||||
/* CONFIGURE: Some systems don't have strstr(), which some routines need.
|
||||
** If you compile and get a link error about this routine, uncomment the
|
||||
** define, which gives you a strstr.
|
||||
*/
|
||||
/* #define NEED_STRSTR */
|
||||
|
||||
/* CONFIGURE: If you don't want a fixed path to an X11 color name file
|
||||
** compiled into PBMPlus, set this option. Now RGB_DB (see Makefile)
|
||||
** defines the name of an environment-variable that holds the complete
|
||||
** path and name of this file.
|
||||
*/
|
||||
/* #define A_RGBENV */
|
||||
#ifdef A_RGBENV
|
||||
#define RGB_DB "RGBDEF" /* name of env-var */
|
||||
#endif /* A_RGBENV */
|
||||
|
||||
/* CONFIGURE: Set this option if your compiler uses strerror(errno)
|
||||
** instead of sys_errlist[errno] for error messages.
|
||||
*/
|
||||
/* #define A_STRERROR */
|
||||
|
||||
/* CONFIGURE: On small systems without VM it is possible that there is
|
||||
** enough memory for a large array, but it is fragmented. So the usual
|
||||
** malloc( all-in-one-big-chunk ) fails. With this option, if the first
|
||||
** method fails, pm_allocarray() tries to allocate the array row by row.
|
||||
*/
|
||||
/* #define A_FRAGARRAY */
|
||||
|
||||
/*
|
||||
** Some special things for the Amiga.
|
||||
*/
|
||||
|
||||
/* End of configurable definitions. */
|
||||
|
||||
|
||||
#ifdef AMIGA
|
||||
#include <clib/exec_protos.h>
|
||||
#define getpid(x) ((long)FindTask(NULL))
|
||||
#endif /* AMIGA */
|
||||
|
||||
/*
|
||||
#undef max
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#undef min
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#undef abs
|
||||
#define abs(a) ((a) >= 0 ? (a) : -(a))
|
||||
#undef odd
|
||||
#define odd(n) ((n) & 1)
|
||||
*/
|
||||
|
||||
/* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
|
||||
|
||||
#if __STDC__
|
||||
#define ARGS(alist) alist
|
||||
#else /*__STDC__*/
|
||||
#define ARGS(alist) ()
|
||||
/*#define const*/
|
||||
#endif /*__STDC__*/
|
||||
|
||||
|
||||
/* Initialization. */
|
||||
|
||||
EXPCL_PANDA void pm_init( int* argcP, char* argv[] );
|
||||
|
||||
/* Variable-sized arrays definitions. */
|
||||
|
||||
char** pm_allocarray ARGS(( int cols, int rows, int size ));
|
||||
EXPCL_PANDA char* pm_allocrow( int cols, int size );
|
||||
void pm_freearray ARGS(( char** its, int rows ));
|
||||
EXPCL_PANDA void pm_freerow( char* itrow );
|
||||
|
||||
|
||||
/* Case-insensitive keyword matcher. */
|
||||
|
||||
int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
|
||||
|
||||
|
||||
/* Log base two hacks. */
|
||||
|
||||
EXPCL_PANDA int pm_maxvaltobits( int maxval );
|
||||
EXPCL_PANDA int pm_bitstomaxval( int bits );
|
||||
|
||||
|
||||
/* Error handling definitions. */
|
||||
|
||||
EXPCL_PANDA void pm_message( char*, ... );
|
||||
EXPCL_PANDA void pm_error( char*, ... ); /* doesn't return */
|
||||
void pm_perror ARGS(( char* reason )); /* doesn't return */
|
||||
void pm_usage ARGS(( char* usage )); /* doesn't return */
|
||||
|
||||
|
||||
/* File open/close that handles "-" as stdin and checks errors. */
|
||||
|
||||
EXPCL_PANDA FILE* pm_openr( char* name );
|
||||
EXPCL_PANDA FILE* pm_openw( char* name );
|
||||
EXPCL_PANDA void pm_close( FILE* f );
|
||||
|
||||
|
||||
/* Endian I/O. */
|
||||
|
||||
EXPCL_PANDA int pm_readbigshort( FILE* in, short* sP );
|
||||
EXPCL_PANDA int pm_writebigshort( FILE* out, short s );
|
||||
EXPCL_PANDA int pm_readbiglong( FILE* in, long* lP );
|
||||
EXPCL_PANDA int pm_writebiglong( FILE* out, long l );
|
||||
EXPCL_PANDA int pm_readlittleshort( FILE* in, short* sP );
|
||||
EXPCL_PANDA int pm_writelittleshort( FILE* out, short s );
|
||||
EXPCL_PANDA int pm_readlittlelong( FILE* in, long* lP );
|
||||
EXPCL_PANDA int pm_writelittlelong( FILE* out, long l );
|
||||
|
||||
|
||||
/* Compatibility stuff */
|
||||
|
||||
#ifdef NEED_STRSTR
|
||||
char *strstr ARGS((char *s1, char *s2));
|
||||
#endif
|
||||
|
||||
#if defined(NEED_VFPRINTF1) || defined(NEED_VFPRINTF2)
|
||||
int vfprintf ARGS(( FILE* stream, char* format, va_list args ));
|
||||
#endif /*NEED_VFPRINTF*/
|
||||
|
||||
|
||||
#endif /*_PBMPLUS_H_*/
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/* pgm.h - header file for libpgm portable graymap library
|
||||
*/
|
||||
|
||||
#ifndef _PGM_H_
|
||||
#define _PGM_H_
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#include "pbm.h"
|
||||
|
||||
#ifdef PGM_BIGGRAYS
|
||||
typedef unsigned short gray;
|
||||
#define PGM_MAXMAXVAL 65535
|
||||
#else /*PGM_BIGGRAYS*/
|
||||
typedef unsigned char gray;
|
||||
#define PGM_MAXMAXVAL 255
|
||||
#endif /*PGM_BIGGRAYS*/
|
||||
|
||||
|
||||
/* Magic constants. */
|
||||
|
||||
#define PGM_MAGIC1 'P'
|
||||
#define PGM_MAGIC2 '2'
|
||||
#define RPGM_MAGIC2 '5'
|
||||
#define PGM_FORMAT (PGM_MAGIC1 * 256 + PGM_MAGIC2)
|
||||
#define RPGM_FORMAT (PGM_MAGIC1 * 256 + RPGM_MAGIC2)
|
||||
#define PGM_TYPE PGM_FORMAT
|
||||
|
||||
|
||||
/* Macro for turning a format number into a type number. */
|
||||
|
||||
#define PGM_FORMAT_TYPE(f) ((f) == PGM_FORMAT || (f) == RPGM_FORMAT ? PGM_TYPE : PBM_FORMAT_TYPE(f))
|
||||
|
||||
|
||||
/* Declarations of routines. */
|
||||
|
||||
void pgm_init ARGS(( int* argcP, char* argv[] ));
|
||||
|
||||
#define pgm_allocarray( cols, rows ) ((gray**) pm_allocarray( cols, rows, sizeof(gray) ))
|
||||
#define pgm_allocrow( cols ) ((gray*) pm_allocrow( cols, sizeof(gray) ))
|
||||
#define pgm_freearray( grays, rows ) pm_freearray( (char**) grays, rows )
|
||||
#define pgm_freerow( grayrow ) pm_freerow( (char*) grayrow )
|
||||
|
||||
gray** pgm_readpgm ARGS(( FILE* file, int* colsP, int* rowsP, gray* maxvalP ));
|
||||
void pgm_readpgminit ARGS(( FILE* file, int* colsP, int* rowsP, gray* maxvalP, int* formatP ));
|
||||
void pgm_readpgmrow ARGS(( FILE* file, gray* grayrow, int cols, gray maxval, int format ));
|
||||
|
||||
void pgm_writepgm ARGS(( FILE* file, gray** grays, int cols, int rows, gray maxval, int forceplain ));
|
||||
void pgm_writepgminit ARGS(( FILE* file, int cols, int rows, gray maxval, int forceplain ));
|
||||
void pgm_writepgmrow ARGS(( FILE* file, gray* grayrow, int cols, gray maxval, int forceplain ));
|
||||
|
||||
extern gray pgm_pbmmaxval;
|
||||
/* This is the maxval used when a PGM program reads a PBM file. Normally
|
||||
** it is 1; however, for some programs, a larger value gives better results
|
||||
*/
|
||||
|
||||
#endif /*_PGM_H_*/
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/* pnm.h - header file for libpnm portable anymap library
|
||||
*/
|
||||
|
||||
#ifndef _PNM_H_
|
||||
#define _PNM_H_
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#include "ppm.h"
|
||||
typedef pixel xel;
|
||||
typedef pixval xelval;
|
||||
#define PNM_MAXMAXVAL PPM_MAXMAXVAL
|
||||
#define PNM_GET1(x) PPM_GETB(x)
|
||||
#define PNM_ASSIGN1(x,v) PPM_ASSIGN(x,0,0,v)
|
||||
#define PNM_EQUAL(x,y) PPM_EQUAL(x,y)
|
||||
#define PNM_FORMAT_TYPE(f) PPM_FORMAT_TYPE(f)
|
||||
|
||||
/* Declarations of routines. */
|
||||
|
||||
void pnm_init ARGS(( int* argcP, char* argv[] ));
|
||||
|
||||
#define pnm_allocarray( cols, rows ) ((xel**) pm_allocarray( cols, rows, sizeof(xel) ))
|
||||
#define pnm_allocrow( cols ) ((xel*) pm_allocrow( cols, sizeof(xel) ))
|
||||
#define pnm_freearray( xels, rows ) pm_freearray( (char**) xels, rows )
|
||||
#define pnm_freerow( xelrow ) pm_freerow( (char*) xelrow )
|
||||
|
||||
xel** pnm_readpnm ARGS(( FILE* file, int* colsP, int* rowsP, xelval* maxvalP, int* formatP ));
|
||||
EXPCL_PANDA void pnm_readpnminit( FILE* file, int* colsP, int* rowsP, xelval* maxvalP, int* formatP );
|
||||
EXPCL_PANDA void pnm_readpnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format );
|
||||
|
||||
void pnm_writepnm ARGS(( FILE* file, xel** xels, int cols, int rows, xelval maxval, int format, int forceplain ));
|
||||
EXPCL_PANDA void pnm_writepnminit( FILE* file, int cols, int rows, xelval maxval, int format, int forceplain );
|
||||
EXPCL_PANDA void pnm_writepnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format, int forceplain );
|
||||
|
||||
xel pnm_backgroundxel ARGS(( xel** xels, int cols, int rows, xelval maxval, int format ));
|
||||
xel pnm_backgroundxelrow ARGS(( xel* xelrow, int cols, xelval maxval, int format ));
|
||||
xel pnm_whitexel ARGS(( xelval maxval, int format ));
|
||||
xel pnm_blackxel ARGS(( xelval maxval, int format ));
|
||||
void pnm_invertxel ARGS(( xel* x, xelval maxval, int format ));
|
||||
void pnm_promoteformat ARGS(( xel** xels, int cols, int rows, xelval maxval, int format, xelval newmaxval, int newformat ));
|
||||
void pnm_promoteformatrow ARGS(( xel* xelrow, int cols, xelval maxval, int format, xelval newmaxval, int newformat ));
|
||||
|
||||
extern EXPCL_PANDA xelval pnm_pbmmaxval;
|
||||
/* This is the maxval used when a PNM program reads a PBM file. Normally
|
||||
** it is 1; however, for some programs, a larger value gives better results
|
||||
*/
|
||||
|
||||
#endif /*_PNM_H_*/
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
/* ppm.h - header file for libppm portable pixmap library
|
||||
*/
|
||||
|
||||
#ifndef _PPM_H_
|
||||
#define _PPM_H_
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#include "pgm.h"
|
||||
|
||||
typedef gray pixval;
|
||||
|
||||
#ifdef PPM_PACKCOLORS
|
||||
|
||||
#define PPM_MAXMAXVAL 1023
|
||||
typedef unsigned long pixel;
|
||||
#define PPM_GETR(p) (((p) & 0x3ff00000) >> 20)
|
||||
#define PPM_GETG(p) (((p) & 0xffc00) >> 10)
|
||||
#define PPM_GETB(p) ((p) & 0x3ff)
|
||||
|
||||
/************* added definitions *****************/
|
||||
#define PPM_PUTR(p, red) ((p) |= (((red) & 0x3ff) << 20))
|
||||
#define PPM_PUTG(p, grn) ((p) |= (((grn) & 0x3ff) << 10))
|
||||
#define PPM_PUTB(p, blu) ((p) |= ( (blu) & 0x3ff))
|
||||
/**************************************************/
|
||||
|
||||
#define PPM_ASSIGN(p,red,grn,blu) (p) = ((pixel) (red) << 20) | ((pixel) (grn) << 10) | (pixel) (blu)
|
||||
#define PPM_EQUAL(p,q) ((p) == (q))
|
||||
|
||||
#else /*PPM_PACKCOLORS*/
|
||||
|
||||
#define PPM_MAXMAXVAL PGM_MAXMAXVAL
|
||||
typedef struct
|
||||
{
|
||||
pixval r, g, b;
|
||||
} pixel;
|
||||
#define PPM_GETR(p) ((p).r)
|
||||
#define PPM_GETG(p) ((p).g)
|
||||
#define PPM_GETB(p) ((p).b)
|
||||
|
||||
/************* added definitions *****************/
|
||||
#define PPM_PUTR(p,red) ((p).r = (red))
|
||||
#define PPM_PUTG(p,grn) ((p).g = (grn))
|
||||
#define PPM_PUTB(p,blu) ((p).b = (blu))
|
||||
/**************************************************/
|
||||
|
||||
#define PPM_ASSIGN(p,red,grn,blu) do { (p).r = (red); (p).g = (grn); (p).b = (blu); } while ( 0 )
|
||||
#define PPM_EQUAL(p,q) ( (p).r == (q).r && (p).g == (q).g && (p).b == (q).b )
|
||||
|
||||
#endif /*PPM_PACKCOLORS*/
|
||||
|
||||
|
||||
/* Magic constants. */
|
||||
|
||||
#define PPM_MAGIC1 'P'
|
||||
#define PPM_MAGIC2 '3'
|
||||
#define RPPM_MAGIC2 '6'
|
||||
#define PPM_FORMAT (PPM_MAGIC1 * 256 + PPM_MAGIC2)
|
||||
#define RPPM_FORMAT (PPM_MAGIC1 * 256 + RPPM_MAGIC2)
|
||||
#define PPM_TYPE PPM_FORMAT
|
||||
|
||||
|
||||
/* Macro for turning a format number into a type number. */
|
||||
|
||||
#define PPM_FORMAT_TYPE(f) ((f) == PPM_FORMAT || (f) == RPPM_FORMAT ? PPM_TYPE : PGM_FORMAT_TYPE(f))
|
||||
|
||||
|
||||
/* Declarations of routines. */
|
||||
|
||||
void ppm_init ARGS(( int* argcP, char* argv[] ));
|
||||
|
||||
#define ppm_allocarray( cols, rows ) ((pixel**) pm_allocarray( cols, rows, sizeof(pixel) ))
|
||||
#define ppm_allocrow( cols ) ((pixel*) pm_allocrow( cols, sizeof(pixel) ))
|
||||
#define ppm_freearray( pixels, rows ) pm_freearray( (char**) pixels, rows )
|
||||
#define ppm_freerow( pixelrow ) pm_freerow( (char*) pixelrow )
|
||||
|
||||
pixel** ppm_readppm ARGS(( FILE* file, int* colsP, int* rowsP, pixval* maxvalP ));
|
||||
void ppm_readppminit ARGS(( FILE* file, int* colsP, int* rowsP, pixval* maxvalP, int* formatP ));
|
||||
void ppm_readppmrow ARGS(( FILE* file, pixel* pixelrow, int cols, pixval maxval, int format ));
|
||||
|
||||
void ppm_writeppm ARGS(( FILE* file, pixel** pixels, int cols, int rows, pixval maxval, int forceplain ));
|
||||
void ppm_writeppminit ARGS(( FILE* file, int cols, int rows, pixval maxval, int forceplain ));
|
||||
void ppm_writeppmrow ARGS(( FILE* file, pixel* pixelrow, int cols, pixval maxval, int forceplain ));
|
||||
|
||||
pixel ppm_parsecolor ARGS(( char* colorname, pixval maxval ));
|
||||
char* ppm_colorname ARGS(( pixel* colorP, pixval maxval, int hexok ));
|
||||
|
||||
extern pixval ppm_pbmmaxval;
|
||||
/* This is the maxval used when a PPM program reads a PBM file. Normally
|
||||
** it is 1; however, for some programs, a larger value gives better results
|
||||
*/
|
||||
|
||||
|
||||
/* Color scaling macro -- to make writing ppmtowhatever easier. */
|
||||
|
||||
#define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \
|
||||
PPM_ASSIGN( (newp), \
|
||||
( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
|
||||
( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
|
||||
( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )
|
||||
|
||||
|
||||
/* Luminance macro. */
|
||||
|
||||
#define PPM_LUMIN(p) ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) )
|
||||
|
||||
#endif /*_PPM_H_*/
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
/* ppmdraw.h - header file for simple drawing routines in libppm
|
||||
**
|
||||
** Simple, yes, and also fairly slow if the truth be told; but also very
|
||||
** flexible and powerful.
|
||||
**
|
||||
** The two basic concepts are the drawproc and clientdata. All the drawing
|
||||
** routines take a drawproc that does the actual drawing. A drawproc draws
|
||||
** a single point, and it looks like this:
|
||||
*/
|
||||
void ppmd_point_drawproc ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, char* clientdata ));
|
||||
/*
|
||||
** So, you call a drawing routine, e.g. ppmd_line(), and pass it a drawproc;
|
||||
** it calls the drawproc for each point it wants to draw. Why so complicated?
|
||||
** Because you can define your own drawprocs to do more interesting things than
|
||||
** simply draw the point. For example, you could make one that calls back into
|
||||
** another drawing routine, say ppmd_circle() to draw a circle at each point
|
||||
** of a line.
|
||||
**
|
||||
** Slow? Well sure, we're talking results here, not realtime. You can do
|
||||
** tricks with this arrangement that you couldn't even think of before.
|
||||
** Still, to speed things up for the 90% case you can use this:
|
||||
*/
|
||||
#if __STDC__
|
||||
#define PPMD_NULLDRAWPROC (void (*)(pixel**, int, int, pixval, int, int, char*)) 0
|
||||
#else /*__STDC__*/
|
||||
#define PPMD_NULLDRAWPROC (void (*)()) 0
|
||||
#endif /*__STDC__*/
|
||||
/*
|
||||
** Just like ppmd_point_drawproc() it simply draws the point, but it's done
|
||||
** inline, and clipping is assumed to be handled at a higher level.
|
||||
**
|
||||
** Now, what about clientdata. Well, it's an arbitrary pointer, and can
|
||||
** mean something different to each different drawproc. For the above two
|
||||
** drawprocs, clientdata should be a pointer to a pixel holding the color
|
||||
** to be drawn. Other drawprocs can use it to point to something else,
|
||||
** e.g. some structure to be modified, or they can ignore it.
|
||||
*/
|
||||
|
||||
|
||||
/* Outline drawing routines. Lines, splines, circles, etc. */
|
||||
|
||||
int ppmd_setlinetype ARGS(( int type ));
|
||||
#define PPMD_LINETYPE_NORMAL 0
|
||||
#define PPMD_LINETYPE_NODIAGS 1
|
||||
/* If you set NODIAGS, all pixels drawn by ppmd_line() will be 4-connected
|
||||
** instead of 8-connected; in other words, no diagonals. This is useful
|
||||
** for some applications, for example when you draw many parallel lines
|
||||
** and you want them to fit together without gaps.
|
||||
*/
|
||||
|
||||
int ppmd_setlineclip ARGS(( int clip ));
|
||||
#define ppmd_setlineclipping(x) ppmd_setlineclip(x)
|
||||
/* Normally, ppmd_line() clips to the edges of the pixmap. You can use this
|
||||
** routine to disable the clipping, for example if you are using a drawproc
|
||||
** that wants to do its own clipping.
|
||||
*/
|
||||
|
||||
void ppmd_line ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int x1, int y1, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
|
||||
/* Draws a line from (x0, y0) to (x1, y1).
|
||||
*/
|
||||
|
||||
void ppmd_spline3 ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int x1, int y1, int x2, int y2, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
|
||||
/* Draws a three-point spline from (x0, y0) to (x2, y2), with (x1, y1) as
|
||||
** the control point. All drawing is done via ppmd_line(), so the routines
|
||||
** that control it control ppmd_spline3() as well.
|
||||
*/
|
||||
|
||||
void ppmd_polyspline ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int nc, int* xc, int* yc, int x1, int y1, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
|
||||
/* Draws a bunch of splines end to end. (x0, y0) and (x1, y1) are the initial
|
||||
** and final points, and the xc and yc are the intermediate control points.
|
||||
** nc is the number of these control points.
|
||||
*/
|
||||
|
||||
void ppmd_circle ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int cx, int cy, int radius, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
|
||||
/* Draws a circle centered at (cx, cy) with the specified radius.
|
||||
*/
|
||||
|
||||
|
||||
/* Simple filling routines. Ok, so there's only one. */
|
||||
|
||||
void ppmd_filledrectangle ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, int width, int height, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
|
||||
/* Fills in the rectangle [x, y, width, height].
|
||||
*/
|
||||
|
||||
|
||||
/* Arbitrary filling routines. With these you can fill any outline that
|
||||
** you can draw with the outline routines.
|
||||
*/
|
||||
|
||||
char* ppmd_fill_init ARGS(( void ));
|
||||
/* Returns a blank fillhandle.
|
||||
*/
|
||||
|
||||
void ppmd_fill_drawproc ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, char* clientdata ));
|
||||
/* Use this drawproc to trace the outline you want filled. Be sure to use
|
||||
** the fillhandle as the clientdata.
|
||||
*/
|
||||
|
||||
void ppmd_fill ARGS(( pixel** pixels, int cols, int rows, pixval maxval, char* fillhandle, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
|
||||
/* Once you've traced the outline, give the fillhandle to this routine to
|
||||
** do the actual drawing. As usual, it takes a drawproc and clientdata;
|
||||
** you could define drawprocs to do stipple fills and such.
|
||||
*/
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
/* rast.h - header file for Sun raster files
|
||||
**
|
||||
** The format of a Sun raster file is as follows. First, a struct
|
||||
** rasterfile. Note the 32-bit magic number at the beginning; this
|
||||
** identifies the file type and lets you figure out whether you need
|
||||
** to do little-endian / big-endian byte-swapping or not. (The PBMPLUS
|
||||
** implementation does not do byte-swapping; instead, it reads all
|
||||
** multi-byte values a byte at a time.)
|
||||
**
|
||||
** After the struct is an optional colormap. If ras_maptype is RMT_NONE,
|
||||
** no map is present; if it's RMT_EQUAL_RGB then the map consists of
|
||||
** three unsigned-char arrays ras_maplength long, one each for r g and b.
|
||||
** I don't know what RMT_RAW means. Black and white bitmaps are stored
|
||||
** as ras_maptype == RMT_NONE and ras_depth == 1, with the bits stored
|
||||
** eight to a byte MSB first.
|
||||
**
|
||||
** Finally comes the image data. If ras_type is RT_OLD or RT_STANDARD,
|
||||
** the data is just plain old uncompressed bytes, padded out to a multiple
|
||||
** of 16 bits in each row. If ras_type is RT_BYTE_ENCODED, a run-length
|
||||
** compression scheme is used: an escape-byte of 128 indicates a run;
|
||||
** the next byte is a count, and the one after that is the byte to be
|
||||
** replicated. The one exception to this is if the count is 1; then
|
||||
** there is no third byte in the packet, it means to put a single 128
|
||||
** in the data stream.
|
||||
*/
|
||||
|
||||
#ifndef _RAST_H_
|
||||
#define _RAST_H_
|
||||
|
||||
#define PIX_ERR -1
|
||||
|
||||
struct rasterfile {
|
||||
long ras_magic;
|
||||
#define RAS_MAGIC 0x59a66a95
|
||||
long ras_width;
|
||||
long ras_height;
|
||||
long ras_depth;
|
||||
long ras_length;
|
||||
long ras_type;
|
||||
#define RT_OLD 0 /* Raw pixrect image in 68000 byte order */
|
||||
#define RT_STANDARD 1 /* Raw pixrect image in 68000 byte order */
|
||||
#define RT_BYTE_ENCODED 2 /* Run-length compression of bytes */
|
||||
#define RT_FORMAT_RGB 3 /* XRGB or RGB instead of XBGR or BGR */
|
||||
#define RT_FORMAT_TIFF 4 /* tiff <-> standard rasterfile */
|
||||
#define RT_FORMAT_IFF 5 /* iff (TAAC format) <-> standard rasterfile */
|
||||
#define RT_EXPERIMENTAL 0xffff /* Reserved for testing */
|
||||
long ras_maptype;
|
||||
#define RMT_NONE 0
|
||||
#define RMT_EQUAL_RGB 1
|
||||
#define RMT_RAW 2
|
||||
long ras_maplength;
|
||||
};
|
||||
|
||||
struct pixrectops {
|
||||
int (*pro_rop)();
|
||||
int (*pro_stencil)();
|
||||
int (*pro_batchrop)();
|
||||
int (*pro_nop)();
|
||||
int (*pro_destroy)();
|
||||
int (*pro_get)();
|
||||
int (*pro_put)();
|
||||
int (*pro_vector)();
|
||||
struct pixrect* (*pro_region)();
|
||||
int (*pro_putcolormap)();
|
||||
int (*pro_getcolormap)();
|
||||
int (*pro_putattributes)();
|
||||
int (*pro_getattributes)();
|
||||
};
|
||||
|
||||
struct pr_size {
|
||||
int x, y;
|
||||
};
|
||||
struct pr_pos {
|
||||
int x, y;
|
||||
};
|
||||
|
||||
struct pixrect {
|
||||
struct pixrectops* pr_ops;
|
||||
struct pr_size pr_size;
|
||||
int pr_depth;
|
||||
struct mpr_data* pr_data; /* work-alike only handles memory pixrects */
|
||||
};
|
||||
|
||||
struct mpr_data {
|
||||
int md_linebytes;
|
||||
unsigned char* md_image; /* note, byte not short -- avoid pr_flip() */
|
||||
struct pr_pos md_offset;
|
||||
short md_primary;
|
||||
short md_flags;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
int length;
|
||||
unsigned char* map[3];
|
||||
} colormap_t;
|
||||
|
||||
/* And the routine definitions. */
|
||||
|
||||
struct pixrect* mem_create ARGS(( int w, int h, int depth ));
|
||||
void mem_free ARGS(( struct pixrect* p ));
|
||||
|
||||
int pr_dump ARGS(( struct pixrect* p, FILE* out, colormap_t* colormap, int type, int copy_flag ));
|
||||
|
||||
int pr_load_header ARGS(( FILE* in, struct rasterfile* hP ));
|
||||
|
||||
int pr_load_colormap ARGS(( FILE* in, struct rasterfile* hP, colormap_t* colormap ));
|
||||
|
||||
struct pixrect* pr_load_image ARGS(( FILE* in, struct rasterfile* hP, colormap_t* colormap ));
|
||||
|
||||
#endif /*_RAST_H_*/
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
/* version.h - define the current version of the package
|
||||
*/
|
||||
|
||||
#define PBMPLUS_VERSION "Netpbm 1 March 1994"
|
||||
|
|
@ -4,19 +4,25 @@
|
|||
#begin lib_target
|
||||
#define TARGET pnmimage
|
||||
#define LOCAL_LIBS \
|
||||
pnm linmath putil express
|
||||
linmath putil express
|
||||
|
||||
#define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx
|
||||
|
||||
#define SOURCES \
|
||||
config_pnmimage.h pnmFileType.h pnmFileTypeRegistry.h pnmImage.I \
|
||||
config_pnmimage.h \
|
||||
pnmbitio.h \
|
||||
pnmFileType.h pnmFileTypeRegistry.h pnmImage.I \
|
||||
pnmImage.h pnmImageHeader.I pnmImageHeader.h pnmReader.I \
|
||||
pnmReader.h pnmWriter.I pnmWriter.h
|
||||
pnmReader.h pnmWriter.I pnmWriter.h pnmimage_base.h \
|
||||
ppmcmap.h
|
||||
|
||||
#define INCLUDED_SOURCES \
|
||||
config_pnmimage.cxx pnm-image-filter.cxx pnmFileType.cxx \
|
||||
config_pnmimage.cxx \
|
||||
pnmbitio.cxx \
|
||||
pnm-image-filter.cxx pnmFileType.cxx \
|
||||
pnmFileTypeRegistry.cxx pnmImage.cxx pnmImageHeader.cxx \
|
||||
pnmReader.cxx pnmWriter.cxx
|
||||
pnmReader.cxx pnmWriter.cxx pnmimage_base.cxx \
|
||||
ppmcmap.cxx
|
||||
|
||||
#define INSTALL_HEADERS \
|
||||
config_pnmimage.h pnmFileType.h pnmFileTypeRegistry.h pnmImage.I \
|
||||
|
|
|
|||
|
|
@ -144,6 +144,9 @@ init_pnm() {
|
|||
if (!_did_init_pnm) {
|
||||
_did_init_pnm = true;
|
||||
|
||||
// No reason to do anything here now.
|
||||
/*
|
||||
|
||||
// Make an argc/argv style copy of the ExecutionEnvironment's
|
||||
// args. We do this because pm_init() might attempt to change
|
||||
// this (for instance, to remove arguments it finds).
|
||||
|
|
@ -164,6 +167,8 @@ init_pnm() {
|
|||
// library might keep pointers to it. But this is a one-time
|
||||
// leak.
|
||||
delete[] argv;
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,16 +21,6 @@
|
|||
#include "pnmWriter.h"
|
||||
#include "config_pnmimage.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../pnm/pnm.h"
|
||||
#include "../pnm/ppm.h"
|
||||
#include "../pnm/pgm.h"
|
||||
#include "../pnm/pbm.h"
|
||||
#include "../pnm/libppm.h"
|
||||
#include "../pnm/libpgm.h"
|
||||
#include "../pnm/libpbm.h"
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMImage::clear
|
||||
// Access: Public
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@
|
|||
#ifndef PNMIMAGE_H
|
||||
#define PNMIMAGE_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "pnmImageHeader.h"
|
||||
|
||||
#include <luse.h>
|
||||
#include "luse.h"
|
||||
|
||||
class PNMReader;
|
||||
class PNMWriter;
|
||||
|
|
@ -31,7 +31,17 @@ class PNMFileType;
|
|||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PNMImage
|
||||
// Description : Conceptually, a PNMImage is a two-dimensional array
|
||||
// Description : The name of this class derives from the fact that we
|
||||
// originally implemented it as a layer on top of the
|
||||
// "pnm library", based on netpbm, which was built to
|
||||
// implement pbm, pgm, and pbm files, and is the
|
||||
// underlying support of a number of public-domain image
|
||||
// file converters. Nowadays we are no longer derived
|
||||
// directly from the pnm library, mainly to allow
|
||||
// support of C++ iostreams instead of the C stdio FILE
|
||||
// interface.
|
||||
//
|
||||
// Conceptually, a PNMImage is a two-dimensional array
|
||||
// of xels, which are the PNM-defined generic pixel
|
||||
// type. Each xel may have a red, green, and blue
|
||||
// component, or (if the image is grayscale) a gray
|
||||
|
|
@ -43,11 +53,8 @@ class PNMFileType;
|
|||
// numbered from top to bottom, left to right, beginning
|
||||
// at zero.
|
||||
//
|
||||
// Files can be specified by filename, or by a
|
||||
// stdio-style FILE pointer. Unfortunately, C++ streams
|
||||
// cannot be supported, because of the underlying C code
|
||||
// in libpnm. The filename "-" refers to stdin or
|
||||
// stdout.
|
||||
// Files can be specified by filename, or by an iostream
|
||||
// pointer. The filename "-" refers to stdin or stdout.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA PNMImage : public PNMImageHeader {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ make_reader(const Filename &filename, PNMFileType *type) const {
|
|||
}
|
||||
owns_file = true;
|
||||
string os_specific = actual_name.to_os_specific();
|
||||
file = pm_openr((char *)os_specific.c_str());
|
||||
file = fopen((char *)os_specific.c_str(), "rb");
|
||||
}
|
||||
|
||||
if (file == (FILE *)NULL) {
|
||||
|
|
@ -143,7 +143,7 @@ make_reader(FILE *file, bool owns_file, const Filename &filename,
|
|||
<< "Image file appears to be empty.\n";
|
||||
}
|
||||
if (owns_file) {
|
||||
pm_close(file);
|
||||
fclose(file);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -200,14 +200,14 @@ make_reader(FILE *file, bool owns_file, const Filename &filename,
|
|||
write_types(pnmimage_cat.error(false), 2);
|
||||
}
|
||||
if (owns_file) {
|
||||
pm_close(file);
|
||||
fclose(file);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PNMReader *reader = type->make_reader(file, owns_file, magic_number);
|
||||
if (reader == NULL && owns_file) {
|
||||
pm_close(file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
if (!reader->is_valid()) {
|
||||
|
|
@ -253,7 +253,7 @@ make_writer(const Filename &filename, PNMFileType *type) const {
|
|||
} else {
|
||||
owns_file = true;
|
||||
string os_specific = actual_name.to_os_specific();
|
||||
file = pm_openw((char *)os_specific.c_str());
|
||||
file = fopen((char *)os_specific.c_str(), "wb");
|
||||
}
|
||||
|
||||
if (file == (FILE *)NULL) {
|
||||
|
|
@ -328,14 +328,14 @@ make_writer(FILE *file, bool owns_file, const Filename &filename,
|
|||
<< "Cannot determine type of image file " << filename << ".\n";
|
||||
}
|
||||
if (owns_file) {
|
||||
pm_close(file);
|
||||
fclose(file);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PNMWriter *writer = type->make_writer(file, owns_file);
|
||||
if (writer == NULL && owns_file) {
|
||||
pm_close(file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
return writer;
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@
|
|||
#ifndef PNMIMAGEHEADER_H
|
||||
#define PNMIMAGEHEADER_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "pnmimage_base.h"
|
||||
|
||||
#include <typedObject.h>
|
||||
#include <filename.h>
|
||||
#include "typedObject.h"
|
||||
#include "filename.h"
|
||||
|
||||
class PNMFileType;
|
||||
class PNMReader;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
PNMReader::
|
||||
~PNMReader() {
|
||||
if (_owns_file) {
|
||||
pm_close(_file);
|
||||
fclose(_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
PNMWriter::
|
||||
~PNMWriter() {
|
||||
if (_owns_file) {
|
||||
pm_close(_file);
|
||||
fclose(_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
#include "bitio.h"
|
||||
#include "pnmbitio.h"
|
||||
#include <assert.h>
|
||||
struct bitstream
|
||||
{
|
||||
|
|
@ -16,9 +16,8 @@
|
|||
#ifndef _BITIO_H_
|
||||
#define _BITIO_H_
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#include "pbmplus.h"
|
||||
#include "pandabase.h"
|
||||
#include "pnmimage_base.h"
|
||||
|
||||
typedef struct bitstream *BITSTREAM;
|
||||
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
// Filename: pnmimage_base.cxx
|
||||
// Created by: drose (04Aug02)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pnmimage_base.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: pm_message
|
||||
// Description: Outputs the given printf-style message to the user
|
||||
// and returns.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
pm_message(const char *format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
static const size_t buffer_size = 1024;
|
||||
char buffer[buffer_size];
|
||||
vsnprintf(buffer, buffer_size, format, ap);
|
||||
|
||||
pnmimage_cat.info() << buffer << "\n";
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: pm_error
|
||||
// Description: Outputs the given printf-style message to the user
|
||||
// and terminates messily. Minimize use of this
|
||||
// function.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
pm_error(const char *format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
static const size_t buffer_size = 1024;
|
||||
char buffer[buffer_size];
|
||||
vsnprintf(buffer, buffer_size, format, ap);
|
||||
|
||||
pnmimage_cat.error() << buffer << "\n";
|
||||
|
||||
va_end(ap);
|
||||
|
||||
// Now we're supposed to exit. Inconvenient if we were running
|
||||
// Panda interactively, but that's the way it is.
|
||||
exit(1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: pm_maxvaltobits
|
||||
// Description: Returns the number of bits sufficient to hold the
|
||||
// indicated maxval value.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int
|
||||
pm_maxvaltobits(int maxval) {
|
||||
int bits = 1;
|
||||
while (maxval > pm_bitstomaxval(bits)) {
|
||||
bits++;
|
||||
nassertr(bits != 0, 16);
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: pm_bitstomaxval
|
||||
// Description: Returns the highest maxval that can be represented in
|
||||
// the indicated number of bits.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int
|
||||
pm_bitstomaxval(int bits) {
|
||||
return ( 1 << bits ) - 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: pm_allocrow
|
||||
// Description: Allocates a row of cols * size bytes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
char *
|
||||
pm_allocrow(int cols, int size) {
|
||||
return new char[cols * size];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: pm_freerow
|
||||
// Description: Frees the row previously allocated withm pm_allocrow().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
pm_freerow(char *itrow) {
|
||||
delete[] itrow;
|
||||
}
|
||||
|
||||
|
||||
/* Endian I/O.
|
||||
*/
|
||||
|
||||
int
|
||||
pm_readbigshort(FILE* in, short* sP)
|
||||
{
|
||||
int c;
|
||||
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*sP = ( c & 0xff ) << 8;
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*sP |= c & 0xff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pm_writebigshort( FILE* out, short s )
|
||||
{
|
||||
(void) putc( ( s >> 8 ) & 0xff, out );
|
||||
(void) putc( s & 0xff, out );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pm_readbiglong(FILE* in, long* lP)
|
||||
{
|
||||
int c;
|
||||
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*lP = ( c & 0xff ) << 24;
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*lP |= ( c & 0xff ) << 16;
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*lP |= ( c & 0xff ) << 8;
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*lP |= c & 0xff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pm_writebiglong(FILE* out, long l)
|
||||
{
|
||||
(void) putc( ( l >> 24 ) & 0xff, out );
|
||||
(void) putc( ( l >> 16 ) & 0xff, out );
|
||||
(void) putc( ( l >> 8 ) & 0xff, out );
|
||||
(void) putc( l & 0xff, out );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pm_readlittleshort(FILE* in, short* sP)
|
||||
{
|
||||
int c;
|
||||
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*sP = c & 0xff;
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*sP |= ( c & 0xff ) << 8;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pm_writelittleshort( FILE* out, short s )
|
||||
{
|
||||
(void) putc( s & 0xff, out );
|
||||
(void) putc( ( s >> 8 ) & 0xff, out );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pm_readlittlelong(FILE* in, long* lP)
|
||||
{
|
||||
int c;
|
||||
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*lP = c & 0xff;
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*lP |= ( c & 0xff ) << 8;
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*lP |= ( c & 0xff ) << 16;
|
||||
if ( (c = getc( in )) == EOF )
|
||||
return -1;
|
||||
*lP |= ( c & 0xff ) << 24;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pm_writelittlelong(FILE* out, long l)
|
||||
{
|
||||
(void) putc( l & 0xff, out );
|
||||
(void) putc( ( l >> 8 ) & 0xff, out );
|
||||
(void) putc( ( l >> 16 ) & 0xff, out );
|
||||
(void) putc( ( l >> 24 ) & 0xff, out );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -22,31 +22,78 @@
|
|||
// This header file make a few typedefs and other definitions
|
||||
// essential to everything in the PNMImage package.
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "pandabase.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
// These include files are kludges against slightly incorrect headers given
|
||||
// in pbm*.h.
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
// Since we no longer include pnm.h directly, we have to provide our
|
||||
// own definitions for xel and xelval.
|
||||
|
||||
extern "C" {
|
||||
#include <pbmplus.h>
|
||||
#include <pbm.h>
|
||||
#include <pgm.h>
|
||||
#include <ppm.h>
|
||||
#include <pnm.h>
|
||||
}
|
||||
// For now, we have PGM_BIGGRAYS defined, which gives us 16-bit
|
||||
// channels. Undefine this if you have memory problems and need to
|
||||
// use 8-bit channels instead.
|
||||
#define PGM_BIGGRAYS
|
||||
|
||||
#ifdef PGM_BIGGRAYS
|
||||
typedef unsigned short gray;
|
||||
#define PGM_MAXMAXVAL 65535
|
||||
#else // PGM_BIGGRAYS
|
||||
typedef unsigned char gray;
|
||||
#define PGM_MAXMAXVAL 255
|
||||
#endif // PGM_BIGGRAYS
|
||||
|
||||
#define PNM_MAXMAXVAL PGM_MAXMAXVAL
|
||||
|
||||
struct pixel {
|
||||
gray r, g, b;
|
||||
};
|
||||
|
||||
typedef gray pixval;
|
||||
typedef pixel xel;
|
||||
typedef gray xelval;
|
||||
|
||||
// These macros are borrowed from ppm.h.
|
||||
|
||||
#define PPM_GETR(p) ((p).r)
|
||||
#define PPM_GETG(p) ((p).g)
|
||||
#define PPM_GETB(p) ((p).b)
|
||||
|
||||
#define PPM_PUTR(p,red) ((p).r = (red))
|
||||
#define PPM_PUTG(p,grn) ((p).g = (grn))
|
||||
#define PPM_PUTB(p,blu) ((p).b = (blu))
|
||||
|
||||
#define PPM_ASSIGN(p,red,grn,blu) { (p).r = (red); (p).g = (grn); (p).b = (blu); }
|
||||
#define PPM_EQUAL(p,q) ( (p).r == (q).r && (p).g == (q).g && (p).b == (q).b )
|
||||
#define PNM_ASSIGN1(x,v) PPM_ASSIGN(x,0,0,v)
|
||||
|
||||
#define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \
|
||||
PPM_ASSIGN( (newp), \
|
||||
( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
|
||||
( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
|
||||
( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )
|
||||
|
||||
|
||||
// Got to undefine the stupid macros that pbmplus leaves us with.
|
||||
#ifdef index
|
||||
#undef index
|
||||
#undef rindex
|
||||
#endif
|
||||
// pnm defines these functions, and it's easier to emulate them than
|
||||
// to rewrite the code that calls them.
|
||||
EXPCL_PANDA void pm_message(const char *format, ...);
|
||||
EXPCL_PANDA void pm_error(const char *format, ...); // doesn't return.
|
||||
|
||||
EXPCL_PANDA int pm_maxvaltobits(int maxval);
|
||||
EXPCL_PANDA int pm_bitstomaxval(int bits);
|
||||
|
||||
EXPCL_PANDA char *pm_allocrow(int cols, int size);
|
||||
EXPCL_PANDA void pm_freerow(char *itrow);
|
||||
|
||||
EXPCL_PANDA int pm_readbigshort(FILE *in, short *sP);
|
||||
EXPCL_PANDA int pm_writebigshort(FILE *out, short s);
|
||||
EXPCL_PANDA int pm_readbiglong(FILE *in, long *lP);
|
||||
EXPCL_PANDA int pm_writebiglong(FILE *out, long l);
|
||||
EXPCL_PANDA int pm_readlittleshort(FILE *in, short *sP);
|
||||
EXPCL_PANDA int pm_writelittleshort(FILE *out, short s);
|
||||
EXPCL_PANDA int pm_readlittlelong(FILE *in, long *lP);
|
||||
EXPCL_PANDA int pm_writelittlelong(FILE *out, long l);
|
||||
|
||||
|
||||
// These ratios are used to compute the brightness of a colored pixel; they
|
||||
// define the relative contributions of each of the components.
|
||||
|
|
@ -54,12 +101,5 @@ static const double lumin_red = 0.299;
|
|||
static const double lumin_grn = 0.587;
|
||||
static const double lumin_blu = 0.114;
|
||||
|
||||
// A handy template function.
|
||||
template <class Type>
|
||||
INLINE Type
|
||||
bounds(const Type &value, const Type &lower, const Type &upper) {
|
||||
return min(max(value, lower), upper);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
#include "config_pnmimage.cxx"
|
||||
#include "pnm-image-filter.cxx"
|
||||
#include "pnmbitio.cxx"
|
||||
#include "pnmFileType.cxx"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "pnmImage.cxx"
|
||||
#include "pnmImageHeader.cxx"
|
||||
#include "pnmReader.cxx"
|
||||
#include "pnmWriter.cxx"
|
||||
#include "pnmFileTypeRegistry.cxx"
|
||||
#include "pnmimage_base.cxx"
|
||||
#include "ppmcmap.cxx"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
// Filename: pnmminmax.h
|
||||
// Created by: drose (23Aug96)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _PNMMINMAX_H_
|
||||
#define _PNMMINMAX_H_
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
// We now inherit these functions from STL.
|
||||
|
||||
/*
|
||||
template <class Type>
|
||||
inline Type
|
||||
max(const Type &a, const Type &b) {
|
||||
return (a<b) ? b : a;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
inline Type
|
||||
min(const Type &a, const Type &b) {
|
||||
return (a<b) ? a : b;
|
||||
}
|
||||
*/
|
||||
|
||||
template <class Type>
|
||||
inline Type
|
||||
bounds(const Type &value, const Type &lower, const Type &upper) {
|
||||
return min(max(value, lower), upper);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -12,9 +12,7 @@
|
|||
** implied warranty.
|
||||
*/
|
||||
|
||||
#include "ppm.h"
|
||||
#include "ppmcmap.h"
|
||||
#include "libppm.h"
|
||||
|
||||
#define HASH_SIZE 20023
|
||||
|
||||
|
|
@ -25,10 +23,9 @@
|
|||
#endif /*PPM_PACKCOLORS*/
|
||||
|
||||
colorhist_vector
|
||||
ppm_computecolorhist( pixels, cols, rows, maxcolors, colorsP )
|
||||
pixel** pixels;
|
||||
int cols, rows, maxcolors;
|
||||
int* colorsP;
|
||||
ppm_computecolorhist(pixel** pixels,
|
||||
int cols, int rows, int maxcolors,
|
||||
int* colorsP)
|
||||
{
|
||||
colorhash_table cht;
|
||||
colorhist_vector chv;
|
||||
|
|
@ -42,11 +39,11 @@ ppm_computecolorhist( pixels, cols, rows, maxcolors, colorsP )
|
|||
}
|
||||
|
||||
void
|
||||
ppm_addtocolorhist( chv, colorsP, maxcolors, colorP, value, position )
|
||||
colorhist_vector chv;
|
||||
pixel* colorP;
|
||||
int* colorsP;
|
||||
int maxcolors, value, position;
|
||||
ppm_addtocolorhist(colorhist_vector chv,
|
||||
int* colorsP,
|
||||
int maxcolors,
|
||||
pixel* colorP,
|
||||
int value, int position)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
|
|
@ -81,10 +78,9 @@ ppm_addtocolorhist( chv, colorsP, maxcolors, colorP, value, position )
|
|||
}
|
||||
|
||||
colorhash_table
|
||||
ppm_computecolorhash( pixels, cols, rows, maxcolors, colorsP )
|
||||
pixel** pixels;
|
||||
int cols, rows, maxcolors;
|
||||
int* colorsP;
|
||||
ppm_computecolorhash(pixel** pixels,
|
||||
int cols, int rows, int maxcolors,
|
||||
int* colorsP)
|
||||
{
|
||||
colorhash_table cht;
|
||||
register pixel* pP;
|
||||
|
|
@ -141,10 +137,9 @@ ppm_alloccolorhash( )
|
|||
}
|
||||
|
||||
int
|
||||
ppm_addtocolorhash( cht, colorP, value )
|
||||
colorhash_table cht;
|
||||
pixel* colorP;
|
||||
int value;
|
||||
ppm_addtocolorhash(colorhash_table cht,
|
||||
pixel* colorP,
|
||||
int value)
|
||||
{
|
||||
register int hash;
|
||||
register colorhist_list chl;
|
||||
|
|
@ -161,9 +156,8 @@ ppm_addtocolorhash( cht, colorP, value )
|
|||
}
|
||||
|
||||
colorhist_vector
|
||||
ppm_colorhashtocolorhist( cht, maxcolors )
|
||||
colorhash_table cht;
|
||||
int maxcolors;
|
||||
ppm_colorhashtocolorhist(colorhash_table cht,
|
||||
int maxcolors)
|
||||
{
|
||||
colorhist_vector chv;
|
||||
colorhist_list chl;
|
||||
|
|
@ -190,9 +184,8 @@ ppm_colorhashtocolorhist( cht, maxcolors )
|
|||
}
|
||||
|
||||
colorhash_table
|
||||
ppm_colorhisttocolorhash( chv, colors )
|
||||
colorhist_vector chv;
|
||||
int colors;
|
||||
ppm_colorhisttocolorhash(colorhist_vector chv,
|
||||
int colors)
|
||||
{
|
||||
colorhash_table cht;
|
||||
int i, hash;
|
||||
|
|
@ -223,9 +216,8 @@ ppm_colorhisttocolorhash( chv, colors )
|
|||
}
|
||||
|
||||
int
|
||||
ppm_lookupcolor( cht, colorP )
|
||||
colorhash_table cht;
|
||||
pixel* colorP;
|
||||
ppm_lookupcolor(colorhash_table cht,
|
||||
pixel* colorP)
|
||||
{
|
||||
int hash;
|
||||
colorhist_list chl;
|
||||
|
|
@ -239,15 +231,13 @@ ppm_lookupcolor( cht, colorP )
|
|||
}
|
||||
|
||||
void
|
||||
ppm_freecolorhist( chv )
|
||||
colorhist_vector chv;
|
||||
ppm_freecolorhist(colorhist_vector chv)
|
||||
{
|
||||
free( (char*) chv );
|
||||
}
|
||||
|
||||
void
|
||||
ppm_freecolorhash( cht )
|
||||
colorhash_table cht;
|
||||
ppm_freecolorhash(colorhash_table cht)
|
||||
{
|
||||
int i;
|
||||
colorhist_list chl, chlnext;
|
||||
|
|
@ -6,6 +6,9 @@
|
|||
#ifndef PPMCMAP_H
|
||||
#define PPMCMAP_H
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "pnmimage_base.h"
|
||||
|
||||
typedef struct colorhist_item* colorhist_vector;
|
||||
struct colorhist_item
|
||||
{
|
||||
|
|
@ -23,7 +26,7 @@ struct colorhist_list_item
|
|||
EXPCL_PANDA colorhist_vector ppm_computecolorhist( pixel** pixels, int cols, int rows, int maxcolors, int* colorsP );
|
||||
/* Returns a colorhist *colorsP long (with space allocated for maxcolors. */
|
||||
|
||||
void ppm_addtocolorhist ARGS(( colorhist_vector chv, int* colorsP, int maxcolors, pixel* colorP, int value, int position ));
|
||||
void ppm_addtocolorhist ( colorhist_vector chv, int* colorsP, int maxcolors, pixel* colorP, int value, int position );
|
||||
|
||||
EXPCL_PANDA void ppm_freecolorhist( colorhist_vector chv );
|
||||
|
||||
|
|
@ -32,18 +35,18 @@ EXPCL_PANDA void ppm_freecolorhist( colorhist_vector chv );
|
|||
|
||||
typedef colorhist_list* colorhash_table;
|
||||
|
||||
colorhash_table ppm_computecolorhash ARGS(( pixel** pixels, int cols, int rows, int maxcolors, int* colorsP ));
|
||||
colorhash_table ppm_computecolorhash ( pixel** pixels, int cols, int rows, int maxcolors, int* colorsP );
|
||||
|
||||
EXPCL_PANDA int
|
||||
ppm_lookupcolor( colorhash_table cht, pixel* colorP );
|
||||
|
||||
colorhist_vector ppm_colorhashtocolorhist ARGS(( colorhash_table cht, int maxcolors ));
|
||||
colorhist_vector ppm_colorhashtocolorhist ( colorhash_table cht, int maxcolors );
|
||||
EXPCL_PANDA colorhash_table ppm_colorhisttocolorhash( colorhist_vector chv, int colors );
|
||||
|
||||
int ppm_addtocolorhash ARGS(( colorhash_table cht, pixel* colorP, int value ));
|
||||
int ppm_addtocolorhash ( colorhash_table cht, pixel* colorP, int value );
|
||||
/* Returns -1 on failure. */
|
||||
|
||||
colorhash_table ppm_alloccolorhash ARGS(( void ));
|
||||
colorhash_table ppm_alloccolorhash ( void );
|
||||
|
||||
void ppm_freecolorhash( colorhash_table cht );
|
||||
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
#begin lib_target
|
||||
#define TARGET pnmimagetypes
|
||||
#define LOCAL_LIBS \
|
||||
pnm pnmimage
|
||||
pnmimage
|
||||
|
||||
#define COMBINED_SOURCES \
|
||||
$[TARGET]_composite1.cxx $[TARGET]_composite2.cxx \
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#define SOURCES \
|
||||
config_pnmimagetypes.h pnmFileTypeAlias.h pnmFileTypeBMP.h \
|
||||
pnmFileTypeIMG.h pnmFileTypePNM.h pnmFileTypeRadiance.h \
|
||||
pnmFileTypeIMG.h pnmFileTypeRadiance.h \
|
||||
pnmFileTypeSGI.h pnmFileTypeSoftImage.h \
|
||||
pnmFileTypeTGA.h pnmFileTypeYUV.h color.c colrops.c resolu.c \
|
||||
header.c \
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#define INCLUDED_SOURCES \
|
||||
config_pnmimagetypes.cxx pnmFileTypeAlias.cxx \
|
||||
pnmFileTypeBMPReader.cxx pnmFileTypeBMPWriter.cxx \
|
||||
pnmFileTypeIMG.cxx pnmFileTypePNM.cxx pnmFileTypeBMP.cxx \
|
||||
pnmFileTypeIMG.cxx pnmFileTypeBMP.cxx \
|
||||
pnmFileTypeRadiance.cxx pnmFileTypeSGI.cxx \
|
||||
pnmFileTypeSGIReader.cxx pnmFileTypeSGIWriter.cxx \
|
||||
pnmFileTypeSoftImage.cxx \
|
||||
|
|
|
|||
|
|
@ -19,9 +19,8 @@
|
|||
#ifndef _BMP_H_
|
||||
#define _BMP_H_
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#include "pbmplus.h"
|
||||
#include "pandabase.h"
|
||||
#include "pnmimage_base.h"
|
||||
|
||||
/* prototypes */
|
||||
static unsigned long BMPlenfileheader(int classv);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "config_pnmimagetypes.h"
|
||||
#include "pnmFileTypePNM.h"
|
||||
#include "pnmFileTypeSGI.h"
|
||||
#include "pnmFileTypeAlias.h"
|
||||
#include "pnmFileTypeRadiance.h"
|
||||
|
|
@ -123,7 +122,6 @@ init_libpnmimagetypes() {
|
|||
initialized = true;
|
||||
|
||||
init_libpnmimage();
|
||||
PNMFileTypePNM::init_type();
|
||||
PNMFileTypeSGI::init_type();
|
||||
PNMFileTypeAlias::init_type();
|
||||
PNMFileTypeRadiance::init_type();
|
||||
|
|
@ -169,7 +167,6 @@ init_libpnmimagetypes() {
|
|||
// Register each type with the PNMFileTypeRegistry.
|
||||
PNMFileTypeRegistry *tr = PNMFileTypeRegistry::get_ptr();
|
||||
|
||||
tr->register_type(new PNMFileTypePNM);
|
||||
tr->register_type(new PNMFileTypeSGI);
|
||||
tr->register_type(new PNMFileTypeAlias);
|
||||
tr->register_type(new PNMFileTypeRadiance);
|
||||
|
|
@ -189,7 +186,6 @@ init_libpnmimagetypes() {
|
|||
#endif
|
||||
|
||||
// Also register with the Bam reader.
|
||||
PNMFileTypePNM::register_with_read_factory();
|
||||
PNMFileTypeSGI::register_with_read_factory();
|
||||
PNMFileTypeAlias::register_with_read_factory();
|
||||
PNMFileTypeRadiance::register_with_read_factory();
|
||||
|
|
|
|||
|
|
@ -18,11 +18,8 @@
|
|||
|
||||
#include "pnmFileTypeBMP.h"
|
||||
#include "config_pnmimagetypes.h"
|
||||
|
||||
extern "C" {
|
||||
#include "bmp.h"
|
||||
#include "../pnm/bitio.h"
|
||||
}
|
||||
#include "bmp.h"
|
||||
#include "pnmbitio.h"
|
||||
|
||||
// Much code in this file is borrowed from Netpbm, specifically bmptoppm.c.
|
||||
/*
|
||||
|
|
@ -46,17 +43,17 @@ extern "C" {
|
|||
* Utilities
|
||||
*/
|
||||
|
||||
static int GetByte ARGS((FILE * fp));
|
||||
static short GetShort ARGS((FILE * fp));
|
||||
static long GetLong ARGS((FILE * fp));
|
||||
static void readto ARGS((FILE *fp, unsigned long *ppos, unsigned long dst));
|
||||
static void BMPreadfileheader ARGS((FILE *fp, unsigned long *ppos,
|
||||
unsigned long *poffBits));
|
||||
static void BMPreadinfoheader ARGS((FILE *fp, unsigned long *ppos,
|
||||
static int GetByte (FILE * fp);
|
||||
static short GetShort (FILE * fp);
|
||||
static long GetLong (FILE * fp);
|
||||
static void readto (FILE *fp, unsigned long *ppos, unsigned long dst);
|
||||
static void BMPreadfileheader (FILE *fp, unsigned long *ppos,
|
||||
unsigned long *poffBits);
|
||||
static void BMPreadinfoheader (FILE *fp, unsigned long *ppos,
|
||||
unsigned long *pcx, unsigned long *pcy, unsigned short *pcBitCount,
|
||||
int *pclassv));
|
||||
static int BMPreadrgbtable ARGS((FILE *fp, unsigned long *ppos,
|
||||
unsigned short cBitCount, int classv, pixval *R, pixval *G, pixval *B));
|
||||
int *pclassv);
|
||||
static int BMPreadrgbtable (FILE *fp, unsigned long *ppos,
|
||||
unsigned short cBitCount, int classv, pixval *R, pixval *G, pixval *B);
|
||||
|
||||
static const char *ifname = "BMP";
|
||||
static char er_read[] = "%s: read error";
|
||||
|
|
|
|||
|
|
@ -19,14 +19,12 @@
|
|||
#include "pnmFileTypeBMP.h"
|
||||
#include "config_pnmimagetypes.h"
|
||||
|
||||
#include <pnmImage.h>
|
||||
#include <pnmWriter.h>
|
||||
#include "pnmImage.h"
|
||||
#include "pnmWriter.h"
|
||||
|
||||
extern "C" {
|
||||
#include "bmp.h"
|
||||
#include "../pnm/ppmcmap.h"
|
||||
#include "../pnm/bitio.h"
|
||||
}
|
||||
#include "bmp.h"
|
||||
#include "ppmcmap.h"
|
||||
#include "pnmbitio.h"
|
||||
|
||||
// Much code in this file is borrowed from Netpbm, specifically ppmtobmp.c.
|
||||
/*
|
||||
|
|
@ -55,19 +53,19 @@ extern "C" {
|
|||
static char er_write[] = "stdout: write error";
|
||||
|
||||
/* prototypes */
|
||||
static void PutByte ARGS((FILE *fp, char v));
|
||||
static void PutShort ARGS((FILE *fp, short v));
|
||||
static void PutLong ARGS((FILE *fp, long v));
|
||||
static int BMPwritefileheader ARGS((FILE *fp, int classv, unsigned long bitcount,
|
||||
unsigned long x, unsigned long y));
|
||||
static int BMPwriteinfoheader ARGS((FILE *fp, int classv, unsigned long bitcount,
|
||||
unsigned long x, unsigned long y));
|
||||
static int BMPwritergb ARGS((FILE *fp, int classv, pixval R, pixval G, pixval B));
|
||||
static int BMPwritergbtable ARGS((FILE *fp, int classv, int bpp, int colors,
|
||||
pixval *R, pixval *G, pixval *B));
|
||||
static int colorstobpp ARGS((int colors));
|
||||
static void BMPEncode ARGS((FILE *fp, int classv, int x, int y, pixel **pixels,
|
||||
int colors, colorhash_table cht, pixval *R, pixval *G, pixval *B));
|
||||
static void PutByte (FILE *fp, char v);
|
||||
static void PutShort (FILE *fp, short v);
|
||||
static void PutLong (FILE *fp, long v);
|
||||
static int BMPwritefileheader (FILE *fp, int classv, unsigned long bitcount,
|
||||
unsigned long x, unsigned long y);
|
||||
static int BMPwriteinfoheader (FILE *fp, int classv, unsigned long bitcount,
|
||||
unsigned long x, unsigned long y);
|
||||
static int BMPwritergb (FILE *fp, int classv, pixval R, pixval G, pixval B);
|
||||
static int BMPwritergbtable (FILE *fp, int classv, int bpp, int colors,
|
||||
pixval *R, pixval *G, pixval *B);
|
||||
static int colorstobpp (int colors);
|
||||
static void BMPEncode (FILE *fp, int classv, int x, int y, pixel **pixels,
|
||||
int colors, colorhash_table cht, pixval *R, pixval *G, pixval *B);
|
||||
static void
|
||||
PutByte(
|
||||
FILE *fp,
|
||||
|
|
|
|||
|
|
@ -1,363 +0,0 @@
|
|||
// Filename: pnmFileTypePNM.cxx
|
||||
// Created by: drose (04Apr98)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pnmFileTypePNM.h"
|
||||
#include "config_pnmimagetypes.h"
|
||||
|
||||
#include <pnmFileTypeRegistry.h>
|
||||
#include <bamReader.h>
|
||||
|
||||
extern "C" {
|
||||
#include "../pnm/pnm.h"
|
||||
#include "../pnm/ppm.h"
|
||||
#include "../pnm/pgm.h"
|
||||
#include "../pnm/pbm.h"
|
||||
#include "../pnm/libppm.h"
|
||||
#include "../pnm/libpgm.h"
|
||||
#include "../pnm/libpbm.h"
|
||||
}
|
||||
|
||||
static const char * const extensions_PNM[] = {
|
||||
"pbm", "ppm", "pnm"
|
||||
};
|
||||
static const int num_extensions_PNM = sizeof(extensions_PNM) / sizeof(const char *);
|
||||
|
||||
TypeHandle PNMFileTypePNM::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PNMFileTypePNM::
|
||||
PNMFileTypePNM() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::get_name
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns a few words describing the file type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string PNMFileTypePNM::
|
||||
get_name() const {
|
||||
return "NetPBM-style PBM/PPM/PNM";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::get_num_extensions
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns the number of different possible filename
|
||||
// extensions_PNM associated with this particular file type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int PNMFileTypePNM::
|
||||
get_num_extensions() const {
|
||||
return num_extensions_PNM;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::get_extension
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns the nth possible filename extension
|
||||
// associated with this particular file type, without a
|
||||
// leading dot.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string PNMFileTypePNM::
|
||||
get_extension(int n) const {
|
||||
nassertr(n >= 0 && n < num_extensions_PNM, string());
|
||||
return extensions_PNM[n];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::get_suggested_extension
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns a suitable filename extension (without a
|
||||
// leading dot) to suggest for files of this type, or
|
||||
// empty string if no suggestions are available.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string PNMFileTypePNM::
|
||||
get_suggested_extension() const {
|
||||
return "pnm";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::has_magic_number
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns true if this particular file type uses a
|
||||
// magic number to identify it, false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PNMFileTypePNM::
|
||||
has_magic_number() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::matches_magic_number
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns true if the indicated "magic number" byte
|
||||
// stream (the initial few bytes read from the file)
|
||||
// matches this particular file type, false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PNMFileTypePNM::
|
||||
matches_magic_number(const string &magic_number) const {
|
||||
return (magic_number.size() >= 2) &&
|
||||
magic_number[0] == 'P' &&
|
||||
(magic_number[1] >= '1' && magic_number[1] <= '6');
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::make_reader
|
||||
// Access: Public, Virtual
|
||||
// Description: Allocates and returns a new PNMReader suitable for
|
||||
// reading from this file type, if possible. If reading
|
||||
// from this file type is not supported, returns NULL.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PNMReader *PNMFileTypePNM::
|
||||
make_reader(FILE *file, bool owns_file, const string &magic_number) {
|
||||
init_pnm();
|
||||
return new Reader(this, file, owns_file, magic_number);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::make_writer
|
||||
// Access: Public, Virtual
|
||||
// Description: Allocates and returns a new PNMWriter suitable for
|
||||
// reading from this file type, if possible. If writing
|
||||
// files of this type is not supported, returns NULL.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PNMWriter *PNMFileTypePNM::
|
||||
make_writer(FILE *file, bool owns_file) {
|
||||
init_pnm();
|
||||
return new Writer(this, file, owns_file);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::Reader::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PNMFileTypePNM::Reader::
|
||||
Reader(PNMFileType *type, FILE *file, bool owns_file, string magic_number) :
|
||||
PNMReader(type, file, owns_file)
|
||||
{
|
||||
if (!read_magic_number(_file, magic_number, 2)) {
|
||||
// No magic number. No image.
|
||||
if (pnmimage_pnm_cat.is_debug()) {
|
||||
pnmimage_pnm_cat.debug()
|
||||
<< "PNM file appears to be empty.\n";
|
||||
}
|
||||
_is_valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// pnm_pbmmaxval = PNM_MAXMAXVAL; /* use larger value for better results */
|
||||
|
||||
_ftype =
|
||||
((unsigned char)magic_number[0] << 8) |
|
||||
(unsigned char)magic_number[1];
|
||||
|
||||
switch ( PNM_FORMAT_TYPE(_ftype) ) {
|
||||
case PPM_TYPE:
|
||||
ppm_readppminitrest( file, &_x_size, &_y_size, &_maxval );
|
||||
_num_channels = 3;
|
||||
break;
|
||||
|
||||
case PGM_TYPE:
|
||||
pgm_readpgminitrest( file, &_x_size, &_y_size, &_maxval );
|
||||
_num_channels = 1;
|
||||
break;
|
||||
|
||||
case PBM_TYPE:
|
||||
pbm_readpbminitrest( file, &_x_size, &_y_size );
|
||||
_num_channels = 1;
|
||||
_maxval = pnm_pbmmaxval;
|
||||
break;
|
||||
|
||||
default:
|
||||
_is_valid = false;
|
||||
}
|
||||
|
||||
if (pnmimage_pnm_cat.is_debug()) {
|
||||
if (is_valid()) {
|
||||
pnmimage_pnm_cat.debug()
|
||||
<< "Reading ";
|
||||
switch (PNM_FORMAT_TYPE(_ftype)) {
|
||||
case PPM_TYPE:
|
||||
pnmimage_pnm_cat.debug(false) << "PPM";
|
||||
break;
|
||||
case PGM_TYPE:
|
||||
pnmimage_pnm_cat.debug(false) << "PGM";
|
||||
break;
|
||||
case PBM_TYPE:
|
||||
pnmimage_pnm_cat.debug(false) << "PBM";
|
||||
break;
|
||||
}
|
||||
pnmimage_pnm_cat.debug(false)
|
||||
<< " " << *this << "\n";
|
||||
} else {
|
||||
pnmimage_pnm_cat.debug()
|
||||
<< "File is not a valid PNM image.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::Reader::supports_read_row
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns true if this particular PNMReader supports a
|
||||
// streaming interface to reading the data: that is, it
|
||||
// is capable of returning the data one row at a time,
|
||||
// via repeated calls to read_row(). Returns false if
|
||||
// the only way to read from this file is all at once,
|
||||
// via read_data().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PNMFileTypePNM::Reader::
|
||||
supports_read_row() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::Reader::read_row
|
||||
// Access: Public, Virtual
|
||||
// Description: If supports_read_row(), above, returns true, this
|
||||
// function may be called repeatedly to read the image,
|
||||
// one horizontal row at a time, beginning from the top.
|
||||
// Returns true if the row is successfully read, false
|
||||
// if there is an error or end of file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PNMFileTypePNM::Reader::
|
||||
read_row(xel *row_data, xelval *) {
|
||||
if (!is_valid()) {
|
||||
return false;
|
||||
}
|
||||
pnm_readpnmrow(_file, row_data, _x_size, _maxval, _ftype);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::Writer::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PNMFileTypePNM::Writer::
|
||||
Writer(PNMFileType *type, FILE *file, bool owns_file) :
|
||||
PNMWriter(type, file, owns_file)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::Writer::supports_write_row
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns true if this particular PNMWriter supports a
|
||||
// streaming interface to writing the data: that is, it
|
||||
// is capable of writing the image one row at a time,
|
||||
// via repeated calls to write_row(). Returns false if
|
||||
// the only way to write from this file is all at once,
|
||||
// via write_data().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PNMFileTypePNM::Writer::
|
||||
supports_write_row() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::Writer::write_header
|
||||
// Access: Public, Virtual
|
||||
// Description: If supports_write_row(), above, returns true, this
|
||||
// function may be called to write out the image header
|
||||
// in preparation to writing out the image data one row
|
||||
// at a time. Returns true if the header is
|
||||
// successfully written, false if there is an error.
|
||||
//
|
||||
// It is the user's responsibility to fill in the header
|
||||
// data via calls to set_x_size(), set_num_channels(),
|
||||
// etc., or copy_header_from(), before calling
|
||||
// write_header().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PNMFileTypePNM::Writer::
|
||||
write_header() {
|
||||
switch (get_color_type()) {
|
||||
case PNMImageHeader::CT_grayscale:
|
||||
case PNMImageHeader::CT_two_channel:
|
||||
_pnm_format = PGM_TYPE;
|
||||
break;
|
||||
|
||||
case PNMImageHeader::CT_color:
|
||||
case PNMImageHeader::CT_four_channel:
|
||||
_pnm_format = PPM_TYPE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pnm_writepnminit(_file, _x_size, _y_size, _maxval, _pnm_format, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::Writer::write_row
|
||||
// Access: Public, Virtual
|
||||
// Description: If supports_write_row(), above, returns true, this
|
||||
// function may be called repeatedly to write the image,
|
||||
// one horizontal row at a time, beginning from the top.
|
||||
// Returns true if the row is successfully written,
|
||||
// false if there is an error.
|
||||
//
|
||||
// You must first call write_header() before writing the
|
||||
// individual rows. It is also important to delete the
|
||||
// PNMWriter class after successfully writing the last
|
||||
// row. Failing to do this may result in some data not
|
||||
// getting flushed!
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PNMFileTypePNM::Writer::
|
||||
write_row(xel *row_data, xelval *) {
|
||||
pnm_writepnmrow(_file, row_data, _x_size, _maxval, _pnm_format, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::register_with_read_factory
|
||||
// Access: Public, Static
|
||||
// Description: Registers the current object as something that can be
|
||||
// read from a Bam file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PNMFileTypePNM::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->
|
||||
register_factory(get_class_type(), make_PNMFileTypePNM);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMFileTypePNM::make_PNMFileTypePNM
|
||||
// Access: Protected, Static
|
||||
// Description: This method is called by the BamReader when an object
|
||||
// of this type is encountered in a Bam file; it should
|
||||
// allocate and return a new object with all the data
|
||||
// read.
|
||||
//
|
||||
// In the case of the PNMFileType objects, since these
|
||||
// objects are all shared, we just pull the object from
|
||||
// the registry.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
TypedWritable *PNMFileTypePNM::
|
||||
make_PNMFileTypePNM(const FactoryParams ¶ms) {
|
||||
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
// Filename: pnmFileTypePNM.h
|
||||
// Created by: drose (17Jun00)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef PNMFILETYPEPNM_H
|
||||
#define PNMFILETYPEPNM_H
|
||||
|
||||
#include <pandabase.h>
|
||||
|
||||
#include <pnmFileType.h>
|
||||
#include <pnmReader.h>
|
||||
#include <pnmWriter.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PNMFileTypePNM
|
||||
// Description : For reading and writing basic PNM files--*.pbm,
|
||||
// *.ppm, *.pnm.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA PNMFileTypePNM : public PNMFileType {
|
||||
public:
|
||||
PNMFileTypePNM();
|
||||
|
||||
virtual string get_name() const;
|
||||
|
||||
virtual int get_num_extensions() const;
|
||||
virtual string get_extension(int n) const;
|
||||
virtual string get_suggested_extension() const;
|
||||
|
||||
virtual bool has_magic_number() const;
|
||||
virtual bool matches_magic_number(const string &magic_number) const;
|
||||
|
||||
virtual PNMReader *make_reader(FILE *file, bool owns_file = true,
|
||||
const string &magic_number = string());
|
||||
virtual PNMWriter *make_writer(FILE *file, bool owns_file = true);
|
||||
|
||||
public:
|
||||
class Reader : public PNMReader {
|
||||
public:
|
||||
Reader(PNMFileType *type, FILE *file, bool owns_file, string magic_number);
|
||||
|
||||
virtual bool supports_read_row() const;
|
||||
virtual bool read_row(xel *array, xelval *alpha);
|
||||
|
||||
private:
|
||||
int _ftype;
|
||||
};
|
||||
|
||||
class Writer : public PNMWriter {
|
||||
public:
|
||||
Writer(PNMFileType *type, FILE *file, bool owns_file);
|
||||
|
||||
virtual bool supports_write_row() const;
|
||||
virtual bool write_header();
|
||||
virtual bool write_row(xel *array, xelval *alpha);
|
||||
|
||||
private:
|
||||
int _pnm_format;
|
||||
};
|
||||
|
||||
|
||||
// The TypedWritable interface follows.
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_PNMFileTypePNM(const FactoryParams ¶ms);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
PNMFileType::init_type();
|
||||
register_type(_type_handle, "PNMFileTypePNM",
|
||||
PNMFileType::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -49,10 +49,10 @@
|
|||
#include "pnmFileTypeTGA.h"
|
||||
#include "config_pnmimagetypes.h"
|
||||
|
||||
#include <pnmFileTypeRegistry.h>
|
||||
#include <bamReader.h>
|
||||
#include "pnmFileTypeRegistry.h"
|
||||
#include "bamReader.h"
|
||||
#include "pnmimage_base.h"
|
||||
|
||||
#include <ppm.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char * const extensions_TGA[] = {
|
||||
|
|
|
|||
|
|
@ -19,15 +19,13 @@
|
|||
#ifndef PNMFILETYPETGA_H
|
||||
#define PNMFILETYPETGA_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "pandabase.h"
|
||||
|
||||
#include <pnmFileType.h>
|
||||
#include <pnmReader.h>
|
||||
#include <pnmWriter.h>
|
||||
|
||||
extern "C" {
|
||||
#include <ppmcmap.h>
|
||||
}
|
||||
#include "pnmFileType.h"
|
||||
#include "pnmReader.h"
|
||||
#include "pnmWriter.h"
|
||||
#include "ppmcmap.h"
|
||||
#include "pnmimage_base.h"
|
||||
|
||||
struct ImageHeader;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,15 +19,15 @@
|
|||
#include "pnmFileTypeTIFF.h"
|
||||
#include "config_pnmimagetypes.h"
|
||||
|
||||
#include <pnmFileTypeRegistry.h>
|
||||
#include <bamReader.h>
|
||||
#include "pnmFileTypeRegistry.h"
|
||||
#include "bamReader.h"
|
||||
#include "ppmcmap.h"
|
||||
|
||||
// Tiff will want to re-typedef these things.
|
||||
#define int32 tiff_int32
|
||||
#define uint32 tiff_uint32
|
||||
|
||||
extern "C" {
|
||||
#include "../pnm/ppmcmap.h"
|
||||
#include <tiff.h>
|
||||
#include <tiffio.h>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include "pnmFileTypeBMPReader.cxx"
|
||||
#include "pnmFileTypeBMPWriter.cxx"
|
||||
#include "pnmFileTypeIMG.cxx"
|
||||
#include "pnmFileTypePNM.cxx"
|
||||
#include "pnmFileTypeBMP.cxx"
|
||||
#include "pnmFileTypeRadiance.cxx"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue