Built SDL2_image and _mixer static
This commit is contained in:
13
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/CHANGES.txt
vendored
Normal file
13
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/CHANGES.txt
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
pnm2png / png2pnm --- conversion from PBM/PGM/PPM-file to PNG-file
|
||||
copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
|
||||
|
||||
version 1.0 - 1999.10.15 - First version.
|
||||
1.1 - 2015.07.29 - Fixed leaks (Glenn Randers-Pehrson)
|
||||
1.2 - 2017.04.22 - Add buffer-size check
|
||||
1.3 - 2017.08.24 - Fix potential overflow in buffer-size check
|
||||
(Glenn Randers-Pehrson)
|
||||
1.4 - 2017.08.28 - Add PNGMINUS_UNUSED (Christian Hesse)
|
||||
1.5 - 2018.08.05 - Fix buffer overflow in tokenizer (Cosmin Truta)
|
||||
1.6 - 2018.08.05 - Improve portability and fix style (Cosmin Truta)
|
||||
1.7 - 2019.01.22 - Change license to MIT (Willem van Schaik)
|
24
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/CMakeLists.txt
vendored
Normal file
24
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
cmake_policy(VERSION 3.1)
|
||||
|
||||
project(PNGMINUS C)
|
||||
|
||||
option(PNGMINUS_USE_STATIC_LIBRARIES "Use the static library builds" ON)
|
||||
|
||||
# libpng
|
||||
add_subdirectory(../.. libpng)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/libpng)
|
||||
if(PNGMINUS_USE_STATIC_LIBRARIES)
|
||||
set(PNGMINUS_PNG_LIBRARY png_static)
|
||||
else()
|
||||
set(PNGMINUS_PNG_LIBRARY png)
|
||||
endif()
|
||||
|
||||
# png2pnm
|
||||
add_executable(png2pnm png2pnm.c)
|
||||
target_link_libraries(png2pnm ${PNGMINUS_PNG_LIBRARY})
|
||||
|
||||
# pnm2png
|
||||
add_executable(pnm2png pnm2png.c)
|
||||
target_link_libraries(pnm2png ${PNGMINUS_PNG_LIBRARY})
|
22
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/LICENSE.txt
vendored
Normal file
22
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/LICENSE.txt
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
pnm2png / png2pnm --- conversion from PBM/PGM/PPM-file to PNG-file
|
||||
|
||||
copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
|
||||
|
||||
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 and this permission notice 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 copyight 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.
|
120
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/README.txt
vendored
Normal file
120
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/README.txt
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
PngMinus
|
||||
--------
|
||||
(copyright Willem van Schaik, 1999-2019)
|
||||
|
||||
|
||||
|
||||
Some history
|
||||
------------
|
||||
Soon after the creation of PNG in 1995, the need was felt for a set of
|
||||
pnmtopng / pngtopnm utilities. Independently Alexander Lehmann and I
|
||||
(Willem van Schaik) started such a project. Luckily we discovered this
|
||||
and merged the two, which later became part of NetPBM, available from
|
||||
SourceForge.
|
||||
|
||||
These two utilities have many, many options and make use of most of the
|
||||
features of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes
|
||||
the utilities quite complex and by now not anymore very maintainable.
|
||||
When we wrote these programs, libpng was still in an early stage.
|
||||
Therefore, lots of the functionality that we put in our software can now
|
||||
be done using transform-functions in libpng.
|
||||
|
||||
Finally, to compile these programs, you need to have installed and
|
||||
compiled three libraries: libpng, zlib and netpbm. Especially the latter
|
||||
makes the whole setup a bit bulky. But that's unavoidable given the many
|
||||
features of pnmtopng.
|
||||
|
||||
|
||||
What now (1999)
|
||||
---------------
|
||||
At this moment libpng is in a very stable state and can do much of the
|
||||
work done in pnmtopng. Also, pnmtopng needs to be upgraded to the new
|
||||
interface of libpng. Hence, it is time for a rewrite from the ground up
|
||||
of pnmtopng and pngtopnm. This will happen in the near future (stay
|
||||
tuned). The new package will get a different name to distinguish it from
|
||||
the old one: PngPlus.
|
||||
|
||||
To experiment a bit with the new interface of libpng, I started off with
|
||||
a small prototype that contains only the basic functionality. It doesn't
|
||||
have any of the options to read or write special chunks and it will do
|
||||
no gamma correction. But this makes it also a simple program that is
|
||||
quite easy to understand and can serve well as a template for other
|
||||
software developments. By now there are of course a couple of programs,
|
||||
like Greg Roelofs' rpng/wpng, that can be used just as good.
|
||||
|
||||
|
||||
Can and can not
|
||||
---------------
|
||||
As this is the small brother of the future PngPlus, I called this fellow
|
||||
PngMinus. Because I started this development in good-old Turbo-C, I
|
||||
avoided the use the netpbm library, which requires DOS extenders. Again,
|
||||
another reason to call it PngMinus (minus netpbm :-). So, part of the
|
||||
program are some elementary routines to read / write pgm- and ppm-files.
|
||||
It does not handle B&W pbm-files, but instead you could do pgm with bit-
|
||||
depth 1.
|
||||
|
||||
The downside of this approach is that you can not use them on images
|
||||
that require blocks of memory bigger than 64k (the DOS version). For
|
||||
larger images you will get an out-of-memory error.
|
||||
|
||||
As said before, PngMinus doesn't correct for gamma. When reading
|
||||
png-files you can do this just as well by piping the output of png2pnm
|
||||
to pnmgamma, one of the standard PbmPlus tools. This same scenario will
|
||||
most probably also be followed in the full-blown future PngPlus, with
|
||||
the addition of course of the possibility to create gamma-chunks when
|
||||
writing png-files.
|
||||
|
||||
On the other hand it supports alpha-channels. When reading a png-image
|
||||
you can write the alpha-channel into a pgm-file. And when creating an
|
||||
RGB+A png-image, you just combine a ppm-file with a corresponding
|
||||
pgm-file containing the alpha-channel. When reading, transparency chunks
|
||||
are converted into an alpha-channel and from there on treated the same
|
||||
way.
|
||||
|
||||
Finally you can opt for writing ascii or binary pgm- and ppm-files. When
|
||||
the bit-depth is 16, the format will always be ascii.
|
||||
|
||||
|
||||
Using it
|
||||
--------
|
||||
To distinguish them from pnmtopng and PngPlus, the utilities are named
|
||||
png2pnm and pnm2png (2 instead of to). The input- and output-files can
|
||||
be given as parameters or through redirection. Therefore the programs
|
||||
can be part of a pipe.
|
||||
|
||||
To list the options type "png2pnm -h" or "pnm2png -h".
|
||||
|
||||
|
||||
Just like Scandinavian furniture
|
||||
--------------------------------
|
||||
You have to put it together yourself. I developed the software on MS-DOS
|
||||
with Turbo-C 3.0 and RedHat Linux 4.2 with gcc. In both cases I used
|
||||
libpng-1.0.4 and zlib-1.1.3. By now (2019) it is twenty years later and
|
||||
more current versions are OK.
|
||||
|
||||
The makefile assumes that the libpng libraries can be found in ../.. and
|
||||
libz in ../../../zlib. But you can change this to for example ../libpng
|
||||
and ../zlib. The makefile creates two versions of each program, one with
|
||||
static library support and the other using shared libraries.
|
||||
|
||||
If you create a ../pngsuite directory and then store the basn####.png
|
||||
files from PngSuite (http://www.schaik.com/pngsuite/) in there, you can
|
||||
test the proper functioning of PngMinus by running pngminus.sh.
|
||||
|
||||
|
||||
Warranty
|
||||
-------
|
||||
Please, remember that this was just a small experiment to learn a few
|
||||
things. It will have many unforeseen features <vbg> ... who said bugs? Use
|
||||
it when you are in need for something simple or when you want a starting
|
||||
point for developing your own stuff.
|
||||
|
||||
|
||||
The end
|
||||
-------
|
||||
Willem van Schaik
|
||||
mailto:willem at schaik dot com
|
||||
http://www.schaik.com/png/
|
||||
|
||||
Oct 1999, Jan 2019
|
||||
|
92
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/makevms.com
vendored
Normal file
92
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/makevms.com
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
$!------------------------------------------------------------------------------
|
||||
$! make Contrib programs of libpng under OpenVMS
|
||||
$!
|
||||
$!
|
||||
$! Look for the compiler used
|
||||
$!
|
||||
$ zlibsrc = "[---.zlib]"
|
||||
$ ccopt="/include=(''zlibsrc',[--])"
|
||||
$ if f$getsyi("HW_MODEL").ge.1024
|
||||
$ then
|
||||
$ ccopt = "/prefix=all"+ccopt
|
||||
$ comp = "__decc__=1"
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||
$ else
|
||||
$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
|
||||
$ then
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||
$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
|
||||
$ then
|
||||
$ comp = "__gcc__=1"
|
||||
$ CC :== GCC
|
||||
$ else
|
||||
$ comp = "__vaxc__=1"
|
||||
$ endif
|
||||
$ else
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
|
||||
$ ccopt = "/decc/prefix=all"+ccopt
|
||||
$ comp = "__decc__=1"
|
||||
$ endif
|
||||
$ endif
|
||||
$ open/write lopt lib.opt
|
||||
$ write lopt "[--]libpng.olb/lib"
|
||||
$ write lopt "''zlibsrc'libz.olb/lib"
|
||||
$ close lopt
|
||||
$ open/write xopt x11.opt
|
||||
$ write xopt "sys$library:decw$xlibshr.exe/share"
|
||||
$ close xopt
|
||||
$ write sys$output "Compiling PNG contrib programs ..."
|
||||
$ write sys$output "Building pnm2png..."
|
||||
$ CALL MAKE pnm2png.OBJ "cc ''CCOPT' pnm2png" -
|
||||
pnm2png.c
|
||||
$ call make pnm2png.exe -
|
||||
"LINK pnm2png,lib.opt/opt" -
|
||||
pnm2png.obj
|
||||
$ write sys$output "Building png2pnm..."
|
||||
$ CALL MAKE png2pnm.OBJ "cc ''CCOPT' png2pnm" -
|
||||
png2pnm.c
|
||||
$ call make png2pnm.exe -
|
||||
"LINK png2pnm,lib.opt/opt" -
|
||||
png2pnm.obj
|
||||
$ exit
|
||||
$!
|
||||
$!
|
||||
$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
|
||||
$ V = 'F$Verify(0)
|
||||
$! P1 = What we are trying to make
|
||||
$! P2 = Command to make it
|
||||
$! P3 - P8 What it depends on
|
||||
$
|
||||
$ If F$Search(P1) .Eqs. "" Then Goto Makeit
|
||||
$ Time = F$CvTime(F$File(P1,"RDT"))
|
||||
$arg=3
|
||||
$Loop:
|
||||
$ Argument = P'arg
|
||||
$ If Argument .Eqs. "" Then Goto Exit
|
||||
$ El=0
|
||||
$Loop2:
|
||||
$ File = F$Element(El," ",Argument)
|
||||
$ If File .Eqs. " " Then Goto Endl
|
||||
$ AFile = ""
|
||||
$Loop3:
|
||||
$ OFile = AFile
|
||||
$ AFile = F$Search(File)
|
||||
$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
|
||||
$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
|
||||
$ Goto Loop3
|
||||
$NextEL:
|
||||
$ El = El + 1
|
||||
$ Goto Loop2
|
||||
$EndL:
|
||||
$ arg=arg+1
|
||||
$ If arg .Le. 8 Then Goto Loop
|
||||
$ Goto Exit
|
||||
$
|
||||
$Makeit:
|
||||
$ VV=F$VERIFY(0)
|
||||
$ write sys$output P2
|
||||
$ 'P2
|
||||
$ VV='F$Verify(VV)
|
||||
$Exit:
|
||||
$ If V Then Set Verify
|
||||
$ENDSUBROUTINE
|
41
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/png2pnm.bat
vendored
Executable file
41
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/png2pnm.bat
vendored
Executable file
@ -0,0 +1,41 @@
|
||||
REM -- grayscale
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g01.png basn0g01.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g02.png basn0g02.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g04.png basn0g04.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g08.png basn0g08.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g16.png basn0g16.pgm
|
||||
REM -- full-color
|
||||
png2pnm.exe -noraw ..\pngsuite\basn2c08.png basn2c08.ppm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn2c16.png basn2c16.ppm
|
||||
REM -- paletted
|
||||
png2pnm.exe -noraw ..\pngsuite\basn3p01.png basn3p01.ppm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn3p02.png basn3p02.ppm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn3p04.png basn3p04.ppm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn3p08.png basn3p08.ppm
|
||||
REM -- gray with alpha-channel
|
||||
png2pnm.exe -noraw ..\pngsuite\basn4a08.png basn4a08.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn4a16.png basn4a16.pgm
|
||||
REM -- color with alpha-channel
|
||||
png2pnm.exe -noraw -alpha basn6a08.pgm ..\pngsuite\basn6a08.png basn6a08.ppm
|
||||
png2pnm.exe -noraw -alpha basn6a16.pgm ..\pngsuite\basn6a16.png basn6a16.ppm
|
||||
REM -- grayscale
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g01.png rawn0g01.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g02.png rawn0g02.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g04.png rawn0g04.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g08.png rawn0g08.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g16.png rawn0g16.pgm
|
||||
REM -- full-color
|
||||
png2pnm.exe -raw ..\pngsuite\basn2c08.png rawn2c08.ppm
|
||||
png2pnm.exe -raw ..\pngsuite\basn2c16.png rawn2c16.ppm
|
||||
REM -- paletted
|
||||
png2pnm.exe -raw ..\pngsuite\basn3p01.png rawn3p01.ppm
|
||||
png2pnm.exe -raw ..\pngsuite\basn3p02.png rawn3p02.ppm
|
||||
png2pnm.exe -raw ..\pngsuite\basn3p04.png rawn3p04.ppm
|
||||
png2pnm.exe -raw ..\pngsuite\basn3p08.png rawn3p08.ppm
|
||||
REM -- gray with alpha-channel
|
||||
png2pnm.exe -raw ..\pngsuite\basn4a08.png rawn4a08.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn4a16.png rawn4a16.pgm
|
||||
REM -- color with alpha-channel
|
||||
png2pnm.exe -noraw -alpha rawn6a08.pgm ..\pngsuite\basn6a08.png rawn6a08.ppm
|
||||
png2pnm.exe -noraw -alpha rawn6a16.pgm ..\pngsuite\basn6a16.png rawn6a16.ppm
|
||||
|
427
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/png2pnm.c
vendored
Normal file
427
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/png2pnm.c
vendored
Normal file
@ -0,0 +1,427 @@
|
||||
/*
|
||||
* png2pnm.c --- conversion from PNG-file to PGM/PPM-file
|
||||
* copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
|
||||
*
|
||||
* This software is released under the MIT license. For conditions of
|
||||
* distribution and use, see the LICENSE file part of this package.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef BOOL
|
||||
#define BOOL unsigned char
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE (BOOL) 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (BOOL) 0
|
||||
#endif
|
||||
|
||||
/* make png2pnm verbose so we can find problems (needs to be before png.h) */
|
||||
#ifndef PNG_DEBUG
|
||||
#define PNG_DEBUG 0
|
||||
#endif
|
||||
|
||||
#include "png.h"
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int main (int argc, char *argv[]);
|
||||
void usage ();
|
||||
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
|
||||
BOOL raw, BOOL alpha);
|
||||
|
||||
/*
|
||||
* main
|
||||
*/
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
FILE *fp_rd = stdin;
|
||||
FILE *fp_wr = stdout;
|
||||
FILE *fp_al = NULL;
|
||||
BOOL raw = TRUE;
|
||||
BOOL alpha = FALSE;
|
||||
int argi;
|
||||
|
||||
for (argi = 1; argi < argc; argi++)
|
||||
{
|
||||
if (argv[argi][0] == '-')
|
||||
{
|
||||
switch (argv[argi][1])
|
||||
{
|
||||
case 'n':
|
||||
raw = FALSE;
|
||||
break;
|
||||
case 'r':
|
||||
raw = TRUE;
|
||||
break;
|
||||
case 'a':
|
||||
alpha = TRUE;
|
||||
argi++;
|
||||
if ((fp_al = fopen (argv[argi], "wb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: cannot create alpha-channel file %s\n",
|
||||
argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
usage ();
|
||||
exit (0);
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
|
||||
usage ();
|
||||
exit (1);
|
||||
break;
|
||||
} /* end switch */
|
||||
}
|
||||
else if (fp_rd == stdin)
|
||||
{
|
||||
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else if (fp_wr == stdout)
|
||||
{
|
||||
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: cannot create file %s\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: too many parameters\n");
|
||||
usage ();
|
||||
exit (1);
|
||||
}
|
||||
} /* end for */
|
||||
|
||||
#if defined(O_BINARY) && (O_BINARY != 0)
|
||||
/* set stdin/stdout if required to binary */
|
||||
if (fp_rd == stdin)
|
||||
setmode (fileno (stdin), O_BINARY);
|
||||
if ((raw) && (fp_wr == stdout))
|
||||
setmode (fileno (stdout), O_BINARY);
|
||||
#endif
|
||||
|
||||
/* call the conversion program itself */
|
||||
if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE)
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: unsuccessful conversion of PNG-image\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* close input file */
|
||||
fclose (fp_rd);
|
||||
/* close output file */
|
||||
fclose (fp_wr);
|
||||
/* close alpha file */
|
||||
if (alpha)
|
||||
fclose (fp_al);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* usage
|
||||
*/
|
||||
|
||||
void usage ()
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, " by Willem van Schaik, 1999\n");
|
||||
fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n");
|
||||
fprintf (stderr, " or: ... | png2pnm [options]\n");
|
||||
fprintf (stderr, "Options:\n");
|
||||
fprintf (stderr,
|
||||
" -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
|
||||
fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n");
|
||||
fprintf (stderr,
|
||||
" -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
|
||||
fprintf (stderr, " -h | -? print this help-information\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* png2pnm
|
||||
*/
|
||||
|
||||
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
|
||||
BOOL raw, BOOL alpha)
|
||||
{
|
||||
png_struct *png_ptr = NULL;
|
||||
png_info *info_ptr = NULL;
|
||||
png_byte buf[8];
|
||||
png_byte *png_pixels = NULL;
|
||||
png_byte **row_pointers = NULL;
|
||||
png_byte *pix_ptr = NULL;
|
||||
png_uint_32 row_bytes;
|
||||
|
||||
png_uint_32 width;
|
||||
png_uint_32 height;
|
||||
int bit_depth;
|
||||
int channels;
|
||||
int color_type;
|
||||
int alpha_present;
|
||||
int row, col;
|
||||
int ret;
|
||||
int i;
|
||||
long dep_16;
|
||||
|
||||
/* read and check signature in PNG file */
|
||||
ret = fread (buf, 1, 8, png_file);
|
||||
if (ret != 8)
|
||||
return FALSE;
|
||||
|
||||
ret = png_sig_cmp (buf, 0, 8);
|
||||
if (ret != 0)
|
||||
return FALSE;
|
||||
|
||||
/* create png and info structures */
|
||||
|
||||
png_ptr = png_create_read_struct (png_get_libpng_ver(NULL),
|
||||
NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
return FALSE; /* out of memory */
|
||||
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, NULL, NULL);
|
||||
return FALSE; /* out of memory */
|
||||
}
|
||||
|
||||
if (setjmp (png_jmpbuf (png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set up the input control for C streams */
|
||||
png_init_io (png_ptr, png_file);
|
||||
png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
|
||||
|
||||
/* read the file information */
|
||||
png_read_info (png_ptr, info_ptr);
|
||||
|
||||
/* get size and bit-depth of the PNG-image */
|
||||
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
/* set-up the transformations */
|
||||
|
||||
/* transform paletted images into full-color rgb */
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand (png_ptr);
|
||||
/* expand images to bit-depth 8 (only applicable for grayscale images) */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||
png_set_expand (png_ptr);
|
||||
/* transform transparency maps into full alpha-channel */
|
||||
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
png_set_expand (png_ptr);
|
||||
|
||||
#ifdef NJET
|
||||
/* downgrade 16-bit images to 8-bit */
|
||||
if (bit_depth == 16)
|
||||
png_set_strip_16 (png_ptr);
|
||||
/* transform grayscale images into full-color */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb (png_ptr);
|
||||
/* only if file has a file gamma, we do a correction */
|
||||
if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
|
||||
png_set_gamma (png_ptr, (double) 2.2, file_gamma);
|
||||
#endif
|
||||
|
||||
/* all transformations have been registered; now update info_ptr data,
|
||||
* get rowbytes and channels, and allocate image memory */
|
||||
|
||||
png_read_update_info (png_ptr, info_ptr);
|
||||
|
||||
/* get the new color-type and bit-depth (after expansion/stripping) */
|
||||
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
/* check for 16-bit files */
|
||||
if (bit_depth == 16)
|
||||
{
|
||||
raw = FALSE;
|
||||
#if defined(O_BINARY) && (O_BINARY != 0)
|
||||
setmode (fileno (pnm_file), O_BINARY);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* calculate new number of channels and store alpha-presence */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||
channels = 1;
|
||||
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
channels = 2;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB)
|
||||
channels = 3;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
channels = 4;
|
||||
else
|
||||
channels = 0; /* should never happen */
|
||||
alpha_present = (channels - 1) % 2;
|
||||
|
||||
/* check if alpha is expected to be present in file */
|
||||
if (alpha && !alpha_present)
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
|
||||
|
||||
if ((row_bytes == 0) ||
|
||||
((size_t) height > (size_t) (-1) / (size_t) row_bytes))
|
||||
{
|
||||
/* too big */
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
if ((png_pixels = (png_byte *)
|
||||
malloc ((size_t) row_bytes * (size_t) height)) == NULL)
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((row_pointers = (png_byte **)
|
||||
malloc ((size_t) height * sizeof (png_byte *))) == NULL)
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
free (png_pixels);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
for (i = 0; i < ((int) height); i++)
|
||||
row_pointers[i] = png_pixels + i * row_bytes;
|
||||
|
||||
/* now we can go ahead and just read the whole image */
|
||||
png_read_image (png_ptr, row_pointers);
|
||||
|
||||
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||
png_read_end (png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the read, and free any memory allocated - REQUIRED */
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
|
||||
/* write header of PNM file */
|
||||
|
||||
if ((color_type == PNG_COLOR_TYPE_GRAY) ||
|
||||
(color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
||||
{
|
||||
fprintf (pnm_file, "%s\n", (raw) ? "P5" : "P2");
|
||||
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
|
||||
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||
}
|
||||
else if ((color_type == PNG_COLOR_TYPE_RGB) ||
|
||||
(color_type == PNG_COLOR_TYPE_RGB_ALPHA))
|
||||
{
|
||||
fprintf (pnm_file, "%s\n", (raw) ? "P6" : "P3");
|
||||
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
|
||||
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||
}
|
||||
|
||||
/* write header of PGM file with alpha channel */
|
||||
|
||||
if ((alpha) &&
|
||||
((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
|
||||
(color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
|
||||
{
|
||||
fprintf (alpha_file, "%s\n", (raw) ? "P5" : "P2");
|
||||
fprintf (alpha_file, "%d %d\n", (int) width, (int) height);
|
||||
fprintf (alpha_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||
}
|
||||
|
||||
/* write data to PNM file */
|
||||
pix_ptr = png_pixels;
|
||||
|
||||
for (row = 0; row < (int) height; row++)
|
||||
{
|
||||
for (col = 0; col < (int) width; col++)
|
||||
{
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
fputc ((int) *pix_ptr++, pnm_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bit_depth == 16)
|
||||
{
|
||||
dep_16 = (long) *pix_ptr++;
|
||||
fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++));
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (pnm_file, "%ld ", (long) *pix_ptr++);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (alpha_present)
|
||||
{
|
||||
if (!alpha)
|
||||
{
|
||||
pix_ptr++; /* alpha */
|
||||
if (bit_depth == 16)
|
||||
pix_ptr++;
|
||||
}
|
||||
else /* output alpha-channel as pgm file */
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
fputc ((int) *pix_ptr++, alpha_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bit_depth == 16)
|
||||
{
|
||||
dep_16 = (long) *pix_ptr++;
|
||||
fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (alpha_file, "%ld ", (long) *pix_ptr++);
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* end if alpha_present */
|
||||
|
||||
if (!raw)
|
||||
if (col % 4 == 3)
|
||||
fprintf (pnm_file, "\n");
|
||||
} /* end for col */
|
||||
|
||||
if (!raw)
|
||||
if (col % 4 != 0)
|
||||
fprintf (pnm_file, "\n");
|
||||
} /* end for row */
|
||||
|
||||
if (row_pointers != NULL)
|
||||
free (row_pointers);
|
||||
if (png_pixels != NULL)
|
||||
free (png_pixels);
|
||||
|
||||
return TRUE;
|
||||
|
||||
} /* end of source */
|
42
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/png2pnm.sh
vendored
Executable file
42
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/png2pnm.sh
vendored
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
# -- grayscale
|
||||
./png2pnm -noraw ../pngsuite/basn0g01.png basn0g01.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn0g02.png basn0g02.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn0g04.png basn0g04.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn0g08.png basn0g08.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn0g16.png basn0g16.pgm
|
||||
# -- full-color
|
||||
./png2pnm -noraw ../pngsuite/basn2c08.png basn2c08.ppm
|
||||
./png2pnm -noraw ../pngsuite/basn2c16.png basn2c16.ppm
|
||||
# -- paletted
|
||||
./png2pnm -noraw ../pngsuite/basn3p01.png basn3p01.ppm
|
||||
./png2pnm -noraw ../pngsuite/basn3p02.png basn3p02.ppm
|
||||
./png2pnm -noraw ../pngsuite/basn3p04.png basn3p04.ppm
|
||||
./png2pnm -noraw ../pngsuite/basn3p08.png basn3p08.ppm
|
||||
# -- gray with alpha-channel
|
||||
./png2pnm -noraw ../pngsuite/basn4a08.png basn4a08.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn4a16.png basn4a16.pgm
|
||||
# -- color with alpha-channel
|
||||
./png2pnm -noraw -alpha basn6a08.pgm ../pngsuite/basn6a08.png basn6a08.ppm
|
||||
./png2pnm -noraw -alpha basn6a16.pgm ../pngsuite/basn6a16.png basn6a16.ppm
|
||||
# -- grayscale
|
||||
./png2pnm -raw ../pngsuite/basn0g01.png rawn0g01.pgm
|
||||
./png2pnm -raw ../pngsuite/basn0g02.png rawn0g02.pgm
|
||||
./png2pnm -raw ../pngsuite/basn0g04.png rawn0g04.pgm
|
||||
./png2pnm -raw ../pngsuite/basn0g08.png rawn0g08.pgm
|
||||
./png2pnm -raw ../pngsuite/basn0g16.png rawn0g16.pgm
|
||||
# -- full-color
|
||||
./png2pnm -raw ../pngsuite/basn2c08.png rawn2c08.ppm
|
||||
./png2pnm -raw ../pngsuite/basn2c16.png rawn2c16.ppm
|
||||
# -- paletted
|
||||
./png2pnm -raw ../pngsuite/basn3p01.png rawn3p01.ppm
|
||||
./png2pnm -raw ../pngsuite/basn3p02.png rawn3p02.ppm
|
||||
./png2pnm -raw ../pngsuite/basn3p04.png rawn3p04.ppm
|
||||
./png2pnm -raw ../pngsuite/basn3p08.png rawn3p08.ppm
|
||||
# -- gray with alpha-channel
|
||||
./png2pnm -raw ../pngsuite/basn4a08.png rawn4a08.pgm
|
||||
./png2pnm -raw ../pngsuite/basn4a16.png rawn4a16.pgm
|
||||
# -- color with alpha-channel
|
||||
./png2pnm -noraw -alpha rawn6a08.pgm ../pngsuite/basn6a08.png rawn6a08.ppm
|
||||
./png2pnm -noraw -alpha rawn6a16.pgm ../pngsuite/basn6a16.png rawn6a16.ppm
|
||||
|
4
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pngminus.bat
vendored
Executable file
4
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pngminus.bat
vendored
Executable file
@ -0,0 +1,4 @@
|
||||
make
|
||||
call png2pnm.bat
|
||||
call pnm2png.bat
|
||||
|
5
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pngminus.sh
vendored
Executable file
5
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pngminus.sh
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
make
|
||||
sh png2pnm.sh
|
||||
sh pnm2png.sh
|
||||
|
41
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pnm2png.bat
vendored
Executable file
41
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pnm2png.bat
vendored
Executable file
@ -0,0 +1,41 @@
|
||||
REM -- grayscale
|
||||
pnm2png.exe basn0g01.pgm basn0g01.png
|
||||
pnm2png.exe basn0g02.pgm basn0g02.png
|
||||
pnm2png.exe basn0g04.pgm basn0g04.png
|
||||
pnm2png.exe basn0g08.pgm basn0g08.png
|
||||
pnm2png.exe basn0g16.pgm basn0g16.png
|
||||
REM -- full-color
|
||||
pnm2png.exe basn2c08.ppm basn2c08.png
|
||||
pnm2png.exe basn2c16.ppm basn2c16.png
|
||||
REM -- paletted
|
||||
pnm2png.exe basn3p01.ppm basn3p01.png
|
||||
pnm2png.exe basn3p02.ppm basn3p02.png
|
||||
pnm2png.exe basn3p04.ppm basn3p04.png
|
||||
pnm2png.exe basn3p08.ppm basn3p08.png
|
||||
REM -- gray with alpha-channel
|
||||
pnm2png.exe -alpha basn6a08.pgm basn4a08.pgm basn4a08.png
|
||||
pnm2png.exe -alpha basn6a16.pgm basn4a16.pgm basn4a16.png
|
||||
REM -- color with alpha-channel
|
||||
pnm2png.exe -alpha basn6a08.pgm basn6a08.ppm basn6a08.png
|
||||
pnm2png.exe -alpha basn6a16.pgm basn6a16.ppm basn6a16.png
|
||||
REM -- grayscale
|
||||
pnm2png.exe rawn0g01.pgm rawn0g01.png
|
||||
pnm2png.exe rawn0g02.pgm rawn0g02.png
|
||||
pnm2png.exe rawn0g04.pgm rawn0g04.png
|
||||
pnm2png.exe rawn0g08.pgm rawn0g08.png
|
||||
pnm2png.exe rawn0g16.pgm rawn0g16.png
|
||||
REM -- full-color
|
||||
pnm2png.exe rawn2c08.ppm rawn2c08.png
|
||||
pnm2png.exe rawn2c16.ppm rawn2c16.png
|
||||
REM -- paletted
|
||||
pnm2png.exe rawn3p01.ppm rawn3p01.png
|
||||
pnm2png.exe rawn3p02.ppm rawn3p02.png
|
||||
pnm2png.exe rawn3p04.ppm rawn3p04.png
|
||||
pnm2png.exe rawn3p08.ppm rawn3p08.png
|
||||
REM -- gray with alpha-channel
|
||||
pnm2png.exe -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png
|
||||
pnm2png.exe -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png
|
||||
REM -- color with alpha-channel
|
||||
pnm2png.exe -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png
|
||||
pnm2png.exe -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png
|
||||
|
620
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pnm2png.c
vendored
Normal file
620
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pnm2png.c
vendored
Normal file
@ -0,0 +1,620 @@
|
||||
/*
|
||||
* pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file
|
||||
* copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
|
||||
*
|
||||
* This software is released under the MIT license. For conditions of
|
||||
* distribution and use, see the LICENSE file part of this package.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef BOOL
|
||||
#define BOOL unsigned char
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE (BOOL) 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (BOOL) 0
|
||||
#endif
|
||||
|
||||
/* make pnm2png verbose so we can find problems (needs to be before png.h) */
|
||||
#ifndef PNG_DEBUG
|
||||
#define PNG_DEBUG 0
|
||||
#endif
|
||||
|
||||
#include "png.h"
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int main (int argc, char *argv[]);
|
||||
void usage ();
|
||||
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file,
|
||||
BOOL interlace, BOOL alpha);
|
||||
void get_token (FILE *pnm_file, char *token_buf, size_t token_buf_size);
|
||||
png_uint_32 get_data (FILE *pnm_file, int depth);
|
||||
png_uint_32 get_value (FILE *pnm_file, int depth);
|
||||
|
||||
/*
|
||||
* main
|
||||
*/
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
FILE *fp_rd = stdin;
|
||||
FILE *fp_al = NULL;
|
||||
FILE *fp_wr = stdout;
|
||||
BOOL interlace = FALSE;
|
||||
BOOL alpha = FALSE;
|
||||
int argi;
|
||||
|
||||
for (argi = 1; argi < argc; argi++)
|
||||
{
|
||||
if (argv[argi][0] == '-')
|
||||
{
|
||||
switch (argv[argi][1])
|
||||
{
|
||||
case 'i':
|
||||
interlace = TRUE;
|
||||
break;
|
||||
case 'a':
|
||||
alpha = TRUE;
|
||||
argi++;
|
||||
if ((fp_al = fopen (argv[argi], "rb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: alpha-channel file %s does not exist\n",
|
||||
argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
usage ();
|
||||
exit (0);
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
|
||||
usage ();
|
||||
exit (1);
|
||||
break;
|
||||
} /* end switch */
|
||||
}
|
||||
else if (fp_rd == stdin)
|
||||
{
|
||||
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else if (fp_wr == stdout)
|
||||
{
|
||||
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: cannot create PNG-file %s\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: too many parameters\n");
|
||||
usage ();
|
||||
exit (1);
|
||||
}
|
||||
} /* end for */
|
||||
|
||||
#if defined(O_BINARY) && (O_BINARY != 0)
|
||||
/* set stdin/stdout to binary,
|
||||
* we're reading the PNM always! in binary format
|
||||
*/
|
||||
if (fp_rd == stdin)
|
||||
setmode (fileno (stdin), O_BINARY);
|
||||
if (fp_wr == stdout)
|
||||
setmode (fileno (stdout), O_BINARY);
|
||||
#endif
|
||||
|
||||
/* call the conversion program itself */
|
||||
if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: unsuccessful converting to PNG-image\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* close input file */
|
||||
fclose (fp_rd);
|
||||
/* close output file */
|
||||
fclose (fp_wr);
|
||||
/* close alpha file */
|
||||
if (alpha)
|
||||
fclose (fp_al);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* usage
|
||||
*/
|
||||
|
||||
void usage ()
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, " by Willem van Schaik, 1999\n");
|
||||
fprintf (stderr, "Usage: pnm2png [options] <file>.<pnm> [<file>.png]\n");
|
||||
fprintf (stderr, " or: ... | pnm2png [options]\n");
|
||||
fprintf (stderr, "Options:\n");
|
||||
fprintf (stderr, " -i[nterlace] write png-file with interlacing on\n");
|
||||
fprintf (stderr,
|
||||
" -a[lpha] <file>.pgm read PNG alpha channel as pgm-file\n");
|
||||
fprintf (stderr, " -h | -? print this help-information\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* pnm2png
|
||||
*/
|
||||
|
||||
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file,
|
||||
BOOL interlace, BOOL alpha)
|
||||
{
|
||||
png_struct *png_ptr = NULL;
|
||||
png_info *info_ptr = NULL;
|
||||
png_byte *png_pixels = NULL;
|
||||
png_byte **row_pointers = NULL;
|
||||
png_byte *pix_ptr = NULL;
|
||||
volatile png_uint_32 row_bytes;
|
||||
|
||||
char type_token[16];
|
||||
char width_token[16];
|
||||
char height_token[16];
|
||||
char maxval_token[16];
|
||||
volatile int color_type = 1;
|
||||
unsigned long ul_width = 0, ul_alpha_width = 0;
|
||||
unsigned long ul_height = 0, ul_alpha_height = 0;
|
||||
unsigned long ul_maxval = 0;
|
||||
volatile png_uint_32 width = 0, height = 0;
|
||||
volatile png_uint_32 alpha_width = 0, alpha_height = 0;
|
||||
png_uint_32 maxval;
|
||||
volatile int bit_depth = 0;
|
||||
int channels = 0;
|
||||
int alpha_depth = 0;
|
||||
int alpha_present = 0;
|
||||
int row, col;
|
||||
BOOL raw, alpha_raw = FALSE;
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
BOOL packed_bitmap = FALSE;
|
||||
#endif
|
||||
png_uint_32 tmp16;
|
||||
int i;
|
||||
|
||||
/* read header of PNM file */
|
||||
|
||||
get_token (pnm_file, type_token, sizeof (type_token));
|
||||
if (type_token[0] != 'P')
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else if ((type_token[1] == '1') || (type_token[1] == '4'))
|
||||
{
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
raw = (type_token[1] == '4');
|
||||
color_type = PNG_COLOR_TYPE_GRAY;
|
||||
get_token (pnm_file, width_token, sizeof (width_token));
|
||||
sscanf (width_token, "%lu", &ul_width);
|
||||
width = (png_uint_32) ul_width;
|
||||
get_token (pnm_file, height_token, sizeof (height_token));
|
||||
sscanf (height_token, "%lu", &ul_height);
|
||||
height = (png_uint_32) ul_height;
|
||||
bit_depth = 1;
|
||||
packed_bitmap = TRUE;
|
||||
#else
|
||||
fprintf (stderr, "PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and\n");
|
||||
fprintf (stderr, "PNG_WRITE_PACK_SUPPORTED can't read PBM (P1,P4) files\n");
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
else if ((type_token[1] == '2') || (type_token[1] == '5'))
|
||||
{
|
||||
raw = (type_token[1] == '5');
|
||||
color_type = PNG_COLOR_TYPE_GRAY;
|
||||
get_token (pnm_file, width_token, sizeof (width_token));
|
||||
sscanf (width_token, "%lu", &ul_width);
|
||||
width = (png_uint_32) ul_width;
|
||||
get_token (pnm_file, height_token, sizeof (height_token));
|
||||
sscanf (height_token, "%lu", &ul_height);
|
||||
height = (png_uint_32) ul_height;
|
||||
get_token (pnm_file, maxval_token, sizeof (maxval_token));
|
||||
sscanf (maxval_token, "%lu", &ul_maxval);
|
||||
maxval = (png_uint_32) ul_maxval;
|
||||
|
||||
if (maxval <= 1)
|
||||
bit_depth = 1;
|
||||
else if (maxval <= 3)
|
||||
bit_depth = 2;
|
||||
else if (maxval <= 15)
|
||||
bit_depth = 4;
|
||||
else if (maxval <= 255)
|
||||
bit_depth = 8;
|
||||
else if (maxval <= 65535U)
|
||||
bit_depth = 16;
|
||||
else /* maxval > 65535U */
|
||||
return FALSE;
|
||||
}
|
||||
else if ((type_token[1] == '3') || (type_token[1] == '6'))
|
||||
{
|
||||
raw = (type_token[1] == '6');
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
get_token (pnm_file, width_token, sizeof (width_token));
|
||||
sscanf (width_token, "%lu", &ul_width);
|
||||
width = (png_uint_32) ul_width;
|
||||
get_token (pnm_file, height_token, sizeof (height_token));
|
||||
sscanf (height_token, "%lu", &ul_height);
|
||||
height = (png_uint_32) ul_height;
|
||||
get_token (pnm_file, maxval_token, sizeof (maxval_token));
|
||||
sscanf (maxval_token, "%lu", &ul_maxval);
|
||||
maxval = (png_uint_32) ul_maxval;
|
||||
if (maxval <= 1)
|
||||
bit_depth = 1;
|
||||
else if (maxval <= 3)
|
||||
bit_depth = 2;
|
||||
else if (maxval <= 15)
|
||||
bit_depth = 4;
|
||||
else if (maxval <= 255)
|
||||
bit_depth = 8;
|
||||
else if (maxval <= 65535U)
|
||||
bit_depth = 16;
|
||||
else /* maxval > 65535U */
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* read header of PGM file with alpha channel */
|
||||
|
||||
if (alpha)
|
||||
{
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||
color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
|
||||
if (color_type == PNG_COLOR_TYPE_RGB)
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
|
||||
get_token (alpha_file, type_token, sizeof (type_token));
|
||||
if (type_token[0] != 'P')
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else if ((type_token[1] == '2') || (type_token[1] == '5'))
|
||||
{
|
||||
alpha_raw = (type_token[1] == '5');
|
||||
get_token (alpha_file, width_token, sizeof (width_token));
|
||||
sscanf (width_token, "%lu", &ul_alpha_width);
|
||||
alpha_width = (png_uint_32) ul_alpha_width;
|
||||
if (alpha_width != width)
|
||||
return FALSE;
|
||||
get_token (alpha_file, height_token, sizeof (height_token));
|
||||
sscanf (height_token, "%lu", &ul_alpha_height);
|
||||
alpha_height = (png_uint_32) ul_alpha_height;
|
||||
if (alpha_height != height)
|
||||
return FALSE;
|
||||
get_token (alpha_file, maxval_token, sizeof (maxval_token));
|
||||
sscanf (maxval_token, "%lu", &ul_maxval);
|
||||
maxval = (png_uint_32) ul_maxval;
|
||||
if (maxval <= 1)
|
||||
alpha_depth = 1;
|
||||
else if (maxval <= 3)
|
||||
alpha_depth = 2;
|
||||
else if (maxval <= 15)
|
||||
alpha_depth = 4;
|
||||
else if (maxval <= 255)
|
||||
alpha_depth = 8;
|
||||
else if (maxval <= 65535U)
|
||||
alpha_depth = 16;
|
||||
else /* maxval > 65535U */
|
||||
return FALSE;
|
||||
if (alpha_depth != bit_depth)
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
} /* end if alpha */
|
||||
|
||||
/* calculate the number of channels and store alpha-presence */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||
channels = 1;
|
||||
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
channels = 2;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB)
|
||||
channels = 3;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
channels = 4;
|
||||
#if 0
|
||||
else
|
||||
channels = 0; /* cannot happen */
|
||||
#endif
|
||||
|
||||
alpha_present = (channels - 1) % 2;
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap)
|
||||
{
|
||||
/* row data is as many bytes as can fit width x channels x bit_depth */
|
||||
row_bytes = (width * channels * bit_depth + 7) / 8;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
|
||||
}
|
||||
|
||||
if ((row_bytes == 0) ||
|
||||
((size_t) height > (size_t) (-1) / (size_t) row_bytes))
|
||||
{
|
||||
/* too big */
|
||||
return FALSE;
|
||||
}
|
||||
if ((png_pixels = (png_byte *)
|
||||
malloc ((size_t) row_bytes * (size_t) height)) == NULL)
|
||||
{
|
||||
/* out of memory */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* read data from PNM file */
|
||||
pix_ptr = png_pixels;
|
||||
|
||||
for (row = 0; row < (int) height; row++)
|
||||
{
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap)
|
||||
{
|
||||
for (i = 0; i < (int) row_bytes; i++)
|
||||
{
|
||||
/* png supports this format natively so no conversion is needed */
|
||||
*pix_ptr++ = get_data (pnm_file, 8);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
for (col = 0; col < (int) width; col++)
|
||||
{
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
*pix_ptr++ = get_data (pnm_file, bit_depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bit_depth <= 8)
|
||||
{
|
||||
*pix_ptr++ = get_value (pnm_file, bit_depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (pnm_file, bit_depth);
|
||||
*pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
pix_ptr++;
|
||||
*pix_ptr = (png_byte) (tmp16 & 0xFF);
|
||||
pix_ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alpha) /* read alpha-channel from pgm file */
|
||||
{
|
||||
if (alpha_raw)
|
||||
{
|
||||
*pix_ptr++ = get_data (alpha_file, alpha_depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alpha_depth <= 8)
|
||||
{
|
||||
*pix_ptr++ = get_value (alpha_file, bit_depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (alpha_file, bit_depth);
|
||||
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
|
||||
}
|
||||
}
|
||||
} /* end if alpha */
|
||||
} /* end if packed_bitmap */
|
||||
} /* end for col */
|
||||
} /* end for row */
|
||||
|
||||
/* prepare the standard PNG structures */
|
||||
png_ptr = png_create_write_struct (png_get_libpng_ver(NULL),
|
||||
NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
free (png_pixels);
|
||||
return FALSE;
|
||||
}
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, NULL);
|
||||
free (png_pixels);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap == TRUE)
|
||||
{
|
||||
png_set_packing (png_ptr);
|
||||
png_set_invert_mono (png_ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (setjmp (png_jmpbuf (png_ptr)))
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
free (png_pixels);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* initialize the png structure */
|
||||
png_init_io (png_ptr, png_file);
|
||||
|
||||
/* we're going to write more or less the same PNG as the input file */
|
||||
png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type,
|
||||
(!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
/* write the file header information */
|
||||
png_write_info (png_ptr, info_ptr);
|
||||
|
||||
/* if needed we will allocate memory for an new array of row-pointers */
|
||||
if (row_pointers == NULL)
|
||||
{
|
||||
if ((row_pointers = (png_byte **)
|
||||
malloc (height * sizeof (png_byte *))) == NULL)
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
free (png_pixels);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
for (i = 0; i < (int) height; i++)
|
||||
row_pointers[i] = png_pixels + i * row_bytes;
|
||||
|
||||
/* write out the entire image data in one call */
|
||||
png_write_image (png_ptr, row_pointers);
|
||||
|
||||
/* write the additional chunks to the PNG file (not really needed) */
|
||||
png_write_end (png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
|
||||
if (row_pointers != NULL)
|
||||
free (row_pointers);
|
||||
if (png_pixels != NULL)
|
||||
free (png_pixels);
|
||||
|
||||
return TRUE;
|
||||
} /* end of pnm2png */
|
||||
|
||||
/*
|
||||
* get_token - gets the first string after whitespace
|
||||
*/
|
||||
|
||||
void get_token (FILE *pnm_file, char *token_buf, size_t token_buf_size)
|
||||
{
|
||||
size_t i = 0;
|
||||
int ret;
|
||||
|
||||
/* remove white-space and comment lines */
|
||||
do
|
||||
{
|
||||
ret = fgetc (pnm_file);
|
||||
if (ret == '#')
|
||||
{
|
||||
/* the rest of this line is a comment */
|
||||
do
|
||||
{
|
||||
ret = fgetc (pnm_file);
|
||||
}
|
||||
while ((ret != '\n') && (ret != '\r') && (ret != EOF));
|
||||
}
|
||||
if (ret == EOF) break;
|
||||
token_buf[i] = (char) ret;
|
||||
}
|
||||
while ((ret == '\n') || (ret == '\r') || (ret == ' '));
|
||||
|
||||
/* read string */
|
||||
do
|
||||
{
|
||||
ret = fgetc (pnm_file);
|
||||
if (ret == EOF) break;
|
||||
if (++i == token_buf_size - 1) break;
|
||||
token_buf[i] = (char) ret;
|
||||
}
|
||||
while ((ret != '\n') && (ret != '\r') && (ret != ' '));
|
||||
|
||||
token_buf[i] = '\0';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_data - takes first byte and converts into next pixel value,
|
||||
* taking as much bits as defined by bit-depth and
|
||||
* using the bit-depth to fill up a byte (0Ah -> AAh)
|
||||
*/
|
||||
|
||||
png_uint_32 get_data (FILE *pnm_file, int depth)
|
||||
{
|
||||
static int bits_left = 0;
|
||||
static int old_value = 0;
|
||||
static int mask = 0;
|
||||
int i;
|
||||
png_uint_32 ret_value;
|
||||
|
||||
if (mask == 0)
|
||||
for (i = 0; i < depth; i++)
|
||||
mask = (mask >> 1) | 0x80;
|
||||
|
||||
if (bits_left <= 0)
|
||||
{
|
||||
old_value = fgetc (pnm_file);
|
||||
bits_left = 8;
|
||||
}
|
||||
|
||||
ret_value = old_value & mask;
|
||||
for (i = 1; i < (8 / depth); i++)
|
||||
ret_value = ret_value || (ret_value >> depth);
|
||||
|
||||
old_value = (old_value << depth) & 0xFF;
|
||||
bits_left -= depth;
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_value - takes first (numeric) string and converts into number,
|
||||
* using the bit-depth to fill up a byte (0Ah -> AAh)
|
||||
*/
|
||||
|
||||
png_uint_32 get_value (FILE *pnm_file, int depth)
|
||||
{
|
||||
static png_uint_32 mask = 0;
|
||||
char token[16];
|
||||
unsigned long ul_ret_value;
|
||||
png_uint_32 ret_value;
|
||||
int i = 0;
|
||||
|
||||
if (mask == 0)
|
||||
for (i = 0; i < depth; i++)
|
||||
mask = (mask << 1) | 0x01;
|
||||
|
||||
get_token (pnm_file, token, sizeof (token));
|
||||
sscanf (token, "%lu", &ul_ret_value);
|
||||
ret_value = (png_uint_32) ul_ret_value;
|
||||
|
||||
ret_value &= mask;
|
||||
|
||||
if (depth < 8)
|
||||
for (i = 0; i < (8 / depth); i++)
|
||||
ret_value = (ret_value << depth) || ret_value;
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/* end of source */
|
42
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pnm2png.sh
vendored
Executable file
42
libsdl2_image/external/libpng-1.6.37/contrib/pngminus/pnm2png.sh
vendored
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
# -- grayscale
|
||||
./pnm2png basn0g01.pgm basn0g01.png
|
||||
./pnm2png basn0g02.pgm basn0g02.png
|
||||
./pnm2png basn0g04.pgm basn0g04.png
|
||||
./pnm2png basn0g08.pgm basn0g08.png
|
||||
./pnm2png basn0g16.pgm basn0g16.png
|
||||
# -- full-color
|
||||
./pnm2png basn2c08.ppm basn2c08.png
|
||||
./pnm2png basn2c16.ppm basn2c16.png
|
||||
# -- paletted
|
||||
./pnm2png basn3p01.ppm basn3p01.png
|
||||
./pnm2png basn3p02.ppm basn3p02.png
|
||||
./pnm2png basn3p04.ppm basn3p04.png
|
||||
./pnm2png basn3p08.ppm basn3p08.png
|
||||
# -- gray with alpha-channel
|
||||
./pnm2png -alpha basn6a08.pgm basn4a08.pgm basn4a08.png
|
||||
./pnm2png -alpha basn6a16.pgm basn4a16.pgm basn4a16.png
|
||||
# -- color with alpha-channel
|
||||
./pnm2png -alpha basn6a08.pgm basn6a08.ppm basn6a08.png
|
||||
./pnm2png -alpha basn6a16.pgm basn6a16.ppm basn6a16.png
|
||||
# -- grayscale
|
||||
./pnm2png rawn0g01.pgm rawn0g01.png
|
||||
./pnm2png rawn0g02.pgm rawn0g02.png
|
||||
./pnm2png rawn0g04.pgm rawn0g04.png
|
||||
./pnm2png rawn0g08.pgm rawn0g08.png
|
||||
./pnm2png rawn0g16.pgm rawn0g16.png
|
||||
# -- full-color
|
||||
./pnm2png rawn2c08.ppm rawn2c08.png
|
||||
./pnm2png rawn2c16.ppm rawn2c16.png
|
||||
# -- paletted
|
||||
./pnm2png rawn3p01.ppm rawn3p01.png
|
||||
./pnm2png rawn3p02.ppm rawn3p02.png
|
||||
./pnm2png rawn3p04.ppm rawn3p04.png
|
||||
./pnm2png rawn3p08.ppm rawn3p08.png
|
||||
# -- gray with alpha-channel
|
||||
./pnm2png -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png
|
||||
./pnm2png -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png
|
||||
# -- color with alpha-channel
|
||||
./pnm2png -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png
|
||||
./pnm2png -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png
|
||||
|
Reference in New Issue
Block a user