Skip to content

Commit

Permalink
0.20210414: FreeImage: fix ImthresholdGenericLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Apr 15, 2021
1 parent 388a1f9 commit 2121c59
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

----------------------------------------------------------------

0.20210414

FreeImage: fix ImthresholdGenericLoader

0.20210325

Stable: the smooth mesh is replaced by Newtonian iterations.
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ PNAME = geoconformimage
PROGNAME = $(PNAME)
CC = gcc
CPP = g++
CFLAGS = -DUNIX -O2 -Wall -s
LIBS = -lfreeimage
CFLAGS = -Isrc -DUNIX -O2 -Wall -s
VER = 0
VERB = 20210325
VERB = 20210414
ifeq ($(OS),Windows_NT)
LIBS = FreeImage.lib
PLIBF = $(PNAME).$(VER).dll
PLIBFI = $(PNAME)freeimage.$(VER).dll
RM = del /Q
else
LIBS = -lfreeimage
PLIBF = lib$(PNAME).so.$(VER)
PLIBFI = lib$(PNAME)freeimage.so.$(VER)
RM = rm -f
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20210325
0.20210414
50 changes: 30 additions & 20 deletions src/geoconformfreeimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@

////////////////////////////////////////////////////////////////////////////////

int filecheck(const char *filename)
{
FILE *file;

if ((file = fopen(filename, "r")) != NULL)
fclose(file);
else
return 0;
return 1;
}

////////////////////////////////////////////////////////////////////////////////

BYTE ImthresholdGet1BitPixel(BYTE *bits, unsigned x)
{
return (bits[x >> 3] & (0x80 >> (x & 0x07))) != 0 ? 1 : 0;
Expand Down Expand Up @@ -214,32 +227,29 @@ FIBITMAP* ImthresholdGenericLoader(const char* lpszPathName, int flag)
// check the file signature and deduce its format
// (the second argument is currently not used by FreeImage)

fif = FreeImage_GetFileType(lpszPathName, 0);

FIBITMAP* dib;

if(fif == FIF_UNKNOWN)
if (filecheck(lpszPathName))
{
// no signature ?
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName);
}
fif = FreeImage_GetFileType(lpszPathName, 0);

// check that the plugin has reading capabilities ...
if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif))
{
// ok, let's load the file
dib = FreeImage_Load(fif, lpszPathName, flag);
FIBITMAP* dib;

if(fif == FIF_UNKNOWN)
fif = FreeImage_GetFIFFromFilename(lpszPathName);

// unless a bad file format, we are done !
if (!dib)
if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif))
{
printf("%s%s%s\n","File \"", lpszPathName, "\" not found.");
return NULL;
dib = FreeImage_Load(fif, lpszPathName, flag);
if (dib)
return dib;
printf("%s%s%s\n","ERROR: File \"", lpszPathName, "\" not read.");
}
}
else
printf("%s%s%s\n","ERROR: File \"", lpszPathName, "\" unknow format.");

return dib;
}
else
printf("%s%s%s\n","ERROR: File \"", lpszPathName, "\" not found.");
return NULL;
}

////////////////////////////////////////////////////////////////////////////////
21 changes: 10 additions & 11 deletions src/geoconformimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,20 @@ int main(int argc, char *argv[])
if (FreeImage_GetImageType(dib) == FIT_BITMAP)
{
FIBITMAP* dst_dib;
imgin.size.width = FreeImage_GetWidth(dib);
imgin.size.height = FreeImage_GetHeight(dib);
params.size1 = imgin.size;
IMTimage p_im = IMTalloc(imgin.size, 24);
p_im = ImthresholdGetData(dib, p_im);
params.size1.width = FreeImage_GetWidth(dib);
params.size1.height = FreeImage_GetHeight(dib);
imgin = IMTalloc(params.size1, 24);
imgin = ImthresholdGetData(dib, imgin);
FreeImage_Unload(dib);
params = GCIcalcallparams(params);
IMTimage d_im = IMTalloc(params.size2, 24);
imgout = IMTalloc(params.size2, 24);
printf("Result image size \"%dx%d\".\n", params.size2.width, params.size2.height);

IMTFilterGeoConform(p_im, d_im, params);
p_im = IMTfree(p_im);
dst_dib = FreeImage_Allocate(d_im.size.width, d_im.size.height, 24);
ImthresholdSetData(dst_dib, d_im);
d_im = IMTfree(d_im);
IMTFilterGeoConform(imgin, imgout, params);
imgin = IMTfree(imgin);
dst_dib = FreeImage_Allocate(imgout.size.width, imgout.size.height, 24);
ImthresholdSetData(dst_dib, imgout);
imgout = IMTfree(imgout);
printf("Result rect from \"(%f,%f)-(%f,%f)\" to \"(%f,%f)-(%f,%f)\".\n", params.rect1.min.x, params.rect1.min.y, params.rect1.max.x, params.rect1.max.y, params.rect2.min.x, params.rect2.min.y, params.rect2.max.x, params.rect2.max.y);

if (dst_dib)
Expand Down

0 comments on commit 2121c59

Please sign in to comment.