From: uz Date: Mon, 5 Mar 2012 20:30:25 +0000 (+0000) Subject: Started to add koala output format. X-Git-Tag: V2.14~485 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8c1aed8b0f47bfdab46ce2602f7cd1feb9973cfd;p=cc65 Started to add koala output format. git-svn-id: svn://svn.cc65.org/cc65/trunk@5578 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/sp65/bitmap.c b/src/sp65/bitmap.c index 7b1cce64d..b9862c879 100644 --- a/src/sp65/bitmap.c +++ b/src/sp65/bitmap.c @@ -178,3 +178,19 @@ Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y) +unsigned GetBitmapColors (const Bitmap* B) +/* Get the number of colors in an image. The function will return the number + * of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps. + */ +{ + switch (B->Type) { + case bmMonochrome: return 2; + case bmIndexed: return B->Pal->Count; + case bmRGB: + case bmRGBA: return (1U << 24); + default: Internal ("Unknown bitmap type %u", B->Type); + } +} + + + diff --git a/src/sp65/bitmap.h b/src/sp65/bitmap.h index 3f28ca9fc..4fe56f752 100644 --- a/src/sp65/bitmap.h +++ b/src/sp65/bitmap.h @@ -126,6 +126,41 @@ Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y); * or a palette index, depending on the type of the bitmap. */ +#if defined(HAVE_INLINE) +INLINE BitmapType GetBitmapType (const Bitmap* B) +/* Get the type of a bitmap */ +{ + return B->Type; +} +#else +# define GetBitmapType(B) ((B)->Type) +#endif + +#if defined(HAVE_INLINE) +INLINE unsigned GetBitmapWidth (const Bitmap* B) +/* Get the width of a bitmap */ +{ + return B->Width; +} +#else +# define GetBitmapWidth(B) ((B)->Width) +#endif + +#if defined(HAVE_INLINE) +INLINE unsigned GetBitmapHeight (const Bitmap* B) +/* Get the height of a bitmap */ +{ + return B->Height; +} +#else +# define GetBitmapHeight(B) ((B)->Height) +#endif + +unsigned GetBitmapColors (const Bitmap* B); +/* Get the number of colors in an image. The function will return the number + * of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps. + */ + /* End of bitmap.h */ diff --git a/src/sp65/koala.c b/src/sp65/koala.c new file mode 100644 index 000000000..317ddbf32 --- /dev/null +++ b/src/sp65/koala.c @@ -0,0 +1,71 @@ +/*****************************************************************************/ +/* */ +/* koala.c */ +/* */ +/* Koala format backend for the sp65 sprite and bitmap utility */ +/* */ +/* */ +/* */ +/* (C) 2012, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +/* sp65 */ +#include "koala.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +StrBuf* GenKoala (const Bitmap* B, const Collection* A) +/* Generate binary output in koala format for the bitmap B. The output is + * stored in a string buffer (which is actually a dynamic char array) and + * returned. + */ +{ + /* Koala pictures are always 160x200 in size with 16 colors */ + if (GetBitmapType (B) != bmIndexed || + GetBitmapColors (B) > 16 || + GetBitmapHeight (B) != 200 || + GetBitmapWidth (B) != 160) { + + Error ("Bitmaps converted to koala format must be in indexed mode " + "with 16 colors max and a size of 160x200"); + } + + + + + + +} + + + diff --git a/src/sp65/koala.h b/src/sp65/koala.h new file mode 100644 index 000000000..57ea86ad5 --- /dev/null +++ b/src/sp65/koala.h @@ -0,0 +1,69 @@ +/*****************************************************************************/ +/* */ +/* koala.h */ +/* */ +/* Koala format backend for the sp65 sprite and bitmap utility */ +/* */ +/* */ +/* */ +/* (C) 2012, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef KOALA_H +#define KOALA_H + + + +/* common */ +#include "coll.h" +#include "strbuf.h" + +/* sp65 */ +#include "bitmap.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +StrBuf* GenKoala (const Bitmap* B, const Collection* A); +/* Generate binary output in koala format for the bitmap B. The output is + * stored in a string buffer (which is actually a dynamic char array) and + * returned. + */ + + + +/* End of koala.h */ + +#endif + + + diff --git a/src/sp65/make/gcc.mak b/src/sp65/make/gcc.mak index d2bac974b..96607004f 100644 --- a/src/sp65/make/gcc.mak +++ b/src/sp65/make/gcc.mak @@ -30,6 +30,7 @@ OBJS = asm.o \ error.o \ fileio.o \ input.o \ + koala.o \ main.o \ output.o \ palette.o \ diff --git a/src/sp65/make/watcom.mak b/src/sp65/make/watcom.mak index 9642644d2..3b1307a84 100644 --- a/src/sp65/make/watcom.mak +++ b/src/sp65/make/watcom.mak @@ -68,6 +68,7 @@ OBJS = asm.obj \ error.obj \ fileio.obj \ input.obj \ + koala.obj \ main.obj \ output.obj \ palette.obj \