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

Function bm_pcx_8bit_alloc_file

bitmap/pcx.cpp:91–177  ·  view source on GitHub ↗

load an 8bit pcx image

Source from the content-addressed store, hash-verified

89
90// load an 8bit pcx image
91int bm_pcx_8bit_alloc_file(CFILE *infile) {
92 int xmin, ymin, xmax, ymax;
93 int width, height;
94 int total, run = 0;
95 int i, t;
96 int src_bm;
97 uint8_t pred[256], pgreen[256], pblue[256];
98 uint8_t buf;
99 uint8_t temp[128];
100
101 cf_ReadBytes(temp, 4, infile);
102
103 if (temp[3] != 8)
104 return -1; // nope...bail
105
106 xmin = cf_ReadShort(infile);
107 ymin = cf_ReadShort(infile);
108 xmax = cf_ReadShort(infile);
109 ymax = cf_ReadShort(infile);
110
111 cf_ReadBytes(temp, 116, infile);
112
113 if (temp[65 - 12] != 1)
114 return -1; // Must be 8 bit only
115
116 width = 1 + xmax - xmin;
117 height = 1 + ymax - ymin;
118 total = width * height;
119
120 uint8_t *rawdata = (uint8_t *)mem_malloc(width * height);
121 if (!rawdata)
122 return -1; // no memory!
123
124 run = 0;
125 while (run < total) {
126 buf = cf_ReadByte(infile);
127 if (buf >= 192) {
128 uint8_t tb;
129 tb = cf_ReadByte(infile);
130 for (i = 0; i < (buf - 192); i++, run++)
131 rawdata[run] = tb;
132 } else {
133 rawdata[run] = buf;
134 run++;
135 }
136 }
137
138 cf_ReadByte(infile); // ignore pad
139
140 // Read palette
141
142 for (i = 0; i < 256; i++) {
143 pred[i] = cf_ReadByte(infile);
144 pgreen[i] = cf_ReadByte(infile);
145 pblue[i] = cf_ReadByte(infile);
146
147 pred[i] >>= 3;
148 pgreen[i] >>= 3;

Callers 1

bm_pcx_alloc_fileFunction · 0.85

Calls 5

cf_ReadBytesFunction · 0.85
cf_ReadShortFunction · 0.85
cf_ReadByteFunction · 0.85
bm_AllocBitmapFunction · 0.85
bm_dataFunction · 0.85

Tested by

no test coverage detected