making good graphics
William Labbett

As I'm concentrating on the drawing side of game creation at the moment I've been writing an art program lately.

What it's done here is take a black and white image and a colour image (the pixies) and blended them together in a way I couldn't get Paint Shop Pro 7 to do.

Posting a WIP in case anyone's interested.

{"name":"613030","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/a\/da308698209674733bcdb137ecd78884.png","w":2500,"h":1786,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/a\/da308698209674733bcdb137ecd78884"}613030

RmBeer2

;D, i already see it before. :P

amarillion

It looks neat, but I wonder what it is that you couldn't do in Paint Shop Pro?

William Labbett

I thought I'd posted it before, but this time it's partway coloured which I guess is not very exciting.

{"name":"613031","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/2\/42312207b4473362dd0d99ab32f4b487.png","w":325,"h":380,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/2\/42312207b4473362dd0d99ab32f4b487"}613031

This is an example of the best I could do with PSP7.

What I've done above is add the painted version of the pixie to the black and white image
as another layer and reduced it's opacity.

What my program does is :

#SelectExpand
1/* shade_coloured_picture_process() : takes the colour bitmap and black and white bitmap and 2blends them. */ 3int shade_coloured_picture_process(ALLEGRO_LOCKED_REGION *coloured_bitmap, ALLEGRO_LOCKED_REGION *check_bitmap_lock_ptr, ALLEGRO_LOCKED_REGION *clone, int process_instructions[NUMBER_OF_INTEGERS_FOR_PROCESSING]) 4{ 5 unsigned char *out_ptr, *ptr2; 6 int r, g, b; 7 int nr, ng, nb; 8 int x, y; 9 int grey; 10 11 unsigned int new_colour; 12 13 14 for(y = 0; y < process_instructions[LOCKED_BITMAP_ONE_HEIGHT_INDEX]; ++y) 15 { 16 for(x = 0; x < process_instructions[LOCKED_BITMAP_TWO_WIDTH_INDEX]; ++x) 17 { 18 ptr2 = ((unsigned char *) coloured_bitmap->data) + coloured_bitmap->pitch * y + x * 4; 19 20 /* Get the r, g, b of the pixel on the colour bitmap. */ 21 22 r = (int) *(ptr2 + 0); 23 g = (int) *(ptr2 + 1); 24 b = (int) *(ptr2 + 2); 25 26 out_ptr = ((unsigned char *) clone->data) + clone->pitch * y + x * 4; 27 28 grey = (int) *(out_ptr); 29 nr = (int) ( ((float) grey / 255.0f) * (float) r); 30 ng = (int) ( ((float) grey / 255.0f) * (float) g); 31 nb = (int) ( ((float) grey / 255.0f) * (float) b); 32 33 34 if( *((unsigned int *) ptr2) != MASK_COLOUR_ABGR ) 35 { 36 /* this pixel on the coloured bitmap is not the mask colour so use blended 37 pixel */ 38 39 new_colour = 255 << 24 | (unsigned char) nb << 16 | ( unsigned char ) ng << 8 | (( unsigned char ) nr ); 40 *((unsigned int *) (out_ptr)) = new_colour; 41 } 42 } 43 } 44 45 return PROCESS_RESULT_OKAY; 46}

Basically I've forgotten exactly what it does but I think approximately it does the equivalent of drawing in the medium used for the black and white image (biro) over the colour painting. Since I draw first with the biro I can't then paint underneath it on the paper so this function achieves that.

There is a big difference between the two images.

BTW, another thing I could do with PSP is rotate an image underneath a superimposed translucent layer. I was trying to rotate a scanned in painting so that the vertical lines on it were exactly vertical on a bitmap (I had trouble scanning it in that way).
I needed a translucent rectangle over it which stretched from top to bottom so I could see 2 straight vertical lines and then I needed to rotate the painting underneath. I could do this in PSP so I decided to add this facility to my program.

Perhaps I'm just being stupid but it pleases me. I'm aware there could be something I don't know which would have saved all the work. It's a small project this art program. I'm doing it also because I want to get better at coding and it's only a small project so I think I can get a first version of it finished.

RmBeer2

the variable 'gray' only takes the red color of the bitmap 'clone' to make the type of blending. As I think it does, it reduces the color to black according to the opacity of the cloned image, if there is any black trace on a white background, that translates directly to the color image, but only taking the intensity of the red.

Although I can't see its result in the displayed images.

Edgar Reynaldo

GIMP has a nice colorization tool. It uses a brush to tint the background.

I've used it with success before to color pencil sketches that I've scanned.

Here's an example :

Before :
https://www.deviantart.com/nemonameless/art/My-friend-Liddee-2-Curly-Hair-pencil-292944859

After :
https://www.deviantart.com/nemonameless/art/My-friend-Liddee-2-Curly-Hair-colored-292944133

Audric

In many layer-based programs this would be defined by the blending mode that you choose for the top layer :

  • If it's the colored one, you would blend it as "Colorize"

  • If it's the greyscale one, you would blend it as Luminance / Lightness

  • In either case, a Multiply mode would also fit the bill - Because one of the two layers happens to be 100% greyscale.

Note that multiplying RGB channels means you're doing math in the RGB color space. Having one layer greyscale limits the damage, but the effect of gammma still applies. So you may obtain a more intuitive coloring if you perform gamma correction before doing the math, and reverse the conversion at the end.

William Labbett

Thanks Edgar and Audric. I couldn't check out those drawings as my ISP blocks loads of sites from my viewing. I tried fixing it to no avail.

Interesting feedback, lots I had no idea about and stuff to look into.

Edgar Reynaldo

I uploaded them here so you can see them :

{"name":"613032","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/e\/2e8f08da28742fa202378032c4ed65fe.jpg","w":1020,"h":1404,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/e\/2e8f08da28742fa202378032c4ed65fe"}613032

{"name":"613033","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/2\/e22a561367ca5c68b6840401be498c67.jpg","w":1020,"h":1404,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/2\/e22a561367ca5c68b6840401be498c67"}613033

William Labbett

Thanks Edgar. I understand now. I'll have to try it out on my drawing.

Thread #618499. Printed from Allegro.cc