comparison tools/libgfx.c @ 1622:009a3e3c54bf

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 16 May 2018 13:49:40 +0300
parents 9aaa8ee24626
children 4c89840a5c89
comparison
equal deleted inserted replaced
1621:9aaa8ee24626 1622:009a3e3c54bf
297 } 297 }
298 298
299 299
300 int dmWriteRAWImageFILE(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) 300 int dmWriteRAWImageFILE(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec)
301 { 301 {
302 int xc, yc, plane, res; 302 int res;
303 DMBitStreamContext bs; 303 DMBitStreamContext bs;
304 304
305 if ((res = dmInitBitStreamFILE(&bs, fp)) != DMERR_OK) 305 if ((res = dmInitBitStreamFILE(&bs, fp)) != DMERR_OK)
306 return res; 306 return res;
307 307
308 if (spec->planar) 308 if (spec->planar)
309 { 309 {
310 // Output bitplanes in planar format 310 // Output bitplanes in planar format
311 // (each plane of line sequentially) 311 // (each plane of line sequentially)
312 for (yc = 0; yc < img->height; yc++) 312 for (int yc = 0; yc < img->height; yc++)
313 for (plane = 0; plane < spec->nplanes; plane++) 313 for (int plane = 0; plane < spec->nplanes; plane++)
314 { 314 {
315 Uint8 *sp = img->data + yc * img->pitch; 315 Uint8 *sp = img->data + yc * img->pitch;
316 for (xc = 0; xc < img->width; xc++) 316 for (int xc = 0; xc < img->width; xc++)
317 { 317 {
318 if (!dmPutBits(&bs, (sp[xc] & (1 << plane)) ? 1 : 0, 1)) 318 if (!dmPutBits(&bs, (sp[xc] & (1 << plane)) ? 1 : 0, 1))
319 return DMERR_FWRITE; 319 return DMERR_FWRITE;
320 } 320 }
321 } 321 }
322 } 322 }
323 else 323 else
324 { 324 {
325 // Output each bitplane in sequence 325 // Output each bitplane in sequence
326 for (plane = 0; plane < spec->nplanes; plane++) 326 for (int plane = 0; plane < spec->nplanes; plane++)
327 for (yc = 0; yc < img->height; yc++) 327 for (int yc = 0; yc < img->height; yc++)
328 { 328 {
329 Uint8 *sp = img->data + yc * img->pitch; 329 Uint8 *sp = img->data + yc * img->pitch;
330 for (xc = 0; xc < img->width; xc++) 330 for (int xc = 0; xc < img->width; xc++)
331 { 331 {
332 if (!dmPutBits(&bs, (sp[xc] & (1 << plane)) ? 1 : 0, 1)) 332 if (!dmPutBits(&bs, (sp[xc] & (1 << plane)) ? 1 : 0, 1))
333 return DMERR_FWRITE; 333 return DMERR_FWRITE;
334 } 334 }
335 } 335 }
1599 else 1599 else
1600 return dmf_read_str(fp, buf, bufLen); 1600 return dmf_read_str(fp, buf, bufLen);
1601 } 1601 }
1602 1602
1603 1603
1604 static inline Uint8 dmDecodeBit(const Uint8 *src, const int xc) 1604 static inline Uint8 dmDecodeBit(const Uint8 *buf, const int xc)
1605 { 1605 {
1606 return (buf[xc / 8] >> (7 - (xc & 7))) & 1; 1606 return (buf[xc / 8] >> (7 - (xc & 7))) & 1;
1607 } 1607 }
1608 1608
1609 1609