comparison libgfx.c @ 465:ffd5e730d313

Adjust verbosity levels.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 04 Nov 2012 16:40:37 +0200
parents 358776103ceb
children 80d09ea85e75
comparison
equal deleted inserted replaced
464:358776103ceb 465:ffd5e730d313
408 fmt, 408 fmt,
409 PNG_INTERLACE_NONE, 409 PNG_INTERLACE_NONE,
410 PNG_COMPRESSION_TYPE_DEFAULT, 410 PNG_COMPRESSION_TYPE_DEFAULT,
411 PNG_FILTER_TYPE_DEFAULT); 411 PNG_FILTER_TYPE_DEFAULT);
412 412
413 dmMsg(2, "PNG: %d x %d, depth=%d, type=%d\n", 413 dmMsg(3, "PNG: %d x %d, depth=%d, type=%d\n",
414 img->width * spec->scale, 414 img->width * spec->scale,
415 img->height * spec->scale, 415 img->height * spec->scale,
416 8, fmt); 416 8, fmt);
417 417
418 // Palette 418 // Palette
559 res = DMERR_NOT_SUPPORTED; 559 res = DMERR_NOT_SUPPORTED;
560 goto error; 560 goto error;
561 } 561 }
562 562
563 // Allocate image 563 // Allocate image
564 dmMsg(2, "PNG: %d x %d, depth=%d, type=%d\n", 564 dmMsg(3, "PNG: %d x %d, depth=%d, type=%d\n",
565 width, height, bit_depth, color_type); 565 width, height, bit_depth, color_type);
566 566
567 if ((*pimg = img = dmImageAlloc(width, height)) == NULL) 567 if ((*pimg = img = dmImageAlloc(width, height)) == NULL)
568 { 568 {
569 dmError("PNG: Could not allocate image data.\n"); 569 dmError("PNG: Could not allocate image data.\n");
583 // Create palette 583 // Create palette
584 switch (color_type) 584 switch (color_type)
585 { 585 {
586 case PNG_COLOR_TYPE_GRAY: 586 case PNG_COLOR_TYPE_GRAY:
587 ncolors = 256; 587 ncolors = 256;
588 dmMsg(2, "PNG: Generating %d color grayscale palette.\n", ncolors); 588 dmMsg(3, "PNG: Generating %d color grayscale palette.\n", ncolors);
589 589
590 if (!dmImageAllocPalette(img, ncolors, -1)) 590 if (!dmImageAllocPalette(img, ncolors, -1))
591 { 591 {
592 res = DMERR_MALLOC; 592 res = DMERR_MALLOC;
593 goto error; 593 goto error;
599 } 599 }
600 break; 600 break;
601 601
602 case PNG_COLOR_TYPE_PALETTE: 602 case PNG_COLOR_TYPE_PALETTE:
603 png_get_PLTE(png_ptr, info_ptr, &palette, &ncolors); 603 png_get_PLTE(png_ptr, info_ptr, &palette, &ncolors);
604 dmMsg(2, "PNG: Palette of %d colors found.\n", ncolors); 604 dmMsg(3, "PNG: Palette of %d colors found.\n", ncolors);
605 if (ncolors <= 0) 605 if (ncolors <= 0)
606 goto error; 606 goto error;
607 607
608 if (!dmImageAllocPalette(img, ncolors, -1)) 608 if (!dmImageAllocPalette(img, ncolors, -1))
609 { 609 {
817 res = (img->width * spec->scale); 817 res = (img->width * spec->scale);
818 hdr.bpl = res / 2; 818 hdr.bpl = res / 2;
819 if (res % 2) hdr.bpl++; 819 if (res % 2) hdr.bpl++;
820 hdr.bpl *= 2; 820 hdr.bpl *= 2;
821 821
822 dmMsg(2, "PCX: paletted=%d, nplanes=%d, bpp=%d, bpl=%d\n", 822 dmMsg(3, "PCX: paletted=%d, nplanes=%d, bpp=%d, bpl=%d\n",
823 spec->paletted, hdr.nplanes, hdr.bpp, hdr.bpl); 823 spec->paletted, hdr.nplanes, hdr.bpp, hdr.bpl);
824 824
825 pcx.bufLen = hdr.bpl * 4; 825 pcx.bufLen = hdr.bpl * 4;
826 if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) 826 if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL)
827 { 827 {
878 // Write VGA palette 878 // Write VGA palette
879 if (spec->paletted) 879 if (spec->paletted)
880 { 880 {
881 int i; 881 int i;
882 dm_fwrite_byte(pcx.fp, 0x0C); 882 dm_fwrite_byte(pcx.fp, 0x0C);
883 dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors); 883 dmMsg(3, "PCX: Writing palette of %d active entries.\n", img->ncolors);
884 884
885 for (i = 0; i < img->ncolors; i++) 885 for (i = 0; i < img->ncolors; i++)
886 { 886 {
887 dm_fwrite_byte(pcx.fp, img->pal[i].r); 887 dm_fwrite_byte(pcx.fp, img->pal[i].r);
888 dm_fwrite_byte(pcx.fp, img->pal[i].g); 888 dm_fwrite_byte(pcx.fp, img->pal[i].g);
1225 1225
1226 static BOOL dmSkipIFFChunkRest(FILE *fp, const DMIFFChunk *chunk, const Uint32 used) 1226 static BOOL dmSkipIFFChunkRest(FILE *fp, const DMIFFChunk *chunk, const Uint32 used)
1227 { 1227 {
1228 if (chunk->size > used) 1228 if (chunk->size > used)
1229 { 1229 {
1230 dmMsg(3, "ILBM: Skipping %d bytes (%d of %d consumed)\n", 1230 dmMsg(4, "ILBM: Skipping %d bytes (%d of %d consumed)\n",
1231 chunk->size - used, used, chunk->size); 1231 chunk->size - used, used, chunk->size);
1232 return fseeko(fp, chunk->size - used, SEEK_CUR) == 0; 1232 return fseeko(fp, chunk->size - used, SEEK_CUR) == 0;
1233 } 1233 }
1234 else 1234 else
1235 return TRUE; 1235 return TRUE;
1333 // Allocate planar decoding buffer 1333 // Allocate planar decoding buffer
1334 bufLen = ((img->width + 15) / 16) * 2; 1334 bufLen = ((img->width + 15) / 16) * 2;
1335 if ((buf = dmMalloc(bufLen)) == NULL) 1335 if ((buf = dmMalloc(bufLen)) == NULL)
1336 return DMERR_MALLOC; 1336 return DMERR_MALLOC;
1337 1337
1338 dmMsg(2, "ILBM: plane row size %d bytes.\n", bufLen); 1338 dmMsg(3, "ILBM: plane row size %d bytes.\n", bufLen);
1339 1339
1340 // Decode the chunk 1340 // Decode the chunk
1341 for (yc = 0; yc < img->height; yc++) 1341 for (yc = 0; yc < img->height; yc++)
1342 { 1342 {
1343 int plane; 1343 int plane;
1487 !dm_fread_be16(fp, (Uint16 *) &iff.bmhd.pageh)) 1487 !dm_fread_be16(fp, (Uint16 *) &iff.bmhd.pageh))
1488 { 1488 {
1489 dmError("ILBM: Error reading BMHD chunk.\n"); 1489 dmError("ILBM: Error reading BMHD chunk.\n");
1490 return DMERR_FREAD; 1490 return DMERR_FREAD;
1491 } 1491 }
1492 dmMsg(2, "ILBM: BMHD %d x %d @ %d, %d : nplanes=%d, comp=%d, mask=%d\n", 1492 dmMsg(3, "ILBM: BMHD %d x %d @ %d, %d : nplanes=%d, comp=%d, mask=%d\n",
1493 iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y, 1493 iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y,
1494 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking); 1494 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking);
1495 1495
1496 // Sanity check 1496 // Sanity check
1497 if (iff.bmhd.nplanes < 1 || iff.bmhd.nplanes > 8 || 1497 if (iff.bmhd.nplanes < 1 || iff.bmhd.nplanes > 8 ||
1518 // Check for sanity 1518 // Check for sanity
1519 if (chunk.size % 3 != 0) 1519 if (chunk.size % 3 != 0)
1520 dmError("ILBM: CMAP chunk size not divisible by 3, possibly broken file.\n"); 1520 dmError("ILBM: CMAP chunk size not divisible by 3, possibly broken file.\n");
1521 1521
1522 iff.ncolors = chunk.size / 3; 1522 iff.ncolors = chunk.size / 3;
1523 dmMsg(2, "ILBM: CMAP %d entries (%d bytes)\n", 1523 dmMsg(3, "ILBM: CMAP %d entries (%d bytes)\n",
1524 iff.ncolors, chunk.size, 1 << iff.bmhd.nplanes); 1524 iff.ncolors, chunk.size, 1 << iff.bmhd.nplanes);
1525 1525
1526 if (iff.bmhd.nplanes > 0 && iff.ncolors != 1 << iff.bmhd.nplanes) 1526 if (iff.bmhd.nplanes > 0 && iff.ncolors != 1 << iff.bmhd.nplanes)
1527 dmMsg(2, "ILBM: Expected %d entries in CMAP.\n", 1 << iff.bmhd.nplanes); 1527 dmMsg(3, "ILBM: Expected %d entries in CMAP.\n", 1 << iff.bmhd.nplanes);
1528 1528
1529 // Read palette 1529 // Read palette
1530 if (iff.ncolors > 0) 1530 if (iff.ncolors > 0)
1531 { 1531 {
1532 if (!dmPaletteAlloc(&iff.pal, iff.ncolors, 1532 if (!dmPaletteAlloc(&iff.pal, iff.ncolors,
1556 { 1556 {
1557 dmError("ILBM: BODY chunk before BMHD?\n"); 1557 dmError("ILBM: BODY chunk before BMHD?\n");
1558 return DMERR_INVALID_DATA; 1558 return DMERR_INVALID_DATA;
1559 } 1559 }
1560 1560
1561 dmMsg(2, "ILBM: BODY chunk size %d bytes\n", chunk.size); 1561 dmMsg(3, "ILBM: BODY chunk size %d bytes\n", chunk.size);
1562 1562
1563 // Decode the body 1563 // Decode the body
1564 if (iff.planar) 1564 if (iff.planar)
1565 { 1565 {
1566 if ((res = dmDecodeILBMBody(fp, &iff, pimg, &read)) != DMERR_OK) 1566 if ((res = dmDecodeILBMBody(fp, &iff, pimg, &read)) != DMERR_OK)
1585 { 1585 {
1586 dmError("ILBM: Error reading CAMG chunk.\n"); 1586 dmError("ILBM: Error reading CAMG chunk.\n");
1587 return DMERR_FREAD; 1587 return DMERR_FREAD;
1588 } 1588 }
1589 1589
1590 dmMsg(2, "ILBM: CAMG value 0x%08x\n", iff.camg); 1590 dmMsg(3, "ILBM: CAMG value 0x%08x\n", iff.camg);
1591 1591
1592 if ((iff.camg & IFF_CAMG_HAM)) 1592 if ((iff.camg & IFF_CAMG_HAM))
1593 { 1593 {
1594 dmError("ILBM: HAM files are not supported.\n"); 1594 dmError("ILBM: HAM files are not supported.\n");
1595 return DMERR_NOT_SUPPORTED; 1595 return DMERR_NOT_SUPPORTED;
1600 break; 1600 break;
1601 1601
1602 1602
1603 default: 1603 default:
1604 { 1604 {
1605 dmMsg(3, "Unknown chunk ID '%s', size %d\n", 1605 dmMsg(4, "Unknown chunk ID '%s', size %d\n",
1606 dmGetIFFChunkID(&chunk), chunk.size); 1606 dmGetIFFChunkID(&chunk), chunk.size);
1607 1607
1608 if (fseeko(fp, chunk.size, SEEK_CUR) != 0) 1608 if (fseeko(fp, chunk.size, SEEK_CUR) != 0)
1609 { 1609 {
1610 dmError("ILBM: Error skipping in file."); 1610 dmError("ILBM: Error skipping in file.");