1 #include "..\include\raMain.h" 3 void bwtorgba(
unsigned char *b,
unsigned char *l,
int n)
14 void latorgba(
unsigned char *b,
unsigned char *a,
unsigned char *l,
int n)
26 unsigned char *b,
unsigned char *l,
int n)
33 l += 4; r++; g++; b++;
38 unsigned char *b,
unsigned char *a,
unsigned char *l,
int n)
45 l += 4; r++; g++; b++; a++;
65 static void ConvertShort(
unsigned short *array,
long length)
70 ptr = (
unsigned char *)array;
74 *array++ = (b1 << 8) | (b2);
78 static void ConvertLong(
unsigned *array,
long length)
80 unsigned b1, b2, b3, b4;
83 ptr = (
unsigned char *)array;
89 *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4);
92 static ImageRec *ImageOpen(
const char *fileName)
102 endianTest.testWord = 1;
103 if (endianTest.testByte[0] == 1) {
111 fprintf(stderr,
"Out of memory!\n");
114 if ((image->
file = fopen(fileName,
"rb")) == NULL) {
119 fread(image, 1, 12, image->
file);
122 ConvertShort(&image->
imagic, 6);
125 image->
tmp = (
unsigned char *)malloc(image->
xsize*256);
126 image->
tmpR = (
unsigned char *)malloc(image->
xsize*256);
127 image->
tmpG = (
unsigned char *)malloc(image->
xsize*256);
128 image->
tmpB = (
unsigned char *)malloc(image->
xsize*256);
129 if (image->
tmp == NULL || image->
tmpR == NULL || image->
tmpG == NULL ||
130 image->
tmpB == NULL) {
131 fprintf(stderr,
"Out of memory!\n");
135 if ((image->
type & 0xFF00) == 0x0100) {
136 x = image->
ysize * image->
zsize *
sizeof(unsigned);
137 image->
rowStart = (
unsigned *)malloc(x);
138 image->
rowSize = (
int *)malloc(x);
140 fprintf(stderr,
"Out of memory!\n");
143 image->
rleEnd = 512 + (2 * x);
144 fseek(image->
file, 512, SEEK_SET);
148 ConvertLong(image->
rowStart, x/(
int)
sizeof(
unsigned));
149 ConvertLong((
unsigned *)image->
rowSize, x/(
int)
sizeof(
int));
158 static void ImageClose(
ImageRec *image)
170 static void ImageGetRow(
ImageRec *image,
171 unsigned char *buf,
int y,
int z)
173 unsigned char *iPtr, *oPtr, pixel;
176 if ((image->
type & 0xFF00) == 0x0100) {
185 count = (int)(pixel & 0x7F);
203 fread(buf, 1, image->
xsize, image->
file);
208 unsigned char *base, *lptr;
209 unsigned char *rbuf, *gbuf, *bbuf, *abuf;
213 image = ImageOpen(name.c_str());
218 m_bmpi->bmiHeader.biWidth = image->
xsize;
219 m_bmpi->bmiHeader.biHeight = image->
ysize;
220 m_zSize = image->
zsize;
222 base = (
unsigned char *)malloc(image->
xsize*image->
ysize*
sizeof(
unsigned));
223 rbuf = (
unsigned char *)malloc(image->
xsize*
sizeof(
unsigned char));
224 gbuf = (
unsigned char *)malloc(image->
xsize*
sizeof(
unsigned char));
225 bbuf = (
unsigned char *)malloc(image->
xsize*
sizeof(
unsigned char));
226 abuf = (
unsigned char *)malloc(image->
xsize*
sizeof(
unsigned char));
227 if(!base || !rbuf || !gbuf || !bbuf)
231 for (y=0; y<image->
ysize; y++) {
232 if (image->
zsize>=4) {
233 ImageGetRow(image,rbuf,y,0);
234 ImageGetRow(image,gbuf,y,1);
235 ImageGetRow(image,bbuf,y,2);
236 ImageGetRow(image,abuf,y,3);
238 lptr += image->
xsize;
239 }
else if(image->
zsize==3) {
240 ImageGetRow(image,rbuf,y,0);
241 ImageGetRow(image,gbuf,y,1);
242 ImageGetRow(image,bbuf,y,2);
244 lptr += image->
xsize;
245 }
else if(image->
zsize==2) {
246 ImageGetRow(image,rbuf,y,0);
247 ImageGetRow(image,abuf,y,1);
249 lptr += image->
xsize;
251 ImageGetRow(image,rbuf,y,0);
253 lptr += image->
xsize;
void rgbatorgba(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a, unsigned char *l, int n)
void bwtorgba(unsigned char *b, unsigned char *l, int n)
struct _ImageRec ImageRec
void rgbtorgba(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *l, int n)
void latorgba(unsigned char *b, unsigned char *a, unsigned char *l, int n)