---
name: "user_write_data"
section: "3"
platform: "linux"
package: "libg2c-dev"
version: "2.1.0-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/decenc_png.c"
---

# user\_write\_data(3)

Decode/encode a PNG stream.

Part of [decenc\_png.c(3)](/decenc_png.c/3.md).

## NAME

decenc\_png.c - Decode/encode a PNG stream.

## SYNOPSIS

`#include 'grib2_int.h'`\
 `#include <png.h>`\
 `#include <stdio.h>`\
 `#include <stdlib.h>`\
 `#include <string.h>`\

### Typedefs

typedef struct png\_stream **png\_stream**\
 Typedef for PNG stream.

### Functions

int **dec\_png** (unsigned char \*pngbuf, **g2int** \*width, **g2int** \*height, unsigned char \*cout)\
 Decode PNG.  int **enc\_png** (unsigned char \*data, **g2int** width, **g2int** height, **g2int** nbits, unsigned char \*pngbuf)\
 Encode PNG.  int **g2c\_dec\_png** (unsigned char \*pngbuf, int \*width, int \*height, unsigned char \*cout)\
 Decode PNG.  int **g2c\_enc\_png** (unsigned char \*data, int width, int height, int nbits, unsigned char \*pngbuf)\
 Encode PNG.  void **user\_flush\_data** (png\_structp png\_ptr)\
 Dummy Custom flush function.  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.  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.

## Detailed Description

Decode/encode a PNG stream.

**Author**

Alyson Stahl

**Date**

2024-13-08

Definition in file **decenc\_png.c**.

## Typedef Documentation

### typedef struct png\_stream png\_stream

Typedef for PNG stream.

Definition at line **21** of file **decenc\_png.c**.

## Function Documentation

### int dec\_png (unsigned char \* pngbuf, g2int \* width, g2int \* height, unsigned char \* cout)

Decode PNG.

**Parameters**

*pngbuf* Pointer to PNG buffer. \
 *width* Pointer to width. \
 *height* Pointer to height. \
 *cout* Output buffer.

**Returns**

0 for success, error code otherwise.

**Author**

Stephen Gilbert

Definition at line **127** of file **decenc\_png.c**.

References **G2C\_PNG\_HEIGHT\_MAX**, **G2C\_PNG\_WIDTH\_MAX**, and **user\_read\_data()**.

Referenced by **g2c\_dec\_png()**, and **pngunpack\_int()**.

### int enc\_png (unsigned char \* data, g2int width, g2int height, g2int nbits, unsigned char \* pngbuf)

Encode PNG.

**Parameters**

*data* data. \
 *width* width. \
 *height* height. \
 *nbits* number of bits. \
 *pngbuf* PNG buffer.

**Returns**

PNG length, or negative number for error.

**Author**

Stephen Gilbert

Definition at line **259** of file **decenc\_png.c**.

References **user\_flush\_data()**, and **user\_write\_data()**.

Referenced by **g2c\_enc\_png()**, and **pngpack\_int()**.

### int g2c\_dec\_png (unsigned char \* pngbuf, int \* width, int \* height, unsigned char \* cout)

Decode PNG.

**Parameters**

*pngbuf* Pointer to PNG buffer. \
 *width* Pointer to width. \
 *height* Pointer to height. \
 *cout* Output buffer.

**Returns**

0 for success, error code otherwise.

**Author**

Alyson Stahl

Definition at line **100** of file **decenc\_png.c**.

References **dec\_png()**.

### int g2c\_enc\_png (unsigned char \* data, int width, int height, int nbits, unsigned char \* pngbuf)

Encode PNG.

**Parameters**

*data* data. \
 *width* width. \
 *height* height. \
 *nbits* number of bits. \
 *pngbuf* PNG buffer.

**Returns**

PNG length, or negative number for error.

**Author**

Alyson Stahl

Definition at line **237** of file **decenc\_png.c**.

References **enc\_png()**.

### void user\_flush\_data (png\_structp png\_ptr)

Dummy Custom flush function.

**Parameters**

*png\_ptr* Pointer to PNG struct.

**Author**

Stephen Gilbert

Definition at line **83** of file **decenc\_png.c**.

Referenced by **enc\_png()**.

### 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.

**Parameters**

*png\_ptr* Pointer to PNG. \
 *data* Pointer to data. \
 *length* Length.

**Author**

Stephen Gilbert

Definition at line **38** of file **decenc\_png.c**.

Referenced by **dec\_png()**.

### 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.

**Parameters**

*png\_ptr* pointer \
 *data* data \
 *length* length

**Author**

Stephen Gilbert

Definition at line **62** of file **decenc\_png.c**.

Referenced by **enc\_png()**.

## Author

Generated automatically by Doxygen for NCEPLIBS-g2c from the source code.
