Пример #1
0
__regargs PaletteT *LoadPalette(const char *filename) {
  PaletteT *palette = NULL;
  IffFileT iff;

  if (OpenIff(&iff, filename)) {
    if (iff.header.type == ID_ILBM) {
      while (ParseChunk(&iff)) {
        switch (iff.chunk.type) {
          case ID_CMAP:
            palette = NewPalette(iff.chunk.length / sizeof(ColorT));
            ReadChunk(&iff, palette->colors);
            break;

          default:
            SkipChunk(&iff);
            break;
        }
      }
    }

    CloseIff(&iff);
  }

  return palette;
}
Пример #2
0
int main() {
  UWORD len = __commandlen;
  STRPTR filename = __builtin_alloca(len);
  IffFileT iff;

  memcpy(filename, __commandline, len--);
  filename[len] = '\0';

  OpenIff(&iff, filename);
  Log("Parsing '%s':\n", filename);
  Log("%.4s %ld\n", (STRPTR)&iff.header.type, iff.header.length);

  while (ParseChunk(&iff)) {
    Log(".%.4s %ld\n", (STRPTR)&iff.chunk.type, iff.chunk.length);
    SkipChunk(&iff);
  }

  CloseIff(&iff);

  return 0;
}
Пример #3
0
__regargs BitmapT *LoadILBM(const char *filename, BOOL interleaved) {
  BitmapT *bitmap = NULL;
  PaletteT *palette = NULL;
  IffFileT iff;

  if (OpenIff(&iff, filename)) {
    if (iff.header.type == ID_ILBM) {
      BOOL compression = FALSE;

      while (ParseChunk(&iff)) {
        BitmapHeaderT bmhd;

        switch (iff.chunk.type) {
          case ID_BMHD:
            ReadChunk(&iff, &bmhd);
            bitmap = NewBitmap(bmhd.w, bmhd.h, bmhd.nPlanes, interleaved);
            compression = bmhd.compression;
            break;

          case ID_CMAP:
            palette = NewPalette(iff.chunk.length / sizeof(ColorT));
            ReadChunk(&iff, palette->colors);
            break;
        
          case ID_BODY:
            {
              BYTE *data = MemAlloc(iff.chunk.length, MEMF_PUBLIC);
              LONG size = iff.chunk.length;

              ReadChunk(&iff, data);

              if (compression) {
                LONG newSize = bitmap->bplSize * bitmap->depth;
                BYTE *uncompressed = MemAlloc(newSize, MEMF_PUBLIC);

                UnRLE(data, size, uncompressed);
                MemFree(data, size);

                data = uncompressed;
                size = newSize;
              }

              if (!interleaved)
                Deinterleave(data, bitmap);
              else
                memcpy(bitmap->planes[0], data, bitmap->bplSize * bitmap->depth);

              MemFree(data, size);
            }
            break;

          default:
            SkipChunk(&iff);
            break;
        }
      }

      if (bitmap)
        bitmap->palette = palette;
    }

    CloseIff(&iff);
  } else {
    Log("File '%s' missing.\n", filename);
  }

  return bitmap;
}