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

# decenc\_jpeg2000.c(3)

Decode/encode a JPEG2000 code stream.

## NAME

decenc\_jpeg2000.c - Decode/encode a JPEG2000 code stream.

## SYNOPSIS

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

### Macros

\#define **MAXOPTSSIZE**   1024\
 Maximum size of options.

### Functions

int **dec\_jpeg2000** (char \*injpc, **g2int** bufsize, **g2int** \*outfld)\
 Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.  int **enc\_jpeg2000** (unsigned char \*cin, **g2int** width, **g2int** height, **g2int** nbits, **g2int** ltype, **g2int** ratio, **g2int** retry, char \*outjpc, **g2int** jpclen)\
 Encode a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.  int **g2c\_dec\_jpeg2000** (char \*injpc, size\_t bufsize, int \*outfld)\
 Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.  int **g2c\_enc\_jpeg2000** (unsigned char \*cin, int width, int height, int nbits, int ltype, int ratio, int retry, char \*outjpc, size\_t jpclen)\
 Encode a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.  static int **int\_dec\_jpeg2000** (char \*injpc, **g2int** bufsize, void \*outfld, int out\_is\_g2int)\
 Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.

## Detailed Description

Decode/encode a JPEG2000 code stream.

**Author**

Alyson Stahl

**Date**

2024-14-08

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

## Macro Definition Documentation

### #define MAXOPTSSIZE 1024

Maximum size of options.

Definition at line **12** of file **decenc\_jpeg2000.c**.

## Function Documentation

### int dec\_jpeg2000 (char \* injpc, g2int bufsize, g2int \* outfld)

Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.

**Parameters**

*injpc* Pointer to buffer that holds the input JPEG2000 code stream. \
 *bufsize* Length (in bytes) of the buffer that holds the input JPEG2000 code stream. \
 *outfld* Pointer to g2int array, already allocated, that gets the unpacked data.

**Returns**

- •

  0 Successful decode

- •

  **G2\_JASPER\_DECODE** Error decode jpeg2000 code stream.

- •

  **G2\_JASPER\_DECODE\_COLOR** decoded image had multiple color components. Only grayscale is expected.

- •

  **G2\_JASPER\_INIT** Error inializing Jasper library.

**Author**

Stephen Gilbert, Ed Hartnett

Definition at line **377** of file **decenc\_jpeg2000.c**.

References **int\_dec\_jpeg2000()**.

Referenced by **jpcunpack\_int()**.

### int enc\_jpeg2000 (unsigned char \* cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char \* outjpc, g2int jpclen)

Encode a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.

- •

  \### Program History Log Date   Programmer   Comments    2002-12-02   Gilbert   Initial    2004-12-16   Gilbert   Added retry argument allowing increased guard bits.    2022-04-15   Hartnett   Converted to use jas\_ instead of jpc\_ functions.

**Parameters**

*cin* Packed matrix of Grayscale image values to encode. \
 *width* width of image. \
 *height* height of image. \
 *nbits* depth (in bits) of image. i.e number of bits used to hold each data value. \
 *ltype* indicator of lossless or lossy compression.

- •

  1, for lossy compression

- •

  != 1, for lossless compression

*ratio* target compression ratio. (ratio:1) Used only when ltype == 1. \
 *retry* If 1 try increasing number of guard bits. \
 *outjpc* Output encoded JPEG2000 code stream. \
 *jpclen* Number of bytes allocated for the output JPEG2000 code stream in outjpc.

**Returns**

- •

  \> 0 = Length in bytes of encoded JPEG2000 code stream

- •

  **G2\_JASPER\_INIT** Error initializing jasper library.

- •

  **G2\_JASPER\_ENCODE** Error encode jpeg2000 code stream.

**Note**

Requires JasPer Software version 1.500.4 or 1.700.2 or later.

**Author**

Stephen Gilbert

**Date**

2002-12-02

**Author**

Ed Hartnett

Definition at line **94** of file **decenc\_jpeg2000.c**.

References **G2\_JASPER\_ENCODE**, **G2\_JASPER\_INIT**, **G2C\_JASPER\_JPEG\_FORMAT\_NAME**, **LOG**, and **MAXOPTSSIZE**.

Referenced by **g2c\_enc\_jpeg2000()**, and **jpcpack\_int()**.

### int g2c\_dec\_jpeg2000 (char \* injpc, size\_t bufsize, int \* outfld)

Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.

**Parameters**

*injpc* Pointer to buffer that holds the input JPEG2000 code stream. \
 *bufsize* Length (in bytes) of the buffer that holds the input JPEG2000 code stream. \
 *outfld* Pointer to int array, already allocated, that gets the unpacked data.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2\_JASPER\_DECODE** Error decode jpeg2000 code stream.

- •

  **G2\_JASPER\_DECODE\_COLOR** decoded image had multiple color components. Only grayscale is expected.

- •

  **G2\_JASPER\_INIT** Error inializing Jasper library.

**Author**

Ed Hartnett

**Date**

9/7/22

Definition at line **350** of file **decenc\_jpeg2000.c**.

References **int\_dec\_jpeg2000()**.

### int g2c\_enc\_jpeg2000 (unsigned char \* cin, int width, int height, int nbits, int ltype, int ratio, int retry, char \* outjpc, size\_t jpclen)

Encode a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.

**Parameters**

*cin* Packed matrix of Grayscale image values to encode. \
 *width* width of image. \
 *height* height of image. \
 *nbits* depth (in bits) of image. i.e number of bits used to hold each data value. \
 *ltype* indicator of lossless or lossy compression.

- •

  1, for lossy compression

- •

  != 1, for lossless compression

*ratio* target compression ratio. (ratio:1) Used only when ltype == 1. \
 *retry* If 1 try increasing number of guard bits. \
 *outjpc* Output encoded JPEG2000 code stream. \
 *jpclen* Number of bytes allocated for the output JPEG2000 code stream in outjpc.

**Returns**

- •

  \> 0 = Length in bytes of encoded JPEG2000 code stream

- •

  **G2\_JASPER\_INIT** Error initializing jasper library.

- •

  **G2\_JASPER\_ENCODE** Error encode jpeg2000 code stream.

**Note**

Requires JasPer Software version 1.500.4 or 1.700.2 or later.

**Author**

Stephen Gilbert

**Date**

2002-12-02

**Author**

Ed Hartnett

Definition at line **45** of file **decenc\_jpeg2000.c**.

References **enc\_jpeg2000()**.

### static int int\_dec\_jpeg2000 (char \* injpc, g2int bufsize, void \* outfld, int out\_is\_g2int)` [static]`

Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using `JasPer Software`.

**Parameters**

*injpc* Pointer to buffer that holds the input JPEG2000 code stream. \
 *bufsize* Length (in bytes) of the buffer that holds the input JPEG2000 code stream. \
 *outfld* Pointer to either int or g2int array, already allocated, that gets the unpacked data. \
 *out\_is\_g2int* Non-zero if the output array is of type g2int (i.e. 64-bit ints), zero if output is an int array (32-bits).

**Returns**

- •

  0 Successful decode

- •

  **G2\_JASPER\_DECODE** Error decode jpeg2000 code stream.

- •

  **G2\_JASPER\_DECODE\_COLOR** decoded image had multiple color components. Only grayscale is expected.

- •

  **G2\_JASPER\_INIT** Error inializing Jasper library.

**Author**

Stephen Gilbert

**Date**

2002-12-02

**Author**

Ed Hartnett

Eric Engle

Definition at line **221** of file **decenc\_jpeg2000.c**.

References **G2\_JASPER\_DECODE**, **G2\_JASPER\_DECODE\_COLOR**, **G2\_JASPER\_INIT**, **G2C\_JASPER\_JPEG\_FORMAT\_NAME**, **G2C\_JASPER\_MAX\_MEM**, and **LOG**.

Referenced by **dec\_jpeg2000()**, and **g2c\_dec\_jpeg2000()**.

## Author

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