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

# pngpack.c(3)

Pack data with PNG compression.

## NAME

pngpack.c - Pack data with PNG compression.

## SYNOPSIS

`#include 'grib2_int.h'`\
 `#include <math.h>`\
 `#include <stdlib.h>`\

### Functions

int **g2c\_pngpackd** (double \*fld, size\_t width, size\_t height, int \*idrstmpl, unsigned char \*cpack, int \*lcpack)\
 This subroutine packs up a double data field into PNG image format.  int **g2c\_pngpackf** (float \*fld, size\_t width, size\_t height, int \*idrstmpl, unsigned char \*cpack, int \*lcpack)\
 This subroutine packs up a float data field into PNG image format.  void **pngpack** (float \*fld, **g2int** width, **g2int** height, **g2int** \*idrstmpl, unsigned char \*cpack, **g2int** \*lcpack)\
 This subroutine packs up a float data field into PNG image format.  static int **pngpack\_int** (void \*fld, int fld\_is\_double, **g2int** width, **g2int** height, **g2int** \*idrstmpl, unsigned char \*cpack, **g2int** \*lcpack, int verbose)\
 Packs float or double data into PNG image format.

## Detailed Description

Pack data with PNG compression.

**Author**

Stephen Gilbert

**Date**

2003-08-27

Definition in file **pngpack.c**.

## Function Documentation

### int g2c\_pngpackd (double \* fld, size\_t width, size\_t height, int \* idrstmpl, unsigned char \* cpack, int \* lcpack)

This subroutine packs up a double data field into PNG image format. After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a PNG encoder. It also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with the appropriate values.

**Parameters**

*fld* Pointer to array of double that contains the data values to pack. \
 *width* Number of points in the x direction. \
 *height* Number of points in the y direction. \
 *idrstmpl* Contains the array of values for Data Representation `Template 5.41` or 5.40010.

- •

  0 Reference value - ignored on input, set by pngpack routine.

- •

  1 Binary Scale Factor - used on input.

- •

  2 Decimal Scale Factor - used on input.

- •

  3 number of bits for each grayscale pixel value - ignored on input.

- •

  4 Original field type - currently ignored on input, set = 0 on output. Data values assumed to be reals.

*cpack* The packed data field. \
 *lcpack* length of packed field cpack.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2C\_EPNG** Error encoding/decoding PNG data.

**Author**

Ed Hartnett

**Date**

Aug 8, 2022

Definition at line **348** of file **pngpack.c**.

References **G2C\_PNG\_DRS\_TEMPLATE\_LEN**, and **pngpack\_int()**.

### int g2c\_pngpackf (float \* fld, size\_t width, size\_t height, int \* idrstmpl, unsigned char \* cpack, int \* lcpack)

This subroutine packs up a float data field into PNG image format. After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a PNG encoder. It also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with the appropriate values.

**Parameters**

*fld* Pointer to array of float that contains the data values to pack. \
 *width* Number of points in the x direction. \
 *height* Number of points in the y direction. \
 *idrstmpl* Contains the array of values for Data Representation `Template 5.41` or 5.40010.

- •

  0 Reference value - ignored on input, set by pngpack routine.

- •

  1 Binary Scale Factor - used on input.

- •

  2 Decimal Scale Factor - used on input.

- •

  3 number of bits for each grayscale pixel value - ignored on input.

- •

  4 Original field type - currently ignored on input, set = 0 on output. Data values assumed to be reals.

*cpack* The packed data field. \
 *lcpack* length of packed field cpack.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2C\_EPNG** Error encoding/decoding PNG data.

**Author**

Ed Hartnett

Definition at line **294** of file **pngpack.c**.

References **G2C\_PNG\_DRS\_TEMPLATE\_LEN**, and **pngpack\_int()**.

### void pngpack (float \* fld, g2int width, g2int height, g2int \* idrstmpl, unsigned char \* cpack, g2int \* lcpack)

This subroutine packs up a float data field into PNG image format. After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a PNG encoder. It also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with the appropriate values.

**Parameters**

*fld* Pointer to array of float that contains the data values to pack. \
 *width* Number of points in the x direction. \
 *height* Number of points in the y direction. \
 *idrstmpl* Contains the array of values for Data Representation `Template 5.41` or 5.40010.

- •

  0 Reference value - ignored on input, set by pngpack routine.

- •

  1 Binary Scale Factor - used on input.

- •

  2 Decimal Scale Factor - used on input.

- •

  3 number of bits for each grayscale pixel value - ignored on input.

- •

  4 Original field type - currently ignored on input, set = 0 on output. Data values assumed to be reals.

*cpack* The packed data field. \
 *lcpack* length of packed field cpack.

**Author**

Stephen Gilbert

**Date**

2003-08-27

**Author**

Ed Hartnett

Definition at line **254** of file **pngpack.c**.

References **pngpack\_int()**.

Referenced by **g2\_addfield()**.

### static int pngpack\_int (void \* fld, int fld\_is\_double, g2int width, g2int height, g2int \* idrstmpl, unsigned char \* cpack, g2int \* lcpack, int verbose)` [static]`

Packs float or double data into PNG image format. This is called by **pngpack()** and pngpackd().

After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a PNG encoder. It also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with the appropriate values.

**Parameters**

*fld* Pointer to array of float or double that contains the data values to pack. \
 *fld\_is\_double* If non-zero, then fld is double, otherwise float. \
 *width* Number of points in the x direction. This is passed to the PNG layer as a uint32. \
 *height* Number of points in the y direction. This is passed to the PNG layer as a uint32. \
 *idrstmpl* Contains the array of values for Data Representation `Template 5.41` or 5.40010.

- •

  0 Reference value - ignored on input, set by pngpack routine.

- •

  1 Binary Scale Factor - used on input.

- •

  2 Decimal Scale Factor - used on input.

- •

  3 number of bits for each grayscale pixel value - ignored on input.

- •

  4 Original field type - currently ignored on input, set = 0 on output. Data values assumed to be reals.

*cpack* The packed data field. \
 *lcpack* length of packed field cpack. \
 *verbose* If non-zero, error messages will be printed in case of error. Otherwise, error codes will be return but no error messages printed. Calls to the original g2c API may cause error messages to be printed in case of error. For the new g2c\_ API, no error messages will be printed - instead an error code will be returned. Call **g2c\_strerror()** to get the error message for any error code.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2C\_EPNG** Error encoding/decoding PNG data.

**Author**

Ed Hartnett

**Date**

Aug 8, 2022

Definition at line **53** of file **pngpack.c**.

References **ALOG2**, **enc\_png()**, **G2C\_EPNG**, **G2C\_NOERROR**, **int\_power()**, **LOG**, **mkieee()**, and **sbits()**.

Referenced by **g2c\_pngpackd()**, **g2c\_pngpackf()**, and **pngpack()**.

## Author

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