MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / bm_pcx_24bit_alloc_file

Function bm_pcx_24bit_alloc_file

bitmap/pcx.cpp:180–316  ·  view source on GitHub ↗

load a 24bit pcx image

Source from the content-addressed store, hash-verified

178
179// load a 24bit pcx image
180int bm_pcx_24bit_alloc_file(CFILE *infile) {
181 int xmin, ymin, xmax, ymax;
182 int width, height;
183 int total, run = 0;
184 int i, t;
185 int src_bm;
186 uint8_t buf;
187 uint8_t temp[128];
188
189 cf_ReadBytes(temp, 4, infile);
190
191 if (temp[1] < 5) {
192 // need at least version 5.0f
193 mprintf(0, "PCXLoad: PCX Not version 5.0 or greater\n");
194 return -1;
195 }
196
197 if (temp[3] != 8) {
198 // need 8 bits per pixel
199 mprintf(0, "PCXLoad: PCX Not 8 bpp\n");
200 return -1; // nope...bail
201 }
202
203 xmin = cf_ReadShort(infile);
204 ymin = cf_ReadShort(infile);
205 xmax = cf_ReadShort(infile);
206 ymax = cf_ReadShort(infile);
207
208 cf_ReadBytes(temp, 116, infile);
209
210#define PCXHEADER_OFFSET 12
211
212 if (temp[65 - PCXHEADER_OFFSET] != 3) {
213 // Must have 3 planes
214 mprintf(0, "PCXLoad: PCX Not 3 Planes for 24bit encoding\n");
215 return -1;
216 }
217
218 width = 1 + xmax - xmin;
219 height = 1 + ymax - ymin;
220
221 // Determine BytesPerLine
222 cfseek(infile, 66, SEEK_SET);
223 int BytesPerLine = cf_ReadShort(infile);
224 cfseek(infile, 128, SEEK_SET);
225
226 // scanline length
227 total = 3 * BytesPerLine;
228
229 uint8_t *rawdata = (uint8_t *)mem_malloc(total * height);
230 if (!rawdata) {
231 mprintf(0, "PCXLoad: Out of memory\n");
232 return -1; // no memory!
233 }
234
235 // Load in the data
236 // the data is divided into scanlines
237 // the first scanline is line 0's red

Callers 1

bm_pcx_alloc_fileFunction · 0.85

Calls 7

cf_ReadBytesFunction · 0.85
cf_ReadShortFunction · 0.85
cfseekFunction · 0.85
cf_ReadByteFunction · 0.85
bm_AllocBitmapFunction · 0.85
bm_dataFunction · 0.85
GR_RGB16Function · 0.85

Tested by

no test coverage detected