00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef _BMP_H_
00016 #define _BMP_H_
00017
00018 #include "pandabase.h"
00019 #include "pnmimage_base.h"
00020
00021
00022 static unsigned long BMPlenfileheader(int classv);
00023 static unsigned long BMPleninfoheader(int classv);
00024 static unsigned long BMPlenrgbtable(int classv, unsigned long bitcount);
00025 static unsigned long BMPlenline(int classv, unsigned long bitcount, unsigned long x);
00026 static unsigned long BMPlenbits(int classv, unsigned long bitcount, unsigned long x, unsigned long y);
00027 static unsigned long BMPlenfile(int classv, unsigned long bitcount, unsigned long x, unsigned long y);
00028 static unsigned long BMPoffbits(int classv, unsigned long bitcount);
00029
00030
00031
00032
00033 #define C_WIN 1
00034 #define C_OS2 2
00035
00036 static char er_internal[] = "%s: internal error!";
00037
00038 static unsigned long
00039 BMPlenfileheader(int classv)
00040 {
00041 switch (classv)
00042 {
00043 case C_WIN:
00044 return 14;
00045 case C_OS2:
00046 return 14;
00047 default:
00048 pm_error(er_internal, "BMPlenfileheader");
00049 return 0;
00050 }
00051 }
00052
00053 static unsigned long
00054 BMPleninfoheader(int classv)
00055 {
00056 switch (classv)
00057 {
00058 case C_WIN:
00059 return 40;
00060 case C_OS2:
00061 return 12;
00062 default:
00063 pm_error(er_internal, "BMPleninfoheader");
00064 return 0;
00065 }
00066 }
00067
00068 static unsigned long
00069 BMPlenrgbtable(int classv, unsigned long bitcount)
00070 {
00071 unsigned long lenrgb;
00072
00073 if (bitcount > 8) {
00074 return 0;
00075 }
00076
00077 if (bitcount < 1)
00078 {
00079 pm_error(er_internal, "BMPlenrgbtable");
00080 return 0;
00081 }
00082 switch (classv)
00083 {
00084 case C_WIN:
00085 lenrgb = 4;
00086 break;
00087 case C_OS2:
00088 lenrgb = 3;
00089 break;
00090 default:
00091 pm_error(er_internal, "BMPlenrgbtable");
00092 return 0;
00093 }
00094
00095 return (1 << bitcount) * lenrgb;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105 static unsigned long
00106 BMPlenline(int classv, unsigned long bitcount, unsigned long x)
00107 {
00108 unsigned long bitsperline;
00109
00110 switch (classv)
00111 {
00112 case C_WIN:
00113 break;
00114 case C_OS2:
00115 break;
00116 default:
00117 pm_error(er_internal, "BMPlenline");
00118 return 0;
00119 }
00120
00121 bitsperline = x * bitcount;
00122
00123
00124
00125
00126
00127 if ((bitsperline % 32) != 0)
00128 {
00129 bitsperline += (32 - (bitsperline % 32));
00130 }
00131
00132 if ((bitsperline % 32) != 0)
00133 {
00134 pm_error(er_internal, "BMPlenline");
00135 return 0;
00136 }
00137
00138
00139 return bitsperline >> 3;
00140 }
00141
00142
00143 static unsigned long
00144 BMPlenbits(
00145 int classv,
00146 unsigned long bitcount,
00147 unsigned long x,
00148 unsigned long y)
00149 {
00150 return y * BMPlenline(classv, bitcount, x);
00151 }
00152
00153
00154 static unsigned long
00155 BMPoffbits(
00156 int classv,
00157 unsigned long bitcount)
00158 {
00159 return BMPlenfileheader(classv)
00160 + BMPleninfoheader(classv)
00161 + BMPlenrgbtable(classv, bitcount);
00162 }
00163
00164
00165 static unsigned long
00166 BMPlenfile(
00167 int classv,
00168 unsigned long bitcount,
00169 unsigned long x,
00170 unsigned long y)
00171 {
00172 return BMPoffbits(classv, bitcount)
00173 + BMPlenbits(classv, bitcount, x, y);
00174 }
00175
00176 #endif
00177