mirror of
https://github.com/cc65/cc65.git
synced 2024-12-25 02:29:52 +00:00
Remove the bitmap type since it is not really needed and complicate things.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5603 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
194a007710
commit
c9d65c56c2
@ -64,7 +64,6 @@ Bitmap* NewBitmap (unsigned Width, unsigned Height)
|
|||||||
B = xmalloc (sizeof (*B) + (Size - 1) * sizeof (B->Data[0]));
|
B = xmalloc (sizeof (*B) + (Size - 1) * sizeof (B->Data[0]));
|
||||||
|
|
||||||
/* Initialize the data */
|
/* Initialize the data */
|
||||||
B->Type = bmUnknown;
|
|
||||||
B->Name = EmptyStrBuf;
|
B->Name = EmptyStrBuf;
|
||||||
B->Width = Width;
|
B->Width = Width;
|
||||||
B->Height = Height;
|
B->Height = Height;
|
||||||
@ -120,7 +119,6 @@ Bitmap* SliceBitmap (const Bitmap* O, unsigned OrigX, unsigned OrigY,
|
|||||||
B = NewBitmap (Width, Height);
|
B = NewBitmap (Width, Height);
|
||||||
|
|
||||||
/* Copy fields from the original */
|
/* Copy fields from the original */
|
||||||
B->Type = O->Type;
|
|
||||||
if (SB_GetLen (&O->Name) > 0) {
|
if (SB_GetLen (&O->Name) > 0) {
|
||||||
SB_CopyStr (&B->Name, "Slice of ");
|
SB_CopyStr (&B->Name, "Slice of ");
|
||||||
SB_Append (&B->Name, &O->Name);
|
SB_Append (&B->Name, &O->Name);
|
||||||
@ -185,15 +183,11 @@ unsigned GetBitmapColors (const Bitmap* B)
|
|||||||
* of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps.
|
* of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
switch (B->Type) {
|
if (B->Pal) {
|
||||||
case bmMonochrome: return 2;
|
return B->Pal->Count;
|
||||||
case bmIndexed: return B->Pal->Count;
|
} else {
|
||||||
case bmRGB:
|
return (1U << 24);
|
||||||
case bmRGBA: return (1U << 24);
|
|
||||||
default: Internal ("Unknown bitmap type %u", B->Type);
|
|
||||||
}
|
}
|
||||||
/* NOTREACHED */
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,23 +60,10 @@
|
|||||||
/* Safety limit for the size of the bitmap in pixels */
|
/* Safety limit for the size of the bitmap in pixels */
|
||||||
#define BM_MAX_SIZE 4194304UL
|
#define BM_MAX_SIZE 4194304UL
|
||||||
|
|
||||||
/* Bitmap type */
|
|
||||||
enum BitmapType {
|
|
||||||
bmUnknown,
|
|
||||||
bmMonochrome,
|
|
||||||
bmIndexed,
|
|
||||||
bmRGB,
|
|
||||||
bmRGBA
|
|
||||||
};
|
|
||||||
typedef enum BitmapType BitmapType;
|
|
||||||
|
|
||||||
/* Bitmap structure */
|
/* Bitmap structure */
|
||||||
typedef struct Bitmap Bitmap;
|
typedef struct Bitmap Bitmap;
|
||||||
struct Bitmap {
|
struct Bitmap {
|
||||||
|
|
||||||
/* Type of the bitmap */
|
|
||||||
BitmapType Type;
|
|
||||||
|
|
||||||
/* Name of the bitmap. This is used for error messages and should be
|
/* Name of the bitmap. This is used for error messages and should be
|
||||||
* something that allows the user to identify which bitmap the message
|
* something that allows the user to identify which bitmap the message
|
||||||
* refers to. For bitmaps loaded from a file, using the file name is
|
* refers to. For bitmaps loaded from a file, using the file name is
|
||||||
@ -88,7 +75,7 @@ struct Bitmap {
|
|||||||
unsigned Width;
|
unsigned Width;
|
||||||
unsigned Height;
|
unsigned Height;
|
||||||
|
|
||||||
/* Palette for monochrome and indexed bitmap types, otherwise NULL */
|
/* Palette for indexed bitmap types, otherwise NULL */
|
||||||
Palette* Pal;
|
Palette* Pal;
|
||||||
|
|
||||||
/* Pixel data, dynamically allocated */
|
/* Pixel data, dynamically allocated */
|
||||||
@ -131,13 +118,13 @@ Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE BitmapType GetBitmapType (const Bitmap* B)
|
INLINE int BitmapIsIndexed (const Bitmap* B)
|
||||||
/* Get the type of a bitmap */
|
/* Return true if this is an indexed bitmap */
|
||||||
{
|
{
|
||||||
return B->Type;
|
return (B->Pal != 0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define GetBitmapType(B) ((B)->Type)
|
# define BitmapIsIndexed(B) ((B)->Pal != 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
|
@ -71,7 +71,7 @@ StrBuf* GenKoala (const Bitmap* B, const Collection* A attribute ((unused)))
|
|||||||
unsigned char X, Y;
|
unsigned char X, Y;
|
||||||
|
|
||||||
/* Koala pictures are always 160x200 in size with 16 colors */
|
/* Koala pictures are always 160x200 in size with 16 colors */
|
||||||
if (GetBitmapType (B) != bmIndexed ||
|
if (!BitmapIsIndexed (B) ||
|
||||||
GetBitmapColors (B) > 16 ||
|
GetBitmapColors (B) > 16 ||
|
||||||
GetBitmapHeight (B) != HEIGHT ||
|
GetBitmapHeight (B) != HEIGHT ||
|
||||||
GetBitmapWidth (B) != WIDTH) {
|
GetBitmapWidth (B) != WIDTH) {
|
||||||
|
@ -86,7 +86,12 @@ Palette* NewMonochromePalette (void)
|
|||||||
|
|
||||||
Palette* DupPalette (const Palette* P)
|
Palette* DupPalette (const Palette* P)
|
||||||
/* Create a copy of a palette */
|
/* Create a copy of a palette */
|
||||||
{
|
{
|
||||||
|
/* Allow to pass a NULL palette */
|
||||||
|
if (P == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create a new palette */
|
/* Create a new palette */
|
||||||
Palette* N = NewPalette (P->Count);
|
Palette* N = NewPalette (P->Count);
|
||||||
|
|
||||||
|
142
src/sp65/pcx.c
142
src/sp65/pcx.c
@ -275,14 +275,6 @@ Bitmap* ReadPCXFile (const Collection* A)
|
|||||||
/* Create the bitmap */
|
/* Create the bitmap */
|
||||||
B = NewBitmap (P->Width, P->Height);
|
B = NewBitmap (P->Width, P->Height);
|
||||||
|
|
||||||
/* Determine the type of the bitmap */
|
|
||||||
switch (P->Planes) {
|
|
||||||
case 1: B->Type = (P->PalInfo? bmIndexed : bmMonochrome); break;
|
|
||||||
case 3: B->Type = bmRGB; break;
|
|
||||||
case 4: B->Type = bmRGBA; break;
|
|
||||||
default:Internal ("Unexpected number of planes");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy the name */
|
/* Copy the name */
|
||||||
SB_CopyStr (&B->Name, Name);
|
SB_CopyStr (&B->Name, Name);
|
||||||
|
|
||||||
@ -332,7 +324,75 @@ Bitmap* ReadPCXFile (const Collection* A)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* One plane means we have a palette which is either part of the header
|
||||||
|
* or follows.
|
||||||
|
*/
|
||||||
|
if (P->PalInfo == 0) {
|
||||||
|
|
||||||
|
/* Create the monochrome palette */
|
||||||
|
B->Pal = NewMonochromePalette ();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* 3 or 4 planes are RGB or RGBA (don't know if this exists) */
|
/* 3 or 4 planes are RGB or RGBA (don't know if this exists) */
|
||||||
for (Y = 0, Px = B->Data; Y < P->Height; ++Y) {
|
for (Y = 0, Px = B->Data; Y < P->Height; ++Y) {
|
||||||
|
|
||||||
@ -368,72 +428,6 @@ Bitmap* ReadPCXFile (const Collection* A)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the file */
|
/* Close the file */
|
||||||
fclose (F);
|
fclose (F);
|
||||||
|
|
||||||
|
@ -74,10 +74,10 @@ StrBuf* GenVic2Sprite (const Bitmap* B, const Collection* A attribute ((unused))
|
|||||||
/* Output the image properties */
|
/* Output the image properties */
|
||||||
Print (stdout, 1, "Image is %ux%u with %u colors%s\n",
|
Print (stdout, 1, "Image is %ux%u with %u colors%s\n",
|
||||||
GetBitmapWidth (B), GetBitmapHeight (B), GetBitmapColors (B),
|
GetBitmapWidth (B), GetBitmapHeight (B), GetBitmapColors (B),
|
||||||
(GetBitmapType (B) == bmIndexed)? " (indexed)" : "");
|
BitmapIsIndexed (B)? " (indexed)" : "");
|
||||||
|
|
||||||
/* Sprites pictures are always 24x21 in size with 2 colors */
|
/* Sprites pictures are always 24x21 in size with 2 colors */
|
||||||
if (GetBitmapType (B) != bmIndexed ||
|
if (!BitmapIsIndexed (B) ||
|
||||||
GetBitmapColors (B) != 2 ||
|
GetBitmapColors (B) != 2 ||
|
||||||
GetBitmapHeight (B) != HEIGHT ||
|
GetBitmapHeight (B) != HEIGHT ||
|
||||||
GetBitmapWidth (B) != WIDTH) {
|
GetBitmapWidth (B) != WIDTH) {
|
||||||
|
Loading…
Reference in New Issue
Block a user