NCEPLIBS-g2c  1.7.0
jpcpack.c File Reference

Pack up a data field into a JPEG2000 code stream. More...

#include <stdlib.h>
#include <math.h>
#include "grib2_int.h"

Go to the source code of this file.

Functions

void jpcpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
 This subroutine packs up a data field into a JPEG2000 code stream. More...
 
static void jpcpack_int (void *fld, int fld_is_double, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
 This subroutine packs up a float or double array into a JPEG2000 code stream. More...
 
void jpcpackd (double *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
 This subroutine packs up a data field into a JPEG2000 code stream. More...
 

Detailed Description

Pack up a data field into a JPEG2000 code stream.

Author
Stephen Gilbert
Date
2003-08-17

Program History Log

Date Programmer Comments
2003-08-17 Gilbert Initial.
2004-11-92 Gilbert Fixed bug packing a near constant field.
2004-07-19 Gilbert If jpeg2000 encoding fails, try again with different encoder options.
2005-05-10 Gilbert Imposed minimum size on cpack.
2022-08-12 Hartnett Now handle doubles too.

Definition in file jpcpack.c.

Function Documentation

◆ jpcpack()

void jpcpack ( float *  fld,
g2int  width,
g2int  height,
g2int idrstmpl,
unsigned char *  cpack,
g2int lcpack 
)

This subroutine packs up a data field into a JPEG2000 code stream.

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

Parameters
fldPointer to the float or double data values to pack.
widthThe number of points in the x direction.
heightThe number of points in the y direction.
idrstmplContains the array of values for Data Representation Template Table 5.40 or 5.40000.
  • 0 Reference value - ignored on input, set by jpcpack routine.
  • 1 Binary Scale Factor - used on input, unchanged by jpcpack routine.
  • 2 Decimal Scale Factor - used on input, unchanged by jpcpack routine.
  • 3 number of bits for each data value - ignored on input
  • 4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.
  • 5 if 0 use lossless compression, if 1 use lossy compression.
  • 6 Desired compression ratio, if idrstmpl[5]=1. Set to 255, if idrstmpl[5]=0.
cpackA pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter.
lcpackPointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.
Author
Stephen Gilbert, Ed Hartnett

Definition at line 253 of file jpcpack.c.

References jpcpack_int().

Referenced by g2_addfield().

◆ jpcpack_int()

static void jpcpack_int ( void *  fld,
int  fld_is_double,
g2int  width,
g2int  height,
g2int idrstmpl,
unsigned char *  cpack,
g2int lcpack 
)
static

This subroutine packs up a float or double array into a JPEG2000 code stream.

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

Parameters
fldPointer to the float or double data values to pack.
fld_is_doubleIf non-zero, then fld points to array of doubles, otherwise an array of floats.
widthThe number of points in the x direction.
heightThe number of points in the y direction.
idrstmplContains the array of values for Data Representation Template Table 5.40 or 5.40000.
  • 0 Reference value - ignored on input, set by jpcpack routine.
  • 1 Binary Scale Factor - used on input, unchanged by jpcpack routine.
  • 2 Decimal Scale Factor - used on input, unchanged by jpcpack routine.
  • 3 number of bits for each data value - ignored on input
  • 4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.
  • 5 if 0 use lossless compression, if 1 use lossy compression.
  • 6 Desired compression ratio, if idrstmpl[5]=1. Set to 255, if idrstmpl[5]=0.
cpackA pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter.
lcpackPointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.
Returns
N/A
Author
Stephen Gilbert, Ed Hartnett

Definition at line 57 of file jpcpack.c.

References ALOG2, enc_jpeg2000(), int_power(), LOG, mkieee(), and sbits().

Referenced by jpcpack(), and jpcpackd().

◆ jpcpackd()

void jpcpackd ( double *  fld,
g2int  width,
g2int  height,
g2int idrstmpl,
unsigned char *  cpack,
g2int lcpack 
)

This subroutine packs up a data field into a JPEG2000 code stream.

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

Parameters
fldPointer to the float or double data values to pack.
widthThe number of points in the x direction.
heightThe number of points in the y direction.
idrstmplContains the array of values for Data Representation Template Table 5.40 or 5.40000.
  • 0 Reference value - ignored on input, set by jpcpack routine.
  • 1 Binary Scale Factor - used on input, unchanged by jpcpack routine.
  • 2 Decimal Scale Factor - used on input, unchanged by jpcpack routine.
  • 3 number of bits for each data value - ignored on input
  • 4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.
  • 5 if 0 use lossless compression, if 1 use lossy compression.
  • 6 Desired compression ratio, if idrstmpl[5]=1. Set to 255, if idrstmpl[5]=0.
cpackA pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter.
lcpackPointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.
Author
Ed Hartnett

Definition at line 294 of file jpcpack.c.

References jpcpack_int().