]> git.sur5r.net Git - cc65/commitdiff
Add lynx sprite generation skeleton
authorkarri <karri@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 11 Mar 2012 13:48:40 +0000 (13:48 +0000)
committerkarri <karri@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 11 Mar 2012 13:48:40 +0000 (13:48 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5609 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/sp65/lynxsprite.c [new file with mode: 0644]
src/sp65/lynxsprite.h [new file with mode: 0644]
src/sp65/make/gcc.mak
src/sp65/make/watcom.mak

diff --git a/src/sp65/lynxsprite.c b/src/sp65/lynxsprite.c
new file mode 100644 (file)
index 0000000..e5cfda4
--- /dev/null
@@ -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;
+}
+
+
+
diff --git a/src/sp65/lynxsprite.h b/src/sp65/lynxsprite.h
new file mode 100644 (file)
index 0000000..c5611e0
--- /dev/null
@@ -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
+
+
+
index 6a47c36ee1d7cb972f0a5876eb467a665b069563..045b792d5d8901290869ce6a760cfec6c086489c 100644 (file)
@@ -33,6 +33,7 @@ OBJS =        asm.o           \
         fileio.o        \
         input.o         \
         koala.o         \
+       lynxsprite.o    \
        main.o          \
         output.o        \
         palette.o       \
index c5b242a7879537c70d63629a87fab0725d6a9535..ff3838c20d2e7f42227939ebfd911db55573c9c5 100644 (file)
@@ -71,6 +71,7 @@ OBJS =  asm.obj         \
         fileio.obj      \
         input.obj       \
         koala.obj       \
+        lynxsprite.obj  \
        main.obj        \
         output.obj      \
         palette.obj     \