Hi,
for my art program I want to be able to use a photo to floodfill one colour of a bitmap which has only two colours.
Here's the specific case which was the example which inspired the idea :
Bitmap to floodfill :
{"name":"613167","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/6\/b61f33feee3867ad2532d91c46aa86fe.png","w":2495,"h":1785,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/6\/b61f33feee3867ad2532d91c46aa86fe"}
Photo to use :
{"name":"613168","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/6\/c6619f459ea931d79866b3a4685369b2.png","w":1920,"h":2560,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/6\/c6619f459ea931d79866b3a4685369b2"}
The reason I want to use the photo is because if I use the bitmap as it is to colour my drawing it looks too uniform and boring :
{"name":"613171","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/e\/5e6da9e45b64d4937e693932fa37e6e9.png","w":1200,"h":858,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/e\/5e6da9e45b64d4937e693932fa37e6e9"}
I'd like the buildings brick and all the stone areas of the drawing to look as if they're made of the same sanstone (or whatever it really is) in the photo.
One idea I have is to just iterate through all the pixels on the 2-tone bitmap which need floodfilling and replace them with a randomly selected pixel from the
photo.
Another idea I've got is to tile the 2-tone bitmap which needs floodfilling with randomly chosen squares of the photo and then blur the edges of the squares.
Finally, I thought I might be able to somehow use Joel Pettersson's noise code
which he meantioned on this thread
https://www.allegro.cc/forums/thread/618617
Hopefully, I've made myself my clear.
Just posting in case anyone's got any useful ideas of what I could do to get a good result.
Write a shader that takes two colors and three images and multiply blends if they are a certain color with the second texture onto the first (your drawing).
Thanks Edgar.
I'm not sure I can write a shader but I like a challenge. Sounds like a good idea.
Luckily shaders are very simple programs. You just have to understand the pipeline and where it flows in the gpu.
bump for progress.
Out of curiosity Edgar, why would you pass 3 bitmaps to the shader? Would it be the photo, the image to fill, and then a copy to perform the multiplier on?
It would be 3 images because you need the stencil, the texture, and the bitmap to draw onto. So maybe two if you don't count the drawing target.
Many thanks for keeping the thread going and for the extra input. I've been very busy. Trying to learn about shaders (I've bought a book). I found the Arithmetic button in PSP7 which does blending. I also had to get up to date with allegro 5 (5.2.7.0). I was delighted I managed to compile it.
I don't know if there's any point in me posting yet but I'd like to keep the thread going.
If you're not concerned about speed, you can also do it by locking bitmaps and reading / writing memory.
Thanks. I'm currently stuck with a makefile. I haven't used makefiles in years.
Every time I run mingw32-make Makefile on the following I get
mingw32-make: Nothing to be done for 'Makefile'.
There aren't any object or executable files in or below the folder I'm using.
Without the seemingly magical abilities of code::blocks and it's makefile generation I'm stuck. Perhaps there's something obvious I've done wrong? Please help.
I personally hate makefiles, so I can't help you there. Well wait. Default make target is 'all' or the first rule in the makefile.
But I can help you with the algorithm to texture your photo.
Assuming all three images are the same size, you could use something like this :
Like this? A quick Gimp hack.
http://www.allegro.cc/files/attachment/613179
The sandstone wall is multiplied with the drawing. No further adjustments. I guess it should be lighter.
[edit]
I've lost the touch. How do you add images?
OR, you can cheat and use GIMP like Johan. ;P
{"name":"613179","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/a\/0a19467d5b6a5f110768fc7349de4489.jpg","w":1024,"h":732,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/a\/0a19467d5b6a5f110768fc7349de4489"}
Many thanks to the both of you. It's nice to know I've got options and to see what GIMP can do. Certainly the result is closer to what I'd hoped for in the beginning.
It'd be a shame for Edgar's nicely written code to go to waste so I'll put that to use given the time. Thanks again.
EDIT B|
EDIT 2 I've got a feeling I find all this harder than you two. I think I try too hard.
Just so you know a multiply blender just darkens the pixel. You can use it with any texture. And that will transfer the pattern to the destination.
Hello William, I have created a basic (OpenGL) shader and program for you. It uses the map and texture, and you set an RGB value, if the shader finds the corresponding RGB value in the map, it multiplies the drawn image (the sketch) with the texture, resulting in the attached image:
{"name":"Wdhf2t.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/7\/176e9f76850905c5186d1cfd0700b7bf.png","w":1200,"h":768,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/7\/176e9f76850905c5186d1cfd0700b7bf"}
Also attached is a zip file containing the shader files, the code and the images which I resized to make life easier.
It may be a good starting point for you if you wan't to write a shader!