Advertisement

Change colors with greyscale ?

Started by February 19, 2000 02:58 PM
6 comments, last by Zombie 25 years ago
I have to do a face editor. I need to give user the ability to change the skin color without touching the face itself. I expect I should do a greyscale image of face, then change the colors of picture in program. The function doesn''t need to be too fast, because the colors aren''t changed too fast. It''s going to be DirectDraw.
I think I see what you''re getting at. You want to let the users change the color of individual pixels in the image without changing the overall appearance of the face.

I think you should look into a little about how colors are describe with HSB (Hue, Saturation and Brightness). Hue describes the the color as the location on a color wheel, where red is at zero degrees, green at 120 degrees and blue at 240. Saturation is the purity of the color, with 0% saturation you have a gray color. Brightness is of course how bright the color is with 0% for black and 100% for white.

By adjusting Hue and Saturation you can change the colors of the image without changing the appearance of the face which is coded in the brightness component.

(Did this make any sense )
Advertisement
It did make sense, but when I tried to use DirectDrawColorControl.GetColorControls (and setColorControls), all I received was a grey screen. That didn''t make sense. So my problem is now, how to use those color things?
DirectDrawColorControl is used to change the color of the entire surface or screen, most likely to set the gamma. You cannot use this to change individual pixels in your image.

You need to make a function that can convert between RGB and HSB and back. That way you can read the color of a pixel, convert it to HSB manipulate the components, convert it back to RGB and finally set the pixel.
Most likely it''ll be too slow in VB. I''ve used PSet function in VB (no DX) and it takes many seconds to draw even a small area! Not good. It can be faster in DirectX, though. Do you know a site where can I find information of HSB, or perhaps the function?

Since i am not a expert VB programmer i cant say so much about this, but if you could get a pointer to the surface, you could make the changes using scanlines. A scanline is a pointer that you give the address of the "Y" component and calculates the address in the memory of the position given. So you can copy the whole line of the picture to the RAM memory, make the changes on the memory and store it back on the surface you want(i think its the video, isnt it?). In C language i know how its done but not in VB.
You can try it, it's a lot faster.

Try to not use single pixel functions, its very slow.


Edited by - chronno on 2/20/00 12:00:28 PM

Edited by - chronno on 2/20/00 12:01:46 PM
-Chronno-
Advertisement
VB is not very fast because it is an interpreted language and DX doesn''t have any support for this.

You will probably have to make your own function in C and put it in a DLL so you can call it from VB.

I don''t know of any site where you can read about it, I read it in the Photoshop help file.
Since you are using a ddcolorcontrol, I assume you are using dx. Just use directdrawsurface7.lock(), then either get the whole array data with ddsurf.getlockedarray, or check every pixel with ddsurf.getlockedpixel. Trust me, it works in VB because I use VB.

The reason PSet is so slow in small areas is that you are using TWIPS and not PIXELS. I don't care if you are using AutoRedraw, Twips is like 15 points per pixel. That is a lot of overdraw. If you are not using twips then, I don't know.

I hope what I replied is what you want. I'm no McDonalds.

Edited by - nes8bit on 2/21/00 2:50:01 AM

This topic is closed to new replies.

Advertisement