Closed sonoro1234 closed 4 years ago
May be I should set something similar to
#ifdef SYNTH_USE_GLIB_THREADS
static GMutex mutex;
#else
// Use POSIX instead
#include <pthread.h>
pthread_mutex_t mutex;
// proxies for glib mutex functions are in glibProxy.c, .h
#endif
around all GMutex declarations?
After some changes it builds but
[ 16%] Linking C shared module liblibresynth.dll
CMakeFiles\libresynth.dir/objects.a(engine.c.obj):engine.c:(.text+0x24a2): undefined reference to `initializeThreadedProgress
Record'
CMakeFiles\libresynth.dir/objects.a(engine.c.obj):engine.c:(.text+0x24e7): undefined reference to `deepProgressCallback'
which means that progress.c must be compiled. But if I also compile progress.c I am getting
In file included from C:\luaGL\gitsources\inpaint\resynthesizer-master\lib\progress.h:6:0,
from C:\luaGL\gitsources\inpaint\resynthesizer-master\lib\progress.c:16:
C:\luaGL\gitsources\inpaint\resynthesizer-master\lib\passes.h:52:9: error: unknown type name 'guint'
typedef guint TRepetionParameters[MAX_PASSES][2] ;
^~~~~
C:\luaGL\gitsources\inpaint\resynthesizer-master\lib\passes.h:54:8: error: unknown type name 'guint'
static guint
so it seems that guint should be replaced or typedefed to something I am not sure (int, long int,unsigned short)?
Ok. I managed to build library. Would you accept a PR?
Certainly I would like to look at your pull request, and merge it after I review it.
Thanks for taking time to work out the issues. I am sorry if my documentation says it can be compiled without glib, but it doesn't. All I can say is that at one time it would build without glib, but since then it seems I introduced changes that broke that aspect?
As I have said elsewhere, threading turned out NOT to speed up the algorithm much, so unless you need every last, small performance gain, you can build without threading. But it seems like you have already got past that.
Thanks for the pull request. I read through it, it looks fine but I will delay merging until I have time to test it.
To be clear, the library not only builds but does what you expect when your run it? That is, I want to know whether you have gotten as far as testing yet?
Also, I am curious why you want to eliminate glib?
Also, what is the general nature of your use? Only a few people have inquired about building the library separately. I have often thought about plugging the library into other applications (e.g. Krita) or into other libraries (e.g. OpenCL? or GEGL)
To be clear, the library not only builds but does what you expect when your run it? That is, I want to know whether you have gotten as far as testing yet?
It is giving a runtime error in adaptImage (any idea?) gdb says:
Program received signal SIGSEGV, Segmentation fault.
0x67041568 in adaptImage (image=image@entry=0x64e970, offset=offset@entry=1, pixelel_count=pixelel_count@entry=4,
pixmap=<optimized out>) at C:/luaGL/gitsources/inpaint/resynthesizer-master/lib/adaptSimple.h:90
90 image->data[srcPixel+pixelel]; // src data is array of uchar
(gdb) thread apply all bt
Thread 1 (Thread 4384.0xdf0):
#0 0x67041568 in adaptImage (image=image@entry=0x64e970, offset=offset@entry=1, pixelel_count=pixelel_count@entry=4,
pixmap=<optimized out>) at C:/luaGL/gitsources/inpaint/resynthesizer-master/lib/adaptSimple.h:90
#1 0x6704160e in adaptImageAndMask (image=image@entry=0x64e970, mask=mask@entry=0x650ae0,
imagePixmap=imagePixmap@entry=0x28fac0, maskPixmap=maskPixmap@entry=0x28fa20, pixelelPerPixel=pixelelPerPixel@entry=4)
at C:/luaGL/gitsources/inpaint/resynthesizer-master/lib/adaptSimple.h:241
#2 0x670416bb in adaptSimpleAPI (imageBuffer=imageBuffer@entry=0x64e970, maskBuffer=maskBuffer@entry=0x650ae0,
targetMap=targetMap@entry=0x28fab0, corpusMap=corpusMap@entry=0x28fac0, pixelelPerPixel=4)
at C:/luaGL/gitsources/inpaint/resynthesizer-master/lib/adaptSimple.h:290
#3 0x6704178f in imageSynth (imageBuffer=0x64e970, mask=0x650ae0, imageFormat=T_RGBA,
parameters=0x67049020 <defaultParameters.2655>, progressCallback=0x3f0000, contextInfo=0x0, cancelFlag=0x64ba10)
at C:\luaGL\gitsources\inpaint\resynthesizer-master\lib\imageSynth.c:92
Also, I am curious why you want to eliminate glib?
Because I dont know it and I want as few dependencies as possible
Also, what is the general nature of your use?
I want to use the library from an LuaJIT openGL framework https://github.com/sonoro1234/anima
I MIGHT be able to help with your code, if you get it to me. Is it in a public repository?
I notice you pass offset=1 and pixelel_count =4. Offset=1 ? usually pass 0. Pixelel_count =4? That says your image is RGBA, having an extra alpha byte.
It has been a long time since I looked at the code, and looking now, it is not as easy to understand, even for myself, as it should be. I can't remember whether I wrote a test harness to test the library alone. I remember the test harness used Gimp to feed images to the library WITHOUT going through the normal Gimp mechanisms, i.e. Gimp was just a way to create the pixmaps to be adapted to the library.
Please let me know how I can help (to a limited extent.)
I MIGHT be able to help with your code, if you get it to me. Is it in a public repository?
my code is simple Lua. It loads an image and a mask, fills ImageBuffer and calls imageSynth
local image = im.FileImageLoad[[C:\luaGL\frames_anima\inpaint\orginS.png]]
-- add alpha as it seems needed by resynthesizer
im.imffi.imImageAddAlpha(image)
local mask = im.FileImageLoad[[C:\luaGL\frames_anima\inpaint\orginSmask.png]]
local function progress(count,ctx)
print("progress",count)
end
local cancel = ffi.new"int[1]"
local imbuf = ffi.new"ImageBuffer"
imbuf.data = ffi.cast("unsigned char*",image.data)
imbuf.width = image.width
imbuf.height = image.height
imbuf.rowBytes = image.width*4
local mbuf = ffi.new"ImageBuffer"
mbuf.data = ffi.cast("unsigned char*",mask.data)
mbuf.width = mask.width
mbuf.height = mask.height
mbuf.rowBytes = mask.width
local err = lib.imageSynth(imbuf, mbuf, lib.T_RGBA, nil, progress, nil,cancel)
image:FileSave([[C:\luaGL\frames_anima\inpaint\inpaintedGIMP.png]],"PNG")
print"done"
I notice you pass offset=1 and pixelel_count =4. Offset=1 ? usually pass 0. Pixelel_count =4? That says your image is RGBA, having an extra alpha byte.
As you can see above I am not setting offset, it is setted by https://github.com/bootchk/resynthesizer/blob/master/lib/adaptSimple.h#L241
The image library http://webserver2.tecgraf.puc-rio.br/im/ has its data in unpacked format (rrr ggg bbb)
so I used imImageGetOpenGLData
to get packed format and the SIGSEV stopped happening (Althought I dont know why)
I am getting very different results compared to using Heal selection on GIMP.
Could be because I have v1.0 version for Windows? Is there another interface-api for using the library giving more options? Where is plug_in_resynthesizer parameters definition as used from python plugins?
My brief answer (I did not think about it too carefully, or look at the code, this is just from my memory) : the data needs to be RGBM, where M is a mask byte. In Gimp, it is called the "selection mask." It is a byte, which means every byte can have selection from None (255?) or Full (0?) or any degree of selection in between. But for SimpleAdaption API, there must be a mask, and the same image is used two ways: the image and the selection is the target (what will be resynthesized, in what context) and the image and the INVERSE selection is the corpus (where the pixels are synthesized from.) If you don't pass a mask byte, loosely speaking, it resynthesizes the whole image from it's whole self, which is usually a strange result.
I could be wrong, again this is a quick answer, and I would need to have your test data to proceed further.
Maybe ignore my previous comment. I just looked at your code and its probably correct. Let me think more.
However, if your result looks like resynthesis is affecting the whole image, then the mask is probably wrong.
Now, you don't have version 1.0 for Windows, because it that version did not even have a separate library.
Let me think about where the parameters for the algorithm come from, I would guess they are defaulted but I can't remember, I will need to study the API.
Now, you don't have version 1.0 for Windows, because it that version did not even have a separate library.
Version 1 is in GIMP, version 2 is from the repo
The issue (compiling library) is solved. I will open a new issue for how to use library. Now closing this one. Thanks!!
Hi,
I am trying to compile library without GIMP and glib. Changed buildSwitches.c according to third option: #define USE_GLIB_PROXY TRUE Set as sources those listed in Makefile.am for building a shared dynamic library
there are errors in the building
even if I comment the additional defines: SYNTH_USE_GLIB_THREADS and DEEP_PROGRESS or even if I comment
//#define SYNTH_THREADED TRUE
What should I do? Thanks!!