comparison libgfx.c @ 449:117f94b253af

Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 04 Nov 2012 09:11:57 +0200
parents f1aab48a76fe
children fdc91f2a0d27
comparison
equal deleted inserted replaced
448:f1aab48a76fe 449:117f94b253af
923 #define IFF_ID_FORM 0x464F524D // "FORM" 923 #define IFF_ID_FORM 0x464F524D // "FORM"
924 #define IFF_ID_ILBM 0x494C424D // "ILBM" 924 #define IFF_ID_ILBM 0x494C424D // "ILBM"
925 #define IFF_ID_BMHD 0x424D4844 // "BMHD" 925 #define IFF_ID_BMHD 0x424D4844 // "BMHD"
926 #define IFF_ID_CMAP 0x434D4150 // "CMAP" 926 #define IFF_ID_CMAP 0x434D4150 // "CMAP"
927 #define IFF_ID_BODY 0x424F4459 // "BODY" 927 #define IFF_ID_BODY 0x424F4459 // "BODY"
928 #define IFF_ID_CAMG 0x43414D47 // "CAMG"
928 929
929 #define IFF_MASK_NONE 0 930 #define IFF_MASK_NONE 0
930 #define IFF_MASK_HAS_MASK 1 931 #define IFF_MASK_HAS_MASK 1
931 #define IFF_MASK_TRANSP 2 932 #define IFF_MASK_TRANSP 2
932 #define IFF_MASK_LASSO 3 933 #define IFF_MASK_LASSO 3
933 934
934 #define IFF_COMP_NONE 0 935 #define IFF_COMP_NONE 0
935 #define IFF_COMP_BYTERUN1 1 936 #define IFF_COMP_BYTERUN1 1
936 937
938 #define IFF_CAMG_LACE 0x00000004
939 #define IFF_CAMG_HALFBRITE 0x00000080
940 #define IFF_CAMG_HAM 0x00000800
937 941
938 typedef struct 942 typedef struct
939 { 943 {
940 Uint32 id; 944 Uint32 id;
941 Uint32 size; 945 Uint32 size;
960 964
961 typedef struct 965 typedef struct
962 { 966 {
963 DMIFFChunk chBMHD, chCMAP, chBODY; 967 DMIFFChunk chBMHD, chCMAP, chBODY;
964 DMIFFBMHD bmhd; 968 DMIFFBMHD bmhd;
969 Uint32 camg;
965 int ncolors; 970 int ncolors;
966 DMColor *pal; 971 DMColor *pal;
967 BOOL paletted; 972 BOOL paletted;
968 } DMIFF; 973 } DMIFF;
969 974
1313 return DMERR_FREAD; 1318 return DMERR_FREAD;
1314 1319
1315 if (iff.chCMAP.count) 1320 if (iff.chCMAP.count)
1316 parsed = TRUE; 1321 parsed = TRUE;
1317 break; 1322 break;
1323
1324
1325 case IFF_ID_CAMG:
1326 if (!dm_fread_be32(fp, &iff.camg))
1327 {
1328 dmError("ILBM: Error reading CAMG chunk.\n");
1329 return DMERR_FREAD;
1330 }
1331
1332 dmMsg(2, "ILBM: CAMG value 0x%08x\n", iff.camg);
1333
1334 if ((iff.camg & IFF_CAMG_HAM))
1335 {
1336 dmError("ILBM: HAM files are not supported.\n");
1337 return DMERR_INVALID_DATA;
1338 }
1339
1340 if (!dmSkipIFFChunkRest(fp, &chunk, 4))
1341 return DMERR_FREAD;
1342 break;
1343
1318 1344
1319 default: 1345 default:
1320 { 1346 {
1321 dmMsg(3, "Unknown chunk ID '%s', size %d\n", 1347 dmMsg(3, "Unknown chunk ID '%s', size %d\n",
1322 dmGetIFFChunkID(&chunk), chunk.size); 1348 dmGetIFFChunkID(&chunk), chunk.size);
1335 } 1361 }
1336 1362
1337 // Set colormap after finishing 1363 // Set colormap after finishing
1338 if (iff.pal != NULL && iff.ncolors > 0 && *pimg != NULL) 1364 if (iff.pal != NULL && iff.ncolors > 0 && *pimg != NULL)
1339 { 1365 {
1366 // If halfbrite is used, duplicate the palette
1367 if (iff.camg & IFF_CAMG_HALFBRITE)
1368 {
1369 if (iff.ncolors > 128)
1370 {
1371 dmError("ILBM: Halfbrite enabled, but ncolors > 128.\n");
1372 return DMERR_INVALID_DATA;
1373 }
1374
1375 if ((iff.pal = dmRealloc(iff.pal, sizeof(DMColor) * iff.ncolors * 2)) == NULL)
1376 return DMERR_MALLOC;
1377
1378 for (i = 0; i < iff.ncolors; i++)
1379 {
1380 int i2 = iff.ncolors + i;
1381 iff.pal[i2].r = iff.pal[i].r / 2;
1382 iff.pal[i2].g = iff.pal[i].g / 2;
1383 iff.pal[i2].b = iff.pal[i].b / 2;
1384 }
1385 }
1386
1340 (*pimg)->ncolors = iff.ncolors; 1387 (*pimg)->ncolors = iff.ncolors;
1341 (*pimg)->pal = iff.pal; 1388 (*pimg)->pal = iff.pal;
1342 } 1389 }
1343 1390
1344 return res; 1391 return res;