00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _BMP_H_
00020 #define _BMP_H_
00021
00022 #include "pandabase.h"
00023 #include "pnmimage_base.h"
00024
00025
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
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
00104
00105
00106
00107
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
00129
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
00143 return bitsperline >> 3;
00144 }
00145
00146
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
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
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
00181