Skip to content

Commit

Permalink
fix g2c_dec_png and make png grid size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
AlysonStahl-NOAA committed Nov 19, 2024
1 parent e58fa60 commit d1083cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ if(USE_PNG)
find_package(ZLIB REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(PNG REQUIRED)
set(PNG_WIDTH_MAX 100000000 CACHE STRING "Default width of PNG grid.")
set(PNG_HEIGHT_MAX 100000 CACHE STRING "Default height of PNG grid.")
message(STATUS "\tWill build with PNG grid width = ${PNG_WIDTH_MAX} and height = ${PNG_HEIGHT_MAX}")
else()
message(STATUS "Will not build PNG support")
endif()
Expand Down
13 changes: 12 additions & 1 deletion src/decenc_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ int
g2c_dec_png(unsigned char *pngbuf, int *width, int *height,
unsigned char *cout)
{
return dec_png(pngbuf, (g2int *)&width, (g2int *)&height, cout);
g2int width8 = *width, height8 = *height;
int ret;

ret = dec_png(pngbuf, (g2int *)&width, (g2int *)&height, cout);

*width = (g2int)width8;
*height = (g2int)height8;

return ret;
}

/**
Expand Down Expand Up @@ -165,6 +173,9 @@ dec_png(unsigned char *pngbuf, g2int *width, g2int *height,
/* Read and decode PNG stream. */
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);

/* support for larger grids */
png_set_user_limits(png_ptr, G2C_PNG_WIDTH_MAX, G2C_PNG_HEIGHT_MAX);

/* Get pointer to each row of image data. */
row_pointers = png_get_rows(png_ptr, info_ptr);

Expand Down
2 changes: 2 additions & 0 deletions src/grib2.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ int g2c_param_all(int param_idx, int *g1ver, int *g1val, int *g2disc, int *g2cat

#define G2C_JASPER_MAX_MEM @JASPER_MAX_MEM@ /**< Maximum size for the Jasper memory buffer. */

#define G2C_PNG_WIDTH_MAX @PNG_WIDTH_MAX@ /**< Maximum width of PNG grid */
#define G2C_PNG_HEIGHT_MAX @PNG_HEIGHT_MAX@ /**< Maximum height of PNG grid */
/* Error codes for G2 API. */
#define G2_NO_ERROR 0 /**< Function succeeded. */
#define G2_CREATE_GRIB_VERSION -1 /**< Wrong GRIB version for g2_create(), must be 2. */
Expand Down

0 comments on commit d1083cf

Please sign in to comment.