w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

png22pnm.c File Reference
#include <math.h>
#include <png.h>
#include <pngstruct.h>
#include <pngpriv.h>
#include <pnginfo.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
Include dependency graph for png22pnm.c:

Go to the source code of this file.

Classes

struct  _jmpbuf_wrapper
 

Macros

#define DUMMY
 
#define INFO_VAR_GAMMA   colorspace.gamma
 
#define VERSION   "0.11"
 
#define PBMPLUS_RAWBITS   1
 
#define PGM_OVERALLMAXVAL   65535
 
#define PPM_OVERALLMAXVAL   PGM_OVERALLMAXVAL
 
#define pm_closer   pm_close
 
#define pm_closew   pm_close
 
#define TRUE   1
 
#define FALSE   0
 
#define NONE   0
 
#define _(args)   ()
 
#define ___(arg2s, arg1s, argafter)   arg1s argafter
 
#define u_char   unsigned char
 
#define PBM_TYPE   1
 
#define PGM_TYPE   2
 
#define PPM_TYPE   3
 
#define pnm_init(_a, _b)
 
#define PMM(immed_str)   stderr, "notice: " immed_str "\n"
 
#define pm_message   printf
 
#define PME(immed_str)   stderr, "error: " immed_str "\n"
 
#define pm_error   printf /* !! exit */
 
#define pm_errexit()   exit(3)
 
#define pm_close(file)   fflush(file)
 
#define pm_keymatch(stra, strb, _x)   (0==strcmp((stra),(strb)))
 
#define PPM_MAXMAXVAL   1023
 
#define PPM_GETR(p)   (((p) & 0x3ff00000) >> 20)
 
#define PPM_GETG(p)   (((p) & 0xffc00) >> 10)
 
#define PPM_GETB(p)   ((p) & 0x3ff)
 
#define PPM_PUTR(p, red)   ((p) |= (((red) & 0x3ff) << 20))
 
#define PPM_PUTG(p, grn)   ((p) |= (((grn) & 0x3ff) << 10))
 
#define PPM_PUTB(p, blu)   ((p) |= ( (blu) & 0x3ff))
 
#define PPM_ASSIGN(p, red, grn, blu)   (p) = ((pixel) (red) << 20) | ((pixel) (grn) << 10) | (pixel) (blu)
 
#define PPM_EQUAL(p, q)   ((p) == (q))
 
#define pnm_allocrow(cols)   ((xel*) pm_allocrow( cols, sizeof(xel) ))
 
#define PNM_ASSIGN1(x, v)   PPM_ASSIGN(x,0,0,v)
 
#define PNM_GET1(x)   PPM_GETB(x)
 
#define pnm_freerow(xelrow)   pm_freerow( (char*) xelrow )
 
#define pm_freerow(x)   free(x)
 
#define get_png_val(p)   _get_png_val (&(p), info_ptr->bit_depth)
 
#define SIG_CHECK_SIZE   4
 

Typedefs

typedef struct _jmpbuf_wrapper jmpbuf_wrapper
 
typedef unsigned dimen_t
 
typedef unsigned pixval
 
typedef unsigned long pixel
 
typedef pixel xel
 
typedef pixval xelval
 

Enumerations

enum  alpha_handling {
  none , alpha_only , mix , none ,
  alpha_only , mix_only , none_and_alpha
}
 

Functions

static char * pm_allocrow (int cols, int size)
 
static pixel ppm_parsecolor ()
 
static FILEpm_openr (char *name)
 
static FILEpm_openw (char *name)
 
static void pm_usage (char usage[], FILE *f)
 
static long rgbnorm (long rgb, long lmaxval, int n, char *colorname)
 
static pixel ppm_parsecolor (char *colorname, pixval maxval)
 
static png_uint_16 _get_png_val (png_byte **pp, int bit_depth)
 
static void store_pixel (xel *pix, png_uint_16 r, png_uint_16 g, png_uint_16 b, png_uint_16 a)
 
static png_uint_16 gamma_correct (png_uint_16 v, float g)
 
static int iscolor (png_color c)
 
static void save_text (png_info *info_ptr, FILE *tfp)
 
static void show_time (png_info *info_ptr)
 
static void pngtopnm_error_handler (png_structp png_ptr, png_const_charp msg)
 
static void convertpng (FILE *ifp, FILE *tfp)
 
int main (int argc, argv)
 

Variables

static png_uint_16 maxval
 
static png_uint_16 maxmaxval
 
static png_uint_16 bgr
 
static png_uint_16 bgg
 
static png_uint_16 bgb
 
static int verbose = 0
 
static enum alpha_handling alpha = none
 
static int background = -1
 
static char * backstring
 
static float displaygamma = -1.0
 
static float totalgamma = -1.0
 
static int text = 0
 
static char * text_file
 
static int mtime = 0
 
static jmpbuf_wrapper pngtopnm_jmpbuf_struct
 

Macro Definition Documentation

◆ _

#define _ (   args)    ()

Definition at line 101 of file png22pnm.c.

◆ ___

#define ___ (   arg2s,
  arg1s,
  argafter 
)    arg1s argafter

Definition at line 105 of file png22pnm.c.

◆ DUMMY

#define DUMMY
Value:
set -ex; \
gcc -O2 -ansi -pedantic -W -Wall -Wshadow -Winline -Wstrict-prototypes \
png22pnm.c -o png22pnm -lpng; \
exit 0
char pedantic
Definition: afm2tfm.c:233
#define W
Definition: dtl.h:141

Definition at line 1 of file png22pnm.c.

◆ FALSE

#define FALSE   0

Definition at line 84 of file png22pnm.c.

◆ get_png_val

#define get_png_val (   p)    _get_png_val (&(p), info_ptr->bit_depth)

Definition at line 415 of file png22pnm.c.

◆ INFO_VAR_GAMMA

#define INFO_VAR_GAMMA   colorspace.gamma

Definition at line 50 of file png22pnm.c.

◆ NONE

#define NONE   0

Definition at line 87 of file png22pnm.c.

◆ PBM_TYPE

#define PBM_TYPE   1

Definition at line 111 of file png22pnm.c.

◆ PBMPLUS_RAWBITS

#define PBMPLUS_RAWBITS   1

Definition at line 62 of file png22pnm.c.

◆ PGM_OVERALLMAXVAL

#define PGM_OVERALLMAXVAL   65535

Definition at line 63 of file png22pnm.c.

◆ PGM_TYPE

#define PGM_TYPE   2

Definition at line 112 of file png22pnm.c.

◆ pm_close

#define pm_close (   file)    fflush(file)

Definition at line 120 of file png22pnm.c.

◆ pm_closer

#define pm_closer   pm_close

Definition at line 76 of file png22pnm.c.

◆ pm_closew

#define pm_closew   pm_close

Definition at line 77 of file png22pnm.c.

◆ pm_errexit

#define pm_errexit ( )    exit(3)

Definition at line 119 of file png22pnm.c.

◆ pm_error

#define pm_error   printf /* !! exit */

Definition at line 118 of file png22pnm.c.

◆ pm_freerow

#define pm_freerow (   x)    free(x)

Definition at line 144 of file png22pnm.c.

◆ pm_keymatch

#define pm_keymatch (   stra,
  strb,
  _x 
)    (0==strcmp((stra),(strb)))

Definition at line 121 of file png22pnm.c.

◆ pm_message

#define pm_message   printf

Definition at line 116 of file png22pnm.c.

◆ PME

#define PME (   immed_str)    stderr, "error: " immed_str "\n"

Definition at line 117 of file png22pnm.c.

◆ PMM

#define PMM (   immed_str)    stderr, "notice: " immed_str "\n"

Definition at line 115 of file png22pnm.c.

◆ pnm_allocrow

#define pnm_allocrow (   cols)    ((xel*) pm_allocrow( cols, sizeof(xel) ))

Definition at line 136 of file png22pnm.c.

◆ PNM_ASSIGN1

#define PNM_ASSIGN1 (   x,
  v 
)    PPM_ASSIGN(x,0,0,v)

Definition at line 137 of file png22pnm.c.

◆ pnm_freerow

#define pnm_freerow (   xelrow)    pm_freerow( (char*) xelrow )

Definition at line 143 of file png22pnm.c.

◆ PNM_GET1

#define PNM_GET1 (   x)    PPM_GETB(x)

Definition at line 138 of file png22pnm.c.

◆ pnm_init

#define pnm_init (   _a,
  _b 
)

Definition at line 114 of file png22pnm.c.

◆ PPM_ASSIGN

#define PPM_ASSIGN (   p,
  red,
  grn,
  blu 
)    (p) = ((pixel) (red) << 20) | ((pixel) (grn) << 10) | (pixel) (blu)

Definition at line 132 of file png22pnm.c.

◆ PPM_EQUAL

#define PPM_EQUAL (   p,
  q 
)    ((p) == (q))

Definition at line 133 of file png22pnm.c.

◆ PPM_GETB

#define PPM_GETB (   p)    ((p) & 0x3ff)

Definition at line 126 of file png22pnm.c.

◆ PPM_GETG

#define PPM_GETG (   p)    (((p) & 0xffc00) >> 10)

Definition at line 125 of file png22pnm.c.

◆ PPM_GETR

#define PPM_GETR (   p)    (((p) & 0x3ff00000) >> 20)

Definition at line 124 of file png22pnm.c.

◆ PPM_MAXMAXVAL

#define PPM_MAXMAXVAL   1023

Definition at line 122 of file png22pnm.c.

◆ PPM_OVERALLMAXVAL

#define PPM_OVERALLMAXVAL   PGM_OVERALLMAXVAL

Definition at line 64 of file png22pnm.c.

◆ PPM_PUTB

#define PPM_PUTB (   p,
  blu 
)    ((p) |= ( (blu) & 0x3ff))

Definition at line 130 of file png22pnm.c.

◆ PPM_PUTG

#define PPM_PUTG (   p,
  grn 
)    ((p) |= (((grn) & 0x3ff) << 10))

Definition at line 129 of file png22pnm.c.

◆ PPM_PUTR

#define PPM_PUTR (   p,
  red 
)    ((p) |= (((red) & 0x3ff) << 20))

Definition at line 128 of file png22pnm.c.

◆ PPM_TYPE

#define PPM_TYPE   3

Definition at line 113 of file png22pnm.c.

◆ SIG_CHECK_SIZE

#define SIG_CHECK_SIZE   4

Definition at line 570 of file png22pnm.c.

◆ TRUE

#define TRUE   1

Definition at line 81 of file png22pnm.c.

◆ u_char

#define u_char   unsigned char

Definition at line 107 of file png22pnm.c.

◆ VERSION

#define VERSION   "0.11"

Definition at line 58 of file png22pnm.c.

Typedef Documentation

◆ dimen_t

typedef unsigned dimen_t

Definition at line 108 of file png22pnm.c.

◆ jmpbuf_wrapper

◆ pixel

typedef unsigned long pixel

Definition at line 123 of file png22pnm.c.

◆ pixval

typedef unsigned pixval

Definition at line 110 of file png22pnm.c.

◆ xel

typedef pixel xel

Definition at line 139 of file png22pnm.c.

◆ xelval

typedef pixval xelval

Definition at line 140 of file png22pnm.c.

Enumeration Type Documentation

◆ alpha_handling

Enumerator
none 
alpha_only 
mix 
none 
alpha_only 
mix_only 
none_and_alpha 

Definition at line 399 of file png22pnm.c.

Function Documentation

◆ _get_png_val()

static png_uint_16 _get_png_val ( png_byte **  pp,
int  bit_depth 
)
static

Definition at line 420 of file png22pnm.c.

References c, maxmaxval, and maxval.

◆ convertpng()

static void convertpng ( FILE ifp,
FILE tfp 
)
static

Definition at line 592 of file png22pnm.c.

References a, abort(), alpha, alpha_only, assert(), backcolor, background, backstring, bgb, bgg, bgr, bP, c, c2, col, cols, displaygamma, dup(), exit(), FALSE, fclose, fdopen(), fflush, FILE, file, fileno, format, fprintf, fread, free, fwrite(), gamma_correct(), get_png_val, grayrow, png_info::height, i, if, ifp, iscolor(), _jmpbuf_wrapper::jmpbuf, L, len, malloc, maxmaxval, maxval, mix_only, mtime, none, none_and_alpha, NULL, O_BINARY, p, pbm_allocrow, PBM_BLACK, pbm_freerow, PBM_TYPE, PBM_WHITE, pbm_writepbmrow(), pgm_allocrow, pgm_freerow, PGM_OVERALLMAXVAL, PGM_TYPE, pgm_writepgmrow(), pm_allocrow(), pm_closer, pm_error, pm_freerow, pm_message, PNG_COLOR_TYPE_GRAY, PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, PNG_COLOR_TYPE_RGB_ALPHA, png_create_info_struct(), png_create_read_struct(), png_destroy_read_struct(), PNG_INFO_bKGD, PNG_INFO_gAMA, PNG_INFO_pHYs, PNG_INFO_sBIT, PNG_INFO_tRNS, png_init_io(), PNG_INTERLACE, PNG_LIBPNG_VER_STRING, png_ptr, png_read_end(), png_read_image(), png_read_info(), png_set_gamma(), png_set_packing(), png_set_shift(), png_set_sig_bytes(), png_sig_cmp(), pngtopnm_error_handler(), pngtopnm_jmpbuf_struct, pnm_allocrow, PNM_FORMAT_TYPE, pnm_freerow, PNM_GET1, pnm_writepnmrow(), PPM_GETB, PPM_GETG, PPM_GETR, PPM_OVERALLMAXVAL, ppm_parsecolor(), PPM_TYPE, ppm_writeppmrow(), r, row, save_text(), setmode(), show_time(), SIG_CHECK_SIZE, sizeof(), check-libstdc++::so, sprintf, fc-lang::stdout, store_pixel(), strcpy(), totalgamma, TRUE, U, verbose, png_info::width, cordic::x, and y.

Referenced by main().

◆ gamma_correct()

static png_uint_16 gamma_correct ( png_uint_16  v,
float  g 
)
static

Definition at line 461 of file png22pnm.c.

References g, maxval, pow(), and v.

Referenced by convertpng().

◆ iscolor()

static int iscolor ( png_color  c)
static

Definition at line 476 of file png22pnm.c.

References c.

Referenced by convertpng().

◆ main()

◆ pm_allocrow()

static char* pm_allocrow ( int  cols,
int  size 
)
static

Definition at line 154 of file png22pnm.c.

References cols, exit(), fprintf, malloc, and size.

Referenced by convertpng().

◆ pm_openr()

static FILE* pm_openr ( char *  name)
static

Definition at line 166 of file png22pnm.c.

References exit(), f, FILE, fopen, fprintf, name, NULL, and strcmp().

Referenced by main().

◆ pm_openw()

static FILE* pm_openw ( char *  name)
static

Definition at line 186 of file png22pnm.c.

References exit(), f, FILE, fopen, fprintf, name, NULL, fc-lang::stdout, and strcmp().

Referenced by main().

◆ pm_usage()

static void pm_usage ( char  usage[],
FILE f 
)
static

Definition at line 149 of file png22pnm.c.

References exit(), f, fprintf, and usage.

Referenced by main().

◆ pngtopnm_error_handler()

static void pngtopnm_error_handler ( png_structp  png_ptr,
png_const_charp  msg 
)
static

Definition at line 540 of file png22pnm.c.

References exit(), fflush, fprintf, _jmpbuf_wrapper::jmpbuf, NULL, png_get_error_ptr(), and png_ptr.

Referenced by convertpng().

◆ ppm_parsecolor() [1/2]

static pixel ppm_parsecolor ( )
static

Referenced by convertpng().

◆ ppm_parsecolor() [2/2]

static pixel ppm_parsecolor ( char *  colorname,
pixval  maxval 
)
static

Definition at line 236 of file png22pnm.c.

References b, cp, exit(), g, i, int(), maxval, p, pm_error, PPM_ASSIGN, r, rgbnorm(), sscanf(), strlen(), and strncmp().

◆ rgbnorm()

static long rgbnorm ( long  rgb,
long  lmaxval,
int  n,
char *  colorname 
)
static

Definition at line 206 of file png22pnm.c.

References exit(), n, and pm_error.

Referenced by ppm_parsecolor().

◆ save_text()

static void save_text ( png_info info_ptr,
FILE tfp 
)
static

Definition at line 486 of file png22pnm.c.

References fprintf, i, j, k, putc, strlen(), and U.

Referenced by convertpng().

◆ show_time()

static void show_time ( png_info info_ptr)
static

Definition at line 521 of file png22pnm.c.

References month, pm_message, and PNG_INFO_tIME.

Referenced by convertpng().

◆ store_pixel()

static void store_pixel ( xel pix,
png_uint_16  r,
png_uint_16  g,
png_uint_16  b,
png_uint_16  a 
)
static

Definition at line 441 of file png22pnm.c.

References a, alpha, alpha_only, b, bgb, bgg, bgr, g, maxval, mix_only, pix, PNM_ASSIGN1, PPM_ASSIGN, and r.

Referenced by convertpng().

Variable Documentation

◆ alpha

enum alpha_handling alpha = none
static

Definition at line 404 of file png22pnm.c.

Referenced by convertpng(), main(), and store_pixel().

◆ background

int background = -1
static

Definition at line 406 of file png22pnm.c.

Referenced by convertpng(), and main().

◆ backstring

char* backstring
static

Definition at line 407 of file png22pnm.c.

Referenced by convertpng(), and main().

◆ bgb

png_uint_16 bgb
static

Definition at line 403 of file png22pnm.c.

Referenced by convertpng(), and store_pixel().

◆ bgg

png_uint_16 bgg
static

Definition at line 403 of file png22pnm.c.

Referenced by convertpng(), and store_pixel().

◆ bgr

png_uint_16 bgr
static

Definition at line 403 of file png22pnm.c.

Referenced by convertpng(), and store_pixel().

◆ displaygamma

float displaygamma = -1.0
static

Definition at line 408 of file png22pnm.c.

Referenced by convertpng(), and main().

◆ maxmaxval

png_uint_16 maxmaxval
static

Definition at line 402 of file png22pnm.c.

Referenced by _get_png_val(), and convertpng().

◆ maxval

png_uint_16 maxval
static

Definition at line 402 of file png22pnm.c.

Referenced by _get_png_val(), convertpng(), gamma_correct(), ppm_parsecolor(), and store_pixel().

◆ mtime

int mtime = 0
static

Definition at line 412 of file png22pnm.c.

Referenced by convertpng(), and main().

◆ pngtopnm_jmpbuf_struct

jmpbuf_wrapper pngtopnm_jmpbuf_struct
static

Definition at line 413 of file png22pnm.c.

Referenced by convertpng().

◆ text

int text = 0
static

Definition at line 410 of file png22pnm.c.

◆ text_file

char* text_file
static

Definition at line 411 of file png22pnm.c.

◆ totalgamma

float totalgamma = -1.0
static

Definition at line 409 of file png22pnm.c.

Referenced by convertpng().

◆ verbose

int verbose = 0
static

Definition at line 404 of file png22pnm.c.

Referenced by convertpng(), and main().