Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pnmimage/pnmimage_base.h

Go to the documentation of this file.
00001 // Filename: pnmimage_base.h
00002 // Created by:  drose (14Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef PNMIMAGE_BASE_H
00020 #define PNMIMAGE_BASE_H
00021 
00022 // This header file make a few typedefs and other definitions
00023 // essential to everything in the PNMImage package.
00024 
00025 #include "pandabase.h"
00026 
00027 #include <string>
00028 
00029 // Since we no longer include pnm.h directly, we have to provide our
00030 // own definitions for xel and xelval.
00031 
00032 // For now, we have PGM_BIGGRAYS defined, which gives us 16-bit
00033 // channels.  Undefine this if you have memory problems and need to
00034 // use 8-bit channels instead.
00035 #define PGM_BIGGRAYS
00036 
00037 #ifdef PGM_BIGGRAYS
00038 typedef unsigned short gray;
00039 #define PGM_MAXMAXVAL 65535
00040 #else  // PGM_BIGGRAYS
00041 typedef unsigned char gray;
00042 #define PGM_MAXMAXVAL 255
00043 #endif  // PGM_BIGGRAYS
00044 
00045 #define PNM_MAXMAXVAL PGM_MAXMAXVAL
00046 
00047 struct pixel {
00048   gray r, g, b;
00049 };
00050 
00051 typedef gray pixval;
00052 typedef pixel xel;
00053 typedef gray xelval;
00054 
00055 // These macros are borrowed from ppm.h.
00056 
00057 #define PPM_GETR(p) ((p).r)
00058 #define PPM_GETG(p) ((p).g)
00059 #define PPM_GETB(p) ((p).b)
00060 
00061 #define PPM_PUTR(p,red) ((p).r = (red))
00062 #define PPM_PUTG(p,grn) ((p).g = (grn))
00063 #define PPM_PUTB(p,blu) ((p).b = (blu))
00064 
00065 #define PPM_ASSIGN(p,red,grn,blu) { (p).r = (red); (p).g = (grn); (p).b = (blu); }
00066 #define PPM_EQUAL(p,q) ( (p).r == (q).r && (p).g == (q).g && (p).b == (q).b )
00067 #define PNM_ASSIGN1(x,v) PPM_ASSIGN(x,0,0,v)
00068 
00069 #define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \
00070     PPM_ASSIGN( (newp), \
00071         ( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
00072         ( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
00073         ( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )
00074 
00075 
00076 // pnm defines these functions, and it's easier to emulate them than
00077 // to rewrite the code that calls them.
00078 EXPCL_PANDA void pm_message(const char *format, ...);
00079 EXPCL_PANDA void pm_error(const char *format, ...);  // doesn't return.
00080 
00081 EXPCL_PANDA int pm_maxvaltobits(int maxval);
00082 EXPCL_PANDA int pm_bitstomaxval(int bits);
00083 
00084 EXPCL_PANDA char *pm_allocrow(int cols, int size);
00085 EXPCL_PANDA void pm_freerow(char *itrow);
00086 
00087 EXPCL_PANDA int pm_readbigshort(istream *in, short *sP);
00088 EXPCL_PANDA int pm_writebigshort(ostream *out, short s);
00089 EXPCL_PANDA int pm_readbiglong(istream *in, long *lP);
00090 EXPCL_PANDA int pm_writebiglong(ostream *out, long l);
00091 EXPCL_PANDA int pm_readlittleshort(istream *in, short *sP);
00092 EXPCL_PANDA int pm_writelittleshort(ostream *out, short s);
00093 EXPCL_PANDA int pm_readlittlelong(istream *in, long *lP);
00094 EXPCL_PANDA int pm_writelittlelong(ostream *out, long l);
00095 
00096 
00097 // These ratios are used to compute the brightness of a colored pixel; they
00098 // define the relative contributions of each of the components.
00099 static const double lumin_red = 0.299;
00100 static const double lumin_grn = 0.587;
00101 static const double lumin_blu = 0.114;
00102 
00103 
00104 #endif

Generated on Fri May 2 00:43:09 2003 for Panda by doxygen1.3