14 #define JPEG_CJPEG_DJPEG 37 #ifdef DONT_USE_B_MODE 38 #define READ_BINARY "r" 39 #define WRITE_BINARY "w" 42 #define READ_BINARY "rb", "ctx=stm" 43 #define WRITE_BINARY "wb", "ctx=stm" 45 #define READ_BINARY "rb" 46 #define WRITE_BINARY "wb" 51 #define EXIT_FAILURE 1 55 #define EXIT_SUCCESS 1 57 #define EXIT_SUCCESS 0 65 #ifndef MAX_COM_LENGTH 66 #define MAX_COM_LENGTH 65000L 78 #define NEXTBYTE() getc(infile) 83 #define PUTBYTE(x) putc((x), outfile) 87 #define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) 98 ERREXIT(
"Premature EOF in JPEG file");
111 ERREXIT(
"Premature EOF in JPEG file");
114 ERREXIT(
"Premature EOF in JPEG file");
115 return (((
unsigned int) c1) << 8) + ((
unsigned int) c2);
128 write_2_bytes (
unsigned int val)
142 copy_rest_of_file (
void)
190 int discarded_bytes = 0;
205 if (discarded_bytes != 0) {
206 fprintf(stderr,
"Warning: garbage data found in JPEG file\n");
228 if (c1 != 0xFF || c2 !=
M_SOI)
250 length = read_2_bytes();
251 write_2_bytes(length);
254 ERREXIT(
"Erroneous JPEG marker length");
258 write_1_byte(read_1_byte());
270 length = read_2_bytes();
273 ERREXIT(
"Erroneous JPEG marker length");
277 (
void) read_1_byte();
289 scan_JPEG_header (
int keep_COM)
295 ERREXIT(
"Expected SOI marker first");
321 ERREXIT(
"SOS without prior SOFn");
329 write_marker(marker);
337 write_marker(marker);
347 static const char * progname;
354 fprintf(stderr,
"wrjpgcom inserts a textual comment in a JPEG file.\n");
355 fprintf(stderr,
"You can add to or replace any existing comment(s).\n");
357 fprintf(stderr,
"Usage: %s [switches] ", progname);
358 #ifdef TWO_FILE_COMMANDLINE 359 fprintf(stderr,
"inputfile outputfile\n");
361 fprintf(stderr,
"[inputfile]\n");
364 fprintf(stderr,
"Switches (names may be abbreviated):\n");
365 fprintf(stderr,
" -replace Delete any existing comments\n");
366 fprintf(stderr,
" -comment \"text\" Insert comment with given text\n");
367 fprintf(stderr,
" -cfile name Read comment from named file\n");
368 fprintf(stderr,
"Notice that you must put quotes around the comment text\n");
369 fprintf(stderr,
"when you use -comment.\n");
370 fprintf(stderr,
"If you do not give either -comment or -cfile on the command line,\n");
371 fprintf(stderr,
"then the comment text is read from standard input.\n");
372 fprintf(stderr,
"It can be multiple lines, up to %u characters total.\n",
374 #ifndef TWO_FILE_COMMANDLINE 375 fprintf(stderr,
"You must specify an input JPEG file name when supplying\n");
376 fprintf(stderr,
"comment text from standard input.\n");
390 register int nmatched = 0;
392 while ((ca = *
arg++) !=
'\0') {
402 if (nmatched < minchars)
418 char * comment_arg =
NULL;
419 FILE * comment_file =
NULL;
420 unsigned int comment_length = 0;
425 argc = ccommand(&argv);
429 if (progname ==
NULL || progname[0] == 0)
430 progname =
"wrjpgcom";
433 for (argn = 1; argn < argc; argn++) {
440 }
else if (
keymatch(arg,
"cfile", 2)) {
441 if (++argn >= argc)
usage();
442 if ((comment_file = fopen(argv[argn],
"r")) ==
NULL) {
443 fprintf(stderr,
"%s: can't open %s\n", progname, argv[argn]);
446 }
else if (
keymatch(arg,
"comment", 1)) {
447 if (++argn >= argc)
usage();
448 comment_arg = argv[argn];
452 if (comment_arg[0] ==
'"') {
454 if (comment_arg ==
NULL)
455 ERREXIT(
"Insufficient memory");
456 strcpy(comment_arg, argv[argn]+1);
458 comment_length = (
unsigned int) strlen(comment_arg);
459 if (comment_length > 0 && comment_arg[comment_length-1] ==
'"') {
460 comment_arg[comment_length-1] =
'\0';
464 ERREXIT(
"Missing ending quote mark");
465 strcat(comment_arg,
" ");
466 strcat(comment_arg, argv[argn]);
469 comment_length = (
unsigned int) strlen(comment_arg);
475 if (comment_arg !=
NULL && comment_file !=
NULL)
480 if (comment_arg ==
NULL && comment_file ==
NULL && argn >= argc)
486 fprintf(stderr,
"%s: can't open %s\n", progname, argv[argn]);
492 setmode(fileno(stdin), O_BINARY);
496 fprintf(stderr,
"%s: can't open stdin\n", progname);
505 #ifdef TWO_FILE_COMMANDLINE 507 if (argn != argc-2) {
508 fprintf(stderr,
"%s: must name one input and one output file\n",
513 fprintf(stderr,
"%s: can't open %s\n", progname, argv[argn+1]);
519 fprintf(stderr,
"%s: only one input file\n", progname);
524 setmode(fileno(stdout), O_BINARY);
528 fprintf(stderr,
"%s: can't open stdout\n", progname);
537 if (comment_arg ==
NULL) {
542 if (comment_arg ==
NULL)
543 ERREXIT(
"Insufficient memory");
545 src_file = (comment_file !=
NULL ? comment_file : stdin);
546 while ((c = getc(src_file)) !=
EOF) {
548 fprintf(stderr,
"Comment text may not exceed %u bytes\n",
552 comment_arg[comment_length++] = (char) c;
554 if (comment_file !=
NULL)
555 fclose(comment_file);
564 marker = scan_JPEG_header(keep_COM);
566 if (comment_length > 0) {
568 write_2_bytes(comment_length + 2);
569 while (comment_length > 0) {
570 write_1_byte(*comment_arg++);
577 write_marker(marker);
GLenum GLuint GLenum GLsizei length
first_marker(j_decompress_ptr cinfo)
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
skip_variable(j_decompress_ptr cinfo)
GLsizeiptr const GLvoid GLenum usage
keymatch(char *arg, const char *keyword, int minchars)
int main(int argc, char **argv)
next_marker(j_decompress_ptr cinfo)