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

panda/src/pnmimagetypes/bmp.h

Go to the documentation of this file.
00001 /* Filename: bmp.h
00002  * Created by:  
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 _BMP_H_
00020 #define _BMP_H_
00021 
00022 #include "pandabase.h"
00023 #include "pnmimage_base.h"
00024 
00025 /* prototypes */
00026 static unsigned long BMPlenfileheader(int classv);
00027 static unsigned long BMPleninfoheader(int classv);
00028 static unsigned long BMPlenrgbtable(int classv, unsigned long bitcount);
00029 static unsigned long BMPlenline(int classv, unsigned long bitcount, unsigned long x);
00030 static unsigned long BMPlenbits(int classv, unsigned long bitcount, unsigned long x, unsigned long y);
00031 static unsigned long BMPlenfile(int classv, unsigned long bitcount, unsigned long x, unsigned long y);
00032 static unsigned long BMPoffbits(int classv, unsigned long bitcount);
00033 /*
00034  * Classves of BMP files
00035  */
00036 
00037 #define C_WIN   1
00038 #define C_OS2   2
00039 
00040 static char     er_internal[] = "%s: internal error!";
00041 
00042 static unsigned long
00043 BMPlenfileheader(int classv)
00044 {
00045         switch (classv)
00046         {
00047         case C_WIN:
00048                 return 14;
00049         case C_OS2:
00050                 return 14;
00051         default:
00052                 pm_error(er_internal, "BMPlenfileheader");
00053                 return 0;
00054         }
00055 }
00056 
00057 static unsigned long
00058 BMPleninfoheader(int classv)
00059 {
00060         switch (classv)
00061         {
00062         case C_WIN:
00063                 return 40;
00064         case C_OS2:
00065                 return 12;
00066         default:
00067                 pm_error(er_internal, "BMPleninfoheader");
00068                 return 0;
00069         }
00070 }
00071 
00072 static unsigned long
00073 BMPlenrgbtable(int classv, unsigned long bitcount)
00074 {
00075         unsigned long   lenrgb;
00076 
00077         if (bitcount > 8) {
00078           return 0;
00079         }
00080 
00081         if (bitcount < 1)
00082         {
00083                 pm_error(er_internal, "BMPlenrgbtable");
00084                 return 0;
00085         }
00086         switch (classv)
00087         {
00088         case C_WIN:
00089                 lenrgb = 4;
00090                 break;
00091         case C_OS2:
00092                 lenrgb = 3;
00093                 break;
00094         default:
00095                 pm_error(er_internal, "BMPlenrgbtable");
00096                 return 0;
00097         }
00098 
00099         return (1 << bitcount) * lenrgb;
00100 }
00101 
00102 /*
00103  * length, in bytes, of a line of the image
00104  *
00105  * Evidently each row is padded on the right as needed to make it a
00106  * multiple of 4 bytes long.  This appears to be true of both
00107  * OS/2 and Windows BMP files.
00108  */
00109 static unsigned long
00110 BMPlenline(int classv, unsigned long bitcount, unsigned long x)
00111 {
00112         unsigned long   bitsperline;
00113 
00114         switch (classv)
00115         {
00116         case C_WIN:
00117                 break;
00118         case C_OS2:
00119                 break;
00120         default:
00121                 pm_error(er_internal, "BMPlenline");
00122                 return 0;
00123         }
00124 
00125         bitsperline = x * bitcount;
00126 
00127         /*
00128          * if bitsperline is not a multiple of 32, then round
00129          * bitsperline up to the next multiple of 32.
00130          */
00131         if ((bitsperline % 32) != 0)
00132         {
00133                 bitsperline += (32 - (bitsperline % 32));
00134         }
00135 
00136         if ((bitsperline % 32) != 0)
00137         {
00138                 pm_error(er_internal, "BMPlenline");
00139                 return 0;
00140         }
00141 
00142         /* number of bytes per line == bitsperline/8 */
00143         return bitsperline >> 3;
00144 }
00145 
00146 /* return the number of bytes used to store the image bits */
00147 static unsigned long
00148 BMPlenbits(
00149         int             classv,
00150         unsigned long   bitcount,
00151         unsigned long   x,
00152         unsigned long   y)
00153 {
00154         return y * BMPlenline(classv, bitcount, x);
00155 }
00156 
00157 /* return the offset to the BMP image bits */
00158 static unsigned long
00159 BMPoffbits(
00160         int             classv,
00161         unsigned long   bitcount)
00162 {
00163         return BMPlenfileheader(classv)
00164                 + BMPleninfoheader(classv)
00165                 + BMPlenrgbtable(classv, bitcount);
00166 }
00167 
00168 /* return the size of the BMP file in bytes */
00169 static unsigned long
00170 BMPlenfile(
00171         int             classv,
00172         unsigned long   bitcount,
00173         unsigned long   x,
00174         unsigned long   y)
00175 {
00176         return BMPoffbits(classv, bitcount)
00177                 + BMPlenbits(classv, bitcount, x, y);
00178 }
00179 
00180 #endif /* _BMP_H_ */
00181 

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