Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Questions that no one could answer in the new groups.

Status
Not open for further replies.

Tremorblue

Programmer
Apr 30, 2004
56
GB
I wrote these emails in the borland newsgroups.
This is my last hope ! :)

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

I would like to find some open source algorithms to convert colour images to monochrome. Preferably the code should be written for Borland Builder.

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

I am writing an application to draw shapes on a form. I draw directly
onto the form to produce grid lines running top to bottom and left to
right where the mouse is. The shapes are image objects that I can move
about.

When I move the mouse over the form I XOR the grid lines directly
onto the form and XOR to remove the old lines (if different).

In the onpaint event I draw a label onto the background.

The trouble I am getting is that other events like resizing the form,
scrolling the form or moving the image objects causes the grid lines
to be partially left and not rubbed out.


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

I want to open a console window from a gui front end application as I need to output some printfs from some legacy code.

How do I a) open the window b) link my printfs so they know where to appear.

---------------------------------
 
There was a series of articles in C/C++ Users Group Journal that dealt with graphics. One of them delat with this very subject. All of the code was in standard C++. The source code is at their site ( sorry, I don't remember what year or month it was.


James P. Cottingham
[sup]
There's no place like 127.0.0.1.
There's no place like 127.0.0.1.
[/sup]
 
You want to convert color images to monochrome?

Depends on how you access pixels. If you have a TBitmap, you can just set the bitmap->Monochrome = true. Then you can set it back to false and use whatever pixelformat you want.

With a TImage, it's image->Picture->Bitmap->Monochrome = true but this may not work if it's on your form as the Image has to stay the same as what your screen is set to.

If you want to convert it manually, you can access individual pixels from a bitmap with:

char *line = bitmap->Scanline[y];
int pixel = line[x];

This is assuming 32 bit graphics: bitmap->PixelFormat = pf32bit;

The above will convert your bitmap automatically to 32 bit format.

Now that you have a pixel, you can use any of the popular conversion equations. Here I'll show the one used by YUV or YV12 format for the intensity level of the pixel, hence it's grayscale value.

First we split the integer into its Red, Green and Blue values. Low byte is Blue, next is Green and second highest is Red. The high order byte is the alpha channel, but we're not using that.

int b = pixel&0x000000ff;
int g = (pixel&0x0000ff00)>>8;
int r = (pixel&0x00ff0000)>>16;

// Now for the conversion
int intensity = (int)(0.299*(double)r + 0.587*(double)g + 0.114*(double)b);

Now you can write the new pixel value back out. The intensity is the value used for all three colors (r,g,b).

pixel = intensity|(intensity<<8)|(intensity<<16);

line[x] = pixel;


About your second problem, I'm not sure I understand what's going on exactly.

For your last problem, why don't you redirect stdout? You could create a pipe, redirect stdout to this handle and tell windows to notify you whenever something writes to that pipe. Upon notification, you can read from the pipe and you would have the data written to stdout via printf. Takes a lot of windows API calls though. There may be easier ways. Not sure if starting up a console and redirecting its output is any easier though.


A programmer is a device for converting Coke into software.
 
In the above, replace
char *line = bitmap->Scanline[y];

with

int *line = (int*)bitmap->ScanLine[y];


A programmer is a device for converting Coke into software.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top