NCEPLIBS-g2  3.5.0
g2cpng.c File Reference

These functions read/write PNG stream to/from memory. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <png.h>

Go to the source code of this file.

Typedefs

typedef int g2int
 Integer type. More...
 
typedef struct png_stream png_stream
 location to write PNG stream More...
 

Functions

int dec_png (unsigned char *pngbuf, g2int *width, g2int *height, char *cout)
 Decode some PNG compressed data. More...
 
int enc_png (char *data, g2int *width, g2int *height, g2int *nbits, char *pngbuf)
 create png_structs to write png stream into memory. More...
 
static void user_flush_data (png_structp png_ptr)
 Dummy Custom flush function. More...
 
static void user_read_data (png_structp png_ptr, png_bytep data, png_uint_32 length)
 Custom read function used so that libpng will read a PNG stream from memory instead of a file on disk. More...
 
static void user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length)
 Custom write function used to that libpng will write to memory location instead of a file on disk. More...
 

Detailed Description

These functions read/write PNG stream to/from memory.

Author
Ed Hartnett
Date
3/5/24

Definition in file g2cpng.c.

Typedef Documentation

◆ g2int

typedef int g2int

Integer type.

Definition at line 12 of file g2cpng.c.

◆ png_stream

typedef struct png_stream png_stream

location to write PNG stream

Definition at line 12 of file g2cpng.c.

Function Documentation

◆ dec_png()

int dec_png ( unsigned char *  pngbuf,
g2int width,
g2int height,
char *  cout 
)

Decode some PNG compressed data.

Parameters
pngbufPointer to the PNG buffer to be uncompressed.
widthPointer to the width.
heightPointer to the height.
coutPointer that gets the unpacked data.
Returns
  • 0 Success
  • -1 Error initializing PNG structs.
  • -2 Error initializing PNG info struct.
  • -3 Error initializing PNG error callbacks, or stream not valid PNG.
Author
Stephen Gilbert

Definition at line 188 of file g2cpng.c.

References drstemplates::j, and user_read_data().

Referenced by pngunpack().

◆ enc_png()

int enc_png ( char *  data,
g2int width,
g2int height,
g2int nbits,
char *  pngbuf 
)

create png_structs to write png stream into memory.

Parameters
datadata.
widthwidth.
heightheight.
nbitsnumber of bits.
pngbufPNG buffer.
Returns
pnglen the length of png stream
Author
Stephen Gilbert

Definition at line 74 of file g2cpng.c.

References drstemplates::j, user_flush_data(), and user_write_data().

Referenced by pngpack().

◆ user_flush_data()

static void user_flush_data ( png_structp  png_ptr)
static

Dummy Custom flush function.

Parameters
png_ptrPointer to PNG struct.
Author
Stephen Gilbert

Definition at line 57 of file g2cpng.c.

Referenced by enc_png().

◆ user_read_data()

static void user_read_data ( png_structp  png_ptr,
png_bytep  data,
png_uint_32  length 
)
static

Custom read function used so that libpng will read a PNG stream from memory instead of a file on disk.

Parameters
png_ptrPointer to PNG.
dataPointer to data.
lengthLength.
Author
Stephen Gilbert

Definition at line 158 of file g2cpng.c.

Referenced by dec_png().

◆ user_write_data()

static void user_write_data ( png_structp  png_ptr,
png_bytep  data,
png_uint_32  length 
)
static

Custom write function used to that libpng will write to memory location instead of a file on disk.

Parameters
png_ptrpointer
datadata
lengthlength
Author
Stephen Gilbert

Definition at line 35 of file g2cpng.c.

Referenced by enc_png().