sdk: added `Png2Rcs` tool

This commit is contained in:
Ivan Tatarinov 2021-05-03 12:49:31 +03:00
parent ab7221a710
commit 9366f19d7d
4 changed files with 93 additions and 21 deletions

BIN
sdk/bin/Png2Rcs.exe Executable file

Binary file not shown.

View File

@ -0,0 +1,11 @@
SPDX-FileName: Png2Rcs.exe
SPDX-FileType: BINARY
SPDX-FileChecksum: SHA1: b4e6b170505332ac11ddc0e163a3de6a6a4cfd3a
SPDX-FileCopyrightText: Copyright (C) 2014, 2015, 2021 Antonio Villena
SPDX-License-Identifier: GPL-3.0-only
SPDX-FileComment: Png2Rcs version 1.20 (31 May 2015) - Image to ZX Spectrum RCS screen.

View File

@ -36,10 +36,14 @@ BINS:=\
fpad$(EXESUFFIX)\
fpoke$(EXESUFFIX)\
rcs$(EXESUFFIX)\
Png2Rcs$(EXESUFFIX)\
GenRom$(EXESUFFIX)\
AddItem$(EXESUFFIX)\
Bit2Bin$(EXESUFFIX)
INCLUDEDIR = $(ZXSDK)/include
LIBDIR = $(ZXSDK)/lib
.PHONY: all
all: $(foreach t,$(BINS),build/$(t))
@ -47,6 +51,13 @@ build\
$(DESTDIR)$(bindir):
mkdir -p $@
build/Png2Rcs$(EXESUFFIX):\
$(srcdir)/Png2Rcs.c\
$(INCLUDEDIR)/lodepng.h\
$(LIBDIR)/liblodepng$(DLLSUFFIX)\
Makefile | build
$(CC) -I$(INCLUDEDIR) -L$(LIBDIR) -l:liblodepng$(DLLSUFFIX) $(CFLAGS) -o $@ $<
build/%$(EXESUFFIX): $(srcdir)/%.c Makefile | build
$(CC) $(CFLAGS) -o $@ $<

View File

@ -1,6 +1,43 @@
/*
* Png2Rcs - convert image to ZX Spectrum RCS screen.
*
* Copyright (C) 2014, 2015, 2021 Antonio Villena
* Contributors:
* 2015 David Skywalker
*
* 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) 2014, 2015, 2021 Antonio Villena
*
* SPDX-FileContributor: 2015 David Skywalker
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#include <stdio.h>
#include <stdlib.h>
#include "lodepng.c"
#include "lodepng.h"
#define PROGRAM "Png2Rcs"
#define DESCRIPTION "Image to ZX Spectrum RCS screen."
#define VERSION "1.20 (31 May 2015)"
#define COPYRIGHT "Copyright (C) 2014, 2015, 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/"
unsigned char *image, *pixel, output[0x5b00], input[0x300];
unsigned error, width, height, i, j, k, l, m, fondo, tinta, outpos= 0,
input1= 0, input2= 0, output1= 0, output2= 0, inverse= 0;
@ -15,16 +52,29 @@ int tospec(int r, int g, int b){
return ((r|g|b)==255 ? 8 : 0) | 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_png> <output_rcs> [output_attr] [-i] [-a input_attr]\n"
"\n"
" <input_png> 256x64, 256x128 or 256x192 png file\n"
" <output_rcs> ZX spectrum output in RCS format\n"
" <output_attr> If specified, output attributes here\n"
" -i Inverse behaviour, force darker inks\n"
" -a <input_attr> Force attributes specifying the file\n"
"\n"
"Example: " PROGRAM " loading.png loading.rcs\n"
);
}
int main(int argc, char *argv[]){
if( argc==1 )
printf("\nPng2Rcs v1.20. Image to ZX Spectrum RCS screen by AntonioVillena, 7 Jul 2014\n\n"
" Png2Rcs <input_png> <output_rcs> [output_attr] [-i] [-a input_attr]\n\n"
" <input_png> 256x64, 256x128 or 256x192 png file\n"
" <output_rcs> ZX spectrum output in RCS format\n"
" <output_attr> If specified, output attributes here\n"
" -i Inverse behaviour, force darker inks\n"
" -a <input_attr> Force attributes specifying the file\n\n"
"Example: Png2Rcs loading.png loading.rcs\n"),
show_help(),
exit(0);
for ( i= 0; i<argc; i++ )
if( argv[i][0]=='-' ){
@ -33,14 +83,14 @@ int main(int argc, char *argv[]){
else if( argv[i][1]=='a' )
input2= ++i;
else
printf("\nInvalid option: %s\n", argv[i]),
printf("Invalid option: %s\n", argv[i]),
exit(-1);
}
else{
if( input1 ){
if( output1 ){
if( output2 )
printf("\nInvalid number of parameters\n"),
printf("Invalid number of parameters\n"),
exit(-1);
else
output2= i;
@ -52,21 +102,21 @@ int main(int argc, char *argv[]){
input1= i;
}
if( !output1 )
printf("\nInvalid number of parameters\n"),
printf("Invalid number of parameters\n"),
exit(-1);
error= lodepng_decode32_file(&image, &width, &height, argv[input1]);
if( error )
printf("\nError %u: %s\n", error, lodepng_error_text(error)),
printf("Error %u: %s\n", error, lodepng_error_text(error)),
exit(-1);
if( width!=256 || height>192 || height&63 )
printf("\nError. Incorrect size on %s, must be 256x64, 256x128 or 256x192", argv[input1]);
printf("Error. Incorrect size on %s, must be 256x64, 256x128 or 256x192", argv[input1]);
if( input2 )
fo= fopen(argv[input2], "rb"),
0!=fread(input, 1, 0x300, fo),
fclose(fo);
fo= fopen(argv[output1], "wb+");
if( !fo )
printf("\nCannot create output file: %s\n", argv[output1]),
printf("Cannot create output file: %s\n", argv[output1]),
exit(-1);
for ( i= 0; i < height>>6; i++ )
for ( j= 0; j < 32; j++ )
@ -83,12 +133,12 @@ int main(int argc, char *argv[]){
pixel= &image[(i<<14 | j<<3 | k<<11 | l<<8 | m)<<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" , m|j<<3, l|k<<3|i<<6),
printf("The pixel (%d, %d) has an incorrect color\n" , m|j<<3, l|k<<3|i<<6),
exit(-1);
if( input2 ){
if( (tinta|8) != (tospec(pixel[0], pixel[1], pixel[2])|8)
&& (fondo|8) != (tospec(pixel[0], pixel[1], pixel[2])|8) )
printf("\nThe pixel (%d, %d) has a third color in the cell\n", m|j<<3, l|k<<3|i<<6),
printf("The pixel (%d, %d) has a third color in the cell\n", m|j<<3, l|k<<3|i<<6),
exit(-1);
celda<<= 1;
celda|= (fondo|8) != (tospec(pixel[0], pixel[1], pixel[2])|8);
@ -97,7 +147,7 @@ int main(int argc, char *argv[]){
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", m|j<<3, l|k<<3|i<<6),
printf("The pixel (%d, %d) has a third color in the cell\n", m|j<<3, l|k<<3|i<<6),
exit(-1);
tinta= tospec(pixel[0], pixel[1], pixel[2]);
}
@ -139,14 +189,14 @@ int main(int argc, char *argv[]){
fclose(fo);
fo= fopen(argv[output2], "wb+");
if( !fo )
printf("\nCannot create output file: %s\n", argv[output2]),
printf("Cannot create output file: %s\n", argv[output2]),
exit(-1);
fwrite(output+(height<<5), 1, height<<2, fo);
printf("\nFiles %s and %s generated from %s\n", argv[output1], argv[output2], argv[input1]);
printf("Files %s and %s generated from %s\n", argv[output1], argv[output2], argv[input1]);
}
else
fwrite(output, 1, height*36, fo),
printf("\nFile %s filtered from %s\n", argv[output1], argv[input1]);
printf("File %s filtered from %s\n", argv[output1], argv[input1]);
fclose(fo);
free(image);
}