Mercurial > hg > dmlib
comparison tools/libgfx.c @ 2157:9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
and DMImageWriteSpec to 'pixfmt' to be more precise about their meaning.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 04 Jun 2019 16:27:09 +0300 |
parents | e6ec7fad9ce2 |
children | 455a3849b8ac |
comparison
equal
deleted
inserted
replaced
2156:e6ec7fad9ce2 | 2157:9a9493809b3a |
---|---|
121 | 121 |
122 int dmImageGetBytesPerPixel(const int format) | 122 int dmImageGetBytesPerPixel(const int format) |
123 { | 123 { |
124 switch (format) | 124 switch (format) |
125 { | 125 { |
126 case DM_COLFMT_GRAYSCALE : return 1; | 126 case DM_PIXFMT_GRAYSCALE : return 1; |
127 case DM_COLFMT_PALETTE : return 1; | 127 case DM_PIXFMT_PALETTE : return 1; |
128 case DM_COLFMT_RGB : return 3; | 128 case DM_PIXFMT_RGB : return 3; |
129 case DM_COLFMT_RGBA : return 4; | 129 case DM_PIXFMT_RGBA : return 4; |
130 default : return -1; | 130 default : return -1; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 | 134 |
144 if (img == NULL) | 144 if (img == NULL) |
145 return NULL; | 145 return NULL; |
146 | 146 |
147 img->width = width; | 147 img->width = width; |
148 img->height = height; | 148 img->height = height; |
149 img->format = format; | 149 img->pixfmt = format; |
150 img->bpp = (bpp <= 0) ? dmImageGetBitsPerPixel(format) : bpp; | 150 img->bpp = (bpp <= 0) ? dmImageGetBitsPerPixel(format) : bpp; |
151 img->pitch = (width * img->bpp) / 8; | 151 img->pitch = (width * img->bpp) / 8; |
152 img->size = img->pitch * img->height; | 152 img->size = img->pitch * img->height; |
153 img->aspect = -1; | 153 img->aspect = -1; |
154 | 154 |
335 int x, y, yscale, xscale, res = 0, rowSize, rowWidth; | 335 int x, y, yscale, xscale, res = 0, rowSize, rowWidth; |
336 Uint8 *row = NULL; | 336 Uint8 *row = NULL; |
337 | 337 |
338 // Allocate memory for row buffer | 338 // Allocate memory for row buffer |
339 rowWidth = img->width * spec->scaleX; | 339 rowWidth = img->width * spec->scaleX; |
340 rowSize = rowWidth * dmImageGetBytesPerPixel(spec->format); | 340 rowSize = rowWidth * dmImageGetBytesPerPixel(spec->pixfmt); |
341 | 341 |
342 if ((row = dmMalloc(rowSize + 16)) == NULL) | 342 if ((row = dmMalloc(rowSize + 16)) == NULL) |
343 { | 343 { |
344 res = DMERR_MALLOC; | 344 res = DMERR_MALLOC; |
345 goto done; | 345 goto done; |
351 Uint8 *ptr1 = row, | 351 Uint8 *ptr1 = row, |
352 *ptr2 = ptr1 + rowWidth, | 352 *ptr2 = ptr1 + rowWidth, |
353 *ptr3 = ptr2 + rowWidth, | 353 *ptr3 = ptr2 + rowWidth, |
354 *ptr4 = ptr3 + rowWidth; | 354 *ptr4 = ptr3 + rowWidth; |
355 | 355 |
356 if (img->format == DM_COLFMT_GRAYSCALE) | 356 if (img->pixfmt == DM_PIXFMT_GRAYSCALE) |
357 { | 357 { |
358 for (x = 0; x < img->width; x++) | 358 for (x = 0; x < img->width; x++) |
359 { | 359 { |
360 Uint8 c = img->data[(y * img->pitch) + (x * img->bpp) / 8]; | 360 Uint8 c = img->data[(y * img->pitch) + (x * img->bpp) / 8]; |
361 | 361 |
362 switch (spec->format) | 362 switch (spec->pixfmt) |
363 { | 363 { |
364 case DM_COLFMT_PALETTE: | 364 case DM_PIXFMT_PALETTE: |
365 case DM_COLFMT_GRAYSCALE: | 365 case DM_PIXFMT_GRAYSCALE: |
366 for (xscale = 0; xscale < spec->scaleX; xscale++) | 366 for (xscale = 0; xscale < spec->scaleX; xscale++) |
367 *ptr1++ = c; | 367 *ptr1++ = c; |
368 break; | 368 break; |
369 | 369 |
370 case DM_COLFMT_RGBA: | 370 case DM_PIXFMT_RGBA: |
371 if (spec->planar) | 371 if (spec->planar) |
372 { | 372 { |
373 for (xscale = 0; xscale < spec->scaleX; xscale++) | 373 for (xscale = 0; xscale < spec->scaleX; xscale++) |
374 { | 374 { |
375 *ptr1++ = c; | 375 *ptr1++ = c; |
388 *ptr1++ = 0xff; | 388 *ptr1++ = 0xff; |
389 } | 389 } |
390 } | 390 } |
391 break; | 391 break; |
392 | 392 |
393 case DM_COLFMT_RGB: | 393 case DM_PIXFMT_RGB: |
394 if (spec->planar) | 394 if (spec->planar) |
395 { | 395 { |
396 for (xscale = 0; xscale < spec->scaleX; xscale++) | 396 for (xscale = 0; xscale < spec->scaleX; xscale++) |
397 { | 397 { |
398 *ptr1++ = c; | 398 *ptr1++ = c; |
416 goto done; | 416 goto done; |
417 } | 417 } |
418 } | 418 } |
419 } | 419 } |
420 else | 420 else |
421 if (img->format == DM_COLFMT_PALETTE) | 421 if (img->pixfmt == DM_PIXFMT_PALETTE) |
422 { | 422 { |
423 for (x = 0; x < img->width; x++) | 423 for (x = 0; x < img->width; x++) |
424 { | 424 { |
425 Uint8 c = img->data[(y * img->pitch) + (x * img->bpp) / 8], | 425 Uint8 c = img->data[(y * img->pitch) + (x * img->bpp) / 8], |
426 qr, qg, qb, qa; | 426 qr, qg, qb, qa; |
429 { | 429 { |
430 res = DMERR_INVALID_DATA; | 430 res = DMERR_INVALID_DATA; |
431 goto done; | 431 goto done; |
432 } | 432 } |
433 | 433 |
434 switch (spec->format) | 434 switch (spec->pixfmt) |
435 { | 435 { |
436 case DM_COLFMT_PALETTE: | 436 case DM_PIXFMT_PALETTE: |
437 case DM_COLFMT_GRAYSCALE: | 437 case DM_PIXFMT_GRAYSCALE: |
438 for (xscale = 0; xscale < spec->scaleX; xscale++) | 438 for (xscale = 0; xscale < spec->scaleX; xscale++) |
439 *ptr1++ = c; | 439 *ptr1++ = c; |
440 break; | 440 break; |
441 | 441 |
442 case DM_COLFMT_RGBA: | 442 case DM_PIXFMT_RGBA: |
443 qr = img->pal->colors[c].r; | 443 qr = img->pal->colors[c].r; |
444 qg = img->pal->colors[c].g; | 444 qg = img->pal->colors[c].g; |
445 qb = img->pal->colors[c].b; | 445 qb = img->pal->colors[c].b; |
446 qa = img->pal->colors[c].a; | 446 qa = img->pal->colors[c].a; |
447 | 447 |
465 *ptr1++ = qa; | 465 *ptr1++ = qa; |
466 } | 466 } |
467 } | 467 } |
468 break; | 468 break; |
469 | 469 |
470 case DM_COLFMT_RGB: | 470 case DM_PIXFMT_RGB: |
471 qr = img->pal->colors[c].r; | 471 qr = img->pal->colors[c].r; |
472 qg = img->pal->colors[c].g; | 472 qg = img->pal->colors[c].g; |
473 qb = img->pal->colors[c].b; | 473 qb = img->pal->colors[c].b; |
474 | 474 |
475 if (spec->planar) | 475 if (spec->planar) |
497 goto done; | 497 goto done; |
498 } | 498 } |
499 } | 499 } |
500 } | 500 } |
501 else | 501 else |
502 if (img->format == DM_COLFMT_RGB || | 502 if (img->pixfmt == DM_PIXFMT_RGB || |
503 img->format == DM_COLFMT_RGBA) | 503 img->pixfmt == DM_PIXFMT_RGBA) |
504 { | 504 { |
505 Uint8 *sp = img->data + (y * img->pitch); | 505 Uint8 *sp = img->data + (y * img->pitch); |
506 | 506 |
507 for (x = 0; x < img->width; x++, sp += img->bpp / 8) | 507 for (x = 0; x < img->width; x++, sp += img->bpp / 8) |
508 switch (spec->format) | 508 switch (spec->pixfmt) |
509 { | 509 { |
510 case DM_COLFMT_RGBA: | 510 case DM_PIXFMT_RGBA: |
511 if (spec->planar) | 511 if (spec->planar) |
512 { | 512 { |
513 for (xscale = 0; xscale < spec->scaleX; xscale++) | 513 for (xscale = 0; xscale < spec->scaleX; xscale++) |
514 { | 514 { |
515 *ptr1++ = sp[0]; | 515 *ptr1++ = sp[0]; |
528 *ptr1++ = sp[3]; | 528 *ptr1++ = sp[3]; |
529 } | 529 } |
530 } | 530 } |
531 break; | 531 break; |
532 | 532 |
533 case DM_COLFMT_RGB: | 533 case DM_PIXFMT_RGB: |
534 if (spec->planar) | 534 if (spec->planar) |
535 { | 535 { |
536 for (xscale = 0; xscale < spec->scaleX; xscale++) | 536 for (xscale = 0; xscale < spec->scaleX; xscale++) |
537 { | 537 { |
538 *ptr1++ = sp[0]; | 538 *ptr1++ = sp[0]; |
584 prefix, img->height * spec->scaleY, | 584 prefix, img->height * spec->scaleY, |
585 prefix, spec->nplanes) < 0) | 585 prefix, spec->nplanes) < 0) |
586 return dmferror(fp); | 586 return dmferror(fp); |
587 | 587 |
588 if (spec->fmtid == DM_IMGFMT_ARAW && | 588 if (spec->fmtid == DM_IMGFMT_ARAW && |
589 img->format == DM_COLFMT_PALETTE && | 589 img->pixfmt == DM_PIXFMT_PALETTE && |
590 img->pal != NULL) | 590 img->pal != NULL) |
591 { | 591 { |
592 if (dmfprintf(fp, | 592 if (dmfprintf(fp, |
593 "%s_ncolors: dw.w %d\n" | 593 "%s_ncolors: dw.w %d\n" |
594 "%s_palette:\n", | 594 "%s_palette:\n", |
769 { | 769 { |
770 DMImageWriteSpec tmpSpec; | 770 DMImageWriteSpec tmpSpec; |
771 char *tmpFmt; | 771 char *tmpFmt; |
772 | 772 |
773 // Check if we can do this | 773 // Check if we can do this |
774 if ((spec->format == DM_COLFMT_PALETTE || spec->format == DM_COLFMT_GRAYSCALE) && | 774 if ((spec->pixfmt == DM_PIXFMT_PALETTE || spec->pixfmt == DM_PIXFMT_GRAYSCALE) && |
775 img->format != spec->format) | 775 img->pixfmt != spec->pixfmt) |
776 { | 776 { |
777 return dmError(DMERR_NOT_SUPPORTED, | 777 return dmError(DMERR_NOT_SUPPORTED, |
778 "Conversion of non-indexed image to indexed not supported yet.\n"); | 778 "Conversion of non-indexed image to indexed not supported yet.\n"); |
779 } | 779 } |
780 | 780 |
781 memcpy(&tmpSpec, spec, sizeof(DMImageWriteSpec)); | 781 memcpy(&tmpSpec, spec, sizeof(DMImageWriteSpec)); |
782 | 782 |
783 switch (spec->format) | 783 switch (spec->pixfmt) |
784 { | 784 { |
785 case DM_COLFMT_RGB: | 785 case DM_PIXFMT_RGB: |
786 case DM_COLFMT_RGBA: | 786 case DM_PIXFMT_RGBA: |
787 case DM_COLFMT_PALETTE: | 787 case DM_PIXFMT_PALETTE: |
788 tmpSpec.format = DM_COLFMT_RGB; | 788 tmpSpec.pixfmt = DM_PIXFMT_RGB; |
789 tmpFmt = "6"; | 789 tmpFmt = "6"; |
790 break; | 790 break; |
791 | 791 |
792 case DM_COLFMT_GRAYSCALE: | 792 case DM_PIXFMT_GRAYSCALE: |
793 tmpFmt = "5"; | 793 tmpFmt = "5"; |
794 break; | 794 break; |
795 | 795 |
796 default: | 796 default: |
797 return dmError(DMERR_NOT_SUPPORTED, | 797 return dmError(DMERR_NOT_SUPPORTED, |
800 | 800 |
801 // Write PPM header | 801 // Write PPM header |
802 char *tmp = dm_strdup_printf( | 802 char *tmp = dm_strdup_printf( |
803 "P%s\n%d %d\n255\n", | 803 "P%s\n%d %d\n255\n", |
804 tmpFmt, | 804 tmpFmt, |
805 img->width * spec->scaleX, | 805 img->width * tmpSpec.scaleX, |
806 img->height * spec->scaleY); | 806 img->height * tmpSpec.scaleY); |
807 | 807 |
808 if (tmp == NULL) | 808 if (tmp == NULL) |
809 return DMERR_MALLOC; | 809 return DMERR_MALLOC; |
810 | 810 |
811 dmfputs(tmp, fp); | 811 dmfputs(tmp, fp); |
876 goto error; | 876 goto error; |
877 } | 877 } |
878 | 878 |
879 switch (hdr1[1]) | 879 switch (hdr1[1]) |
880 { | 880 { |
881 case '6': itype = DM_COLFMT_RGB; break; | 881 case '6': itype = DM_PIXFMT_RGB; break; |
882 case '5': itype = DM_COLFMT_GRAYSCALE; break; | 882 case '5': itype = DM_PIXFMT_GRAYSCALE; break; |
883 default: | 883 default: |
884 res = dmError(DMERR_NOT_SUPPORTED, | 884 res = dmError(DMERR_NOT_SUPPORTED, |
885 "PPM: Unsupported PPM/PNM/PGM subtype.\n"); | 885 "PPM: Unsupported PPM/PNM/PGM subtype.\n"); |
886 goto error; | 886 goto error; |
887 } | 887 } |
979 png_structp png_ptr = NULL; | 979 png_structp png_ptr = NULL; |
980 png_infop info_ptr = NULL; | 980 png_infop info_ptr = NULL; |
981 int fmt, res; | 981 int fmt, res; |
982 | 982 |
983 // Check if we can do this | 983 // Check if we can do this |
984 if ((spec->format == DM_COLFMT_PALETTE || spec->format == DM_COLFMT_GRAYSCALE) && | 984 if ((spec->pixfmt == DM_PIXFMT_PALETTE || spec->pixfmt == DM_PIXFMT_GRAYSCALE) && |
985 img->format != spec->format) | 985 img->pixfmt != spec->pixfmt) |
986 { | 986 { |
987 return dmError(DMERR_NOT_SUPPORTED, | 987 return dmError(DMERR_NOT_SUPPORTED, |
988 "Conversion of non-indexed image to indexed not supported yet.\n"); | 988 "Conversion of non-indexed image to indexed not supported yet.\n"); |
989 } | 989 } |
990 | 990 |
1018 | 1018 |
1019 res = DMERR_OK; | 1019 res = DMERR_OK; |
1020 png_set_write_fn(png_ptr, fp, dmPNGWriteData, dmPNGWriteFlush); | 1020 png_set_write_fn(png_ptr, fp, dmPNGWriteData, dmPNGWriteFlush); |
1021 | 1021 |
1022 // Write PNG header info | 1022 // Write PNG header info |
1023 switch (spec->format) | 1023 switch (spec->pixfmt) |
1024 { | 1024 { |
1025 case DM_COLFMT_PALETTE : fmt = PNG_COLOR_TYPE_PALETTE; break; | 1025 case DM_PIXFMT_PALETTE : fmt = PNG_COLOR_TYPE_PALETTE; break; |
1026 case DM_COLFMT_GRAYSCALE : fmt = PNG_COLOR_TYPE_GRAY; break; | 1026 case DM_PIXFMT_GRAYSCALE : fmt = PNG_COLOR_TYPE_GRAY; break; |
1027 case DM_COLFMT_RGB : fmt = PNG_COLOR_TYPE_RGB; break; | 1027 case DM_PIXFMT_RGB : fmt = PNG_COLOR_TYPE_RGB; break; |
1028 case DM_COLFMT_RGBA : fmt = PNG_COLOR_TYPE_RGB_ALPHA; break; | 1028 case DM_PIXFMT_RGBA : fmt = PNG_COLOR_TYPE_RGB_ALPHA; break; |
1029 default: | 1029 default: |
1030 res = dmError(DMERR_NOT_SUPPORTED, | 1030 res = dmError(DMERR_NOT_SUPPORTED, |
1031 "PNG: Unsupported image format %d.\n", | 1031 "PNG: Unsupported image format %d.\n", |
1032 spec->format); | 1032 spec->pixfmt); |
1033 goto error; | 1033 goto error; |
1034 } | 1034 } |
1035 | 1035 |
1036 png_set_compression_level(png_ptr, spec->compression); | 1036 png_set_compression_level(png_ptr, spec->compression); |
1037 | 1037 |
1048 img->width * spec->scaleX, | 1048 img->width * spec->scaleX, |
1049 img->height * spec->scaleY, | 1049 img->height * spec->scaleY, |
1050 8, fmt); | 1050 8, fmt); |
1051 | 1051 |
1052 // Palette | 1052 // Palette |
1053 if (spec->format == DM_COLFMT_PALETTE) | 1053 if (spec->pixfmt == DM_PIXFMT_PALETTE) |
1054 { | 1054 { |
1055 png_colorp palette = png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); | 1055 png_colorp palette = png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); |
1056 | 1056 |
1057 if (palette == NULL) | 1057 if (palette == NULL) |
1058 { | 1058 { |
1169 } | 1169 } |
1170 | 1170 |
1171 if (bit_depth < 8) | 1171 if (bit_depth < 8) |
1172 png_set_expand_gray_1_2_4_to_8(png_ptr); | 1172 png_set_expand_gray_1_2_4_to_8(png_ptr); |
1173 | 1173 |
1174 itype = DM_COLFMT_GRAYSCALE; | 1174 itype = DM_PIXFMT_GRAYSCALE; |
1175 break; | 1175 break; |
1176 | 1176 |
1177 case PNG_COLOR_TYPE_PALETTE: | 1177 case PNG_COLOR_TYPE_PALETTE: |
1178 png_set_packing(png_ptr); | 1178 png_set_packing(png_ptr); |
1179 itype = DM_COLFMT_PALETTE; | 1179 itype = DM_PIXFMT_PALETTE; |
1180 break; | 1180 break; |
1181 | 1181 |
1182 case PNG_COLOR_TYPE_RGB: | 1182 case PNG_COLOR_TYPE_RGB: |
1183 itype = DM_COLFMT_RGB; | 1183 itype = DM_PIXFMT_RGB; |
1184 break; | 1184 break; |
1185 | 1185 |
1186 case PNG_COLOR_TYPE_RGBA: | 1186 case PNG_COLOR_TYPE_RGBA: |
1187 itype = DM_COLFMT_RGBA; | 1187 itype = DM_PIXFMT_RGBA; |
1188 break; | 1188 break; |
1189 | 1189 |
1190 default: | 1190 default: |
1191 res = dmError(DMERR_NOT_SUPPORTED, | 1191 res = dmError(DMERR_NOT_SUPPORTED, |
1192 "PNG: RGB/RGBA images not supported for loading.\n"); | 1192 "PNG: RGB/RGBA images not supported for loading.\n"); |
1425 // Always force planar for PCX | 1425 // Always force planar for PCX |
1426 memcpy(&spec, pspec, sizeof(DMImageWriteSpec)); | 1426 memcpy(&spec, pspec, sizeof(DMImageWriteSpec)); |
1427 spec.planar = TRUE; | 1427 spec.planar = TRUE; |
1428 | 1428 |
1429 // XXX: 24bit PCX does not work yet .. | 1429 // XXX: 24bit PCX does not work yet .. |
1430 if ((img->format != DM_COLFMT_PALETTE && img->format != DM_COLFMT_GRAYSCALE) || | 1430 if ((img->pixfmt != DM_PIXFMT_PALETTE && img->pixfmt != DM_PIXFMT_GRAYSCALE) || |
1431 (spec.format != DM_COLFMT_PALETTE && spec.format != DM_COLFMT_GRAYSCALE)) | 1431 (spec.pixfmt != DM_PIXFMT_PALETTE && spec.pixfmt != DM_PIXFMT_GRAYSCALE)) |
1432 { | 1432 { |
1433 return dmError(DMERR_NOT_SUPPORTED, | 1433 return dmError(DMERR_NOT_SUPPORTED, |
1434 "24bit PCX not supported yet.\n"); | 1434 "24bit PCX not supported yet.\n"); |
1435 } | 1435 } |
1436 | 1436 |
1437 if (spec.format == DM_COLFMT_PALETTE && img->pal == NULL) | 1437 if (spec.pixfmt == DM_PIXFMT_PALETTE && img->pal == NULL) |
1438 { | 1438 { |
1439 return dmError(DMERR_NULLPTR, | 1439 return dmError(DMERR_NULLPTR, |
1440 "Image spec says paletted/indexed image, but palette pointer is NULL.\n"); | 1440 "Image spec says paletted/indexed image, but palette pointer is NULL.\n"); |
1441 } | 1441 } |
1442 | 1442 |
1445 pcx.header = &hdr; | 1445 pcx.header = &hdr; |
1446 pcx.fp = fp; | 1446 pcx.fp = fp; |
1447 | 1447 |
1448 // Create PCX header | 1448 // Create PCX header |
1449 dmMemset(&hdr, 0, sizeof(hdr)); | 1449 dmMemset(&hdr, 0, sizeof(hdr)); |
1450 if (spec.format == DM_COLFMT_PALETTE || | 1450 if (spec.pixfmt == DM_PIXFMT_PALETTE || |
1451 spec.format == DM_COLFMT_GRAYSCALE) | 1451 spec.pixfmt == DM_PIXFMT_GRAYSCALE) |
1452 { | 1452 { |
1453 const int ncolors = img->pal->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->pal->ncolors; | 1453 const int ncolors = img->pal->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->pal->ncolors; |
1454 for (int i = 0; i < ncolors; i++) | 1454 for (int i = 0; i < ncolors; i++) |
1455 { | 1455 { |
1456 hdr.colorMap[i].r = img->pal->colors[i].r; | 1456 hdr.colorMap[i].r = img->pal->colors[i].r; |
1470 hdr.hScreenSize = hdr.hres; | 1470 hdr.hScreenSize = hdr.hres; |
1471 hdr.vScreenSize = hdr.vres; | 1471 hdr.vScreenSize = hdr.vres; |
1472 | 1472 |
1473 // TODO XXX .. maybe actually compute these asdf | 1473 // TODO XXX .. maybe actually compute these asdf |
1474 hdr.bitsPerPlane = 8; | 1474 hdr.bitsPerPlane = 8; |
1475 hdr.nplanes = dmImageGetBytesPerPixel(spec.format); | 1475 hdr.nplanes = dmImageGetBytesPerPixel(spec.pixfmt); |
1476 | 1476 |
1477 res = img->width * spec.scaleX; | 1477 res = img->width * spec.scaleX; |
1478 hdr.bpl = res / 2; | 1478 hdr.bpl = res / 2; |
1479 if (res % 2) hdr.bpl++; | 1479 if (res % 2) hdr.bpl++; |
1480 hdr.bpl *= 2; | 1480 hdr.bpl *= 2; |
1485 hdr.hres, hdr.vres, | 1485 hdr.hres, hdr.vres, |
1486 hdr.hScreenSize, hdr.vScreenSize); | 1486 hdr.hScreenSize, hdr.vScreenSize); |
1487 | 1487 |
1488 dmMsg(2, "PCX: nplanes=%d, bpp=%d, bpl=%d, colfmt=%d, planar=%s\n", | 1488 dmMsg(2, "PCX: nplanes=%d, bpp=%d, bpl=%d, colfmt=%d, planar=%s\n", |
1489 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, | 1489 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, |
1490 spec.format, | 1490 spec.pixfmt, |
1491 spec.planar ? "yes" : "no" | 1491 spec.planar ? "yes" : "no" |
1492 ); | 1492 ); |
1493 | 1493 |
1494 // TODO XXX this is also bogus | 1494 // TODO XXX this is also bogus |
1495 pcx.bufLen = hdr.bpl * 4; | 1495 pcx.bufLen = hdr.bpl * 4; |
1546 | 1546 |
1547 // Write image data | 1547 // Write image data |
1548 res = dmWriteImageData(img, (void *) &pcx, dmWritePCXRow, &spec); | 1548 res = dmWriteImageData(img, (void *) &pcx, dmWritePCXRow, &spec); |
1549 | 1549 |
1550 // Write VGA palette | 1550 // Write VGA palette |
1551 if (spec.format == DM_COLFMT_PALETTE || | 1551 if (spec.pixfmt == DM_PIXFMT_PALETTE || |
1552 spec.format == DM_COLFMT_GRAYSCALE) | 1552 spec.pixfmt == DM_PIXFMT_GRAYSCALE) |
1553 { | 1553 { |
1554 dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->pal->ncolors); | 1554 dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->pal->ncolors); |
1555 | 1555 |
1556 dmf_write_byte(pcx.fp, 0x0C); | 1556 dmf_write_byte(pcx.fp, 0x0C); |
1557 | 1557 |
1704 goto error; | 1704 goto error; |
1705 } | 1705 } |
1706 | 1706 |
1707 // Allocate image | 1707 // Allocate image |
1708 if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1, | 1708 if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1, |
1709 isPaletted ? DM_COLFMT_PALETTE : DM_COLFMT_RGB, | 1709 isPaletted ? DM_PIXFMT_PALETTE : DM_PIXFMT_RGB, |
1710 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp | 1710 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp |
1711 // isPaletted ? (hdr.bitsPerPlane * hdr.nplanes) : -1 | 1711 // isPaletted ? (hdr.bitsPerPlane * hdr.nplanes) : -1 |
1712 -1 | 1712 -1 |
1713 )) == NULL) | 1713 )) == NULL) |
1714 { | 1714 { |
2354 | 2354 |
2355 dmMsg(2, "IFF: %s chunk size %d bytes\n", chunk.idStr, chunk.size); | 2355 dmMsg(2, "IFF: %s chunk size %d bytes\n", chunk.idStr, chunk.size); |
2356 | 2356 |
2357 // Allocate image | 2357 // Allocate image |
2358 if ((*pimg = dmImageAlloc(iff.bmhd.w, iff.bmhd.h, | 2358 if ((*pimg = dmImageAlloc(iff.bmhd.w, iff.bmhd.h, |
2359 iff.bmhd.nplanes <= 8 ? DM_COLFMT_PALETTE : DM_COLFMT_RGBA, | 2359 iff.bmhd.nplanes <= 8 ? DM_PIXFMT_PALETTE : DM_PIXFMT_RGBA, |
2360 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp | 2360 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp |
2361 //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1 | 2361 //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1 |
2362 -1 | 2362 -1 |
2363 )) == NULL) | 2363 )) == NULL) |
2364 return DMERR_MALLOC; | 2364 return DMERR_MALLOC; |
2410 if ((res = dmSkipIFFChunkRest(fp, &chunk)) != DMERR_OK) | 2410 if ((res = dmSkipIFFChunkRest(fp, &chunk)) != DMERR_OK) |
2411 return res; | 2411 return res; |
2412 } | 2412 } |
2413 | 2413 |
2414 // Check if we should have a palette | 2414 // Check if we should have a palette |
2415 if (*pimg != NULL && (*pimg)->format == DM_COLFMT_PALETTE) | 2415 if (*pimg != NULL && (*pimg)->pixfmt == DM_PIXFMT_PALETTE) |
2416 { | 2416 { |
2417 // Check that we DO have a palette .. | 2417 // Check that we DO have a palette .. |
2418 if (iff.pal == NULL || iff.pal->ncolors == 0) | 2418 if (iff.pal == NULL || iff.pal->ncolors == 0) |
2419 { | 2419 { |
2420 return dmError(DMERR_INVALID_DATA, | 2420 return dmError(DMERR_INVALID_DATA, |
2636 Uint8 *buf = NULL; | 2636 Uint8 *buf = NULL; |
2637 size_t bufLen; | 2637 size_t bufLen; |
2638 int res = DMERR_OK; | 2638 int res = DMERR_OK; |
2639 | 2639 |
2640 // XXX: Non-paletted IFF not supported! | 2640 // XXX: Non-paletted IFF not supported! |
2641 if ((img->format != DM_COLFMT_PALETTE && img->format != DM_COLFMT_GRAYSCALE) || | 2641 if ((img->pixfmt != DM_PIXFMT_PALETTE && img->pixfmt != DM_PIXFMT_GRAYSCALE) || |
2642 (spec->format != DM_COLFMT_PALETTE && spec->format != DM_COLFMT_GRAYSCALE)) | 2642 (spec->pixfmt != DM_PIXFMT_PALETTE && spec->pixfmt != DM_PIXFMT_GRAYSCALE)) |
2643 { | 2643 { |
2644 return dmError(DMERR_NOT_SUPPORTED, | 2644 return dmError(DMERR_NOT_SUPPORTED, |
2645 "Non-paletted IFF is not supported.\n"); | 2645 "Non-paletted IFF is not supported.\n"); |
2646 } | 2646 } |
2647 | 2647 |
2717 goto out; | 2717 goto out; |
2718 | 2718 |
2719 // | 2719 // |
2720 // CMAP | 2720 // CMAP |
2721 // | 2721 // |
2722 if (spec->format == DM_COLFMT_PALETTE && | 2722 if (spec->pixfmt == DM_PIXFMT_PALETTE && |
2723 img->pal != NULL && | 2723 img->pal != NULL && |
2724 img->pal->ncolors > 0) | 2724 img->pal->ncolors > 0) |
2725 { | 2725 { |
2726 if ((res = dmWriteIFFChunkHdr(fp, &iff.chCMAP, IFF_ID_CMAP)) != DMERR_OK) | 2726 if ((res = dmWriteIFFChunkHdr(fp, &iff.chCMAP, IFF_ID_CMAP)) != DMERR_OK) |
2727 goto out; | 2727 goto out; |
2879 const DMImageFormat dmImageFormatList[] = | 2879 const DMImageFormat dmImageFormatList[] = |
2880 { | 2880 { |
2881 #ifdef DM_USE_LIBPNG | 2881 #ifdef DM_USE_LIBPNG |
2882 { | 2882 { |
2883 "png", "Portable Network Graphics", | 2883 "png", "Portable Network Graphics", |
2884 DM_IMGFMT_PNG, DM_FMT_RDWR | DM_COLFMT_ANY, | 2884 DM_IMGFMT_PNG, DM_FMT_RDWR | DM_PIXFMT_ANY, |
2885 fmtProbePNG, dmReadPNGImage, dmWritePNGImage, | 2885 fmtProbePNG, dmReadPNGImage, dmWritePNGImage, |
2886 }, | 2886 }, |
2887 #endif | 2887 #endif |
2888 { | 2888 { |
2889 "ppm", "Portable PixMap", | 2889 "ppm", "Portable PixMap", |
2890 DM_IMGFMT_PPM, DM_FMT_RDWR | DM_COLFMT_GRAYSCALE | DM_COLFMT_RGB, | 2890 DM_IMGFMT_PPM, DM_FMT_RDWR | DM_PIXFMT_GRAYSCALE | DM_PIXFMT_RGB, |
2891 fmtProbePPM, dmReadPPMImage, dmWritePPMImage, | 2891 fmtProbePPM, dmReadPPMImage, dmWritePPMImage, |
2892 }, | 2892 }, |
2893 { | 2893 { |
2894 "pcx", "Z-Soft Paintbrush", | 2894 "pcx", "Z-Soft Paintbrush", |
2895 DM_IMGFMT_PCX, DM_FMT_RDWR | DM_COLFMT_PALETTE | DM_COLFMT_RGB, | 2895 DM_IMGFMT_PCX, DM_FMT_RDWR | DM_PIXFMT_PALETTE | DM_PIXFMT_RGB, |
2896 fmtProbePCX, dmReadPCXImage, dmWritePCXImage, | 2896 fmtProbePCX, dmReadPCXImage, dmWritePCXImage, |
2897 }, | 2897 }, |
2898 { | 2898 { |
2899 "ilbm", "IFF ILBM (interleaved/old DP2)", | 2899 "ilbm", "IFF ILBM (interleaved/old DP2)", |
2900 DM_IMGFMT_IFF_ILBM, DM_FMT_RDWR | DM_COLFMT_PALETTE, | 2900 DM_IMGFMT_IFF_ILBM, DM_FMT_RDWR | DM_PIXFMT_PALETTE, |
2901 fmtProbeIFF_ILBM, dmReadIFFImage, dmWriteIFFImage, | 2901 fmtProbeIFF_ILBM, dmReadIFFImage, dmWriteIFFImage, |
2902 }, | 2902 }, |
2903 { | 2903 { |
2904 "pbm", "IFF PBM (DP2e)", | 2904 "pbm", "IFF PBM (DP2e)", |
2905 DM_IMGFMT_IFF_PBM, DM_FMT_RDWR | DM_COLFMT_PALETTE, | 2905 DM_IMGFMT_IFF_PBM, DM_FMT_RDWR | DM_PIXFMT_PALETTE, |
2906 fmtProbeIFF_PBM, dmReadIFFImage, dmWriteIFFImage, | 2906 fmtProbeIFF_PBM, dmReadIFFImage, dmWriteIFFImage, |
2907 }, | 2907 }, |
2908 { | 2908 { |
2909 "acbm", "IFF ACBM (Amiga Basic)", | 2909 "acbm", "IFF ACBM (Amiga Basic)", |
2910 DM_IMGFMT_IFF_ACBM, DM_FMT_RDWR | DM_COLFMT_PALETTE, | 2910 DM_IMGFMT_IFF_ACBM, DM_FMT_RDWR | DM_PIXFMT_PALETTE, |
2911 fmtProbeIFF_ACBM, dmReadIFFImage, dmWriteIFFImage, | 2911 fmtProbeIFF_ACBM, dmReadIFFImage, dmWriteIFFImage, |
2912 }, | 2912 }, |
2913 { | 2913 { |
2914 "raw", "Plain bitplaned (planar or non-planar) RAW", | 2914 "raw", "Plain bitplaned (planar or non-planar) RAW", |
2915 DM_IMGFMT_RAW, DM_FMT_WR | DM_COLFMT_PALETTE, | 2915 DM_IMGFMT_RAW, DM_FMT_WR | DM_PIXFMT_PALETTE, |
2916 NULL, NULL, dmWriteRAWImage, | 2916 NULL, NULL, dmWriteRAWImage, |
2917 }, | 2917 }, |
2918 { | 2918 { |
2919 "araw", "IFFMaster Amiga RAW", | 2919 "araw", "IFFMaster Amiga RAW", |
2920 DM_IMGFMT_ARAW, DM_FMT_WR | DM_COLFMT_PALETTE, | 2920 DM_IMGFMT_ARAW, DM_FMT_WR | DM_PIXFMT_PALETTE, |
2921 NULL, NULL, dmWriteRAWImage, | 2921 NULL, NULL, dmWriteRAWImage, |
2922 }, | 2922 }, |
2923 { | 2923 { |
2924 "cdump", "'C' dump (image data only)", | 2924 "cdump", "'C' dump (image data only)", |
2925 DM_IMGFMT_CDUMP, DM_FMT_WR | DM_COLFMT_ANY, | 2925 DM_IMGFMT_CDUMP, DM_FMT_WR | DM_PIXFMT_ANY, |
2926 NULL, NULL, dmWriteCDumpImage, | 2926 NULL, NULL, dmWriteCDumpImage, |
2927 } | 2927 } |
2928 }; | 2928 }; |
2929 | 2929 |
2930 const int ndmImageFormatList = sizeof(dmImageFormatList) / sizeof(dmImageFormatList[0]); | 2930 const int ndmImageFormatList = sizeof(dmImageFormatList) / sizeof(dmImageFormatList[0]); |