mirror of
https://github.com/cc65/cc65.git
synced 2024-12-29 13:31:59 +00:00
Add lynx sprite generation skeleton
git-svn-id: svn://svn.cc65.org/cc65/trunk@5609 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
735b2811fc
commit
cba5d0af56
167
src/sp65/lynxsprite.c
Normal file
167
src/sp65/lynxsprite.c
Normal file
@ -0,0 +1,167 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* lynxsprite.c */
|
||||
/* */
|
||||
/* Lynx sprite 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. */
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "attrib.h"
|
||||
#include "print.h"
|
||||
|
||||
/* sp65 */
|
||||
#include "attr.h"
|
||||
#include "error.h"
|
||||
#include "lynxsprite.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* Sprite mode */
|
||||
enum Mode {
|
||||
smAuto,
|
||||
smLiteral,
|
||||
smPacked
|
||||
};
|
||||
|
||||
/* Screen size of a koala picture */
|
||||
#define WIDTH_HR 24U
|
||||
#define WIDTH_MC 12U
|
||||
#define HEIGHT 21U
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
static enum Mode GetMode (const Collection* A)
|
||||
/* Return the sprite mode from the attribute collection A */
|
||||
{
|
||||
/* Check for a mode attribute */
|
||||
const char* Mode = GetAttrVal (A, "mode");
|
||||
if (Mode) {
|
||||
if (strcmp (Mode, "literal") == 0) {
|
||||
return smLiteral;
|
||||
} else if (strcmp (Mode, "packed") == 0) {
|
||||
return smPacked;
|
||||
} else {
|
||||
Error ("Invalid value for attribute `mode'");
|
||||
}
|
||||
} else {
|
||||
return smAuto;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
StrBuf* GenLynxSprite (const Bitmap* B, const Collection* A)
|
||||
/* Generate binary output in Lynx sprite format for the bitmap B. The output
|
||||
* is stored in a string buffer (which is actually a dynamic char array) and
|
||||
* returned.
|
||||
*/
|
||||
{
|
||||
enum Mode M;
|
||||
StrBuf* D;
|
||||
unsigned X, Y;
|
||||
|
||||
|
||||
/* Output the image properties */
|
||||
Print (stdout, 1, "Image is %ux%u with %u colors%s\n",
|
||||
GetBitmapWidth (B), GetBitmapHeight (B), GetBitmapColors (B),
|
||||
BitmapIsIndexed (B)? " (indexed)" : "");
|
||||
|
||||
/* Get the sprite mode */
|
||||
M = GetMode (A);
|
||||
|
||||
/* Check the height of the bitmap */
|
||||
if (GetBitmapHeight (B) != HEIGHT) {
|
||||
Error ("Invalid bitmap height (%u) for conversion to vic2 sprite",
|
||||
GetBitmapHeight (B));
|
||||
}
|
||||
|
||||
/* If the mode wasn't given, fallback to packed */
|
||||
if (M == smAuto) {
|
||||
M = smPacked;
|
||||
}
|
||||
|
||||
/* Now check if bitmap indexes are ok */
|
||||
if (GetBitmapColors (B) > 16) {
|
||||
Error ("Too many colors for a Lynx sprite");
|
||||
}
|
||||
|
||||
/* Create the output buffer and resize it to the required size. */
|
||||
D = NewStrBuf ();
|
||||
SB_Realloc (D, 63);
|
||||
|
||||
/* Convert the image */
|
||||
for (Y = 0; Y < HEIGHT; ++Y) {
|
||||
unsigned char V = 0;
|
||||
if (M == smLiteral) {
|
||||
for (X = 0; X < WIDTH_HR; ++X) {
|
||||
|
||||
/* Fetch next bit into byte buffer */
|
||||
V = (V << 1) | (GetPixel (B, X, Y).Index & 0x01);
|
||||
|
||||
/* Store full bytes into the output buffer */
|
||||
if ((X & 0x07) == 0x07) {
|
||||
SB_AppendChar (D, V);
|
||||
V = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (X = 0; X < WIDTH_MC; ++X) {
|
||||
|
||||
/* Fetch next bit into byte buffer */
|
||||
V = (V << 2) | (GetPixel (B, X, Y).Index & 0x03);
|
||||
|
||||
/* Store full bytes into the output buffer */
|
||||
if ((X & 0x03) == 0x03) {
|
||||
SB_AppendChar (D, V);
|
||||
V = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the converted bitmap */
|
||||
return D;
|
||||
}
|
||||
|
||||
|
||||
|
69
src/sp65/lynxsprite.h
Normal file
69
src/sp65/lynxsprite.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* lynxsprite.h */
|
||||
/* */
|
||||
/* Lynx sprite 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 LYNXSPRITE_H
|
||||
#define LYNXSPRITE_H
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "coll.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
/* sp65 */
|
||||
#include "bitmap.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
StrBuf* GenLynxSprite (const Bitmap* B, const Collection* A);
|
||||
/* Generate binary output in packed Lynx sprite format for the bitmap B. The output
|
||||
* is stored in a string buffer (which is actually a dynamic char array) and
|
||||
* returned.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End of lynxsprite.h */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -33,6 +33,7 @@ OBJS = asm.o \
|
||||
fileio.o \
|
||||
input.o \
|
||||
koala.o \
|
||||
lynxsprite.o \
|
||||
main.o \
|
||||
output.o \
|
||||
palette.o \
|
||||
|
@ -71,6 +71,7 @@ OBJS = asm.obj \
|
||||
fileio.obj \
|
||||
input.obj \
|
||||
koala.obj \
|
||||
lynxsprite.obj \
|
||||
main.obj \
|
||||
output.obj \
|
||||
palette.obj \
|
||||
|
Loading…
Reference in New Issue
Block a user