firmware/scroll: added `Makefile` for `FuenteABin` tool

* moved `FuenteABin` tool into `tools` sub-directory
This commit is contained in:
Ivan Tatarinov 2021-05-03 23:05:19 +03:00
parent f3a1881d65
commit 69593ab14c
4 changed files with 196 additions and 57 deletions

View File

@ -1,57 +0,0 @@
#include "lodepng.c"
#include <stdio.h>
#include <stdlib.h>
unsigned char *image, *pixel, output[0x280];
unsigned error, i, j, k, l, celda, fondo, tinta, outpos= 0;
FILE *fo;
int check(int value){
return value==0 || value==192 || value==255;
}
int tospec(int r, int g, int b){
return g>>7<<2 | r>>7<<1 | b>>7;
}
int main(int argc, char *argv[]){
error= lodepng_decode32_file(&image, &i, &j, "fuente6x8.png");
if( error )
printf("\nError %u: %s\n", error, lodepng_error_text(error)),
exit(-1);
if( i!= 96 || j!= 40 )
printf("\nError. Incorrect size, must be 96x40\n"),
exit(-1);
fo= fopen("fuente6x8.bin", "wb+");
if( !fo )
printf("\nCannot create output file\n"),
exit(-1);
for ( i= 0; i < 5; i++ )
for ( j= 0; j < 16; j++ ){
pixel= &image[((j|i<<7)*6)<<2];
fondo= tinta= tospec(pixel[0], pixel[1], pixel[2]);
for ( k= 0; k < 8; k++ ){
celda= 0;
for ( l= 0; l < 6; l++ ){
pixel= &image[((j|i<<7)*6 + k*96 + l)<<2];
if( !(check(pixel[0]) && check(pixel[1]) && check(pixel[2]))
|| ((char)pixel[0]*-1 | (char)pixel[1]*-1 | (char)pixel[2]*-1)==65 )
printf("\nThe pixel (%d, %d) has an incorrect color\n" , j*6+l, i*8+k),
exit(-1);
if( tinta != tospec(pixel[0], pixel[1], pixel[2]) )
if( fondo != tospec(pixel[0], pixel[1], pixel[2]) ){
if( tinta != fondo )
printf("\nThe pixel (%d, %d) has a third color in the cell\n", j*6+l, i*8+k),
exit(-1);
tinta= tospec(pixel[0], pixel[1], pixel[2]);
}
celda<<= 1;
celda|= fondo != tospec(pixel[0], pixel[1], pixel[2]);
}
output[outpos++]= celda<<2;
}
}
fwrite(output, outpos, 1, fo);
fclose(fo);
printf("\nDone\n");
free(image);
}

5
firmware/scroll/tools/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2021 Ivan Tatarinov <ivan-tat@ya.ru>
#
# SPDX-License-Identifier: CC0-1.0
build

View File

@ -0,0 +1,123 @@
/*
* FuenteABin - convert PNG image to a binary font file.
*
* Copyright (C) 2019, 2021 Antonio Villena
* Contributors:
* 2021 Ivan Tatarinov <ivan-tat@ya.ru>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-FileCopyrightText: Copyright (C) 2019, 2021 Antonio Villena
*
* SPDX-FileContributor: 2021 Ivan Tatarinov <ivan-tat@ya.ru>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#include <stdio.h>
#include <stdlib.h>
#include "lodepng.h"
#define PROGRAM "FuenteABin"
#define DESCRIPTION "convert PNG image to a binary font file."
#define VERSION "0.1"
#define COPYRIGHT "Copyright (C) 2016, 2021 Antonio Villena"
#define LICENSE \
"This program is free software: you can redistribute it and/or modify\n" \
"it under the terms of the GNU General Public License as published by\n" \
"the Free Software Foundation, version 3."
#define HOMEPAGE "https://github.com/zxdos/zxuno/"
#define IMAGE_WIDTH 96
#define IMAGE_HEIGHT 40
#define CHAR_WIDTH 6
#define CHAR_HEIGHT 8
#define BUF_SIZE ((IMAGE_WIDTH/CHAR_WIDTH)*(IMAGE_HEIGHT/CHAR_HEIGHT)*CHAR_HEIGHT)
unsigned char *image, *pixel, output[BUF_SIZE];
unsigned error, i, j, k, l, celda, fondo, tinta, outpos= 0;
FILE *fo;
int check(int value){
return value==0 || value==192 || value==255;
}
int tospec(int r, int g, int b){
return g>>7<<2 | r>>7<<1 | b>>7;
}
void show_help() {
printf(
PROGRAM " version " VERSION " - " DESCRIPTION "\n"
COPYRIGHT "\n"
LICENSE "\n"
"Home page: " HOMEPAGE "\n"
"\n"
"Usage:\n"
" " PROGRAM " <input_file> <output_file>\n"
"\n"
" <input_file> Input PNG file, %ux%u pixels in size\n"
" <output_file> Output binary file\n",
IMAGE_WIDTH,
IMAGE_HEIGHT
);
}
#define image_pixel_off(i, j, k, l) (((j|i<<7)*CHAR_WIDTH + k*IMAGE_WIDTH + l)<<2)
int main(int argc, char *argv[]){
if (argc!=3){
show_help(),
exit(argc==1 ? 0 : -1);
}
error= lodepng_decode32_file(&image, &i, &j, argv[1]);
if( error )
printf("Error %u: %s\n", error, lodepng_error_text(error)),
exit(-1);
if( i!= IMAGE_WIDTH || j!= IMAGE_HEIGHT )
printf("Error. Incorrect image size, must be %ux%u pixels\n", IMAGE_WIDTH, IMAGE_HEIGHT),
exit(-1);
fo= fopen(argv[2], "wb+");
if( !fo )
printf("Cannot create output file: %s\n", argv[2]),
exit(-1);
for ( i= 0; i < IMAGE_HEIGHT/CHAR_HEIGHT; i++ )
for ( j= 0; j < IMAGE_WIDTH/CHAR_WIDTH; j++ ){
pixel= &image[image_pixel_off(i, j, 0, 0)];
fondo= tinta= tospec(pixel[0], pixel[1], pixel[2]);
for ( k= 0; k < CHAR_HEIGHT; k++ ){
celda= 0;
for ( l= 0; l < CHAR_WIDTH; l++ ){
pixel= &image[image_pixel_off(i, j, k, l)];
if( !(check(pixel[0]) && check(pixel[1]) && check(pixel[2]))
|| ((char)pixel[0]*-1 | (char)pixel[1]*-1 | (char)pixel[2]*-1)==65 )
printf("The pixel (%d, %d) has an incorrect color\n" , j*CHAR_WIDTH+l, i*CHAR_HEIGHT+k),
exit(-1);
if( tinta != tospec(pixel[0], pixel[1], pixel[2]) )
if( fondo != tospec(pixel[0], pixel[1], pixel[2]) ){
if( tinta != fondo )
printf("The pixel (%d, %d) has a third color in the cell\n", j*CHAR_WIDTH+l, i*CHAR_HEIGHT+k),
exit(-1);
tinta= tospec(pixel[0], pixel[1], pixel[2]);
}
celda<<= 1;
celda|= fondo != tospec(pixel[0], pixel[1], pixel[2]);
}
output[outpos++]= celda<<2;
}
}
fwrite(output, outpos, 1, fo);
fclose(fo);
printf("File `%s' successfully created\n", argv[2]);
free(image);
}

View File

@ -0,0 +1,68 @@
# SPDX-FileCopyrightText: 2021 Ivan Tatarinov <ivan-tat@ya.ru>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Supported environments:
# * GNU on Linux, FreeBSD etc.
# * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL)
#
# Build:
# make [BUILD=<BUILD>] [<TARGET> ...]
# Install / Uninstall:
# make [BUILD=<BUILD>] [prefix=<PREFIX>] install | uninstall
# Clean:
# make [BUILD=<BUILD>] clean
# make distclean
#
# where:
# <BUILD> - see included `common.mk'.
# <TARGET> is one of values for `BINS' variable prefixed with "build/"
# (see target `all' below).
# <PREFIX> is a prefix directory to install files into.
include ../../../sdk/common.mk
srcdir = .
prefix ?= .
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
INSTALL ?= install
INSTALL_PROGRAM ?= $(INSTALL)
BINS := FuenteABin$(EXESUFFIX)
INCLUDEDIR = $(ZXSDK)/include
LIBDIR = $(ZXSDK)/lib
.PHONY: all
all: $(foreach t,$(BINS),build/$(t))
build\
$(DESTDIR)$(bindir):
mkdir -p $@
build/FuenteABin$(EXESUFFIX):\
$(srcdir)/FuenteABin.c\
$(INCLUDEDIR)/lodepng.h\
$(LIBDIR)/liblodepng$(DLLSUFFIX)\
Makefile | build
$(CC) -I$(INCLUDEDIR) -L$(LIBDIR) -l:liblodepng$(DLLSUFFIX) $(CFLAGS) -o $@ $<
.PHONY: install
install: $(foreach t,$(BINS),$(DESTDIR)$(bindir)/$(t))
$(DESTDIR)$(bindir)/%$(EXESUFFIX): build/%$(EXESUFFIX) | $(DESTDIR)$(bindir)
$(INSTALL_PROGRAM) $< $@
.PHONY: uninstall
uninstall:
rm -f $(foreach t,$(BINS),$(DESTDIR)$(bindir)/$(t))
.PHONY: clean
clean:
rm -f $(foreach t,$(BINS),build/$(t))
.PHONY: distclean
distclean:
rm -rf build/*