Skip to content

Commit

Permalink
Merge pull request NOAA-EMC#252 from NOAA-EMC/png_wne
Browse files Browse the repository at this point in the history
png with large grids, add tests
  • Loading branch information
AlysonStahl-NOAA authored Sep 30, 2024
2 parents 10c9737 + 756c293 commit cb9fcf7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ option(USE_NETCDF "Use NetCDF" on)
option(USE_REGEX "Use Regex?" on)
option(USE_TIGGE "Use tigge?" on)
option(USE_MYSQL "Use MySQL?" off)
option(USE_IPOLATES "Use Ipolates" on)
option(USE_IPOLATES "Use Ipolates" off)
option(USE_UDF "Use UDF?" off)
option(USE_OPENMP "Use OpenMP?" on)
option(USE_PROJ4 "Use Proj4?" off)
Expand Down
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,18 @@ copy_test_data(ref_sec_len.gdaswave.t00z.wcoast.0p16.f000.grib2.txt)
copy_test_data(ref_sec_len.simple_packing.grib2.txt)
copy_test_data(ref_simple_packing.grib2.spread.txt)
copy_test_data(ref_new_grid_gdt_32769.grib2)
copy_test_data(png_4bits.png)
copy_test_data(large_png.grb2)


# Run these shell tests.
shell_test(run_wgrib2_tests)
shell_test(run_wgrib2_rpn_tests)

if (USE_PNG)
shell_test(run_wgrib2_png_tests)
endif()

if (USE_NETCDF)
shell_test(run_wgrib2_netcdf4_tests)
shell_test(run_wgrib2_netcdf3_tests)
Expand Down
Binary file added tests/data/large_png.grb2
Binary file not shown.
Binary file added tests/data/png_4bits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions tests/run_wgrib2_png_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
# This script runs a series of tests using the RPN calculator
#
# Alyson Stahl 5/7/2024

set -e
echo ""
echo "*** Running wgrib2 png tests"



r1="1:0:(2000,1000),lon=304.937500,lat=-27.584172,val=1"
r2=`../wgrib2/wgrib2 data/png_4bits.png -ijlat 2000 1000`
if [ "$r1" != "$r2" ] ; then
echo "failed png test1 $r2"
echo "expected $r1"
exit 1
fi

r1="1:0:(2000,2000),lon=249.995002,lat=39.995000,val=0"
r2=`../wgrib2/wgrib2 data/large_png.grb2 -ijlat 2000 2000`
if [ "$r1" != "$r2" ] ; then
echo "failed png test2 $r2"
echo "expected $r1"
exit 1
fi

echo "*** SUCCESS!"
exit 0
4 changes: 3 additions & 1 deletion wgrib2/dec_png_clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ int dec_png_clone(unsigned char *pngbuf,int *width,int *height, unsigned char *c
png_set_read_fn(png_ptr,(png_voidp)&read_io_ptr,(png_rw_ptr)user_read_data_clone);
/* png_init_io(png_ptr, fptr); */

/* Read and decode PNG stream */
/* support for larger grids */
png_set_user_limits(png_ptr, PNG_WIDTH_MAX, PNG_HEIGHT_MAX);

/* Read and decode PNG stream */
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);

/* Get pointer to each row of image data */
Expand Down
4 changes: 4 additions & 0 deletions wgrib2/wgrib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#endif
#endif

/* parameters to PNG encode routine */
#define PNG_WIDTH_MAX 100000000
#define PNG_HEIGHT_MAX 100000


/* 1/2007 M. Schwarb unsigned int ndata */

Expand Down

0 comments on commit cb9fcf7

Please sign in to comment.