Skip to content

Commit

Permalink
Merge branch 'develop' into ejh_try_2
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett authored Nov 6, 2024
2 parents f08514d + c8122bd commit ecd4c9a
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 1 deletion.
1 change: 1 addition & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class G2c(CMakePackage):
maintainers("AlexanderRichert-NOAA", "Hang-Lei-NOAA", "edwardhartnett")

version("develop", branch="develop")
version("2.0.0", sha256="39c23bf1219c60101548c8525e3a879c84119558f768081779d404a8caf4cec9")
version("1.9.0", sha256="5554276e18bdcddf387a08c2dd23f9da310c6598905df6a2a244516c22ded9aa")
version("1.8.0", sha256="4ce9f5a7cb0950699fe08ebc5a463ab4d09ef550c050391a319308a2494f971f")
version("1.7.0", sha256="73afba9da382fed73ed8692d77fa037bb313280879cd4012a5e5697dccf55175")
Expand Down
72 changes: 72 additions & 0 deletions src/decenc_openjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,33 @@ opj_stream_create_default_memory_stream(opj_memory_stream *memoryStream, OPJ_BOO
return stream;
}

/**
* This Function decodes a JPEG2000 code stream specified in the
* JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using OpenJPEG.
*
* PROGRAM HISTORY LOG:
* - 2002-12-02 Gilbert
* - 2016-06-08 Jovic
*
* @param injpc Input JPEG2000 code stream.
* @param bufsize Length (in bytes) of the input JPEG2000 code stream.
* @param outfld Output matrix of grayscale image values.
*
* @return
* - 0 Successful decode
* - -3 Error decode jpeg2000 code stream.
* - -5 decoded image had multiple color components. Only grayscale is expected.
*
* @note Requires OpenJPEG Version 2.
*
* @author Alyson Stahl
*/
int
g2c_dec_jpeg2000(char *injpc, size_t bufsize, int *outfld)
{
return dec_jpeg2000(injpc, bufsize, (g2int *)outfld);
}

/**
* This Function decodes a JPEG2000 code stream specified in the
* JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using OpenJPEG.
Expand Down Expand Up @@ -342,6 +369,51 @@ dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld)
return iret;
}

/**
* This Function encodes a grayscale image into a JPEG2000 code stream
* specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1)
* using OpenJPEG library.
*
* PROGRAM HISTORY LOG:
* - 2002-12-02 Gilbert
* - 2016-06-08 Jovic
*
* @param cin Packed matrix of Grayscale image values to encode.
* @param width width of image
* @param height height of image
* @param nbits depth (in bits) of image.i.e number of bits used to
* hold each data value
* @param ltype indicator of lossless or lossy compression = 1, for
* lossy compression != 1, for lossless compression.
* @param ratio target compression ratio. (ratio:1) Used only when
* ltype == 1.
* @param retry Pointer to option type. 1 = try increasing number of
* guard bits otherwise, no additional options.
* @param outjpc Output encoded JPEG2000 code stream.
* @param jpclen Number of bytes allocated for new JPEG2000 code
* stream in outjpc.
*
* @return
* - > 0 Length in bytes of encoded JPEG2000 code stream
* - -3 Error decode jpeg2000 code stream.
* - -5 decoded image had multiple color components. Only grayscale is expected.
*
* @note Requires OpenJPEG Version 2.
*
* @author Alyson Stahl
*/
int
g2c_enc_jpeg2000(unsigned char *cin, int width, int height, int nbits,
int ltype, int ratio, int retry, char *outjpc,
size_t jpclen)
{
g2int width8 = width, height8 = height, nbits8 = nbits, ltype8 = ltype;
g2int ratio8 = ratio, retry8 = retry, jpclen8 = jpclen;

return enc_jpeg2000(cin, width8, height8, nbits8, ltype8, ratio8, retry8,
outjpc, jpclen8);
}

/**
* This Function encodes a grayscale image into a JPEG2000 code stream
* specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1)
Expand Down
41 changes: 41 additions & 0 deletions src/decenc_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ user_flush_data(png_structp png_ptr)
{
}

/**
* Decode PNG.
*
* @param pngbuf Pointer to PNG buffer.
* @param width Pointer to width.
* @param height Pointer to height.
* @param cout Output buffer.
*
* @return 0 for success, error code otherwise.
*
* @author Alyson Stahl
*/
int
g2c_dec_png(unsigned char *pngbuf, int *width, int *height,
unsigned char *cout)
{
return dec_png(pngbuf, (g2int *)&width, (g2int *)&height, cout);
}

/**
* Decode PNG.
*
Expand Down Expand Up @@ -190,6 +209,28 @@ dec_png(unsigned char *pngbuf, g2int *width, g2int *height,
return 0;
}

/**
* Encode PNG.
*
* @param data data.
* @param width width.
* @param height height.
* @param nbits number of bits.
* @param pngbuf PNG buffer.
*
* @return PNG length, or negative number for error.
*
* @author Alyson Stahl
*/
int
g2c_enc_png(unsigned char *data, int width, int height, int nbits,
unsigned char *pngbuf)
{
g2int width8 = width, height8 = height, nbits8 = nbits;

return enc_png(data, width8, height8, nbits8, pngbuf);
}

/**
* Encode PNG.
*
Expand Down
2 changes: 1 addition & 1 deletion src/g2ccsv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Ed Hartnett @date 8/25/22
*/

#include <grib2_int.h>
#include "grib2_int.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
11 changes: 11 additions & 0 deletions src/g2cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,17 @@ g2c_add_file(const char *path, int mode, int *g2cid)
}

/** Open an existing GRIB2 file.
*
* This function opens the GRIB2 file and reads its metadata.
*
* GRIB2 messages in the file are assigned a message ID, starting with
* 0 for the first message in the file.
*
* Each product within a message is assigned a product ID, starting
* with 0 for the first product in the message.
*
* Files opened with this function should be closed with a call
* g2c_close() to release resources.
*
* @param path Path of the file.
* @param mode Open mode flags.
Expand Down
12 changes: 12 additions & 0 deletions src/g2cindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@ read_hdr_rec2(FILE *f, int *skipp, int *total_lenp, int *num_recp,
/**
* Open a GRIB1 index file and read the contents.
*
* This function opens the GRIB2 index file and reads its metadata,
* and opens the accompanying GRIB2 file.
*
* GRIB2 messages in the file are assigned a message ID, starting with
* 0 for the first message in the file.
*
* Each product within a message is assigned a product ID, starting
* with 0 for the first product in the message.
*
* Files opened with this function should be closed with a call
* g2c_close() to release resources.
*
* @param index_file The name that will be given to the index file. An
* existing file will be overwritten.
*
Expand Down
4 changes: 4 additions & 0 deletions src/grib2.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ int g2c_enc_jpeg2000(unsigned char *cin, int width, int height, int nbits,
int ltype, int ratio, int retry, char *outjpc,
size_t jpclen);
int g2c_dec_jpeg2000(char *injpc, size_t bufsize, int *outfld);
int g2c_enc_png(unsigned char *data, int width, int height, int nbits,
unsigned char *pngbuf);
int g2c_dec_png(unsigned char *pngbuf, int *width, int *height,
unsigned char *cout);
int g2c_aecpackf(float *fld, size_t width, size_t height, int *idrstmpl,
unsigned char *cpack, size_t *lcpack);
int g2c_aecpackd(double *fld, size_t width, size_t height, int *idrstmpl,
Expand Down
28 changes: 28 additions & 0 deletions tests/tst_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ main()
return G2C_ERROR;
}
printf("ok!\n");
printf("Testing g2c_enc_png()/g2c_dec_png() calls...");
{
unsigned char data[4] = {1, 2, 3, 4};
int width = 1, height = 1, nbits = 32;
int width_in, height_in;
unsigned char pngbuf[200];
unsigned char cout[200];
int i, ret;

/* Encode some data. */
if ((ret = g2c_enc_png(data, width, height, nbits, pngbuf)) != 70)
{
printf("%d\n", ret);
return G2C_ERROR;
}

/* Now decode it. */
if ((ret = g2c_dec_png((unsigned char *)pngbuf, &width_in, &height_in, cout)))
{
printf("%d\n", ret);
return G2C_ERROR;
}

for (i = 0; i < 4; i++)
if (cout[i] != data[i])
return G2C_ERROR;
}
printf("ok!\n");
printf("Testing pngpack()/pngunpack() calls...");
{
g2int height = 2, width = 2, ndpts = DATA_LEN, len = PACKED_LEN;
Expand Down

0 comments on commit ecd4c9a

Please sign in to comment.