git » fp-git.git » commit 469c8a8

autodetect now detects 16 and 256 image as different types

author ecalot
2006-03-06 07:21:24 UTC
committer ecalot
2006-03-06 07:21:24 UTC
parent 6d6e8de7ccb77b1568fe85a90375580b492f3a4d

autodetect now detects 16 and 256 image as different types

PR/src/lib/actions/export.c +0 -1
PR/src/lib/layers/autodetect.c +21 -9

diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index 6690bd8..79ec011 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -121,7 +121,6 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti
 						list_insert(&paletteBuffer,(void*)&e);
 					}	break;
 					case eResTypeImage16: /* save image */
-					case eResTypeImage2: /* save image */
 					case eResTypeImage256: /* save image */
 						/* Palette handling */
 						if (resourceListCompareId(res.paletteId,bufferedPalette) /*TODO: add &&!paletteCheckCompatibility(currentPalette,image) */) { /* The palette isn't in the buffer */
diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c
index c2919ba..c475f55 100644
--- a/PR/src/lib/layers/autodetect.c
+++ b/PR/src/lib/layers/autodetect.c
@@ -50,11 +50,22 @@ int verifyLevelHeader(tBinary c) {
 	return (c.size==12025) || (((c.size==2306)||(c.size==2305))&&!(c.data[1698]&0x0F)&&!(c.data[1700]&0x0F)&&!(c.data[1702]&0x0F));
 }
 
-int verifyImageHeader(tBinary c) {
+int verifyImage16Header(tBinary c) {
 	unsigned char imageBitRate;
 	if (c.size<=7) return 0; /* false */
-	imageBitRate=(( ((unsigned char)c.data[6])>>4 ) & 7)+1;
-	return (c.size>7) && (((unsigned char)c.data[5])<2) && ((imageBitRate==4 || imageBitRate==8));
+	imageBitRate=(( (c.data[6])>>4 ) & 7)+1;
+	return (c.size>7) && ((c.data[5])==0) && (imageBitRate==4);
+	/* NOTE:
+	 *   imageBitRate==1
+	 * works for monochrome images (but is very common and matches more than that)
+	 */
+}
+
+int verifyImage256Header(tBinary c) {
+	unsigned char imageBitRate;
+	if (c.size<=7) return 0; /* false */
+	imageBitRate=(( (c.data[6])>>4 ) & 7)+1;
+	return (c.size>7) && ((c.data[5])==1) && (imageBitRate==8);
 	/* NOTE:
 	 *   imageBitRate==1
 	 * works for monochrome images (but is very common and matches more than that)
@@ -99,12 +110,13 @@ int verifyMidiHeader(tBinary c) {
 }
 
 tResourceType verifyHeader(tBinary c) { /* TODO: add the pop version as another parameter to detect types */
-	if (verifyLevelHeader  (c)) return eResTypeLevel;
-	if (verifyMidiHeader   (c)) return eResTypeMidi;
-	if (verifyImageHeader  (c)) return eResTypeImage16;
-	if (verifyPaletteHeader(c)) return eResTypePop1Palette4bits;
-	if (verifyWaveHeader   (c)) return eResTypeWave;
-	if (verifySpeakerHeader(c)) return eResTypePcspeaker;
+	if (verifyLevelHeader    (c)) return eResTypeLevel;
+	if (verifyMidiHeader     (c)) return eResTypeMidi;
+	if (verifyImage16Header  (c)) return eResTypeImage16;
+	if (verifyImage256Header (c)) return eResTypeImage256;
+	if (verifyPaletteHeader  (c)) return eResTypePop1Palette4bits;
+	if (verifyWaveHeader     (c)) return eResTypeWave;
+	if (verifySpeakerHeader  (c)) return eResTypePcspeaker;
 	return eResTypeBinary;
 }