Click to See Complete Forum and Search --> : How to find x and y of an image?


answer
May 12th, 2004, 09:45 PM
For images that retain a constant size I can calculate the x and y coordinates quickly :) e.g. 640*480 image; (y<<7)+(y<<9)+x. What about for images that the sizes vary :confused:. Currently Iam basicly doing y*width+x to find starting point and adding by (bitsperpixel >> 3) to goto the next pixel. there should be a faster way. Is there?

Thanx in advance :)

yiannakop
May 14th, 2004, 07:55 AM
Originally posted by answer
For images that retain a constant size I can calculate the x and y coordinates quickly :) e.g. 640*480 image; (y<<7)+(y<<9)+x. What about for images that the sizes vary :confused:. Currently Iam basicly doing y*width+x to find starting point and adding by (bitsperpixel >> 3) to goto the next pixel. there should be a faster way. Is there?

Thanx in advance :)
What exactly do u mean by "faster way to calculate x and y"? Please explain some more your problem.
Regards,
Theodore

khp
May 14th, 2004, 08:25 AM
I suspect that 'answer' thinks that evaluating (y<<7)+(y<<9)+x is faster than y*640+x.
I belive this is a somewhat flawed assumption.

yiannakop
May 14th, 2004, 08:38 AM
Shift operators when used for multiplications and divisions with powers of 2 are faster than simple calculations. But when image size is variable to compute width and height as a power of 2 would be much slower than to use the cordinates in the classical way.

answer
May 14th, 2004, 04:45 PM
What exactly do u mean by "faster way to calculate x and y"? Please explain some more your problem.

sorry if I wasn't too clear with my problem ...

Iam trying to make my game run more smoother by optomising it. I have variose images with various sizes. I try to keep all the images with widths powers of 2 e.g. All character images have widths with powers of 2 such as 16x32.

I first write directly to a dib created by CreateDibSection(). all the graphics and I have varous characters loaded as DIB's. My game draws very little with poor framerate. I use Bitblt to paste the dibsection onto my window. When using an image that does not have power of 2 width and the size of the image varies I use multiplication to calculate y then plus (x<<bytes perpixel). Any tips for increasing the frame rate?

Thanx in advance :)

TheCPUWizard
May 14th, 2004, 05:36 PM
I will bet fairly large sums of money that this type of optimization will NOT pay off.

Use a good monitoring tool and determine where the bottleneck REALLY is.

answer
May 14th, 2004, 06:31 PM
Use a good monitoring tool and determine where the bottleneck REALLY is.

You're right. Bitblt() is a very large time consumer wich is causing the poor quality :(. Is there anyway I can put on the screen images without bitblt? I tryed using SelectObject with the windows HDC got with GetWIndowDC() but that didn't work :confused:.

Thanx in advance :)

TheCPUWizard
May 14th, 2004, 09:05 PM
The best way do handle this issue is to keep all of your image information on the graphics card itself and have it do the blitting between different memory areas.

If you are using Direct-X this is fairly simply to set up. Developing a good graphics engine from scratch is a large undertaking.

answer
May 16th, 2004, 04:51 PM
The best way do handle this issue is to keep all of your image information on the graphics card itself and have it do the blitting between different memory areas.

I wanted to know how to do that for a long time. I was seraching and searching ... ... As I was searching I was mainly comming up with using interupts and MS-DOS 16 related way's which do not work under win32 anymore :( e.g. Interupts. How may I write to video memory under win32?

Thanx in advance :)

TheCPUWizard
May 16th, 2004, 09:08 PM
Direct-X is the easiest way. It will do all of the work for you and even run on non-accelerated cards (if you so choose..)