summaryrefslogtreecommitdiff
path: root/src/im_file.cpp
diff options
context:
space:
mode:
authorscuri <scuri>2009-08-13 22:34:25 +0000
committerscuri <scuri>2009-08-13 22:34:25 +0000
commit380fdb5d8c80d094e5a8bc82bfc091bc87e6c43e (patch)
tree82e1142d204b405febd4554b76c0b81187f22d5a /src/im_file.cpp
parent22eee5011ab2699a3267bde4a7b4430d8460314c (diff)
*** empty log message ***
Diffstat (limited to 'src/im_file.cpp')
-rw-r--r--src/im_file.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/im_file.cpp b/src/im_file.cpp
index a43b0d4..81e0e1b 100644
--- a/src/im_file.cpp
+++ b/src/im_file.cpp
@@ -2,7 +2,7 @@
* \brief File Access
*
* See Copyright Notice in im_lib.h
- * $Id: im_file.cpp,v 1.2 2008/12/03 15:45:34 scuri Exp $
+ * $Id: im_file.cpp,v 1.3 2009/08/13 22:34:25 scuri Exp $
*/
#include <stdlib.h>
@@ -176,13 +176,28 @@ void imFileGetInfo(imFile* ifile, char* format, char* compression, int *image_co
static int iFileCheckPaletteGray(imFile* ifile)
{
+ int i;
imbyte r, g, b;
- for (int i = 0; i < ifile->palette_count; i++)
+ imbyte remaped[256];
+ memset(remaped, 0, 256);
+
+ for (i = 0; i < ifile->palette_count; i++)
{
imColorDecode(&r, &g, &b, ifile->palette[i]);
- if (i != r || r != g || g != b)
+ /* if there are colors abort */
+ if (r != g || g != b)
return 0;
+
+ /* grays out of order, will be remapped, but must be unique,
+ if there are duplicates maybe they are used for different pourposes */
+ if (i != r)
+ {
+ if (!remaped[r])
+ remaped[r] = 1;
+ else
+ return 0;
+ }
}
return 1;
@@ -305,6 +320,16 @@ static void iFileCheckConvertGray(imFile* ifile, imbyte* data)
*data = remap[*data];
data++;
}
+
+ int transp_count;
+ imbyte* transp_map = (imbyte*)imFileGetAttribute(ifile, "TransparencyMap", NULL, &transp_count);
+ if (transp_map)
+ {
+ imbyte new_transp_map[256];
+ for (i=0; i<transp_count; i++)
+ new_transp_map[i] = transp_map[remap[i]];
+ imFileSetAttribute(ifile, "TransparencyMap", IM_BYTE, transp_count, new_transp_map);
+ }
}
static void iFileCheckConvertBinary(imFile* ifile, imbyte* data)