730 {
731 int nRetCode = 0;
732
733
734 enum Operation {Encode, Decode, Measure} op = Encode;
735 char *source=nullptr, *dest=nullptr, *temp=nullptr;
736 int level = 0, levels = 0, quality = 0;
737 PGFRect rect;
738 int arg = 1;
739 bool bSource = true;
740 bool bStreaming = false;
741 bool bROI = false;
742 bool bMemStream = false;
743 bool bWrongArgs = (argc < 4);
744
745 while (!bWrongArgs && arg < argc) {
746 if (argv[arg][0] == '-') {
747
748 switch(argv[arg][1]) {
749 case 'e': op = Encode; arg++; break;
750 case 'd': op = Decode; arg++; break;
751 case 'm': op = Measure;
752 if (argv[arg][2] == 'm') {
753
754 bMemStream = true;
755 arg++;
756 } else {
757 arg++;
758 if (arg == argc) {
759 bWrongArgs = true;
760 } else {
761 temp = argv[arg]; arg++;
762 }
763 }
764 break;
765 case 'l':
766 if (argv[arg][2] == 'e') {
767
768 arg++;
769 if (arg == argc) {
770 bWrongArgs = true;
771 } else {
772 level = atoi(argv[arg]); arg++;
773 bWrongArgs = (level < 1) || (level > MaxLevel);
774 }
775 } else {
776
777 arg++;
778 if (arg == argc) {
779 bWrongArgs = true;
780 } else {
781 levels = atoi(argv[arg]); arg++;
782 bWrongArgs = (levels < 1) || (levels > MaxLevel);
783 }
784 }
785 break;
786 case 'q': arg++;
787 if (arg == argc) {
788 bWrongArgs = true;
789 } else {
790 quality = atoi(argv[arg]); arg++;
791 bWrongArgs = (quality < 0) || (quality > MaxQuality);
792 }
793 break;
794 #ifdef __PGFROISUPPORT__
795 case 'r': bROI = true;
796 if (argv[arg][2] == 'e') {
797
798 arg++;
799 if (arg + 4 > argc) {
800 bWrongArgs = true;
801 } else {
802 rect = PGFRect(atoi(argv[arg]), atoi(argv[arg+1]), atoi(argv[arg+2]), atoi(argv[arg+3]));
803 arg += 4;
804 }
805 } else {
806
807 arg++;
808 if (arg == argc) bWrongArgs = true;
809 }
810 break;
811 case 's': bStreaming = true; arg++; break;
812 #endif
813 case 'v':
bQuiet =
true; arg++;
break;
814 default: arg++; bWrongArgs = true; break;
815 }
816 } else {
817 if (bSource) {
818 source = argv[arg];
819 bSource = false;
820 } else {
821 dest = argv[arg];
822 }
823 arg++;
824 }
825 }
826 if (!
bQuiet) cout <<
"PGF Console - Copyright (c) 2001-" CurrentYear " xeraina GmbH, Switzerland" << endl <<
828 "libpgf Version : " PGFCodecVersion ", www.libpgf.org" << endl << endl;
829 if (bWrongArgs) {
831 cout << "Usage: " << endl <<
832 #ifdef __PGFROISUPPORT__
833 "- Encoding: pgfconsole -e [-l levels] [-q quality] [-r] [-s] [-v] source dest" << endl <<
834 #else
835 "- Encoding: pgfconsole -e [-l levels] [-q quality] [-v] source dest" << endl <<
836 #endif
837 " Create from a source file a PGF image (dest)." << endl <<
838 " The most popular image file formats with the following image" << endl <<
839 " types are supported:" << endl <<
840 " - bitmap (1 bit)" << endl <<
841 " - grayscale (8 and 16 bit)" << endl <<
842 " - indexed color (8 bit)" << endl <<
843 " - RGB (16 [565], 24, 32, and 48 bit)" << endl <<
844 " - RGBA (32 bit)" << endl <<
845 " Options:" << endl <<
846 " -l levels Number of hierarchical levels [1.." << MaxLevel << "]. Default is 0." << endl <<
847 " 0 means the number of levels are automatically set." << endl <<
848 " -q quality Quality [0.." << MaxQuality << "]. Default is 0." << endl <<
849 " 0 means perfect quality (lossless compression)," << endl <<
850 " " << MaxQuality << " means maximum compression." << endl <<
851 #ifdef __PGFROISUPPORT__
852 " -r Region of interest (ROI) encoding scheme is used." << endl <<
853 " This encoding scheme has a slightly worse compression ratio." << endl <<
854 " -s Level wise encoding in separate writing calls." << endl <<
855 #endif
856 " -v Numbers only: All text output is reduced to numbers." << endl <<
857 endl <<
858 #ifdef __PGFROISUPPORT__
859 "- Decoding: pgfconsole -d [-lev level] [-rect left top width height] [-s] [-v] source dest" << endl <<
860 #else
861 "- Decoding: pgfconsole -d [-v] source dest" << endl <<
862 #endif
863 " Create from a PGF image (source) a new image (dest)." << endl <<
864 " Options:" << endl <<
865 " -lev level The image level of the resulting image. Default is 0." << endl <<
866 #ifdef __PGFROISUPPORT__
867 " -rect rect Read a rectangular region of a PGF image supporting Region of" << endl <<
868 " interests (ROI). The rectangle is defined by 4 blank-separated" << endl <<
869 " positive parameters: left top width height" << endl <<
870 " -s Level wise decoding in separate reading calls." << endl <<
871 #endif
872 " -v Numbers only: All text output is reduced to numbers." << endl <<
873 endl <<
874 "- Measuring: pgfconsole -m temp-file [...] source destination" << endl <<
875 " Measure quality between source and destination bitmap." << endl <<
876 " Encode from an input image (source) a PGF image" << endl <<
877 " (temp-file) and decode from the temp-file a new output" << endl <<
878 " (destination image)." << endl <<
879 " Options:" << endl <<
880 " -mm Instead of using the option -m temp-file you can use " << endl <<
881 " the option -mm (without temp-file). The latter writes the PGF" << endl <<
882 " image into a memory stream instead of a file stream." << endl <<
883 " In both cases all encoding and decoding options are valid." << endl <<
884 endl <<
885 endl;
886 }
887 nRetCode = 2;
888 } else {
890
891#ifdef __PNMEXSUPPORT__
892
894#endif
895
896 switch(op) {
897 case Encode:
898 if (!
Encoding(image, source, dest, levels, quality, bROI, bStreaming,
nullptr)) nRetCode = 3;
899 break;
900 case Decode:
901 if (!
Decoding(image, source, dest, level, bROI, rect, bStreaming,
nullptr)) nRetCode = 4;
902 break;
903 case Measure:
904 if (!
Measurement(source, dest, temp, levels, level, quality, bROI, rect, bStreaming, bMemStream)) nRetCode = 5;
905 break;
906 default:
907 nRetCode = 6;
908 ASSERT(false);
909 }
911
912 delete image;
913 }
914 return nRetCode;
915}
static bool Encoding(CImage *&image, char *source, char *dest, int levels, int quality, bool roi, bool streaming, CPGFMemoryStream **memStream)
static bool Decoding(CImage *&image, char *source, char *dest, int level, bool roi, PGFRect &rect, bool streaming, CPGFMemoryStream **memStream)
static bool Measurement(char *source, char *dest, char *temp, int levels, int level, int quality, bool roi, PGFRect &rect, bool streaming, bool useMemStream)
#define PGFConsoleVersion
static void RegisterPNM()