comparison src/libgfx.c @ 1287:32051ad352c8

Adjust debug messages and debug message levels in libgfx.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Aug 2017 15:27:36 +0300
parents b812fad6f33e
children 6c8b19d1d196
comparison
equal deleted inserted replaced
1286:b812fad6f33e 1287:32051ad352c8
432 fmt, 432 fmt,
433 PNG_INTERLACE_NONE, 433 PNG_INTERLACE_NONE,
434 PNG_COMPRESSION_TYPE_DEFAULT, 434 PNG_COMPRESSION_TYPE_DEFAULT,
435 PNG_FILTER_TYPE_DEFAULT); 435 PNG_FILTER_TYPE_DEFAULT);
436 436
437 dmMsg(3, "PNG: %d x %d, depth=%d, type=%d\n", 437 dmMsg(2, "PNG: %d x %d, depth=%d, type=%d\n",
438 img->width * spec->scaleX, 438 img->width * spec->scaleX,
439 img->height * spec->scaleY, 439 img->height * spec->scaleY,
440 8, fmt); 440 8, fmt);
441 441
442 // Palette 442 // Palette
582 "PNG: RGB/RGBA images not supported for loading.\n"); 582 "PNG: RGB/RGBA images not supported for loading.\n");
583 goto error; 583 goto error;
584 } 584 }
585 585
586 // Allocate image 586 // Allocate image
587 dmMsg(3, "PNG: %d x %d, depth=%d, type=%d\n", 587 dmMsg(2, "PNG: %d x %d, depth=%d, type=%d\n",
588 width, height, bit_depth, color_type); 588 width, height, bit_depth, color_type);
589 589
590 if ((*pimg = img = dmImageAlloc(width, height, DM_IFMT_PALETTE, bit_depth)) == NULL) 590 if ((*pimg = img = dmImageAlloc(width, height, DM_IFMT_PALETTE, bit_depth)) == NULL)
591 { 591 {
592 res = dmError(DMERR_MALLOC, 592 res = dmError(DMERR_MALLOC,
606 // Create palette 606 // Create palette
607 switch (color_type) 607 switch (color_type)
608 { 608 {
609 case PNG_COLOR_TYPE_GRAY: 609 case PNG_COLOR_TYPE_GRAY:
610 ncolors = 256; 610 ncolors = 256;
611 dmMsg(3, "PNG: Generating %d color grayscale palette.\n", ncolors); 611 dmMsg(2, "PNG: Generating %d color grayscale palette.\n", ncolors);
612 612
613 if (!dmImageAllocPalette(img, ncolors, -1)) 613 if (!dmImageAllocPalette(img, ncolors, -1))
614 { 614 {
615 res = DMERR_MALLOC; 615 res = DMERR_MALLOC;
616 goto error; 616 goto error;
622 } 622 }
623 break; 623 break;
624 624
625 case PNG_COLOR_TYPE_PALETTE: 625 case PNG_COLOR_TYPE_PALETTE:
626 png_get_PLTE(png_ptr, info_ptr, &palette, &ncolors); 626 png_get_PLTE(png_ptr, info_ptr, &palette, &ncolors);
627 dmMsg(3, "PNG: Palette of %d colors found.\n", ncolors); 627 dmMsg(2, "PNG: Palette of %d colors found.\n", ncolors);
628 if (ncolors > 0 && palette != NULL) 628 if (ncolors > 0 && palette != NULL)
629 { 629 {
630 if (!dmImageAllocPalette(img, ncolors, -1)) 630 if (!dmImageAllocPalette(img, ncolors, -1))
631 { 631 {
632 res = DMERR_MALLOC; 632 res = DMERR_MALLOC;
849 res = img->width * spec->scaleX; 849 res = img->width * spec->scaleX;
850 hdr.bpl = res / 2; 850 hdr.bpl = res / 2;
851 if (res % 2) hdr.bpl++; 851 if (res % 2) hdr.bpl++;
852 hdr.bpl *= 2; 852 hdr.bpl *= 2;
853 853
854 dmMsg(3, "PCX: paletted=%d, nplanes=%d, bpp=%d, bpl=%d\n", 854 dmMsg(2, "PCX: paletted=%d, nplanes=%d, bpp=%d, bpl=%d\n",
855 spec->paletted, hdr.nplanes, hdr.bitsPerPlane, hdr.bpl); 855 spec->paletted, hdr.nplanes, hdr.bitsPerPlane, hdr.bpl);
856 856
857 pcx.bufLen = hdr.bpl * 4; 857 pcx.bufLen = hdr.bpl * 4;
858 if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) 858 if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL)
859 { 859 {
912 // Write VGA palette 912 // Write VGA palette
913 if (spec->paletted) 913 if (spec->paletted)
914 { 914 {
915 int i; 915 int i;
916 dm_fwrite_byte(pcx.fp, 0x0C); 916 dm_fwrite_byte(pcx.fp, 0x0C);
917 dmMsg(3, "PCX: Writing palette of %d active entries.\n", img->ncolors); 917 dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors);
918 918
919 for (i = 0; i < img->ncolors; i++) 919 for (i = 0; i < img->ncolors; i++)
920 { 920 {
921 dm_fwrite_byte(pcx.fp, img->pal[i].r); 921 dm_fwrite_byte(pcx.fp, img->pal[i].r);
922 dm_fwrite_byte(pcx.fp, img->pal[i].g); 922 dm_fwrite_byte(pcx.fp, img->pal[i].g);
1081 "PCX: Unsupported number of bitplanes %d.\n", 1081 "PCX: Unsupported number of bitplanes %d.\n",
1082 hdr.nplanes); 1082 hdr.nplanes);
1083 goto error; 1083 goto error;
1084 } 1084 }
1085 1085
1086 dmMsg(3, "PCX: nplanes=%d, bpp=%d, bpl=%d\n", 1086 dmMsg(2,
1087 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl); 1087 "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n",
1088 hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax,
1089 hdr.hres, hdr.vres,
1090 hdr.hScreenSize, hdr.vScreenSize);
1091
1092 dmMsg(2,
1093 "PCX: nplanes=%d, bpp=%d, bpl=%d, bitsPerPlane=%d\n",
1094 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, hdr.bitsPerPlane);
1088 1095
1089 isPaletted = (hdr.bitsPerPlane * hdr.nplanes) < 8; 1096 isPaletted = (hdr.bitsPerPlane * hdr.nplanes) < 8;
1090 if (!isPaletted) 1097 if (!isPaletted)
1091 { 1098 {
1092 res = dmError(DMERR_NOT_SUPPORTED, 1099 res = dmError(DMERR_NOT_SUPPORTED,
1444 // Allocate planar decoding buffer 1451 // Allocate planar decoding buffer
1445 bufLen = ((img->width + 15) / 16) * 2; 1452 bufLen = ((img->width + 15) / 16) * 2;
1446 if ((buf = dmMalloc(bufLen)) == NULL) 1453 if ((buf = dmMalloc(bufLen)) == NULL)
1447 return DMERR_MALLOC; 1454 return DMERR_MALLOC;
1448 1455
1449 dmMsg(3, "ILBM: plane row size %d bytes.\n", bufLen); 1456 dmMsg(2, "ILBM: plane row size %d bytes.\n", bufLen);
1450 1457
1451 // Decode the chunk 1458 // Decode the chunk
1452 for (yc = 0; yc < img->height; yc++) 1459 for (yc = 0; yc < img->height; yc++)
1453 { 1460 {
1454 int plane; 1461 int plane;
1603 { 1610 {
1604 return dmError(DMERR_FREAD, 1611 return dmError(DMERR_FREAD,
1605 "ILBM: Error reading BMHD chunk.\n"); 1612 "ILBM: Error reading BMHD chunk.\n");
1606 } 1613 }
1607 1614
1608 dmMsg(3, "ILBM: BMHD %d x %d @ %d, %d : nplanes=%d, comp=%d, mask=%d\n", 1615 dmMsg(2, "ILBM: BMHD %d x %d @ %d, %d : nplanes=%d, comp=%d, mask=%d\n",
1609 iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y, 1616 iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y,
1610 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking); 1617 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking);
1611 1618
1612 // Sanity check 1619 // Sanity check
1613 if (iff.bmhd.nplanes < 1 || iff.bmhd.nplanes > 8 || 1620 if (iff.bmhd.nplanes < 1 || iff.bmhd.nplanes > 8 ||
1638 dmError(DMERR_INVALID_DATA, 1645 dmError(DMERR_INVALID_DATA,
1639 "ILBM: CMAP chunk size not divisible by 3, possibly broken file.\n"); 1646 "ILBM: CMAP chunk size not divisible by 3, possibly broken file.\n");
1640 } 1647 }
1641 1648
1642 iff.ncolors = chunk.size / 3; 1649 iff.ncolors = chunk.size / 3;
1643 dmMsg(3, "ILBM: CMAP %d entries (%d bytes)\n", 1650 dmMsg(2, "ILBM: CMAP %d entries (%d bytes)\n",
1644 iff.ncolors, chunk.size, 1 << iff.bmhd.nplanes); 1651 iff.ncolors, chunk.size, 1 << iff.bmhd.nplanes);
1645 1652
1646 if (iff.bmhd.nplanes > 0 && iff.ncolors != 1 << iff.bmhd.nplanes) 1653 if (iff.bmhd.nplanes > 0 && iff.ncolors != 1 << iff.bmhd.nplanes)
1647 dmMsg(3, "ILBM: Expected %d entries in CMAP.\n", 1 << iff.bmhd.nplanes); 1654 dmMsg(2, "ILBM: Expected %d entries in CMAP.\n", 1 << iff.bmhd.nplanes);
1648 1655
1649 // Read palette 1656 // Read palette
1650 if (iff.ncolors > 0) 1657 if (iff.ncolors > 0)
1651 { 1658 {
1652 if (!dmPaletteAlloc(&iff.pal, iff.ncolors, 1659 if (!dmPaletteAlloc(&iff.pal, iff.ncolors,
1676 { 1683 {
1677 return dmError(DMERR_INVALID_DATA, 1684 return dmError(DMERR_INVALID_DATA,
1678 "ILBM: BODY chunk before BMHD?\n"); 1685 "ILBM: BODY chunk before BMHD?\n");
1679 } 1686 }
1680 1687
1681 dmMsg(3, "ILBM: BODY chunk size %d bytes\n", chunk.size); 1688 dmMsg(2, "ILBM: BODY chunk size %d bytes\n", chunk.size);
1682 1689
1683 // Decode the body 1690 // Decode the body
1684 if (iff.planar) 1691 if (iff.planar)
1685 { 1692 {
1686 if ((res = dmDecodeILBMBody(fp, &iff, pimg, &read)) != DMERR_OK) 1693 if ((res = dmDecodeILBMBody(fp, &iff, pimg, &read)) != DMERR_OK)
1705 { 1712 {
1706 return dmError(DMERR_FREAD, 1713 return dmError(DMERR_FREAD,
1707 "ILBM: Error reading CAMG chunk.\n"); 1714 "ILBM: Error reading CAMG chunk.\n");
1708 } 1715 }
1709 1716
1710 dmMsg(3, "ILBM: CAMG value 0x%08x\n", iff.camg); 1717 dmMsg(2, "ILBM: CAMG value 0x%08x\n", iff.camg);
1711 1718
1712 if ((iff.camg & IFF_CAMG_HAM)) 1719 if ((iff.camg & IFF_CAMG_HAM))
1713 { 1720 {
1714 return dmError(DMERR_NOT_SUPPORTED, 1721 return dmError(DMERR_NOT_SUPPORTED,
1715 "ILBM: HAM files are not supported.\n"); 1722 "ILBM: HAM files are not supported.\n");