mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
Added two more conversion targets: geos-bitmap, which will create a GEOS
compacted bitmap, and raw, which is probably mostly useful for debugging. It converts an indexed image to a row of bytes which correspond to the color indices of the pixels. git-svn-id: svn://svn.cc65.org/cc65/trunk@5615 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
1c91618a5d
commit
fbbf7e50d2
@ -39,9 +39,11 @@
|
||||
#include "attr.h"
|
||||
#include "convert.h"
|
||||
#include "error.h"
|
||||
#include "geosbitmap.h"
|
||||
#include "geosicon.h"
|
||||
#include "koala.h"
|
||||
#include "lynxsprite.h"
|
||||
#include "raw.h"
|
||||
#include "vic2sprite.h"
|
||||
|
||||
|
||||
@ -61,9 +63,11 @@ struct ConverterMapEntry {
|
||||
|
||||
/* Converter table, alphabetically sorted */
|
||||
static const ConverterMapEntry ConverterMap[] = {
|
||||
{ "geos-bitmap", GenGeosBitmap },
|
||||
{ "geos-icon", GenGeosIcon },
|
||||
{ "koala", GenKoala },
|
||||
{ "lynx-sprite", GenLynxSprite },
|
||||
{ "raw", GenRaw },
|
||||
{ "vic2-sprite", GenVic2Sprite },
|
||||
};
|
||||
|
||||
|
234
src/sp65/geosbitmap.c
Normal file
234
src/sp65/geosbitmap.c
Normal file
@ -0,0 +1,234 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* geosbitmap.c */
|
||||
/* */
|
||||
/* GEOS compacted bitmap 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"
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* sp65 */
|
||||
#include "attr.h"
|
||||
#include "error.h"
|
||||
#include "geosbitmap.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#define UNIQUE_MAX 91U /* Maximum number of unique bytes */
|
||||
#define REPEAT_MAX 127U /* Maximum number of repeated bytes */
|
||||
|
||||
|
||||
|
||||
/* Structure used for RLE compression */
|
||||
struct RLE {
|
||||
unsigned char* Buf; /* Pointer to pixel buffer */
|
||||
unsigned Remaining; /* Remaining bytes in buffer */
|
||||
unsigned char LastVal; /* Last value seen */
|
||||
unsigned Count; /* Number of occurrences for LastVal */
|
||||
StrBuf* D; /* Buffer for compressed data */
|
||||
StrBuf UniqueData; /* Temp buffer for unique data */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
static void StoreByte (struct RLE* RLE)
|
||||
/* Store a unique byte or a run of repeated bytes. If count is zero, the
|
||||
* function will flush the internal buffers, so that all data is in RLE->D.
|
||||
*/
|
||||
{
|
||||
|
||||
|
||||
if (RLE->Count == 1 || RLE->Count == 2) {
|
||||
/* A run of two identical bytes is treated as two unique bytes, since
|
||||
* this will usually merge with the following run.
|
||||
*/
|
||||
SB_AppendChar (&RLE->UniqueData, RLE->LastVal);
|
||||
if (RLE->Count == 2) {
|
||||
SB_AppendChar (&RLE->UniqueData, RLE->LastVal);
|
||||
}
|
||||
|
||||
/* Clear the repeat counter */
|
||||
RLE->Count = 0;
|
||||
|
||||
} else {
|
||||
|
||||
/* Run of repeated bytes. First flush the temp buffer for unique
|
||||
* bytes.
|
||||
*/
|
||||
const char* Buf = SB_GetConstBuf (&RLE->UniqueData);
|
||||
unsigned Count = SB_GetLen (&RLE->UniqueData);
|
||||
while (Count) {
|
||||
|
||||
/* Determine the count for this sequence */
|
||||
unsigned Chunk = Count;
|
||||
if (Chunk > UNIQUE_MAX) {
|
||||
Chunk = UNIQUE_MAX;
|
||||
}
|
||||
|
||||
/* Output the unique op */
|
||||
SB_AppendChar (RLE->D, 0x80 + (unsigned char) Chunk);
|
||||
SB_AppendBuf (RLE->D, Buf, Chunk);
|
||||
|
||||
/* Bump the counters */
|
||||
Buf += Chunk;
|
||||
Count -= Chunk;
|
||||
}
|
||||
|
||||
/* Clear the unique byte buffer */
|
||||
SB_Clear (&RLE->UniqueData);
|
||||
|
||||
/* Now output the repeat sequence */
|
||||
while (RLE->Count) {
|
||||
|
||||
/* Determine the count for this sequence */
|
||||
unsigned Chunk = RLE->Count;
|
||||
if (Chunk > REPEAT_MAX) {
|
||||
Chunk = REPEAT_MAX;
|
||||
}
|
||||
/* Output the repeat op */
|
||||
SB_AppendChar (RLE->D, (unsigned char) Chunk);
|
||||
SB_AppendChar (RLE->D, RLE->LastVal);
|
||||
|
||||
/* Bump the counters */
|
||||
RLE->Count -= Chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
StrBuf* GenGeosBitmap (const Bitmap* B, const Collection* A attribute ((unused)))
|
||||
/* Generate binary output in GEOS compacted bitmap format for the bitmap B.
|
||||
* The output is stored in a string buffer (which is actually a dynamic char
|
||||
* array) and returned.
|
||||
*/
|
||||
{
|
||||
unsigned LineWidth;
|
||||
unsigned char* Buf;
|
||||
unsigned char* BP;
|
||||
StrBuf* D;
|
||||
unsigned X, Y;
|
||||
struct RLE RLE;
|
||||
|
||||
|
||||
/* 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)" : "");
|
||||
|
||||
/* Check the bitmap properties */
|
||||
if (!BitmapIsIndexed (B) || GetBitmapColors (B) > 2) {
|
||||
Error ("Bitmaps converted to GEOS compacted bitmap must be "
|
||||
"indexed with two colors");
|
||||
}
|
||||
|
||||
/* Calculate the width of one line in bytes */
|
||||
LineWidth = (GetBitmapWidth (B) + 7U) / 8U;
|
||||
|
||||
/* Allocate a buffer for the raw image */
|
||||
Buf = xmalloc (LineWidth * GetBitmapHeight (B));
|
||||
|
||||
/* Convert the bitmap into a raw image */
|
||||
BP = Buf;
|
||||
for (Y = 0; Y < GetBitmapHeight (B); ++Y) {
|
||||
for (X = 0; X < GetBitmapWidth (B); ) {
|
||||
unsigned char V = 0;
|
||||
int Bits = 8;
|
||||
if ((unsigned)Bits > GetBitmapWidth (B) - X) {
|
||||
Bits = (GetBitmapWidth (B) - X);
|
||||
}
|
||||
while (--Bits >= 0) {
|
||||
V |= (GetPixel (B, X++, Y).Index & 0x01) << Bits;
|
||||
}
|
||||
*BP++ = V;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the output buffer and resize it to something reasonable */
|
||||
D = NewStrBuf ();
|
||||
SB_Realloc (D, 64);
|
||||
|
||||
/* Compact the image. We're currently using only REPEAT and UNIQUE opcodes.
|
||||
* BIGCOUNT is rather difficult to apply.
|
||||
*/
|
||||
RLE.Buf = Buf;
|
||||
RLE.Remaining = LineWidth * GetBitmapHeight (B) - 1;
|
||||
RLE.LastVal = *RLE.Buf++;
|
||||
RLE.Count = 1;
|
||||
RLE.D = D;
|
||||
RLE.UniqueData = EmptyStrBuf;
|
||||
while (RLE.Remaining--) {
|
||||
/* */
|
||||
if (RLE.LastVal == *RLE.Buf) {
|
||||
++RLE.Buf;
|
||||
++RLE.Count;
|
||||
} else {
|
||||
StoreByte (&RLE);
|
||||
RLE.LastVal = *RLE.Buf++;
|
||||
RLE.Count = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* If something remains, store it */
|
||||
if (RLE.Count) {
|
||||
StoreByte (&RLE);
|
||||
}
|
||||
|
||||
/* Flush the unique byte buffer */
|
||||
StoreByte (&RLE);
|
||||
|
||||
/* Release the unique byte buffer */
|
||||
SB_Done (&RLE.UniqueData);
|
||||
|
||||
/* Free the raw image buffer */
|
||||
xfree (Buf);
|
||||
|
||||
/* Return the converted bitmap */
|
||||
return D;
|
||||
}
|
||||
|
||||
|
||||
|
70
src/sp65/geosbitmap.h
Normal file
70
src/sp65/geosbitmap.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* geosbitmap.h */
|
||||
/* */
|
||||
/* GEOS compacted bitmap 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 GEOSBITMAP_H
|
||||
#define GEOSBITMAP_H
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "coll.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
/* sp65 */
|
||||
#include "bitmap.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
StrBuf* GenGeosBitmap (const Bitmap* B, const Collection* A);
|
||||
/* Generate binary output in GEOS compacted bitmap format for the bitmap B.
|
||||
* The output is stored in a string buffer (which is actually a dynamic char
|
||||
* array) and returned.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End of geosbitmap.h */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -31,6 +31,7 @@ OBJS = asm.o \
|
||||
convert.o \
|
||||
error.o \
|
||||
fileio.o \
|
||||
geosbitmap.o \
|
||||
geosicon.o \
|
||||
input.o \
|
||||
koala.o \
|
||||
@ -39,6 +40,7 @@ OBJS = asm.o \
|
||||
output.o \
|
||||
palette.o \
|
||||
pcx.o \
|
||||
raw.o \
|
||||
vic2sprite.o
|
||||
|
||||
LIBS = $(COMMON)/common.a
|
||||
|
@ -69,6 +69,7 @@ OBJS = asm.obj \
|
||||
convert.obj \
|
||||
error.obj \
|
||||
fileio.obj \
|
||||
geosbitmap.obj \
|
||||
geosicon.obj \
|
||||
input.obj \
|
||||
koala.obj \
|
||||
@ -77,6 +78,7 @@ OBJS = asm.obj \
|
||||
output.obj \
|
||||
palette.obj \
|
||||
pcx.obj \
|
||||
raw.obj \
|
||||
vic2sprite.obj
|
||||
|
||||
LIBS = ../common/common.lib
|
||||
|
89
src/sp65/raw.c
Normal file
89
src/sp65/raw.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* raw.c */
|
||||
/* */
|
||||
/* Raw image converter 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 "raw.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
StrBuf* GenRaw (const Bitmap* B, const Collection* A attribute ((unused)))
|
||||
/* Generate binary output in raw format. The output is stored in a string
|
||||
* buffer (which is actually a dynamic char array) and returned.
|
||||
*/
|
||||
{
|
||||
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)" : "");
|
||||
|
||||
/* Check the bitmap properties */
|
||||
if (!BitmapIsIndexed (B)) {
|
||||
Error ("The raw format needs an input bitmap in indexed format");
|
||||
}
|
||||
|
||||
/* Create the output buffer and resize it to the required size. */
|
||||
D = NewStrBuf ();
|
||||
SB_Realloc (D, GetBitmapWidth (B) * GetBitmapHeight (B));
|
||||
|
||||
/* Convert the image */
|
||||
for (Y = 0; Y < GetBitmapHeight (B); ++Y) {
|
||||
for (X = 0; X < GetBitmapWidth (B); ++X) {
|
||||
/* Place one pixel into the buffer */
|
||||
SB_AppendChar (D, (unsigned char) GetPixel (B, X, Y).Index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the converted bitmap */
|
||||
return D;
|
||||
}
|
||||
|
||||
|
||||
|
67
src/sp65/raw.h
Normal file
67
src/sp65/raw.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* raw.h */
|
||||
/* */
|
||||
/* Raw image converter 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 RAW_H
|
||||
#define RAW_H
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "coll.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
/* sp65 */
|
||||
#include "bitmap.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
StrBuf* GenRaw (const Bitmap* B, const Collection* A);
|
||||
/* Generate binary output in raw format. The output is stored in a string
|
||||
* buffer (which is actually a dynamic char array) and returned.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End of raw.h */
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user