mirror of
https://github.com/cc65/cc65.git
synced 2024-12-31 11:32:00 +00:00
New function to create a bitmap slice.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5557 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
4abdecc728
commit
7a3e6abb13
@ -100,6 +100,46 @@ int ValidBitmapSize (unsigned Width, unsigned Height)
|
||||
|
||||
|
||||
|
||||
Bitmap* SliceBitmap (const Bitmap* O, unsigned OrigX, unsigned OrigY,
|
||||
unsigned Width, unsigned Height)
|
||||
/* Create a slice of the given bitmap. The slice starts at position X/Y of
|
||||
* the original and has the given width and height. Location 0/0 is at the
|
||||
* upper left corner.
|
||||
*/
|
||||
{
|
||||
Bitmap* B;
|
||||
unsigned Y;
|
||||
|
||||
|
||||
/* Check the coordinates and size */
|
||||
PRECONDITION (OrigX != 0 && OrigY != 0 &&
|
||||
OrigX + Width <= O->Width &&
|
||||
OrigY + Height <= O->Height);
|
||||
|
||||
/* Create a new bitmap with the given size */
|
||||
B = NewBitmap (Width, Height);
|
||||
|
||||
/* Copy fields from the original */
|
||||
B->Type = O->Type;
|
||||
if (SB_GetLen (&O->Name) > 0) {
|
||||
SB_CopyStr (&B->Name, "Slice of ");
|
||||
SB_Append (&B->Name, &O->Name);
|
||||
}
|
||||
B->Pal = DupPalette (O->Pal);
|
||||
|
||||
/* Copy the pixel data */
|
||||
for (Y = 0; Y < Height; ++Y) {
|
||||
memcpy (B->Data + Y * B->Width,
|
||||
O->Data + (OrigY + Y) * O->Width + OrigX,
|
||||
Width * sizeof (O->Data[0]));
|
||||
}
|
||||
|
||||
/* Return the slice */
|
||||
return B;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Color GetPixelColor (const Bitmap* B, unsigned X, unsigned Y)
|
||||
/* Get the color for a given pixel. For indexed bitmaps, the palette entry
|
||||
* is returned.
|
||||
|
@ -113,6 +113,14 @@ void FreeBitmap (Bitmap* B);
|
||||
int ValidBitmapSize (unsigned Width, unsigned Height);
|
||||
/* Return true if this is a valid size for a bitmap */
|
||||
|
||||
Bitmap* SliceBitmap (const Bitmap* Original,
|
||||
unsigned X, unsigned Y,
|
||||
unsigned Width, unsigned Height);
|
||||
/* Create a slice of the given bitmap. The slice starts at position X/Y of
|
||||
* the original and has the given width and height. Location 0/0 is at the
|
||||
* upper left corner.
|
||||
*/
|
||||
|
||||
Color GetPixelColor (const Bitmap* B, unsigned X, unsigned Y);
|
||||
/* Get the color for a given pixel. For indexed bitmaps, the palette entry
|
||||
* is returned.
|
||||
|
@ -33,6 +33,8 @@
|
||||
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* common */
|
||||
#include "check.h"
|
||||
#include "xmalloc.h"
|
||||
@ -68,7 +70,7 @@ Palette* NewPalette (unsigned Entries)
|
||||
|
||||
Palette* NewMonochromePalette (void)
|
||||
/* Create and return a palette with two entries (black and white) */
|
||||
{
|
||||
{
|
||||
/* Create a new palette */
|
||||
Palette* P = NewPalette (2);
|
||||
|
||||
@ -82,6 +84,21 @@ Palette* NewMonochromePalette (void)
|
||||
|
||||
|
||||
|
||||
Palette* DupPalette (const Palette* P)
|
||||
/* Create a copy of a palette */
|
||||
{
|
||||
/* Create a new palette */
|
||||
Palette* N = NewPalette (P->Count);
|
||||
|
||||
/* Copy the palette data */
|
||||
memcpy (N->Entries, P->Entries, P->Count * sizeof (P->Entries[0]));
|
||||
|
||||
/* Return the copy */
|
||||
return N;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FreePalette (Palette* P)
|
||||
/* Free a dynamically allocated palette */
|
||||
{
|
||||
|
@ -69,6 +69,9 @@ Palette* NewPalette (unsigned Entries);
|
||||
Palette* NewMonochromePalette (void);
|
||||
/* Create and return a palette with two entries (black and white) */
|
||||
|
||||
Palette* DupPalette (const Palette* P);
|
||||
/* Create a copy of a palette */
|
||||
|
||||
void FreePalette (Palette* P);
|
||||
/* Free a dynamically allocated palette */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user