- /* One plane means we have a palette which is either part of the header
- * or follows.
- */
- if (B->Type == bmMonochrome) {
-
- /* Create the monochrome palette */
- B->Pal = NewMonochromePalette ();
-
- } else if (B->Type == bmIndexed) {
-
- unsigned Count;
- unsigned I;
- unsigned char Palette[256][3];
- unsigned long EndPos;
-
- /* Determine the current file position */
- unsigned long CurPos = FileGetPos (F);
-
- /* Seek to the end of the file */
- (void) fseek (F, 0, SEEK_END);
-
- /* Get this position */
- EndPos = FileGetPos (F);
-
- /* There's a palette if the old location is 769 bytes from the end */
- if (EndPos - CurPos == sizeof (Palette) + 1) {
-
- /* Seek back */
- FileSetPos (F, CurPos);
-
- /* Check for palette marker */
- if (Read8 (F) != 0x0C) {
- Error ("Invalid palette marker in PCX file `%s'", Name);
- }
-
- } else if (EndPos == CurPos) {
-
- /* The palette is in the header */
- FileSetPos (F, 16);
-
- /* Check the maximum index for safety */
- if (MaxIdx > 15) {
- Error ("PCX file `%s' contains more than 16 indexed colors "
- "but no extra palette", Name);
- }
-
- } else {
- Error ("Error in PCX file `%s': %lu bytes at end of pixel data",
- Name, EndPos - CurPos);
- }
-
- /* Read the palette. We will just read what we need. */
- Count = MaxIdx + 1;
- ReadData (F, Palette, Count * sizeof (Palette[0]));
-
- /* Create the palette from the data */
- B->Pal = NewPalette (Count);
- for (I = 0; I < Count; ++I) {
- B->Pal->Entries[I].R = Palette[I][0];
- B->Pal->Entries[I].G = Palette[I][1];
- B->Pal->Entries[I].B = Palette[I][2];
- B->Pal->Entries[I].A = 0;
- }
-
- }
-