Mercurial > hg > batmud > maputils
comparison map2ppm.c @ 1771:72adabd8e746
More cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 27 Oct 2017 05:10:08 +0300 |
parents | cc59f80b0e78 |
children | 79dd960610cb |
comparison
equal
deleted
inserted
replaced
1770:cc59f80b0e78 | 1771:72adabd8e746 |
---|---|
143 } | 143 } |
144 | 144 |
145 | 145 |
146 int writeImageData(MapBlock *map, void *cbdata, BOOL (*writeRowCB)(void *, uint8_t *, size_t), int scale) | 146 int writeImageData(MapBlock *map, void *cbdata, BOOL (*writeRowCB)(void *, uint8_t *, size_t), int scale) |
147 { | 147 { |
148 int x, y, yscale, xscale, res = 0; | 148 int res = 0; |
149 uint8_t *row = NULL; | 149 uint8_t *row = NULL; |
150 | 150 |
151 // Allocate memory for row buffer | 151 // Allocate memory for row buffer |
152 if ((row = th_malloc(map->width * 3 * scale + 16)) == NULL) | 152 if ((row = th_malloc(map->width * 3 * scale + 16)) == NULL) |
153 { | 153 { |
154 res = -16; | 154 res = -16; |
155 goto done; | 155 goto done; |
156 } | 156 } |
157 | 157 |
158 for (y = 0; y < map->height; y++) | 158 for (int y = 0; y < map->height; y++) |
159 { | 159 { |
160 uint8_t *ptr = row; | 160 uint8_t *ptr = row; |
161 | 161 |
162 for (x = 0; x < map->width; x++) | 162 for (int x = 0; x < map->width; x++) |
163 { | 163 { |
164 int qr, qg, qb, c; | 164 int qr, qg, qb, c; |
165 qr = 255; qg = qb = 0; | 165 qr = 255; qg = qb = 0; |
166 c = (uint8_t) map->data[(y * map->scansize) + x]; | 166 c = (uint8_t) map->data[(y * map->scansize) + x]; |
167 | 167 |
200 qg = mapPieces[c].g; | 200 qg = mapPieces[c].g; |
201 qb = mapPieces[c].b; | 201 qb = mapPieces[c].b; |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 for (xscale = 0; xscale < scale; xscale++) | 205 for (int xscale = 0; xscale < scale; xscale++) |
206 { | 206 { |
207 *ptr++ = qr; | 207 *ptr++ = qr; |
208 *ptr++ = qg; | 208 *ptr++ = qg; |
209 *ptr++ = qb; | 209 *ptr++ = qb; |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 for (yscale = 0; yscale < scale; yscale++) | 213 for (int yscale = 0; yscale < scale; yscale++) |
214 { | 214 { |
215 if (!writeRowCB(cbdata, row, map->width * 3 * scale)) | 215 if (!writeRowCB(cbdata, row, map->width * 3 * scale)) |
216 { | 216 { |
217 res = -32; | 217 res = -32; |
218 goto done; | 218 goto done; |
405 | 405 |
406 fclose(outFile); | 406 fclose(outFile); |
407 | 407 |
408 mapBlockFree(map); | 408 mapBlockFree(map); |
409 | 409 |
410 exit(ret); | |
411 return ret; | 410 return ret; |
412 } | 411 } |