|
Ok.
Modern computer graphics consist of pixels, which are the smallest units of color that can be represented on the screen. A screen of 1280x1024 contains 1.3 million pixels, and a modern display can set each one of those pixels to an individual color.
These pixels are divided into 3 components: the red, the green, and the blue. This is because almost every color that our eyes can distinguish can be obtained by combining diferent amounts of red, green, and blue. So, controlling only these 3 components can make it possible to obtain almost any possible color.
Then there is component resolution. Each component can be varied in intensity to achieve diferent colors, as I mentioned before. Usually we cannot distinguish between more than about 150 steps, meaning that if the span of a given component (from invisible (or off) to its full intensity) is divided into more than about 150 steps then we cannot tell the difference from one step to another. So we don't need to divide the span into more than 150 steps. However we divide it into 256 steps, to make it confortable to store components in computer memory (one byte per component) and for some other not so obvious reasons. This givs us a total of over 16 million individual colors (with 256 steps per component we get a total of 256x256x256 different colors).
To get white you sum all components (you set red, green, and blue, to full intensity). This is the whitest that a screen is able to represent. To get black you turn them all off, and that is the blackest that a screen can represent. Screens vary in their ability to make full white or full black. For example, my video projector is unable to make perfect white because the blue component is a little weaker than the others (as with many of the mid-range video projectors). Also, LCD's/TFT's are unable to make perfect black, usually because the material used for their construction usually reflects some envoronmental light.
If you want a gradient from black to white (from left to right, for example) then you should vary the component intensity from off (to the left) to on (to the right). Imagine an image of 800x600 and the following formula:
for(x=0; x<800; x++) {
for(y=0; y<600; y++) {
pixel(x,y).red=x/799*255;
pixel(x,y).green=x/799*255;
pixel(x,y).blue=x/799*255;
} // next y
} // next x
As you can see, x/799 is 1.0 only when x is 799, and that happens only at the rightmost pixel. Also, x/799 is zero on the left. An inversion would be simple, just replace x/799 by (799-x)/799. Also note that the component intensity does not depend on y, so there are changes only from left to right and not from top to bottom.
If you wanted full white on the top left and full white on the bottom right, the formula would be:
for(x=0; x<800; x++) {
for(y=0; y<600; y++) {
pixel(x,y).red=(x+y)/(799+599)*255;
pixel(x,y).green=(x+y)/(799+599)*255;
pixel(x,y).blue=(x+y)/(799+599)*255;
} // next y
} // next x
Again (x+y)/(799/599) is zero at the top left, and one at the bottom right. At the bottom left it is some intermediate level of gray (between black and white) as well as on the top right. If instead of black to white you wanted black to red then you just keep the green and blue at zero through all the operation.
for(x=0; x<800; x++) {
for(y=0; y<600; y++) {
pixel(x,y).red=(x+y)/(799+599)*255;
pixel(x,y).green=0;
pixel(x,y).blue=0;
} // next y
} // next x
At the top left all components are zero (black) and at the bottom right red is one and the others are zero. Orange is about full red, half gree, and zero blue. To go from black to orange you would do:
for(x=0; x<800; x++) {
for(y=0; y<600; y++) {
pixel(x,y).red=(x+y)/(799+599)*255;
pixel(x,y).green=(x+y)/(799+599)*128;
pixel(x,y).blue=0;
} // next y
} // next x
At the bottom right the pixel is full red, half green, and zero blue.
So, as you can see, the formula is simple after you know what you want. As you can imagine it would be easy to get gradients with many diferent colors by using more elaborate formulas. In general, you just need a function...
GetPixelComponets(float dx, float dy, int& dst_red, int& dst_green, int& dst_blue);
... that takes normalized X/Y coordinates (dx/dy from 0.0 to 1.0 so as not to depend on screen resolution) and computes what the component values dst_red, dst_green, and dst_blue should be for that screen point. Then that function simply has to take some set of references of the colors you want and where (in the above examples I wanted 2 reference points: a given color on the top left and another on the bottom right) and interpolate them (making smooth spatial transitions from a reference point to the next).
I hope this helps,
Rilhas
|
|
|
|
|
Thank you very much for this, it is fantastic advise.
Brad
Australian
- peterchen on "Who has the worst keyboard"
Keyboard? Ha! I throw magnets over the RAM chips!
|
|
|
|
|
Hi
I'm working on a teleprompter software (that flips a given text and lets the user to scroll it pixel by pixel)
I tried GDI+ using C# .Each time the user wants to scroll the text an image of the current lines is made.Then the image is rotated and loaded into a pciture box.
Unfortunately this procedure is very slow.
I like to ask if there is anyway that I can do the same thing using DirectX or OpenGL (I've already searched the ineternet but I couldn't find any answer)
Is there any other way that I can show the text upside down and let the user to scorll it?
Thanks a lot
|
|
|
|
|
beatles1692 wrote: I like to ask if there is anyway that I can do the same thing using DirectX or OpenGL (I've already searched the ineternet but I couldn't find any answer)
Actually, you probably did, but didn't realize its use. Using a render-to-texture method for the text, you can with either directX or OpenGL (I am only familiar with OpenGL), render your text to a texture "off screen" this is your graphical text, you can then position and scroll it and then reset the texture and position coordinates when the next line comes up. The net effect is the appearance of single pixel, continuous scrolling. Alternately, you can just render the text to a quad surface as texture fonts and then just scroll the quads off the screen while adding new ones below. (See lesson 17[^]
the demo doesn't do what you want, but is capable of doing what you want when you learn the technique.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
HI,
I am a software engineer & i have been working on webdevelopment (ASP.NET) around 1 and a half year. Now i want to work on Directx game programming.. so i cant gets where to start and how to start..
Can anybody help me how to work on directx for game programming..or anyother way for game programming..??
Please help me..
thanks in advance
KHATRI
|
|
|
|
|
|
Hi there!
I was wondering how I could write/draw on my desktop and I tried using native C#-methods (System.Drawing, ...).
I managed to draw outside my application's window, but I could not force my application to draw between the desktop background and the icons on my desktop.
I once found a snippet of C/C++ source code that did exactly that, but was not able to translate it to C# successfully. (The snippet can be found here)
Does anyone in here know how to do what I want to do?
I mean, the space between desktop background and icons is somewhat unused and could get somehow useful through this method...like for example displaying a calendar or a CPU-load-meter or something similar to this...
I'm looking forward to your answers!
Regards - Soykaf
|
|
|
|
|
I am getting the exception "BufferedGraphicContext cannot be disposed of because a buffer operation is currently in progress". I am working in VS2005 writing in C#. It is being generated when zooming on a large bitmap (125+ meg) in pictureBox (I am servicing code and would like to not have to rewrite to remove pictureBox) . I am unable to locate where this exception is being thrown. I put a try/catch block on Application.Run() and found main app dispose is called shutting down the app, and the catch block is executed after the app has shut down. I had heard Microsoft had hard coded a size limit on pictureBox but cannot find the comment again. Does anyone know where this exception could be caught to prevent the app from shutting down or what I might try to prevent it from being thrown (disabling zoom is a last resort)
Thanks
Jim
|
|
|
|
|
An update. There is a size limit, it is associated with the bitmap not picture box, of 32767 (a signed 2^16) pixels height and width. I still am not sure where the exception was/is being thrown. Any suggestions would be greatly appreciated.
Jim
|
|
|
|
|
I am looking into the DirectShow Editing Services and it seems quite interesting, I was already able to play an mpg file with it (after dividing its sound and video apart according to the documentation!
I am currently reading about the "Writing a Project to a File".
I am interested in recieving a number of mpgs and adding background music to them programatically (without external tools).
1. How exactly is it supposed to work if i do not have a multiplexer codec for mpeg2's from a third party? How does microsoft do the muxing of the uncompressed audio and video data, if they do?
2. If i want to output to mpeg2 what sort of MediaSubType should i be working with?
Does anybody have experience with Directshow Editing Services?
Does anybody know if what i want to do is possible with this?
(Appending Mpeg2 and then adding background music)....
Thanks,
Michael
mjmimmm@hotmail.com
|
|
|
|
|
How do i create 9 images that each contain part of a source image? I want to split the source image into 9 parts and put each into an image array.
Posted by The ANZAC
|
|
|
|
|
|
Thank You So So Much, this is brilliant, thanks again. You have no idea how much you've helped.
Posted by The ANZAC
|
|
|
|
|
Glad to be of help
|
|
|
|
|
Just a side note.
Larger JPEG files, because of how they
decompress, will not always split up
evenly. (Especially higher resolution images.)
Saving an errant JPEG as a BMP and then using
the BMP with the program fixes the problem.
When I get a chance, I will see if I can make this
adjustment dynamically in the program.
|
|
|
|
|
I updated the zip file at the previous link
to handle the problem I described in my last post.
However, some of the side code, (that I added for testing this,)
acts 'squirrelly'. (The hovering of the small pictureboxs
which changings a setting in the picturebox, results in
the picturebox picking up a 'stray' image.)
The code hopefully is still useful to you.
I have posted in a graphics forum trying to find out
why I am getting the strange behavior on the small picturebox
hover event. (That was added for testing purposes.)
|
|
|
|
|
I have posted a final fix for all the problems
I described, at the same link as before.
Everything behaves now
|
|
|
|
|
WOW! Thanks a heap. The first post was useful, this is excellent! Thanks again!
Posted by The ANZAC
|
|
|
|
|
I have a list of mpgs that i want to merge.
How can i merge two mpg's in my program. I am not interested in using an outside tool.
Is this possible with Graphedit?
Is there any open source code that does this.
If i do a binary copy like with : copy /b (names of files) (output file) than the length of the movie is incorrect (i basically corrupt the header i guess).
Any suggestions?
Thank You,
Michael
mjmimmm@hotmail.com
mjmimmm@hotmail.com
|
|
|
|
|
Graphedit could maybe do it but it can't ouput an mpeg file unless you have a 3rd-party MPEG
encoder filter.
Here's some online resources that may help.
The MPEG Home Page[^]
mpeg.org[^]
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
I have a an mpeg2 encoder.
How can i merge the current mpgs in directshow with graphedit for instance?
thnx,
Michael
mjmimmm@hotmail.com
|
|
|
|
|
Are you just looking for a tool to do it or are you writing a tool to do it?
Graphedit isn't a viseo editor - it's just for testing filter graphs.
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
I have 4-5 mpgs with video and sound.
I am writing a program that among other things needs to merge the mpgs into one long mpg and then add background music from a seperate .wav file.
I was thinking of doing this with directshow. I know that graphedit is only a tool . But a lot of times it is possible to use it to test different filters to see how it works out. Basically i need to do two things:
1. Merge the mpgs (which have video and sound).
2. Add background music (this is turning out to be the more complicated demand).
Any advice, guidelines, open source code that does these things?
(windows environment)
thank you,
Michael
mjmimmm@hotmail.com
|
|
|
|
|
|
First of all, I would like to say thank you for the reference, I had not even heard of this before.
It seems from a short glimpse that this would definitly work for my first problem. But I haven't been able to see how i could use this to solve my second problem (inserting\joining\merging\adding a wav to an mpeg file).
Thank You Very Much,
Michael
Mjmimmm@hotmail.com
|
|
|
|
|