Browse Source

initial

master
CrunkLord420 5 months ago
commit
8b61932313
12 changed files with 228 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +8
    -0
      LICENSE
  3. +8
    -0
      Makefile
  4. +42
    -0
      PxBlot.HC
  5. +30
    -0
      README.md
  6. +5
    -0
      extra/sweetie16/Sweetie16.HC
  7. +20
    -0
      extra/sweetie16/sweetie-16.gpl
  8. BIN
      extra/sweetie16/sweetie-16.png
  9. +4
    -0
      extra/sweetie16/sweetie16.txt
  10. +92
    -0
      main.c
  11. +18
    -0
      palette/templeos_palette.gpl
  12. BIN
      palette/templeos_palette.png

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
png2holyc

+ 8
- 0
LICENSE View File

@ -0,0 +1,8 @@
Copyright 2020 CrunkLord420
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice, this permission notice and the word "NIGGER" shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 8
- 0
Makefile View File

@ -0,0 +1,8 @@
CC := gcc
CFLAGS = -O2 -Wall -pedantic
png2holyc: main.c
$(CC) $(CFLAGS) -lpng main.c -o png2holyc
clean:
rm png2holyc

+ 42
- 0
PxBlot.HC View File

@ -0,0 +1,42 @@
#ifndef PXBLOT_HC
#define PXBLOT_HC
class PxData {
I32 width;
I32 height;
U8 *body;
};
public U0 PxBlot(CDC *dc, PxData *data, I64 x, I64 y) {
// Cull
if (x >= dc->width_internal || y >= dc->height ||
x+data->width < 0 || y+data->height < 0) {
return;
}
// Clip X
I64 maxX = data->width;
if (maxX+x >= dc->width_internal) {
maxX -= maxX+x - dc->width_internal;
}
// Clip Y
I64 maxY = data->height;
if (maxY+y >= dc->height) {
maxY -= maxY+y - dc->height;
}
I64 d = dc->body + y*dc->width_internal + x;
I64 dy, dx;
for (dy=0; dy<maxY; dy++) {
U8 *dst = d + dy*dc->width_internal;
for (dx=0; dx<maxX; dx++, dst++) {
U8 color = data->body[dy*data->width+dx];
if (color != TRANSPARENT) {
*dst = color;
}
}
}
}
#endif

+ 30
- 0
README.md View File

@ -0,0 +1,30 @@
# PNG Requirements
General: PNG must be saved in indexed mode.
GIMP: Import the .gpl as your palette and enable alpha layer. Functionally pixels with transparency will become indexed to #0.
Aseprite: Import the .png as your palette, the magenta in slot #0 will be treated as transparent while in indexed mode by default.
Note: The colors of your palette don't actually matter, we only care about the index number. Below is the default colors and how they're converted.
# Conversion Chart
* TRANSPARENT 0 -> 0xFF
* BLACK 1 -> 0
* BLUE 2 -> 1
* GREEN 3 -> 2
* CYAN 4 -> 3
* RED 5 -> 4
* PURPLE 6 -> 5
* BROWN 7 -> 6
* LTGRAY 8 -> 7
* DKGRAY 9 -> 8
* LTBLUE 10 -> 9
* LTGREEN 11 -> 10
* LTCYAN 12 -> 11
* LTRED 13 -> 12
* LTPURPLE 14 -> 13
* YELLOW 15 -> 14
* WHITE 16 -> 15

+ 5
- 0
extra/sweetie16/Sweetie16.HC View File

@ -0,0 +1,5 @@
public CBGR48 gr_palette_sweetie16[COLORS_NUM]={
0x1A1A1C1C2C2C,0x5D5D27275D5D,0xB1B13E3E5353,0xEFEF7D7D5757,
0xFFFFCDCD7575,0xA7A7F0F07070,0x3838B7B76464,0x252571717979,
0x292936366F6F,0x3B3B5D5DC9C9,0x4141A6A6F6F6,0x7373EFEFF7F7,
0xF4F4F4F4F4F4,0x9494B0B0C2C2,0x56566C6C8686,0x33333C3C5757};

+ 20
- 0
extra/sweetie16/sweetie-16.gpl View File

@ -0,0 +1,20 @@
GIMP Palette
#Palette Name: Sweetie 16
#Description: Palette created by <a href="http://grafxkid.tumblr.com/palettes" target="_blank">GrafxKid</a>.
#Colors: 16
26 28 44 1a1c2c
93 39 93 5d275d
177 62 83 b13e53
239 125 87 ef7d57
255 205 117 ffcd75
167 240 112 a7f070
56 183 100 38b764
37 113 121 257179
41 54 111 29366f
59 93 201 3b5dc9
65 166 246 41a6f6
115 239 247 73eff7
244 244 244 f4f4f4
148 176 194 94b0c2
86 108 134 566c86
51 60 87 333c57

BIN
extra/sweetie16/sweetie-16.png View File

Before After
Width: 16  |  Height: 2  |  Size: 149 B

+ 4
- 0
extra/sweetie16/sweetie16.txt View File

@ -0,0 +1,4 @@
Sweetie 16 Palette by GrafxKid
https://grafxkid.tumblr.com/palettes
https://lospec.com/palette-list/sweetie-16

+ 92
- 0
main.c View File

@ -0,0 +1,92 @@
#include <stdio.h>
#include <stdlib.h>
#include <png.h>
int main(int argc, char **argv) {
if (argc != 4) {
printf("ERROR: %s <name> <input> <output>\n", argv[0]);
return EXIT_FAILURE;
}
printf("Opening %s\n", argv[2]);
FILE *fp = fopen(argv[2], "rb");
if (!fp) {
printf("ERROR: can't open %s\n", argv[2]);
return EXIT_FAILURE;
}
unsigned char header[8];
if (fread(header, 1, 8, fp) != 8) {
fclose(fp);
printf("ERROR: can't read %s\n", argv[2]);
return EXIT_FAILURE;
}
if (png_sig_cmp(header, 0, 8)) {
fclose(fp);
printf("ERROR: %s not recognized as a PNG file\n", argv[2]);
return EXIT_FAILURE;
}
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(fp);
printf("ERROR: can't create read struct\n");
return EXIT_FAILURE;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
fclose(fp);
printf("ERROR: can't create info struct\n");
return EXIT_FAILURE;
}
if (setjmp(png_jmpbuf(png_ptr))) {
fclose(fp);
printf("ERROR: can't set jmpbuf\n");
return EXIT_FAILURE;
}
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 8);
png_read_info(png_ptr, info_ptr);
png_byte color_type = png_get_color_type(png_ptr, info_ptr);
if (color_type != PNG_COLOR_TYPE_PALETTE) {
fclose(fp);
printf("ERROR: %s is not palette-encoded\n", argv[2]);
return EXIT_FAILURE;
}
int width = png_get_image_width(png_ptr, info_ptr);
int height = png_get_image_height(png_ptr, info_ptr);
png_bytep *row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
for (int y=0; y<height; y++) {
row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
}
png_read_image(png_ptr, row_pointers);
fclose(fp);
FILE *fOutput = fopen(argv[3], "w");
fprintf(fOutput, "#include \"PxBlot\"\nU8 %sBody[%d]={", argv[1], width*height);
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
unsigned int color = row_pointers[y][x];
if (color == 0) {
color = 0xff;
} else {
color--;
}
fprintf(fOutput, "%d,", color);
}
}
fseek(fOutput, -1, SEEK_CUR);
fprintf(fOutput, "};\nPxData %s={%d,%d,%sBody};", argv[1], width, height, argv[1]);
fclose(fOutput);
return EXIT_SUCCESS;
}

+ 18
- 0
palette/templeos_palette.gpl View File

@ -0,0 +1,18 @@
GIMP Palette
#
0 0 0 Untitled
0 0 170 Untitled
0 170 0 Untitled
0 170 170 Untitled
170 0 0 Untitled
170 0 170 Untitled
170 85 0 Untitled
170 170 170 Untitled
85 85 85 Untitled
85 85 255 Untitled
85 255 85 Untitled
85 255 255 Untitled
255 85 85 Untitled
255 85 255 Untitled
255 255 85 Untitled
255 255 255 Untitled

BIN
palette/templeos_palette.png View File

Before After
Width: 16  |  Height: 2  |  Size: 149 B

Loading…
Cancel
Save