Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use g2c for png decoding #293

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
export CFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0 -I/home/runner/work/wgrib2/wgrib2/nceplibs/NCEPLIBS-g2c/include'
export FCFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
export FFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
cmake .. -DENABLE_DOCS=ON -DFTP_TEST_FILES=ON -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-ip;$GITHUB_WORKSPACE/nceplibs/jasper;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-g2c" -DTEST_FILE_DIR=/home/runner/data -DMAKE_FTN_API=ON -DUSE_NETCDF4=ON -DUSE_AEC=ON -DUSE_IPOLATES=ON -DUSE_JASPER=ON
cmake .. -DENABLE_DOCS=ON -DFTP_TEST_FILES=ON -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-ip;$GITHUB_WORKSPACE/nceplibs/jasper;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-g2c" -DTEST_FILE_DIR=/home/runner/data -DMAKE_FTN_API=ON -DUSE_NETCDF4=ON -DUSE_AEC=ON -DUSE_IPOLATES=ON -DUSE_JASPER=ON -DUSE_PNG=ON
make VERBOSE=1
ctest --verbose --output-on-failure --rerun-failed
gcovr --root .. -v --html-details --exclude ../tests --exclude CMakeFiles --print-summary -o test-coverage.html &> /dev/null
Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ endif()

message(STATUS "Checking if the user wants to use PNG...")
if(USE_PNG)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
find_package(g2c 1.9.0 CONFIG REQUIRED)
endif()

# Find required packages to use AEC
Expand Down
9 changes: 5 additions & 4 deletions spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ def url_for_version(self, version):
depends_on("[email protected]:", when="@3.2: +aec")
depends_on("netcdf-c", when="@3.2: +netcdf4")
depends_on("jasper@:2", when="@3.2:3.4 +jasper")
depends_on("g2c", when="@develop +jasper")
depends_on("zlib-api", when="@3.2: +png")
depends_on("libpng", when="@3.2: +png")
depends_on("g2c@develop +jasper", when="@develop +jasper")
depends_on("zlib-api", when="@3.2:3.4 +png")
depends_on("libpng", when="@3.2:3.4 +png")
depends_on("g2c@develop +png", when="@develop +png")
depends_on("openjpeg", when="@3.2:3.4 +openjpeg")
depends_on("g2c +openjpeg", when="@develop +openjpeg")
depends_on("g2c@develop +openjpeg", when="@develop +openjpeg")

@when("@:2 ^[email protected]:")

Expand Down
13 changes: 4 additions & 9 deletions wgrib2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ Alias.c Ave_test.c Ave_var.c Bbox.c bitstream.c Box_ave.c
Check_pdt_size.c Checksum.c Cluster.c cname.c codetable_4_230.c
CodeTable.c Code_Values.c Code_Values_JMA.c complex_pk.c Config.c
copy.c crc32.c Cress_lola.c Csv.c Csv_long.c cubed_sphere2ll.c
CubeFace2global.c Cyclic.c Data.c dec_png_clone.c
Dump.c Earth.c Else.c End.c Endif.c Ensemble.c
Ens_processing.c Ens_qc.c EOF.c Export_lonlat.c ExtName.c
fatal_error.c Fcst_ave.c ffopen.c Fi.c File.c Fix_CFSv2_fcst.c
CubeFace2global.c Cyclic.c Data.c Dump.c Earth.c Else.c End.c
Endif.c Ensemble.c Ens_processing.c Ens_qc.c EOF.c Export_lonlat.c
ExtName.c fatal_error.c Fcst_ave.c ffopen.c Fi.c File.c Fix_CFSv2_fcst.c
Fix_ncep_2.c Fix_ncep_3.c Fix_ncep_4.c Fix_ncep.c Fix_undef.c
FlagTable.c flt2ieee.c flt2ieee_nan.c Flush.c fnlist.c For.c Ftime1.c
Ftime2.c Ftime.c Ftn_api.c gaussian2ij.c Gctpc.c gctpc_ll2xy.c GDT.c
Expand Down Expand Up @@ -108,10 +107,6 @@ if(USE_NETCDF)
target_link_libraries(wgrib2_exe PUBLIC NetCDF::NetCDF_C)
endif()

if(USE_PNG)
target_link_libraries(obj_lib PUBLIC PNG::PNG)
endif()

if(USE_OPENMP)
target_link_libraries(obj_lib PUBLIC OpenMP::OpenMP_C)
if(BUILD_SHARED_LIB)
Expand Down Expand Up @@ -143,7 +138,7 @@ if(USE_AEC)
target_link_libraries(wgrib2_exe PRIVATE ${LIBAEC_LIBRARIES})
endif()

if(USE_JASPER OR USE_OPENJPEG)
if(USE_JASPER OR USE_OPENJPEG OR USE_PNG)
target_link_libraries(obj_lib PUBLIC g2c::g2c)
target_link_libraries(wgrib2_exe PRIVATE g2c::g2c)
endif()
Expand Down
199 changes: 0 additions & 199 deletions wgrib2/dec_png_clone.c

This file was deleted.

7 changes: 3 additions & 4 deletions wgrib2/unpk.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#endif

#ifdef USE_PNG
#include <png.h>
int i;
#include "grib2.h"
#endif

#ifdef USE_AEC
Expand Down Expand Up @@ -47,7 +46,7 @@ int unpk_grib(unsigned char **sec, float *data) {
double bin_scale, dec_scale, b;

#ifdef USE_PNG
int width, height;
int i, width, height;
#endif

#if (defined USE_JASPER || defined USE_OPENJPEG)
Expand Down Expand Up @@ -251,7 +250,7 @@ int unpk_grib(unsigned char **sec, float *data) {
if ((c = (unsigned char *) malloc(4*sizeof(char) * (size_t) ndata)) == NULL)
fatal_error("unpk: png decode allocation error", "");

i = (int) dec_png_clone(sec[7]+5, &width, &height, (unsigned char *) c, &nbits, ndata);
i = g2c_dec_png(sec[7]+5, &width, &height, (unsigned char *) c);
if (i) fatal_error_i("unpk: png decode error %d",i);
mask_pointer = (bitmap_flag == 255) ? NULL : sec[6] + 6;

Expand Down
2 changes: 1 addition & 1 deletion wgrib2/wgrib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ int wrt_sec(unsigned const char *sec0, unsigned const char *sec1, unsigned const
int scaling(unsigned char **sec, double *base, int *decimal, int *binary, int *nbits);
unsigned char *mk_bms(float *data, unsigned int *ndata);

int dec_png_clone(unsigned char *pngbuf,int *width,int *height, unsigned char *cout, int *grib2_bit_depth, unsigned int ndata);
int g2c_dec_png(unsigned char *pngbuf, int *width, int *height, unsigned char *cout);
int ieee_grib_out(unsigned char **sec, float *data, unsigned int ndata, struct seq_file *out);
int jpeg_grib_out(unsigned char **sec, float *data, unsigned int ndata,
int nx, int ny, int use_scale, int dec_scale, int bin_scale, FILE *out);
Expand Down
Loading