|
9 | 9 | #include "core_image.h" |
10 | 10 |
|
11 | 11 | #include <jpeglib.h> |
12 | | -#include <tiffio.h> |
13 | 12 | #include <png.h> |
14 | 13 | #include <gif_lib.h> |
15 | 14 |
|
|
19 | 18 |
|
20 | 19 | #define BLP2_MAGIC 0x32504C42 // "BLP2" |
21 | 20 |
|
22 | | -// Generic client data structure, used by JPEG, TIFF and PNG |
| 21 | +// Generic client data structure, used by JPEG and PNG |
23 | 22 | struct clientData_s { |
24 | 23 | IConsole* con; |
25 | 24 | const char* fileName; |
@@ -89,9 +88,6 @@ image_c* image_c::LoaderForFile(IConsole* conHnd, const char* fileName) |
89 | 88 | if (dat[0] == 0xFF && dat[1] == 0xD8) { |
90 | 89 | // JPEG Start Of Image marker |
91 | 90 | return new jpeg_c(conHnd); |
92 | | - } else if (*(dword*)dat == 0x002A4949 || *(dword*)dat == 0x2A004D4D) { |
93 | | - // Little-endian / Big-endian marker + version |
94 | | - return new tiff_c(conHnd); |
95 | 91 | } else if (*(dword*)dat == 0x474E5089) { |
96 | 92 | // 0x89 P N G |
97 | 93 | return new png_c(conHnd); |
@@ -624,163 +620,6 @@ bool jpeg_c::ImageInfo(const char* fileName, imageInfo_s* info) |
624 | 620 | return (comp != 1 && comp != 3); |
625 | 621 | } |
626 | 622 |
|
627 | | -// ========== |
628 | | -// TIFF Image |
629 | | -// ========== |
630 | | - |
631 | | -static void ITIFF_ErrorProc(thandle_t clientData, const char* module, const char* fmt, va_list va) |
632 | | -{ |
633 | | - clientData_s* cd = (clientData_s*)clientData; |
634 | | - char text[1024]; |
635 | | - vsprintf(text, fmt, va); |
636 | | - cd->con->Warning("TIFF '%s': Error in '%.20s%s': %s", cd->fileName, module, strlen(module)>20?"...":"", text); |
637 | | -} |
638 | | - |
639 | | -static void ITIFF_WarningProc(thandle_t clientData, const char* module, const char* fmt, va_list va) |
640 | | -{ |
641 | | - clientData_s* cd = (clientData_s*)clientData; |
642 | | - char text[1024]; |
643 | | - vsprintf(text, fmt, va); |
644 | | - cd->con->Warning("TIFF '%s': Warning in '%.20s%s': %s", cd->fileName, module, strlen(module)>20?"...":"", text); |
645 | | -} |
646 | | - |
647 | | -static tsize_t ITIFF_ReadProc(thandle_t clientData, tdata_t data, tsize_t len) |
648 | | -{ |
649 | | - clientData_s* cd = (clientData_s*)clientData; |
650 | | - return cd->io->Read(data, len)? 0 : len; |
651 | | -} |
652 | | - |
653 | | -static tsize_t ITIFF_WriteProc(thandle_t clientData, tdata_t data, tsize_t len) |
654 | | -{ |
655 | | - clientData_s* cd = (clientData_s*)clientData; |
656 | | - return cd->io->Write(data, len)? 0 : len; |
657 | | -} |
658 | | - |
659 | | -static toff_t ITIFF_SeekProc(thandle_t clientData, toff_t pos, int mode) |
660 | | -{ |
661 | | - clientData_s* cd = (clientData_s*)clientData; |
662 | | - cd->io->Seek((size_t)pos, mode); |
663 | | - return cd->io->GetPos(); |
664 | | -} |
665 | | - |
666 | | -static int ITIFF_CloseProc(thandle_t clientData) |
667 | | -{ |
668 | | - return 0; |
669 | | -} |
670 | | - |
671 | | -static toff_t ITIFF_SizeProc(thandle_t clientData) |
672 | | -{ |
673 | | - clientData_s* cd = (clientData_s*)clientData; |
674 | | - return cd->io->GetLen(); |
675 | | -} |
676 | | - |
677 | | -bool tiff_c::Load(const char* fileName) |
678 | | -{ |
679 | | - Free(); |
680 | | - |
681 | | - // Open the file |
682 | | - fileInputStream_c in; |
683 | | - if (in.FileOpen(fileName, true)) { |
684 | | - return true; |
685 | | - } |
686 | | - |
687 | | - // Initialise TIFF |
688 | | - TIFFSetErrorHandler(NULL); |
689 | | - TIFFSetErrorHandlerExt(ITIFF_ErrorProc); |
690 | | - TIFFSetWarningHandler(NULL); |
691 | | - TIFFSetWarningHandlerExt(ITIFF_WarningProc); |
692 | | - clientData_s cd; |
693 | | - cd.con = con; |
694 | | - cd.fileName = fileName; |
695 | | - cd.io = ∈ |
696 | | - TIFF* t = TIFFClientOpen(fileName, "r", &cd, ITIFF_ReadProc, ITIFF_WriteProc, ITIFF_SeekProc, ITIFF_CloseProc, ITIFF_SizeProc, NULL, NULL); |
697 | | - if ( !t ) { |
698 | | - return true; |
699 | | - } |
700 | | - |
701 | | - // Get image info and read image |
702 | | - TIFFGetField(t, TIFFTAG_IMAGEWIDTH, &width); |
703 | | - TIFFGetField(t, TIFFTAG_IMAGELENGTH, &height); |
704 | | - dat = new byte[width * height * 4]; |
705 | | - comp = 4; |
706 | | - type = IMGTYPE_RGBA; |
707 | | - bool ret = !TIFFReadRGBAImageOriented(t, width, height, (dword*)dat, ORIENTATION_TOPLEFT, 0); |
708 | | - TIFFClose(t); |
709 | | - return ret; |
710 | | -} |
711 | | - |
712 | | -bool tiff_c::Save(const char* fileName) |
713 | | -{ |
714 | | - // Only save RGB or RGBA |
715 | | - if (type != IMGTYPE_RGB && type != IMGTYPE_RGBA) { |
716 | | - return true; |
717 | | - } |
718 | | - |
719 | | - // Open the file |
720 | | - fileOutputStream_c out; |
721 | | - if (out.FileOpen(fileName, true)) { |
722 | | - return true; |
723 | | - } |
724 | | - |
725 | | - // Initialise TIFF |
726 | | - TIFFSetErrorHandler(NULL); |
727 | | - TIFFSetErrorHandlerExt(ITIFF_ErrorProc); |
728 | | - TIFFSetWarningHandler(NULL); |
729 | | - TIFFSetWarningHandlerExt(ITIFF_WarningProc); |
730 | | - clientData_s cd; |
731 | | - cd.con = con; |
732 | | - cd.fileName = fileName; |
733 | | - cd.io = &out; |
734 | | - TIFF* t = TIFFClientOpen(fileName, "w", &cd, ITIFF_ReadProc, ITIFF_WriteProc, ITIFF_SeekProc, ITIFF_CloseProc, ITIFF_SizeProc, NULL, NULL); |
735 | | - if ( !t ) { |
736 | | - return true; |
737 | | - } |
738 | | - |
739 | | - // Save image |
740 | | - TIFFSetField(t, TIFFTAG_IMAGEWIDTH, width); |
741 | | - TIFFSetField(t, TIFFTAG_BITSPERSAMPLE, 8); |
742 | | - TIFFSetField(t, TIFFTAG_SAMPLESPERPIXEL, comp); |
743 | | - TIFFSetField(t, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); |
744 | | - TIFFSetField(t, TIFFTAG_COMPRESSION, COMPRESSION_LZW); |
745 | | - TIFFSetField(t, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); |
746 | | - for (dword r = 0; r < height; r++) { |
747 | | - TIFFWriteScanline(t, dat + r*width*comp, r); |
748 | | - } |
749 | | - TIFFClose(t); |
750 | | - return false; |
751 | | -} |
752 | | - |
753 | | -bool tiff_c::ImageInfo(const char* fileName, imageInfo_s* info) |
754 | | -{ |
755 | | - // Open the file |
756 | | - fileInputStream_c in; |
757 | | - if (in.FileOpen(fileName, true)) { |
758 | | - return true; |
759 | | - } |
760 | | - |
761 | | - // Initialise TIFF |
762 | | - TIFFSetErrorHandler(NULL); |
763 | | - TIFFSetErrorHandlerExt(ITIFF_ErrorProc); |
764 | | - TIFFSetWarningHandler(NULL); |
765 | | - TIFFSetWarningHandlerExt(ITIFF_WarningProc); |
766 | | - clientData_s cd; |
767 | | - cd.con = con; |
768 | | - cd.fileName = fileName; |
769 | | - cd.io = ∈ |
770 | | - TIFF* t = TIFFClientOpen(fileName, "r", &cd, ITIFF_ReadProc, ITIFF_WriteProc, ITIFF_SeekProc, ITIFF_CloseProc, ITIFF_SizeProc, NULL, NULL); |
771 | | - if ( !t ) { |
772 | | - return true; |
773 | | - } |
774 | | - |
775 | | - // Get image info |
776 | | - TIFFGetField(t, TIFFTAG_IMAGEWIDTH, &info->width); |
777 | | - TIFFGetField(t, TIFFTAG_IMAGELENGTH, &info->height); |
778 | | - TIFFGetField(t, TIFFTAG_SAMPLESPERPIXEL, &info->comp); |
779 | | - info->alpha = info->comp == 4; |
780 | | - TIFFClose(t); |
781 | | - return false; |
782 | | -} |
783 | | - |
784 | 623 | // ========= |
785 | 624 | // PNG Image |
786 | 625 | // ========= |
|
0 commit comments