| 1 |
/* |
| 2 |
png2yuv |
| 3 |
======== |
| 4 |
|
| 5 |
Converts a collection of PNG images to a YUV4MPEG stream. |
| 6 |
(see png2yuv -h for help (or have a look at the function "usage")) |
| 7 |
|
| 8 |
PNG (Portable Network Graphics) is a lossless 2D image format. |
| 9 |
See www.libpng.org for more information. |
| 10 |
|
| 11 |
Based on rpf2yuv.c. |
| 12 |
|
| 13 |
Copyright (C) 1999, 2002 Gernot Ziegler ([email protected]) |
| 14 |
Copyright (C) 2001, 2004 Matthew Marjanovic ([email protected]) |
| 15 |
|
| 16 |
This program is free software; you can redistribute it and/or modify |
| 17 |
it under the terms of the GNU General Public License as published by |
| 18 |
the Free Software Foundation; either version 2 of the License, or |
| 19 |
(at your option) any later version. |
| 20 |
|
| 21 |
This program is distributed in the hope that it will be useful, |
| 22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
GNU General Public License for more details. |
| 25 |
|
| 26 |
You should have received a copy of the GNU General Public License |
| 27 |
along with this program; if not, write to the Free Software |
| 28 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include <config.h>cxx . . $ `<file>/config.h`/ |
| 32 |
|
| 33 |
#include <stdio.h> |
| 34 |
#include <stdlib.h> |
| 35 |
#include <unistd.h> |
| 36 |
#include <limits.h> |
| 37 |
|
| 38 |
#include <string.h> |
| 39 |
#include <errno.h> |
| 40 |
|
| 41 |
#include <sys/types.h> |
| 42 |
|
| 43 |
#include <png.h> |
| 44 |
|
| 45 |
#include "mjpeg_logging.h"cxx . . $ `<file>/utils/mjpeg_logging.h`/ |
| 46 |
#include "mjpeg_types.h"cxx . . $ `<file>/utils/mjpeg_types.h`/ |
| 47 |
|
| 48 |
#include "yuv4mpeg.h"cxx . . $ `<file>/utils/yuv4mpeg.h`/ |
| 49 |
#include "mpegconsts.h"cxx . . $ `<file>/utils/mpegconsts.h`/ |
| 50 |
|
| 51 |
#include "subsample.h"cxx . . $ `<file>/lavtools/subsample.h`/ |
| 52 |
#include "colorspace.h"cxx . . $ `<file>/lavtools/colorspace.h`/ |
| 53 |
|
| •54 |
#ifndef PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`! |
| 55 |
# define PATH_MAX 4096 |
| 56 |
#endif |
| 57 |
|
| 58 |
#define DEFAULT_CHROMA_MODEcxx . . $ `lavtools/png2yuv.c:58:9`! Y4M_CHROMA_420JPEGcxx . . $ `utils/yuv4mpeg.h:65:9`! |
| 59 |
|
| 60 |
typedef struct _parameterscxx . . $ _parameters# |
| 61 |
{ |
| 62 |
char *pngformatstrcxx . . $ _parameters#pngformatstr.; |
| 63 |
uint32_tcxx . . $ uint32_t# begincxx . . $ _parameters#begin.; /**< the video frame start */ |
| 64 |
int32_tcxx . . $ int32_t# numframescxx . . $ _parameters#numframes.; /**< -1 means: take all frames */ |
| 65 |
y4m_ratio_tcxx . . $ y4m_ratio_t# frameratecxx . . $ _parameters#framerate.; |
| 66 |
int interlacecxx . . $ _parameters#interlace.; /**< will the YUV4MPEG stream be interlaced? */ |
| 67 |
int interleavecxx . . $ _parameters#interleave.; /**< are the PNG frames field-interleaved? */ |
| 68 |
int verbosecxx . . $ _parameters#verbose.; /**< the verbosity of the program (see mjpeg_logging.h) */ |
| 69 |
|
| 70 |
png_uint_32cxx . . $ png_uint_32# widthcxx . . $ _parameters#width.; |
| 71 |
png_uint_32cxx . . $ png_uint_32# heightcxx . . $ _parameters#height.; |
| 72 |
int ss_modecxx . . $ _parameters#ss_mode.; /**< subsampling mode (based on ssm_id from subsample.h) */ |
| 73 |
|
| 74 |
int new_widthcxx . . $ _parameters#new_width.; /// new MPEG2 width, in case the original one is uneven |
| 75 |
int new_heightcxx . . $ _parameters#new_height.; /// new MPEG2 width, in case the original one is uneven |
| 76 |
} parameters_tcxx . . $ parameters_t#; |
| 77 |
|
| 78 |
|
| 79 |
/* |
| 80 |
* The User Interface parts |
| 81 |
*/ |
| 82 |
|
| 83 |
/* usage |
| 84 |
* Prints a short description of the program, including default values |
| 85 |
* in: prog: The name of the program |
| 86 |
*/ |
| 87 |
static void usagecxx . . $ usage(fda57c8427c60377).(char *prog) |
| 88 |
{ |
| 89 |
char *h; |
| 90 |
|
| 91 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != (h = (char *)strrchrcxx . . $ strrchr(2050848944e00d54).(prog,'/'))) |
| 92 |
prog = h+1; |
| 93 |
|
| 94 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, |
| 95 |
"usage: %s [ options ]\n" |
| 96 |
"\n" |
| 97 |
"where options are ([] shows the defaults):\n" |
| 98 |
" -v num verbosity (0,1,2) [1]\n" |
| 99 |
" -b framenum starting frame number [0]\n" |
| 100 |
" -f framerate framerate for output stream (fps) \n" |
| 101 |
" -n numframes number of frames to process [-1 = all]\n" |
| 102 |
" -j {1}%%{2}d{3} Read PNG frames with the name components as follows:\n" |
| 103 |
" {1} PNG filename prefix (e g rendered_ )\n" |
| 104 |
" {2} Counting placeholder (like in C, printf, eg 06 ))\n" |
| 105 |
" -I x interlacing mode: p = none/progressive\n" |
| 106 |
" t = top-field-first\n" |
| 107 |
" b = bottom-field-first\n" |
| 108 |
" -L x interleaving mode: 0 = non-interleaved (two successive\n" |
| 109 |
" fields per PNG file)\n" |
| 110 |
" 1 = interleaved fields\n" |
| 111 |
" -S mode chroma subsampling mode [%s]\n" |
| 112 |
"\n" |
| 113 |
"%s pipes a sequence of PNG files to stdout,\n" |
| 114 |
"making the direct encoding of MPEG files possible under mpeg2enc.\n" |
| 115 |
"Any 8bit PNG format supported by libpng can be read.\n" |
| 116 |
"stdout will be filled with the YUV4MPEG movie data stream,\n" |
| 117 |
"so be prepared to pipe it on to mpeg2enc or to write it into a file.\n" |
| 118 |
"\n" |
| 119 |
"\n" |
| 120 |
"examples:\n" |
| 121 |
" %s -j in_%%06d.png -f 25 -I p -b 100000 > result.yuv\n" |
| 122 |
" | combines all the available PNGs that match \n" |
| 123 |
" in_??????.png, starting with 100000 (in_100000.png, \n" |
| 124 |
" in_100001.png, etc...) into the uncompressed YUV4MPEG videofile result.yuv\n" |
| 125 |
" The videofile has 25 frames per second and does not use any interlacing.\n" |
| 126 |
" %s -Ip -L0 -j abc_%%04d.png | mpeg2enc -f3 -o out.m2v\n" |
| 127 |
" | combines all the available PNGs that match \n" |
| 128 |
" abc_??????.png, starting with 0000 (abc_0000.png, \n" |
| 129 |
" abc_0001.png, etc...) and pipes it to mpeg2enc which encodes\n" |
| 130 |
" an MPEG2-file called out.m2v out of it\n" |
| 131 |
"\n", |
| 132 |
prog, y4m_chroma_keywordcxx . . $ y4m_chroma_keyword(f7ae7e56280f18ae).(DEFAULT_CHROMA_MODEcxx . . $ `lavtools/png2yuv.c:58:9`!), prog, prog, prog); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
/** parse_commandline |
| 138 |
* Parses the commandline for the supplied parameters. |
| 139 |
* in: argc, argv: the classic commandline parameters |
| 140 |
*/ |
| 141 |
static void parse_commandlinecxx . . $ parse_commandline(f06bafd4396a7533).(int argc, char ** argv, parameters_tcxx . . $ parameters_t# *param) |
| 142 |
{ |
| 143 |
int c; |
| 144 |
|
| 145 |
param->pngformatstrcxx . . $ _parameters#pngformatstr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 146 |
param->begincxx . . $ _parameters#begin. = 0; |
| 147 |
param->numframescxx . . $ _parameters#numframes. = -1; |
| 148 |
param->frameratecxx . . $ _parameters#framerate. = y4m_fps_UNKNOWNcxx . . $ y4m_fps_UNKNOWN.; |
| 149 |
param->interlacecxx . . $ _parameters#interlace. = Y4M_UNKNOWNcxx . . $ `utils/yuv4mpeg.h:52:9`!; |
| 150 |
param->interleavecxx . . $ _parameters#interleave. = -1; |
| 151 |
param->verbosecxx . . $ _parameters#verbose. = 1; |
| 152 |
param->ss_modecxx . . $ _parameters#ss_mode. = DEFAULT_CHROMA_MODEcxx . . $ `lavtools/png2yuv.c:58:9`!; |
| 153 |
|
| 154 |
/* parse options */ |
| 155 |
for (;;) { |
| 156 |
if (-1 == (c = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, "I:hv:L:b:j:n:f:z:S:"))) |
| 157 |
break; |
| 158 |
switch (c) { |
| 159 |
case 'j': |
| 160 |
param->pngformatstrcxx . . $ _parameters#pngformatstr. = strdupcxx . . $ strdup(a8b8e32347182212).(optargcxx . . $ optarg.); |
| 161 |
break; |
| 162 |
#if 0 |
| 163 |
case 'z': |
| 164 |
param->mza_filename = strdup(optarg); |
| 165 |
param->make_z_alpha = 1; |
| 166 |
break; |
| 167 |
#else |
| 168 |
case 'z': |
| 169 |
mjpeg_errorcxx . . $ mjpeg_error(326aeb464d16410c).("Z encoding currently unsupported !\n"); |
| 170 |
exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 171 |
break; |
| 172 |
#endif |
| 173 |
case 'S': |
| 174 |
param->ss_modecxx . . $ _parameters#ss_mode. = y4m_chroma_parse_keywordcxx . . $ y4m_chroma_parse_keyword(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 175 |
if (param->ss_modecxx . . $ _parameters#ss_mode. == Y4M_UNKNOWNcxx . . $ `utils/yuv4mpeg.h:52:9`!) { |
| 176 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("Unknown subsampling mode option: %s", optargcxx . . $ optarg.); |
| 177 |
} else if (!chroma_sub_implementedcxx . . $ chroma_sub_implemented(7864480464b09eea).(param->ss_modecxx . . $ _parameters#ss_mode.)) { |
| 178 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("Unsupported subsampling mode option: %s", optargcxx . . $ optarg.); |
| 179 |
} |
| 180 |
break; |
| 181 |
case 'b': |
| 182 |
param->begincxx . . $ _parameters#begin. = atolcxx . . $ atol(3c95bd14d5d5d286).(optargcxx . . $ optarg.); |
| 183 |
break; |
| 184 |
case 'n': |
| 185 |
param->numframescxx . . $ _parameters#numframes. = atolcxx . . $ atol(3c95bd14d5d5d286).(optargcxx . . $ optarg.); |
| 186 |
break; |
| 187 |
case 'f': |
| 188 |
param->frameratecxx . . $ _parameters#framerate. = mpeg_conform_frameratecxx . . $ mpeg_conform_framerate(602f0d1f73d0fb86).(atofcxx . . $ atof(9a18bdb0e56c1bc2).(optargcxx . . $ optarg.)); |
| 189 |
break; |
| 190 |
case 'I': |
| 191 |
switch (optargcxx . . $ optarg.[0]) { |
| 192 |
case 'p': |
| 193 |
param->interlacecxx . . $ _parameters#interlace. = Y4M_ILACE_NONEcxx . . $ `utils/yuv4mpeg.h:57:9`!; |
| 194 |
break; |
| 195 |
case 't': |
| 196 |
param->interlacecxx . . $ _parameters#interlace. = Y4M_ILACE_TOP_FIRSTcxx . . $ `utils/yuv4mpeg.h:58:9`!; |
| 197 |
break; |
| 198 |
case 'b': |
| 199 |
param->interlacecxx . . $ _parameters#interlace. = Y4M_ILACE_BOTTOM_FIRSTcxx . . $ `utils/yuv4mpeg.h:59:9`!; |
| 200 |
break; |
| 201 |
default: |
| 202 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c). ("-I option requires arg p, t, or b"); |
| 203 |
} |
| 204 |
break; |
| 205 |
case 'L': |
| 206 |
param->interleavecxx . . $ _parameters#interleave. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 207 |
if ((param->interleavecxx . . $ _parameters#interleave. != 0) && |
| 208 |
(param->interleavecxx . . $ _parameters#interleave. != 1)) |
| 209 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c). ("-L option requires arg 0 or 1"); |
| 210 |
break; |
| 211 |
case 'v': |
| 212 |
param->verbosecxx . . $ _parameters#verbose. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 213 |
if (param->verbosecxx . . $ _parameters#verbose. < 0 || param->verbosecxx . . $ _parameters#verbose. > 2) |
| 214 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).( "-v option requires arg 0, 1, or 2"); |
| 215 |
break; |
| 216 |
case 'h': |
| 217 |
default: |
| 218 |
usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 219 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 220 |
} |
| 221 |
} |
| 222 |
if (param->pngformatstrcxx . . $ _parameters#pngformatstr. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 223 |
{ |
| 224 |
mjpeg_errorcxx . . $ mjpeg_error(326aeb464d16410c).("%s: input format string not specified. (Use -j option.)", |
| 225 |
argv[0]); |
| 226 |
usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 227 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 228 |
} |
| 229 |
|
| 230 |
if (Y4M_RATIO_EQLcxx . . $ `utils/yuv4mpeg.h:170:9`!(param->framerate, y4m_fps_UNKNOWN)) |
| 231 |
{ |
| 232 |
mjpeg_errorcxx . . $ mjpeg_error(326aeb464d16410c).("%s: framerate not specified. (Use -f option)", |
| 233 |
argv[0]); |
| 234 |
usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 235 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
/* |
| 241 |
* The file handling parts |
| 242 |
*/ |
| 243 |
/** |
| 244 |
Reads one PNG file. |
| 245 |
@param process Process the image data (NULL for initial parameter determination) |
| 246 |
@returns -1 on failure, 1 on sucess |
| 247 |
@on success returns RGB data in the second, yuv, parameter |
| 248 |
*/ |
| 249 |
int decode_pngcxx . . $ decode_png(2e933782e515b112).(const char *pngname, uint8_tcxx . . $ uint8_t# *yuv[], parameters_tcxx . . $ parameters_t# *param) |
| 250 |
{ |
| 251 |
png_structpcxx . . $ png_structp# png_ptr; |
| 252 |
png_infopcxx . . $ png_infop# info_ptr; |
| 253 |
FILEcxx . . $ FILE# *pngfile; |
| 254 |
|
| 255 |
/* libpng needs two structs - a png_struct and a png_info, there is no |
| 256 |
* need to make the third, another png_info, because that is only used |
| 257 |
* to store data (such as textual information) that can come after the |
| 258 |
* PNG image. This code only cares about the image. |
| 259 |
*/ |
| 260 |
info_ptr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 261 |
pngfile = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 262 |
png_ptr = png_create_read_structcxx . . $ png_create_read_struct(4d6f3c43768ab869).(PNG_LIBPNG_VER_STRINGcxx . . $ `<external>/15466183176234753646/png.h:277:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 263 |
if (!png_ptr) |
| 264 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("%s: Could not allocate PNG read struct !", pngname); |
| 265 |
|
| 266 |
/* This needs to be done immediately after creation of the png_struct |
| 267 |
* because storage allocation failures will longjmp back to here: |
| 268 |
*/ |
| 269 |
if (setjmpcxx . . $ `<external>/4367339001007250937/setjmp.h:49:9`!(png_jmpbufcxx . . $ `<external>/15466183176234753646/png.h:973:11`!(png_ptr))) |
| 270 |
{ |
| 271 |
png_destroy_read_structcxx . . $ png_destroy_read_struct(2d6666e0dbc83140).(&png_ptr, &info_ptr, 0); |
| 272 |
if (pngfile) (void)fclosecxx . . $ fclose(89bc1efcdac0ca22).(pngfile); |
| 273 |
mjpeg_errorcxx . . $ mjpeg_error(326aeb464d16410c).("%s: Corrupted PNG file !", pngname); |
| 274 |
return -1; |
| 275 |
} |
| 276 |
|
| 277 |
info_ptr = png_create_info_structcxx . . $ png_create_info_struct(1d6b551ef7875aa9).(png_ptr); |
| 278 |
if (!info_ptr) |
| 279 |
{ |
| 280 |
png_destroy_read_structcxx . . $ png_destroy_read_struct(2d6666e0dbc83140).(&png_ptr, |
| 281 |
(png_infoppcxx . . $ png_infopp#)NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, (png_infoppcxx . . $ png_infopp#)NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 282 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("%s: Could not allocate PNG info struct !", pngname); |
| 283 |
} |
| 284 |
|
| 285 |
/* Now open this PNG file, and examine its header to retrieve the |
| 286 |
* YUV4MPEG info that shall be written */ |
| 287 |
pngfile = fopencxx . . $ fopen(82ec0787cd37e0a3).(pngname, "rb"); |
| 288 |
if (!pngfile) |
| 289 |
{ |
| 290 |
perrorcxx . . $ perror(85c52e162fed56f9).(pngname); |
| 291 |
png_errorcxx . . $ png_error(38b9ebb04943db50).(png_ptr, "PNG file open failed"); |
| 292 |
} |
| 293 |
|
| 294 |
png_init_iocxx . . $ png_init_io(df7934befe3ccd5d).(png_ptr, pngfile); |
| 295 |
|
| 296 |
if (yuv) |
| 297 |
{ |
| 298 |
png_uint_32cxx . . $ png_uint_32# nr, input_height, input_width, output_height, output_width; |
| 299 |
uint8_tcxx . . $ uint8_t# *r, *g, *b; |
| 300 |
png_byteppcxx . . $ png_bytepp# rows; |
| 301 |
|
| 302 |
/* The code uses png_read_png to obtain a complete buffered copy of the |
| 303 |
* PNG file reduced (or expanded) to 8 bit RGB. This is a little wasteful |
| 304 |
* in the case of a non-interlaced image - the code could work row by |
| 305 |
* row without buffering the whole image - but the interlaced case is |
| 306 |
* almost impossible to handle this way so it is better to be simple and |
| 307 |
* correct. |
| 308 |
*/ |
| 309 |
# if PNG_LIBPNG_VERcxx . . $ `<external>/15466183176234753646/png.h:319:9`! >= 10500 && PNG_LIBPNG_VERcxx . . $ `<external>/15466183176234753646/png.h:319:9`! < 10502 |
| 310 |
/* There is a bug in 1.5 before 1.5.2 which causes png_read_png to |
| 311 |
* whine most terribly on interlaced images, this stops it: |
| 312 |
*/ |
| 313 |
(void)png_set_interlace_handling(png_ptr); |
| 314 |
# endif |
| 315 |
png_read_pngcxx . . $ png_read_png(6ff755085c5752e5).(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16cxx . . $ `<external>/15466183176234753646/png.h:851:9`! | |
| 316 |
PNG_TRANSFORM_STRIP_ALPHAcxx . . $ `<external>/15466183176234753646/png.h:852:9`! | PNG_TRANSFORM_EXPANDcxx . . $ `<external>/15466183176234753646/png.h:855:9`! | |
| 317 |
PNG_TRANSFORM_GRAY_TO_RGBcxx . . $ `<external>/15466183176234753646/png.h:867:9`! /* requires libpng 1.4 or later */, 0); |
| 318 |
|
| 319 |
/* And return the separated data to the parameters. */ |
| 320 |
rows = png_get_rowscxx . . $ png_get_rows(b805219a1e0e2fe9).(png_ptr, info_ptr); |
| 321 |
|
| 322 |
/* Since the PNG files for the frames are separate the actual PNG file |
| 323 |
* that was read could be unrelated - a random width and height. Because |
| 324 |
* the output may be interleaved the output height may be twice the input |
| 325 |
* PNG height. Because the MPEG code requires an even width the output |
| 326 |
* width may be one more than the original frame width. |
| 327 |
* |
| 328 |
* For the interleaving the PNG data is smashed into the lower half of |
| 329 |
* the yuv rows. For the other cases the input data is cropped or |
| 330 |
* top-lefted as appropriate. |
| 331 |
*/ |
| 332 |
output_height = param->new_heightcxx . . $ _parameters#new_height.; |
| 333 |
|
| 334 |
input_height = png_get_image_heightcxx . . $ png_get_image_height(20049e7771c3ccdc).(png_ptr, info_ptr); |
| 335 |
if (input_height > output_height) |
| 336 |
input_height = output_height; |
| 337 |
|
| 338 |
output_width = param->new_widthcxx . . $ _parameters#new_width.; |
| 339 |
|
| 340 |
input_width = png_get_image_widthcxx . . $ png_get_image_width(20049e7771c3ccdc).(png_ptr, info_ptr); |
| 341 |
if (input_width > output_width) |
| 342 |
input_width = output_width; |
| 343 |
|
| 344 |
/* Breaking up the RGB data is not hard to do, the separated channels are |
| 345 |
* simply packed into the three raw yuv arrays with new_width values per |
| 346 |
* row. |
| 347 |
*/ |
| 348 |
r = yuv[0]; |
| 349 |
g = yuv[1]; |
| 350 |
b = yuv[2]; |
| 351 |
for (nr=0; nr<input_height; ++nr) |
| 352 |
{ |
| 353 |
png_uint_32cxx . . $ png_uint_32# nc; |
| 354 |
png_bytepcxx . . $ png_bytep# row = *rows++; |
| 355 |
|
| 356 |
for (nc=0; nc<input_width; ++nc) |
| 357 |
{ |
| 358 |
*r++ = *row++; |
| 359 |
*g++ = *row++; |
| 360 |
*b++ = *row++; |
| 361 |
} |
| 362 |
|
| 363 |
/* Pad the output: */ |
| 364 |
for (; nc<output_width; ++nc) |
| 365 |
*r++ = *g++ = *b++ = 0; |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
else |
| 370 |
{ |
| 371 |
/* Just return the image width and height in *param */ |
| 372 |
png_read_infocxx . . $ png_read_info(896d601d3796326c).(png_ptr, info_ptr); |
| 373 |
|
| 374 |
param->widthcxx . . $ _parameters#width. = png_get_image_widthcxx . . $ png_get_image_width(20049e7771c3ccdc).(png_ptr, info_ptr); |
| 375 |
param->heightcxx . . $ _parameters#height. = png_get_image_heightcxx . . $ png_get_image_height(20049e7771c3ccdc).(png_ptr, info_ptr); |
| 376 |
|
| 377 |
} |
| 378 |
|
| 379 |
/* Successful exit: */ |
| 380 |
png_destroy_read_structcxx . . $ png_destroy_read_struct(2d6666e0dbc83140).(&png_ptr, &info_ptr, 0); |
| 381 |
|
| 382 |
fclosecxx . . $ fclose(89bc1efcdac0ca22).(pngfile); |
| 383 |
return 1; |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
/** init_parse_files |
| 388 |
* Verifies the PNG input files and prepares YUV4MPEG header information. |
| 389 |
* @returns 0 on success |
| 390 |
*/ |
| 391 |
static int init_parse_filescxx . . $ init_parse_files(9d22819ac7f21af9).(parameters_tcxx . . $ parameters_t# *param) |
| 392 |
{ |
| 393 |
char *pngname; |
| 394 |
size_t pngnamelen; |
| 395 |
|
| 396 |
pngnamelen = strlencxx . . $ strlen(751346f8406fd082).(param->pngformatstrcxx . . $ _parameters#pngformatstr.) + sizeof(param->begincxx . . $ _parameters#begin.) * 3 + 1; |
| 397 |
pngname = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(pngnamelen * sizeof(char)); |
| 398 |
snprintfcxx . . $ snprintf(ea502d73e74c754c).(pngname, pngnamelen, |
| 399 |
param->pngformatstrcxx . . $ _parameters#pngformatstr., param->begincxx . . $ _parameters#begin.); |
| 400 |
mjpeg_debugcxx . . $ mjpeg_debug(326aeb464d16410c).("Analyzing %s to get the right pic params", pngname); |
| 401 |
|
| 402 |
/* The first frame (the param->begin frame) determines the height and |
| 403 |
* width of the output. Passing NULL instead of yuv (see below) causes |
| 404 |
* decode_png to fill in param with the image dimensions. |
| 405 |
*/ |
| 406 |
if (decode_pngcxx . . $ decode_png(2e933782e515b112).(pngname, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, param) == -1) |
| 407 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("Reading of %s failed.\n", pngname); |
| 408 |
|
| 409 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Image dimensions are %ux%u", |
| 410 |
param->widthcxx . . $ _parameters#width., param->heightcxx . . $ _parameters#height.); |
| 411 |
|
| 412 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Movie frame rate is: %f frames/second", |
| 413 |
Y4M_RATIO_DBLcxx . . $ `utils/yuv4mpeg.h:173:9`!(param->framerate)); |
| 414 |
|
| 415 |
switch (param->interlacecxx . . $ _parameters#interlace.) |
| 416 |
{ |
| 417 |
case Y4M_ILACE_NONEcxx . . $ `utils/yuv4mpeg.h:57:9`!: |
| 418 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Non-interlaced/progressive frames."); |
| 419 |
break; |
| 420 |
case Y4M_ILACE_BOTTOM_FIRSTcxx . . $ `utils/yuv4mpeg.h:59:9`!: |
| 421 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Interlaced frames, bottom field first."); |
| 422 |
break; |
| 423 |
case Y4M_ILACE_TOP_FIRSTcxx . . $ `utils/yuv4mpeg.h:58:9`!: |
| 424 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Interlaced frames, top field first."); |
| 425 |
break; |
| 426 |
default: |
| 427 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("Interlace has not been specified (use -I option)"); |
| 428 |
break; |
| 429 |
} |
| 430 |
|
| 431 |
if ((param->interlacecxx . . $ _parameters#interlace. != Y4M_ILACE_NONEcxx . . $ `utils/yuv4mpeg.h:57:9`!) && (param->interleavecxx . . $ _parameters#interleave. == -1)) |
| 432 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("Interleave has not been specified (use -L option)"); |
| 433 |
|
| 434 |
if (!(param->interleavecxx . . $ _parameters#interleave.) && (param->interlacecxx . . $ _parameters#interlace. != Y4M_ILACE_NONEcxx . . $ `utils/yuv4mpeg.h:57:9`!)) |
| 435 |
{ |
| 436 |
/* So the height in 'param' might be twice the PNG input height:*/ |
| 437 |
param->heightcxx . . $ _parameters#height. *= 2; |
| 438 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Non-interleaved fields (image height doubled)"); |
| 439 |
} |
| 440 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Frame size: %u x %u", param->widthcxx . . $ _parameters#width., param->heightcxx . . $ _parameters#height.); |
| 441 |
|
| 442 |
freecxx . . $ free(5d22bdacc48458e8).(pngname); |
| 443 |
return 0; |
| 444 |
} |
| 445 |
|
| 446 |
static int generate_YUV4MPEGcxx . . $ generate_YUV4MPEG(9d22819ac7f21af9).(parameters_tcxx . . $ parameters_t# *param) |
| 447 |
{ |
| 448 |
uint32_tcxx . . $ uint32_t# frame; |
| 449 |
uint8_tcxx . . $ uint8_t# *yuv[3]; /* Buffers, initially for R,G,B then Y,Cb,Cr */ |
| 450 |
y4m_stream_info_tcxx . . $ y4m_stream_info_t# streaminfo; |
| 451 |
y4m_frame_info_tcxx . . $ y4m_frame_info_t# frameinfo; |
| 452 |
char *pngname; |
| 453 |
size_t pngnamelen; |
| 454 |
|
| 455 |
/* Make the output even, so the output may be one larger than the |
| 456 |
* original PNG image width. |
| 457 |
*/ |
| 458 |
param->new_widthcxx . . $ _parameters#new_width. = param->widthcxx . . $ _parameters#width. + (param->widthcxx . . $ _parameters#width. & 1); |
| 459 |
param->new_heightcxx . . $ _parameters#new_height. = param->heightcxx . . $ _parameters#height. + (param->heightcxx . . $ _parameters#height. & 1); |
| 460 |
|
| 461 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Now generating YUV4MPEG stream."); |
| 462 |
y4m_init_stream_infocxx . . $ y4m_init_stream_info(a3d75d837a19fc60).(&streaminfo); |
| 463 |
y4m_init_frame_infocxx . . $ y4m_init_frame_info(ef94011914463163).(&frameinfo); |
| 464 |
|
| 465 |
y4m_si_set_widthcxx . . $ y4m_si_set_width(1e4ad25e9e468757).(&streaminfo, param->new_widthcxx . . $ _parameters#new_width.); |
| 466 |
y4m_si_set_heightcxx . . $ y4m_si_set_height(1e4ad25e9e468757).(&streaminfo, param->new_heightcxx . . $ _parameters#new_height.); |
| 467 |
y4m_si_set_interlacecxx . . $ y4m_si_set_interlace(1e4ad25e9e468757).(&streaminfo, param->interlacecxx . . $ _parameters#interlace.); |
| 468 |
y4m_si_set_frameratecxx . . $ y4m_si_set_framerate(8f5a9e58e0c6aed4).(&streaminfo, param->frameratecxx . . $ _parameters#framerate.); |
| 469 |
y4m_si_set_chromacxx . . $ y4m_si_set_chroma(1e4ad25e9e468757).(&streaminfo, param->ss_modecxx . . $ _parameters#ss_mode.); |
| 470 |
|
| 471 |
yuv[0] = (uint8_tcxx . . $ uint8_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(param->new_widthcxx . . $ _parameters#new_width. * param->new_heightcxx . . $ _parameters#new_height. * sizeof(yuv[0][0])); |
| 472 |
yuv[1] = (uint8_tcxx . . $ uint8_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(param->new_widthcxx . . $ _parameters#new_width. * param->new_heightcxx . . $ _parameters#new_height. * sizeof(yuv[1][0])); |
| 473 |
yuv[2] = (uint8_tcxx . . $ uint8_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(param->new_widthcxx . . $ _parameters#new_width. * param->new_heightcxx . . $ _parameters#new_height. * sizeof(yuv[2][0])); |
| 474 |
|
| 475 |
y4m_write_stream_headercxx . . $ y4m_write_stream_header(ab5bea2bc1b355f0).(STDOUT_FILENOcxx . . $ `<external>/12628407106812493757/unistd.h:211:9`!, &streaminfo); |
| 476 |
|
| 477 |
pngnamelen = strlencxx . . $ strlen(751346f8406fd082).(param->pngformatstrcxx . . $ _parameters#pngformatstr.) + sizeof(frame) * 3 + 1; |
| 478 |
pngname = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(pngnamelen * sizeof(char)); |
| 479 |
|
| 480 |
for (frame = param->begincxx . . $ _parameters#begin.; |
| 481 |
(frame < param->numframescxx . . $ _parameters#numframes. + param->begincxx . . $ _parameters#begin.) || (param->numframescxx . . $ _parameters#numframes. == -1); |
| 482 |
frame++) |
| 483 |
{ |
| 484 |
snprintfcxx . . $ snprintf(ea502d73e74c754c).(pngname, pngnamelen, param->pngformatstrcxx . . $ _parameters#pngformatstr., frame); |
| 485 |
|
| 486 |
/* decode_png reads the PNG into the yuv buffers as r,g,b [0..255] |
| 487 |
* values. |
| 488 |
*/ |
| 489 |
if (decode_pngcxx . . $ decode_png(2e933782e515b112).(pngname, yuv, param) == -1) |
| 490 |
{ |
| 491 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Read from '%s' failed: %s", pngname, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 492 |
if (param->numframescxx . . $ _parameters#numframes. == -1) |
| 493 |
{ |
| 494 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("No more frames. Stopping."); |
| 495 |
break; /* we are done; leave 'while' loop */ |
| 496 |
} |
| 497 |
else |
| 498 |
{ |
| 499 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Rewriting latest frame instead."); |
| 500 |
} |
| 501 |
} |
| 502 |
else |
| 503 |
{ |
| 504 |
mjpeg_debugcxx . . $ mjpeg_debug(326aeb464d16410c).("Converting frame to YUV format."); |
| 505 |
/* Transform colorspace, then subsample (in place) */ |
| 506 |
convert_RGB_to_YCbCrcxx . . $ convert_RGB_to_YCbCr(38e800ccd16be6ed).(yuv, param->new_heightcxx . . $ _parameters#new_height. * param->new_widthcxx . . $ _parameters#new_width.); |
| 507 |
chroma_subsamplecxx . . $ chroma_subsample(1539e9ad78cc26af).(param->ss_modecxx . . $ _parameters#ss_mode., yuv, param->new_widthcxx . . $ _parameters#new_width., param->new_heightcxx . . $ _parameters#new_height.); |
| 508 |
|
| 509 |
mjpeg_debugcxx . . $ mjpeg_debug(326aeb464d16410c).("Frame decoded, now writing to output stream."); |
| 510 |
} |
| 511 |
|
| 512 |
mjpeg_debugcxx . . $ mjpeg_debug(326aeb464d16410c).("Frame decoded, now writing to output stream."); |
| 513 |
y4m_write_framecxx . . $ y4m_write_frame(85f4db58422369df).(STDOUT_FILENOcxx . . $ `<external>/12628407106812493757/unistd.h:211:9`!, &streaminfo, &frameinfo, yuv); |
| 514 |
} |
| 515 |
|
| 516 |
y4m_fini_stream_infocxx . . $ y4m_fini_stream_info(a3d75d837a19fc60).(&streaminfo); |
| 517 |
y4m_fini_frame_infocxx . . $ y4m_fini_frame_info(ef94011914463163).(&frameinfo); |
| 518 |
freecxx . . $ free(5d22bdacc48458e8).(yuv[0]); |
| 519 |
freecxx . . $ free(5d22bdacc48458e8).(yuv[1]); |
| 520 |
freecxx . . $ free(5d22bdacc48458e8).(yuv[2]); |
| 521 |
freecxx . . $ free(5d22bdacc48458e8).(pngname); |
| 522 |
|
| 523 |
return 0; |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
/* main |
| 529 |
* in: argc, argv: Classic commandline parameters. |
| 530 |
* returns: int: 0: success, !0: !success :-) |
| 531 |
*/ |
| 532 |
int maincxx . . $ main(afcd3168fc1188a4).(int argc, char ** argv) |
| 533 |
{ |
| 534 |
parameters_tcxx . . $ parameters_t# param; |
| 535 |
|
| 536 |
y4m_accept_extensionscxx . . $ y4m_accept_extensions(7864480464b09eea).(1); |
| 537 |
|
| 538 |
parse_commandlinecxx . . $ parse_commandline(f06bafd4396a7533).(argc, argv, ¶m); |
| 539 |
mjpeg_default_handler_verbositycxx . . $ mjpeg_default_handler_verbosity(7864480464b09eea).(param.verbosecxx . . $ _parameters#verbose.); |
| 540 |
|
| 541 |
mjpeg_infocxx . . $ mjpeg_info(326aeb464d16410c).("Parsing & checking input files."); |
| 542 |
if (init_parse_filescxx . . $ init_parse_files(9d22819ac7f21af9).(¶m)) { |
| 543 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("* Error processing the PNG input."); |
| 544 |
} |
| 545 |
|
| 546 |
if (generate_YUV4MPEGcxx . . $ generate_YUV4MPEG(9d22819ac7f21af9).(¶m)) { |
| 547 |
mjpeg_error_exit1cxx . . $ mjpeg_error_exit1(326aeb464d16410c).("* Error processing the input files."); |
| 548 |
} |
| 549 |
|
| 550 |
return 0; |
| 551 |
} |