mirror of
https://github.com/cc65/cc65.git
synced 2024-12-25 17:29:50 +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) {
|
||||||
|
@ -87,6 +87,11 @@ 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);
|
||||||
|
|
||||||
|
@ -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,51 +324,16 @@ Bitmap* ReadPCXFile (const Collection* A)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/* 3 or 4 planes are RGB or RGBA (don't know if this exists) */
|
|
||||||
for (Y = 0, Px = B->Data; Y < P->Height; ++Y) {
|
|
||||||
|
|
||||||
/* Read the R plane and move the data */
|
|
||||||
ReadPlane (F, P, L);
|
|
||||||
for (X = 0; X < P->Width; ++X, ++Px) {
|
|
||||||
Px->C.R = L[X];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the G plane and move the data */
|
|
||||||
ReadPlane (F, P, L);
|
|
||||||
for (X = 0; X < P->Width; ++X, ++Px) {
|
|
||||||
Px->C.G = L[X];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the B plane and move the data */
|
|
||||||
ReadPlane (F, P, L);
|
|
||||||
for (X = 0; X < P->Width; ++X, ++Px) {
|
|
||||||
Px->C.B = L[X];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Either read the A plane or clear it */
|
|
||||||
if (P->Planes == 4) {
|
|
||||||
ReadPlane (F, P, L);
|
|
||||||
for (X = 0; X < P->Width; ++X, ++Px) {
|
|
||||||
Px->C.A = L[X];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (X = 0; X < P->Width; ++X, ++Px) {
|
|
||||||
Px->C.A = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* One plane means we have a palette which is either part of the header
|
/* One plane means we have a palette which is either part of the header
|
||||||
* or follows.
|
* or follows.
|
||||||
*/
|
*/
|
||||||
if (B->Type == bmMonochrome) {
|
if (P->PalInfo == 0) {
|
||||||
|
|
||||||
/* Create the monochrome palette */
|
/* Create the monochrome palette */
|
||||||
B->Pal = NewMonochromePalette ();
|
B->Pal = NewMonochromePalette ();
|
||||||
|
|
||||||
} else if (B->Type == bmIndexed) {
|
} else {
|
||||||
|
|
||||||
unsigned Count;
|
unsigned Count;
|
||||||
unsigned I;
|
unsigned I;
|
||||||
@ -434,6 +391,43 @@ Bitmap* ReadPCXFile (const Collection* A)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* 3 or 4 planes are RGB or RGBA (don't know if this exists) */
|
||||||
|
for (Y = 0, Px = B->Data; Y < P->Height; ++Y) {
|
||||||
|
|
||||||
|
/* Read the R plane and move the data */
|
||||||
|
ReadPlane (F, P, L);
|
||||||
|
for (X = 0; X < P->Width; ++X, ++Px) {
|
||||||
|
Px->C.R = L[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the G plane and move the data */
|
||||||
|
ReadPlane (F, P, L);
|
||||||
|
for (X = 0; X < P->Width; ++X, ++Px) {
|
||||||
|
Px->C.G = L[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the B plane and move the data */
|
||||||
|
ReadPlane (F, P, L);
|
||||||
|
for (X = 0; X < P->Width; ++X, ++Px) {
|
||||||
|
Px->C.B = L[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Either read the A plane or clear it */
|
||||||
|
if (P->Planes == 4) {
|
||||||
|
ReadPlane (F, P, L);
|
||||||
|
for (X = 0; X < P->Width; ++X, ++Px) {
|
||||||
|
Px->C.A = L[X];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (X = 0; X < P->Width; ++X, ++Px) {
|
||||||
|
Px->C.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