comparison src/libgfx.c @ 1288:6c8b19d1d196

More work on libgfx.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Aug 2017 17:32:19 +0300
parents 32051ad352c8
children e7dc9bb9777e
comparison
equal deleted inserted replaced
1287:32051ad352c8 1288:6c8b19d1d196
135 135
136 return TRUE; 136 return TRUE;
137 } 137 }
138 138
139 139
140 int dmImageConvertTo(DMImage **dst, const DMImage *src, const DMImageSpec *spec)
141 {
142 return DMERR_OK;
143 }
144
145
140 int dmWriteImageData(DMImage *img, void *cbdata, int (*writeRowCB)(void *, Uint8 *, size_t), const DMImageSpec *spec) 146 int dmWriteImageData(DMImage *img, void *cbdata, int (*writeRowCB)(void *, Uint8 *, size_t), const DMImageSpec *spec)
141 { 147 {
142 int x, y, yscale, xscale, res = 0, rowSize, rowWidth; 148 int x, y, yscale, xscale, res = 0, rowSize, rowWidth;
143 Uint8 *row = NULL; 149 Uint8 *row = NULL;
144 150
252 258
253 return DMERR_OK; 259 return DMERR_OK;
254 } 260 }
255 261
256 262
257 int dmWriteRAWImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec) 263 int dmWriteRAWImageFILE(FILE *fp, DMImage *img, const DMImageSpec *spec)
258 { 264 {
259 int xc, yc, plane, res; 265 int xc, yc, plane, res;
260 DMBitStreamContext bs; 266 DMBitStreamContext bs;
261 267
262 if ((res = dmInitBitStreamFILE(&bs, fp)) != DMERR_OK) 268 if ((res = dmInitBitStreamFILE(&bs, fp)) != DMERR_OK)
297 303
298 return dmFlushBitStream(&bs); 304 return dmFlushBitStream(&bs);
299 } 305 }
300 306
301 307
302 int dmWriteRAWImage(const char *filename, DMImage *img, DMImageSpec *spec) 308 int dmWriteRAWImage(const char *filename, DMImage *img, const DMImageSpec *spec)
303 { 309 {
304 FILE *fp; 310 FILE *fp;
305 int res; 311 int res;
306 312
307 if ((fp = fopen(filename, "wb")) == NULL) 313 if ((fp = fopen(filename, "wb")) == NULL)
325 else 331 else
326 return DMERR_FWRITE; 332 return DMERR_FWRITE;
327 } 333 }
328 334
329 335
330 int dmWritePPMImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec) 336 int dmWritePPMImageFILE(FILE *fp, DMImage *img, const DMImageSpec *spec)
331 { 337 {
338 DMImageSpec tmpSpec;
339
332 // Write PPM header 340 // Write PPM header
333 fprintf(fp, 341 fprintf(fp,
334 "P6\n%d %d\n255\n", 342 "P6\n%d %d\n255\n",
335 img->width * spec->scaleX, 343 img->width * spec->scaleX,
336 img->height * spec->scaleY); 344 img->height * spec->scaleY);
337 345
338 // Write image data 346 // Write image data
339 spec->format = DM_IFMT_RGB; 347 memcpy(&tmpSpec, spec, sizeof(DMImageSpec));
340 return dmWriteImageData(img, (void *) fp, dmWritePPMRow, spec); 348 tmpSpec.format = DM_IFMT_RGB;
341 } 349 return dmWriteImageData(img, (void *) fp, dmWritePPMRow, &tmpSpec);
342 350 }
343 351
344 int dmWritePPMImage(const char *filename, DMImage *img, DMImageSpec *spec) 352
353 int dmWritePPMImage(const char *filename, DMImage *img, const DMImageSpec *spec)
345 { 354 {
346 FILE *fp; 355 FILE *fp;
347 int res; 356 int res;
348 357
349 // Create output file 358 // Create output file
374 383
375 return DMERR_OK; 384 return DMERR_OK;
376 } 385 }
377 386
378 387
379 int dmWritePNGImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec) 388 int dmWritePNGImageFILE(FILE *fp, DMImage *img, const DMImageSpec *spec)
380 { 389 {
381 png_structp png_ptr = NULL; 390 png_structp png_ptr = NULL;
382 png_infop info_ptr = NULL; 391 png_infop info_ptr = NULL;
383 int fmt, res = DMERR_OK; 392 int fmt, res = DMERR_OK;
384 393
481 490
482 return res; 491 return res;
483 } 492 }
484 493
485 494
486 int dmWritePNGImage(const char *filename, DMImage *img, DMImageSpec *spec) 495 int dmWritePNGImage(const char *filename, DMImage *img, const DMImageSpec *spec)
487 { 496 {
488 int res; 497 int res;
489 FILE *fp; 498 FILE *fp;
490 499
491 if ((fp = fopen(filename, "wb")) == NULL) 500 if ((fp = fopen(filename, "wb")) == NULL)
697 706
698 707
699 typedef struct 708 typedef struct
700 { 709 {
701 Uint8 manufacturer, // always 0x0a 710 Uint8 manufacturer, // always 0x0a
702 version, // Z-Soft PCX Paintbrush version: 711 version, // Z-Soft PC Paintbrush version:
703 // 0 = v2.5, 2 = v2.8 with palette, 3 = v2.8 without palette, 5 = v3.0 or better 712 // 0 = v2.5
713 // 2 = v2.8 with palette,
714 // 3 = v2.8 without palette
715 // 4 = PC Paintbrush for Windows
716 // 5 = v3.0 or better
704 encoding, // usually 0x01 = RLE, 0x00 = uncompressed 717 encoding, // usually 0x01 = RLE, 0x00 = uncompressed
705 bitsPerPlane; // bits per pixel per plane 718 bitsPerPlane; // bits per pixel per plane
706 719
707 Uint16 xmin, ymin, xmax, ymax; 720 Uint16 xmin, ymin, xmax, ymax;
708 Uint16 hres, vres; // resolution in DPI, can be image dimensions as well. 721 Uint16 hres, vres; // resolution in DPI, can be image dimensions as well.
807 820
808 return DMERR_OK; 821 return DMERR_OK;
809 } 822 }
810 823
811 824
812 int dmWritePCXImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec) 825 int dmWritePCXImageFILE(FILE *fp, DMImage *img, const DMImageSpec *spec)
813 { 826 {
814 DMPCXData pcx; 827 DMPCXData pcx;
815 DMPCXHeader hdr; 828 DMPCXHeader hdr;
816 int res; 829 int res;
817 830
821 pcx.header = &hdr; 834 pcx.header = &hdr;
822 pcx.fp = fp; 835 pcx.fp = fp;
823 836
824 // Create PCX header 837 // Create PCX header
825 dmMemset(&hdr, 0, sizeof(hdr)); 838 dmMemset(&hdr, 0, sizeof(hdr));
826 if (spec->paletted) 839 if (spec->paletted && img->pal != NULL)
827 { 840 {
828 for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++) 841 for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++)
829 { 842 {
830 hdr.colorMap[i].r = img->pal[i].r; 843 hdr.colorMap[i].r = img->pal[i].r;
831 hdr.colorMap[i].g = img->pal[i].g; 844 hdr.colorMap[i].g = img->pal[i].g;
936 dmFree(pcx.buf); 949 dmFree(pcx.buf);
937 return res; 950 return res;
938 } 951 }
939 952
940 953
941 int dmWritePCXImage(const char *filename, DMImage *img, DMImageSpec *spec) 954 int dmWritePCXImage(const char *filename, DMImage *img, const DMImageSpec *spec)
942 { 955 {
943 FILE *fp; 956 FILE *fp;
944 int res; 957 int res;
945 958
946 if ((fp = fopen(filename, "wb")) == NULL) 959 if ((fp = fopen(filename, "wb")) == NULL)
1824 1837
1825 1838
1826 static int fmtProbePCX(const Uint8 *buf, const size_t len) 1839 static int fmtProbePCX(const Uint8 *buf, const size_t len)
1827 { 1840 {
1828 if (len > 128 + 32 && 1841 if (len > 128 + 32 &&
1829 buf[0] == 10 && 1842
1830 (buf[1] == 5 || buf[1] == 2 || buf[1] == 3) && 1843 (buf[1] == 5 || buf[1] == 2 || buf[1] == 3) &&
1831 buf[2] == 1 && 1844 buf[2] == 1 &&
1832 (buf[3] == 8 || buf[3] == 4 || buf[3] == 3 || buf[3] == 1) && 1845 (buf[3] == 8 || buf[3] == 4 || buf[3] == 3 || buf[3] == 1) &&
1833 buf[65] >= 1 && buf[65] <= 4) 1846 buf[65] >= 1 && buf[65] <= 4)
1834 return DM_PROBE_SCORE_GOOD; 1847 return DM_PROBE_SCORE_GOOD;