Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement sprites with RLE transparency #76

Merged
merged 2 commits into from
Jul 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/gfx_rletsprite/autotester.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"rom": "84pce_515.rom",
"transfer_files": [
"bin/DEMO.8xp"
],
"target": {
"name": "DEMO",
"isASM": true
},
"sequence": [
"action|launch",
"hashWait|1",
"key|enter",
"hashWait|2"
],
"hashes": {
"1": {
"description": "Make sure the sprites are displayed properly",
"start": "vram_start",
"size": "vram_8_size",
"expected_CRCs": [ "7C9ADADE" ]
},
"2": {
"description": "Back to the home screen (exit check)",
"start": "vram_start",
"size": "vram_16_size",
"expected_CRCs": [ "FFAF89BA", "101734A5", "9DA19F44" ]
}
}
}
33 changes: 33 additions & 0 deletions examples/gfx_rletsprite/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ----------------------------
# Set NAME to the program name
# Set DEBUGMODE to "DEBUG" to use debug functions
# Set ICON to the png icon file name
# Set DESCRIPTION to display within a compatible shell
# Set COMPRESSED to "YES" to create a compressed program
# ** Add all shared library names to L **
# ----------------------------

NAME ?= DEMO
DEBUGMODE ?= NDEBUG
COMPRESSED ?= NO
ICON ?= iconc.png
DESCRIPTION ?= "C SDK Demo"

L ?= graphx

# ----------------------------
# Specify source and output locations
# ----------------------------

SRCDIR ?= src
OBJDIR ?= obj
BINDIR ?= bin
GFXDIR ?= src/gfx

# ----------------------------
# Use OS helper functions (Advanced)
# ----------------------------

USE_FLASH_FUNCTIONS ?= YES

include $(CEDEV)/include/.makefile
10 changes: 10 additions & 0 deletions examples/gfx_rletsprite/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### GraphX RLETSprite Demo

Draws a sprite with RLE transparency in many clipping scenarios and converts to
and from a normal sprite with transparency. Created for testing.

![Screenshot](screenshot.png)

---

This demo is a part of the C SDK Toolchain for use on the CE.
Binary file added examples/gfx_rletsprite/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/gfx_rletsprite/src/gfx/convpng.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#GroupC : logo_gfx
#Style : rlet
#TransparentColor : 255,255,255
#PNGImages :
ubuntu
204 changes: 204 additions & 0 deletions examples/gfx_rletsprite/src/gfx/logo_gfx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// Converted using ConvPNG
#include <stdint.h>
#include "logo_gfx.h"

uint16_t logo_gfx_pal[198] = {
0xFFFF, // 00 :: rgba(255,255,255,255)
0xFFE0, // 01 :: rgba(255,255,0,255)
0x7C00, // 02 :: rgba(255,0,0,255)
0x001F, // 03 :: rgba(0,0,255,255)
0xFFFF, // 04 :: rgba(255,254,254,255)
0xFFFF, // 05 :: rgba(255,255,254,255)
0x83E0, // 06 :: rgba(0,255,0,255)
0x6800, // 07 :: rgba(212,0,0,255)
0x7E20, // 08 :: rgba(251,139,0,255)
0x7920, // 09 :: rgba(244,72,0,255)
0x6800, // 10 :: rgba(212,2,2,255)
0xE821, // 11 :: rgba(213,11,11,255)
0x7E20, // 12 :: rgba(251,139,2,255)
0x7E20, // 13 :: rgba(251,139,1,255)
0xFE20, // 14 :: rgba(251,140,4,255)
0xFFFF, // 15 :: rgba(255,253,253,255)
0xFFFF, // 16 :: rgba(255,254,253,255)
0xFECC, // 17 :: rgba(252,182,97,255)
0x7A90, // 18 :: rgba(249,163,128,255)
0x7FDC, // 19 :: rgba(254,244,231,255)
0xF985, // 20 :: rgba(245,100,40,255)
0x7F9A, // 21 :: rgba(253,225,213,255)
0x7FDD, // 22 :: rgba(253,242,242,255)
0x6D6B, // 23 :: rgba(226,90,90,255)
0xFFBC, // 24 :: rgba(254,239,233,255)
0xF921, // 25 :: rgba(244,77,7,255)
0x7EED, // 26 :: rgba(252,187,107,255)
0xFF99, // 27 :: rgba(254,231,203,255)
0xFFFE, // 28 :: rgba(255,253,250,255)
0xFF16, // 29 :: rgba(251,199,177,255)
0xF921, // 30 :: rgba(244,78,8,255)
0x7F31, // 31 :: rgba(253,204,143,255)
0xF18C, // 32 :: rgba(229,102,102,255)
0x7FDD, // 33 :: rgba(252,241,241,255)
0xFE87, // 34 :: rgba(251,164,56,255)
0xFF76, // 35 :: rgba(253,221,181,255)
0x7B5A, // 36 :: rgba(247,212,212,255)
0x7652, // 37 :: rgba(236,145,145,255)
0xF652, // 38 :: rgba(237,151,151,255)
0xE800, // 39 :: rgba(212,3,3,255)
0x6D29, // 40 :: rgba(224,74,74,255)
0x718C, // 41 :: rgba(228,98,98,255)
0xFF54, // 42 :: rgba(253,214,165,255)
0xFB7B, // 43 :: rgba(250,224,224,255)
0x7EEC, // 44 :: rgba(252,185,102,255)
0x7FFF, // 45 :: rgba(254,252,252,255)
0x7FBA, // 46 :: rgba(254,234,211,255)
0xFF77, // 47 :: rgba(253,224,187,255)
0x7F75, // 48 :: rgba(253,218,175,255)
0x7FFE, // 49 :: rgba(254,249,249,255)
0xFF32, // 50 :: rgba(252,205,148,255)
0xE842, // 51 :: rgba(215,20,20,255)
0xFFFF, // 52 :: rgba(255,253,251,255)
0x6CC6, // 53 :: rgba(219,48,48,255)
0x7EED, // 54 :: rgba(252,188,109,255)
0xF652, // 55 :: rgba(237,149,149,255)
0x7673, // 56 :: rgba(237,153,153,255)
0x7FBD, // 57 :: rgba(252,236,236,255)
0x7EA8, // 58 :: rgba(251,169,68,255)
0xFAF4, // 59 :: rgba(250,190,165,255)
0xFE87, // 60 :: rgba(251,167,61,255)
0xECA5, // 61 :: rgba(218,43,43,255)
0x7AD2, // 62 :: rgba(250,179,149,255)
0xFAF7, // 63 :: rgba(243,189,189,255)
0xFAF7, // 64 :: rgba(244,192,192,255)
0x7B9B, // 65 :: rgba(250,225,225,255)
0x7B7B, // 66 :: rgba(249,220,220,255)
0xED09, // 67 :: rgba(224,70,70,255)
0x6D08, // 68 :: rgba(222,63,63,255)
0xF1AD, // 69 :: rgba(229,109,109,255)
0xED08, // 70 :: rgba(223,69,69,255)
0x76D6, // 71 :: rgba(242,178,178,255)
0x6D4A, // 72 :: rgba(225,82,82,255)
0xECC6, // 73 :: rgba(220,51,51,255)
0x718C, // 74 :: rgba(228,97,97,255)
0x76D6, // 75 :: rgba(242,179,179,255)
0xFFDD, // 76 :: rgba(254,246,235,255)
0xFFBC, // 77 :: rgba(254,239,234,255)
0xFF77, // 78 :: rgba(253,223,187,255)
0x6863, // 79 :: rgba(216,26,26,255)
0x7AB1, // 80 :: rgba(249,169,136,255)
0xFF9C, // 81 :: rgba(251,230,230,255)
0xE843, // 82 :: rgba(215,21,21,255)
0xF9A6, // 83 :: rgba(245,108,51,255)
0x7942, // 84 :: rgba(244,81,13,255)
0xFE21, // 85 :: rgba(251,143,11,255)
0x7F97, // 86 :: rgba(253,225,189,255)
0x7FBA, // 87 :: rgba(254,236,215,255)
0x7FBC, // 88 :: rgba(251,234,234,255)
0x7F9A, // 89 :: rgba(253,227,217,255)
0x76D6, // 90 :: rgba(242,177,177,255)
0xFB18, // 91 :: rgba(245,197,197,255)
0x7AB1, // 92 :: rgba(249,171,139,255)
0xFFBB, // 93 :: rgba(254,239,221,255)
0xFAB2, // 94 :: rgba(249,176,144,255)
0xF694, // 95 :: rgba(240,167,167,255)
0x71AD, // 96 :: rgba(229,106,106,255)
0x7FDE, // 97 :: rgba(253,243,243,255)
0x7FDD, // 98 :: rgba(254,242,237,255)
0x6842, // 99 :: rgba(214,16,16,255)
0xE801, // 100 :: rgba(213,5,5,255)
0xE822, // 101 :: rgba(214,14,14,255)
0x6D29, // 102 :: rgba(223,71,71,255)
0x7672, // 103 :: rgba(237,152,152,255)
0x7A8F, // 104 :: rgba(249,161,124,255)
0xF694, // 105 :: rgba(239,165,165,255)
0x7FBB, // 106 :: rgba(253,233,224,255)
0xFFBC, // 107 :: rgba(254,238,231,255)
0xFEAA, // 108 :: rgba(251,175,80,255)
0x7FFE, // 109 :: rgba(255,251,247,255)
0xFA6F, // 110 :: rgba(249,159,121,255)
0x7694, // 111 :: rgba(239,163,163,255)
0xF920, // 112 :: rgba(244,75,4,255)
0x7694, // 113 :: rgba(239,161,161,255)
0xFF76, // 114 :: rgba(253,222,183,255)
0x7A8F, // 115 :: rgba(249,160,123,255)
0x7F0E, // 116 :: rgba(253,193,117,255)
0xFB39, // 117 :: rgba(247,208,208,255)
0xFF55, // 118 :: rgba(253,215,169,255)
0xFFBA, // 119 :: rgba(254,237,216,255)
0xFF7A, // 120 :: rgba(253,224,213,255)
0xFF32, // 121 :: rgba(253,207,151,255)
0x7631, // 122 :: rgba(235,138,138,255)
0xFB7B, // 123 :: rgba(250,223,223,255)
0x7B38, // 124 :: rgba(246,201,201,255)
0x7AF3, // 125 :: rgba(250,186,160,255)
0x7FFF, // 126 :: rgba(254,251,251,255)
0xF16C, // 127 :: rgba(227,95,95,255)
0x7FDB, // 128 :: rgba(254,241,224,255)
0xFE87, // 129 :: rgba(251,165,60,255)
0xFA6F, // 130 :: rgba(249,159,122,255)
0xFE87, // 131 :: rgba(251,164,57,255)
0x7F0E, // 132 :: rgba(252,193,119,255)
0xFF9B, // 133 :: rgba(253,229,219,255)
0x7A2B, // 134 :: rgba(247,138,92,255)
0x7E42, // 135 :: rgba(251,146,19,255)
0x7FDC, // 136 :: rgba(254,243,230,255)
0x7963, // 137 :: rgba(244,89,24,255)
0x7E41, // 138 :: rgba(251,144,12,255)
0x7F79, // 139 :: rgba(252,220,207,255)
0xFF33, // 140 :: rgba(252,208,154,255)
0x7F36, // 141 :: rgba(251,202,182,255)
0xFA6E, // 142 :: rgba(249,157,119,255)
0xFFDD, // 143 :: rgba(254,245,240,255)
0xF964, // 144 :: rgba(245,95,32,255)
0x7920, // 145 :: rgba(244,74,3,255)
0xF921, // 146 :: rgba(244,76,6,255)
0xFFDE, // 147 :: rgba(254,246,243,255)
0xFAD3, // 148 :: rgba(250,183,155,255)
0x7B18, // 149 :: rgba(245,195,195,255)
0x7FFE, // 150 :: rgba(255,252,250,255)
0xFAD3, // 151 :: rgba(250,182,154,255)
0x6800, // 152 :: rgba(212,1,1,255)
0x7FFE, // 153 :: rgba(255,251,250,255)
0xF985, // 154 :: rgba(245,103,44,255)
0x7EA8, // 155 :: rgba(251,169,69,255)
0xFEAA, // 156 :: rgba(251,176,82,255)
0x7ECB, // 157 :: rgba(251,179,87,255)
0x7AD2, // 158 :: rgba(250,178,148,255)
0x6D08, // 159 :: rgba(222,65,65,255)
0x71EF, // 160 :: rgba(231,120,120,255)
0xFAD3, // 161 :: rgba(250,181,153,255)
0x7A4D, // 162 :: rgba(248,147,106,255)
0xFB5A, // 163 :: rgba(248,216,216,255)
0x7FDE, // 164 :: rgba(253,244,244,255)
0x7F15, // 165 :: rgba(251,196,173,255)
0x7F79, // 166 :: rgba(253,220,206,255)
0xFFDD, // 167 :: rgba(254,246,242,255)
0x7652, // 168 :: rgba(236,146,146,255)
0xF9E9, // 169 :: rgba(246,126,76,255)
0xFB39, // 170 :: rgba(247,206,206,255)
0xFF37, // 171 :: rgba(252,208,190,255)
0xF942, // 172 :: rgba(244,83,16,255)
0x7F31, // 173 :: rgba(252,201,137,255)
0xFAB2, // 174 :: rgba(250,176,145,255)
0xF9C8, // 175 :: rgba(246,116,62,255)
0xFF9B, // 176 :: rgba(253,232,224,255)
0xFF10, // 177 :: rgba(252,198,131,255)
0x7A6E, // 178 :: rgba(248,155,117,255)
0xFFBB, // 179 :: rgba(254,240,221,255)
0xFE21, // 180 :: rgba(251,143,10,255)
0xFEA9, // 181 :: rgba(251,174,78,255)
0x7E87, // 182 :: rgba(251,163,54,255)
0xFF54, // 183 :: rgba(253,213,164,255)
0xF9E9, // 184 :: rgba(247,127,77,255)
0x79E8, // 185 :: rgba(246,120,67,255)
0xFE21, // 186 :: rgba(251,141,6,255)
0xFFDD, // 187 :: rgba(254,248,240,255)
0xFF58, // 188 :: rgba(252,213,197,255)
0x7FDC, // 189 :: rgba(254,243,229,255)
0x7F53, // 190 :: rgba(253,210,155,255)
0xFE87, // 191 :: rgba(251,164,58,255)
0x7920, // 192 :: rgba(244,74,2,255)
0x7F57, // 193 :: rgba(252,210,193,255)
0xC3E0, // 194 :: rgba(128,255,0,255)
0x7E00, // 195 :: rgba(255,128,0,255)
0x0210, // 196 :: rgba(0,128,128,255)
0x4030, // 197 :: rgba(128,8,128,255)
};
14 changes: 14 additions & 0 deletions examples/gfx_rletsprite/src/gfx/logo_gfx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Converted using ConvPNG
// This file contains all the graphics sources for easier inclusion in a project
#ifndef __logo_gfx__
#define __logo_gfx__
#include <stdint.h>

#define logo_gfx_transparent_color_index 0

extern uint8_t ubuntu_data[552];
#define ubuntu ((gfx_rletsprite_t*)ubuntu_data)
#define sizeof_logo_gfx_pal 396
extern uint16_t logo_gfx_pal[198];

#endif
26 changes: 26 additions & 0 deletions examples/gfx_rletsprite/src/gfx/ubuntu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Converted using ConvPNG
#include <stdint.h>
#include "logo_gfx.h"

// 8 bpp image
uint8_t ubuntu_data[552] = {
32,32, // width,height
0x00,0x04,0xC2,0x01,0x01,0x01,0x18,0x04,0x01,0x01,0x01,0xC3,0x00,0x01,0x06,0x1E,0x01,0x02,0x00,0x01,0x06,0x15,0x04,0x0F,0x47,0x25,0x42,0x05,0x01,0x02,0x00,0x01,
0x06,0x14,0x06,0x04,0x17,0x07,0x07,0x0B,0x40,0x04,0x01,0x02,0x0E,0x0D,0x04,0x59,0x3B,0x50,0x12,0x94,0x18,0xA3,0x07,0x07,0x07,0x07,0x28,0x05,0x0D,0x0E,0x8D,0x14,
0x09,0x09,0x09,0x09,0x09,0xA5,0xAA,0x07,0x07,0x07,0x07,0x46,0x05,0x0B,0x01,0x88,0x01,0x0E,0x85,0x19,0x09,0x09,0x09,0x09,0x09,0xA2,0x04,0x9F,0x07,0x07,0x98,0x5A,
0x05,0x0A,0x03,0x8C,0x87,0x13,0x01,0x0C,0x8E,0x09,0x09,0x09,0x09,0x09,0x19,0xA6,0xA4,0xA8,0xA0,0x95,0x06,0x09,0x04,0x76,0x0D,0x08,0x11,0x01,0x0E,0x8F,0x89,0x70,
0x90,0x9A,0x1E,0x09,0xAC,0xA1,0xA7,0x99,0x15,0x5C,0x04,0x04,0x08,0x06,0x5D,0x55,0x08,0x08,0x0C,0x1B,0x01,0x03,0x78,0x62,0x05,0x01,0x09,0x96,0xAB,0xA9,0x09,0x09,
0x92,0x09,0x09,0x3E,0x04,0x07,0x07,0x05,0x9C,0x08,0x08,0x08,0x08,0x84,0x07,0x08,0x04,0x97,0x91,0x09,0x09,0x09,0x54,0x4D,0x03,0x07,0x07,0xB3,0x0D,0x08,0x08,0x08,
0x81,0x1C,0x09,0x06,0x5E,0x09,0x09,0x09,0x09,0x12,0x03,0x07,0x06,0xB7,0x08,0x08,0x08,0x0C,0x57,0x0A,0x07,0x04,0x53,0x09,0x09,0x09,0x14,0x04,0x02,0x03,0x09,0x93,
0xAE,0xB2,0xC1,0x05,0x1A,0x08,0x08,0x9B,0x0C,0x06,0x7D,0x09,0x09,0x09,0x09,0x18,0x02,0x02,0x0A,0x10,0xAF,0x09,0x09,0xC0,0x1D,0xBB,0xB4,0x08,0xB1,0x0C,0x06,0x6B,
0x68,0x73,0x82,0x6E,0x6A,0x02,0x02,0x06,0x8B,0x09,0x09,0x09,0x09,0xB9,0x01,0x03,0xBF,0x08,0xBE,0x14,0x02,0x06,0x15,0x09,0x09,0x09,0x09,0xB8,0x01,0x03,0xB6,0x08,
0xAD,0x0C,0x06,0x61,0x71,0x6F,0x69,0x5F,0x58,0x02,0x02,0x0A,0x04,0x86,0x09,0x09,0x1E,0xBC,0xBD,0xBA,0x08,0x9D,0x0C,0x06,0x4B,0x07,0x07,0x07,0x07,0x51,0x02,0x03,
0x0A,0x10,0x1D,0x9E,0xB0,0x1C,0xB5,0x08,0x08,0x8A,0x4C,0x0B,0x06,0x48,0x07,0x07,0x07,0x4F,0x0F,0x02,0x07,0x07,0x1B,0x08,0x08,0x08,0x08,0x2C,0x05,0x09,0x06,0x3F,
0x0A,0x07,0x07,0x07,0x45,0x03,0x07,0x07,0x04,0x83,0x08,0x08,0x08,0x08,0x32,0x08,0x07,0x75,0x52,0x07,0x07,0x07,0x27,0x24,0x03,0x08,0x06,0x4E,0x08,0x08,0x08,0x08,
0x30,0x01,0x02,0x31,0x04,0x03,0x08,0x16,0x7A,0x0B,0x07,0x07,0x07,0x07,0x20,0x04,0x08,0x14,0x05,0x36,0x08,0x08,0x3A,0x04,0x2D,0x35,0x49,0x4A,0x60,0x66,0x65,0x07,
0x07,0x0A,0x0B,0x07,0x3D,0x21,0x04,0x09,0x04,0x34,0x11,0x0E,0x2E,0x01,0x0D,0x37,0x07,0x07,0x07,0x07,0x07,0x07,0x63,0x67,0x16,0x7E,0x7B,0x41,0x05,0x0A,0x02,0x05,
0x2F,0x01,0x0D,0x39,0x33,0x07,0x07,0x07,0x07,0x07,0x64,0x7C,0x6D,0x79,0x74,0x56,0x06,0x0D,0x0E,0x38,0x0A,0x07,0x07,0x07,0x07,0x07,0x7F,0x04,0x6C,0x08,0x08,0x0D,
0x2A,0x05,0x0E,0x0D,0x2B,0x26,0x29,0x43,0x44,0x17,0x5B,0x80,0x08,0x08,0x08,0x08,0x22,0x05,0x15,0x06,0x13,0x0C,0x08,0x08,0x08,0x3C,0x05,0x00,0x01,0x06,0x15,0x05,
0x1A,0x08,0x08,0x0E,0x72,0x04,0x01,0x02,0x00,0x01,0x06,0x15,0x04,0x05,0x23,0x1F,0x77,0x05,0x01,0x02,0x00,0x01,0x06,0x1E,0x01,0x02,0x00,0x04,0xC4,0x03,0x03,0x03,
0x18,0x04,0x03,0x03,0x03,0xC5,
};
Binary file added examples/gfx_rletsprite/src/gfx/ubuntu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions examples/gfx_rletsprite/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#include <graphx.h>

/* Include the sprite data */
#include "gfx/logo_gfx.h"

#define xmin 64
#define ymin 24
#define xmax 256
#define ymax 216

#define xmin2 180
#define ymin2 92
#define xmax2 204
#define ymax2 116

/* For testing conversions */
gfx_UninitedSprite(ubuntu_normal, 32, 32);
gfx_UninitedRLETSprite(ubuntu_uninited, 33 * 32);

void main(void) {
/* For testing conversions */
gfx_rletsprite_t *ubuntu_malloc;

/* Initialize the 8bpp graphics */
gfx_Begin(gfx_8bpp);

/* Set up the palette for our sprites */
gfx_SetPalette(logo_gfx_pal, sizeof logo_gfx_pal, 0);
gfx_palette[255] = gfx_RGBTo1555(192, 192, 192);

/* Set a centered 192*192 clip region, bordered by gray and filled with color index 0 */
gfx_FillScreen(255);
gfx_SetColor(0);
gfx_FillRectangle_NoClip(xmin, ymin, xmax - xmin, ymax - ymin);
gfx_SetClipRegion(xmin, ymin, xmax, ymax);

/* Test no clipping */
gfx_RLETSprite_NoClip(ubuntu, xmin + 48, ymin + 64);
gfx_RLETSprite(ubuntu, xmin + 80, ymin + 64);

/* Test top clipping */
gfx_RLETSprite(ubuntu, xmin + 32, ymin);
gfx_RLETSprite(ubuntu, xmin + 64, ymin - 31);
gfx_RLETSprite(ubuntu, xmin + 96, ymin - 32);
gfx_RLETSprite(ubuntu, xmin + 128, INT_MIN);

/* Test bottom clipping */
gfx_RLETSprite(ubuntu, xmin + 128, ymax - 32);
gfx_RLETSprite(ubuntu, xmin + 96, ymax - 1);
gfx_RLETSprite(ubuntu, xmin + 64, ymax);
gfx_RLETSprite(ubuntu, xmin + 32, INT_MAX);

/* Test right clipping */
gfx_RLETSprite(ubuntu, xmax - 32, ymin + 32);
gfx_RLETSprite(ubuntu, xmax - 1, ymin + 64);
gfx_RLETSprite(ubuntu, xmax, ymin + 96);
gfx_RLETSprite(ubuntu, INT_MAX, ymin + 128);

/* Test left clipping */
gfx_RLETSprite(ubuntu, xmin, ymin + 128);
gfx_RLETSprite(ubuntu, xmin - 31, ymin + 96);
gfx_RLETSprite(ubuntu, xmin - 32, ymin + 64);
gfx_RLETSprite(ubuntu, INT_MIN, ymin + 32);

/* Test corner clipping */
gfx_RLETSprite(ubuntu, xmin - 31, ymin - 31);
gfx_RLETSprite(ubuntu, xmax - 1, ymin - 31);
gfx_RLETSprite(ubuntu, xmax - 1, ymax - 1);
gfx_RLETSprite(ubuntu, xmin - 31, ymax - 1);

/* Set a centered 16*16 clip region, bordered by gray and filled with color index 0 */
gfx_SetColor(255);
gfx_FillRectangle_NoClip(xmin2 - 4, ymin2 - 4, xmax2 - xmin2 + 8, ymax2 - ymin2 + 8);
gfx_SetColor(0);
gfx_FillRectangle_NoClip(xmin2, ymin2, xmax2 - xmin2, ymax2 - ymin2);
gfx_SetClipRegion(xmin2, ymin2, xmax2, ymax2);

/* Test all-around clipping */
gfx_RLETSprite(ubuntu, xmin2 - 4, ymin2 - 4);

/* Test conversions */
gfx_SetTransparentColor(0);
gfx_ConvertFromRLETSprite(ubuntu, ubuntu_normal);
gfx_TransparentSprite_NoClip(ubuntu_normal, xmin + 48, ymin + 96);
gfx_ConvertToRLETSprite(ubuntu_normal, ubuntu_uninited);
gfx_RLETSprite_NoClip(ubuntu_uninited, xmin + 80, ymin + 96);
ubuntu_malloc = gfx_ConvertMallocRLETSprite(ubuntu_normal);
gfx_RLETSprite_NoClip(ubuntu_malloc, xmin + 112, ymin + 96);

/* Wait for a key to be pressed */
while (!os_GetCSC());

/* Close the graphics */
gfx_End();
}
20 changes: 8 additions & 12 deletions examples/gfx_sprite_compress/src/main.c
Original file line number Diff line number Diff line change
@@ -18,32 +18,28 @@
void main(void) {
/* Define our sprite */
gfx_sprite_t *apple;

/* This is just here so that the malloc function is compiled into the binary */
malloc(0);


/* Allocate space for the decompressed sprite */
apple = gfx_MallocSprite(220, 240);

/* Decompress the sprite */
dzx7_Standard(apple_compressed, apple); // or dzx7_Turbo

/* Initialize the 8bpp graphics */
gfx_Begin(gfx_8bpp);

/* Set up the palette */
gfx_SetPalette(all_gfx_pal, sizeof all_gfx_pal, 0);
gfx_FillScreen(0);

/* Draw the decompressed sprite */
gfx_Sprite(apple, (320 - 220) / 2, (240 - 240) / 2);

/* Wait for a key */
while (!os_GetCSC());

/* Please, don't forget to free the apple image memory :) */
free(apple);

gfx_End();
}

20 changes: 10 additions & 10 deletions examples/gfx_tilemap_compress/src/main.c
Original file line number Diff line number Diff line change
@@ -42,15 +42,16 @@ void main(void) {
unsigned int y_offset = 0;
gfx_sprite_t *tmp_ptr;
gfx_tilemap_t tilemap;

/* Decompress the tiles */
for (i = 0; i < sizeof(tileset_tiles)/sizeof(gfx_sprite_t*) ; i++) {
tmp_ptr = gfx_MallocSprite(TILE_WIDTH, TILE_HEIGHT);
dzx7_Turbo(tileset_tiles_compressed[i], tmp_ptr); // or dzx7_Standard, but in this case we have a lot of tiles
tileset_tiles[i] = tmp_ptr;
}

dzx7_Turbo(tilemap_compressed, tilemap_map);

/* Initialize the tilemap structure */
tilemap.map = tilemap_map;
tilemap.tiles = tileset_tiles;
@@ -64,31 +65,31 @@ void main(void) {
tilemap.width = TILEMAP_WIDTH;
tilemap.y_loc = Y_OFFSET;
tilemap.x_loc = X_OFFSET;

/* Initialize the graphics scene */
gfx_Begin();

/* Set up the palette */
gfx_SetPalette(tiles_gfx_pal, sizeof tiles_gfx_pal, 0);
gfx_SetColor(gfx_white);

/* Draw to buffer to avoid tearing */
gfx_SetDrawBuffer();

/* Set monospace font with width of 8 */
gfx_SetMonospaceFont(8);

/* Wait for the enter key to quit */
while ((key = os_GetCSC()) != sk_Enter) {

/* Draw tilemap and coords */
gfx_Tilemap(&tilemap, x_offset, y_offset);
gfx_FillRectangle(0, 0, 320, 16);
gfx_PrintStringXY("x offset:", 48, 4);
gfx_PrintUInt(x_offset, 4);
gfx_PrintString(" y offset:");
gfx_PrintUInt(y_offset, 4);

/* Do something based on the keypress */
switch (key) {
case sk_Down:
@@ -112,8 +113,7 @@ void main(void) {
}
gfx_SwapDraw();
}

/* Close the graphics */
gfx_End();
}

583 changes: 582 additions & 1 deletion src/graphx/graphx.asm

Large diffs are not rendered by default.

382 changes: 324 additions & 58 deletions src/graphx/graphx.h

Large diffs are not rendered by default.