|
El Corazon wrote: are you blending these via vertex coloring or via alpha textures?
I am blending via vertex colouring. And you're right, i don't really care about all of the High Dynamic events. I do a Computer Science degree at uni but graphics is not one of my courses. I am just doing this as a hobby because i like graphics. So i really shouldn't waste my time learning about OpenGL lighting effects (i might read up on it on the holidays). I guess i will just use GL_SRC_ALPHA, GL_ONE for now, as long as i don't blend many colours at once and end up with a white screen!
thanks for your help anyway
--------------------------------
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
I've been using CastorTiu's amazing IconLib in my application.
http://www.codeproject.com/cs/library/IconLib.asp
He has a function in the library that adds an image to an icon. It can add images of many different bit types and they all work fine except for 8bit images. When 8 bit images go through this code which reproduces a full palette the for loop iterates 256 times and this causes the program to go unresponsive for too long... It does eventually finish but only after nearly freezing the program for a few seconds. I was wondering if anyone knew of an alternative for creating a full palette that isn't so intensive on the system.
Here is the function that causes the delays with 8bit images but not 4bit [16 iterations] or 32 bit [skips loop altogether]
public static RGBQUAD[] RGBQUADFromColorArray(Bitmap bmp)<br />
{<br />
int bits = Tools.BitsFromPixelFormat(bmp.PixelFormat);<br />
RGBQUAD[] rgbArray = new RGBQUAD[bits <= 8 ? (1 << bits) : 0];<br />
for(int i=0; i < bmp.Palette.Entries.Length; i++)<br />
{<br />
rgbArray[i].rgbRed = bmp.Palette.Entries[i].R;<br />
rgbArray[i].rgbGreen= bmp.Palette.Entries[i].G;<br />
rgbArray[i].rgbBlue = bmp.Palette.Entries[i].B;<br />
}<br />
return rgbArray;<br />
}
|
|
|
|
|
Hmm that loop should take under a millisecond if bmp.Palette.Entries.Length is 256.
Are you positive that's where time is being consumed (on the thread executing the loop)?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Positive... I stepped through the entire thing and the slowdowns happen during the iterations of the loop.
Happens in my program and just to make sure it wasn't something I did, I loaded up the IconLib project itself and passed it an 8bit image and had the same problem.
|
|
|
|
|
This sounds kinda strange...
Copying 1 byte from one location to another 768 times shouldn't take long (unless you have a
REALLY slow machine. I'm pretty sure the original PC at 4.77 MHz could do it in under a
millisecond
If you break execution when it stalls is it really in the loop or is it maybe in the
Tools.BitsFromPixelFormat(bmp.PixelFormat) call.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Machine can more than handle this that's why I posted the question because it's so strange... Yes it does stall during the loop not during the bitsfrompixel
Bits from pixel is just a simply switch anyway
public static int BitsFromPixelFormat(PixelFormat pixelFormat)<br />
{<br />
switch (pixelFormat)<br />
{<br />
case PixelFormat.Format1bppIndexed:<br />
return 1;<br />
case PixelFormat.Format4bppIndexed:<br />
return 4;<br />
case PixelFormat.Format8bppIndexed:<br />
return 8;<br />
... etc.
|
|
|
|
|
Here's a picture of my actual breakpoints...
http://wwwp.mirror.waffleimages.com/files/13/13e214fd705683442d70081bb7c901230aac708a.png
With the wya they are setup in the picture it takes a while to manually step through 256times but it reaches the end eventually and all is fine... But only because it took some time to do manually.
If I remove the breakpoints on i < bmp.Palette.Entries.Length; and i++; the stall happens directly between int i=0; and return rgbArray;
There isn't any further question in my mind that something is going wrong during that palette copying inside that loop. But the real question is why? This machine is a beast and the rest of the code is fine just for somereason 256 iterations of
rgbArray[i].rgbRed = bmp.Palette.Entries[i].R;<br />
rgbArray[i].rgbGreen= bmp.Palette.Entries[i].G;<br />
rgbArray[i].rgbBlue = bmp.Palette.Entries[i].B;
stalls the program for 30 seconds or so.
|
|
|
|
|
I'm wondering if it's reallocating/recreating a new palette every time the Palette property is
accessed.
Maybe the optimized loop I posted below will help
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hmmm...
Is this managed C++? If so, does optimizing the loop help any?
public static RGBQUAD[] RGBQUADFromColorArray(Bitmap bmp)
{
int bits = Tools.BitsFromPixelFormat(bmp.PixelFormat);
if (bits <= 8)
{
RGBQUAD[] rgbArray = new RGBQUAD[1 << bits];
ColorPalette ^palette = bmp.Palette;
array<Color>^palcolors = palette->Entries;
for(int i=0; i < palcolors->Length; i++)
{
rgbArray[i].rgbRed = palcolors[i].R;
rgbArray[i].rgbGreen= palcolors[i].G;
rgbArray[i].rgbBlue = palcolors[i].B;
}
return rgbArray;
}
return 0;
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
You should be able to do the same thing. The point is, pull the Palette and Palette.Entries
property accesses OUT of the loop and loop through the entries array only.
Sorry I don't know the syntax - it should be simple for you I would think
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Wow that worked... You're a lifesaver and a genius.
I wouldn't have thought that could fix it either but I was willing to try anything, so thanks for suggesting what I thought didn't matter.
|
|
|
|
|
Cool! I had no idea using the properties in the loop would be that slow!
Good to know!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I'll take a WILD stab at the C# syntax LOL...
public static RGBQUAD[] RGBQUADFromColorArray(Bitmap bmp)
{
int bits = Tools.BitsFromPixelFormat(bmp.PixelFormat);
if (bits <= 8)
{
RGBQUAD[] rgbArray = new RGBQUAD[1 << bits];
ColorPalette palette = bmp.Palette;
Color[] palcolors = palette.Entries;
for(int i=0; i < palcolors.Length; i++)
{
rgbArray[i].rgbRed = palcolors[i].R;
rgbArray[i].rgbGreen= palcolors[i].G;
rgbArray[i].rgbBlue = palcolors[i].B;
}
return rgbArray;
}
return 0;
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Yep you got it, same thing I translated your C++ to.
In case you didn't see my above reply... You got it fixed thanks so much.
|
|
|
|
|
Hi fellows!
Did anyone of you ever something like a winamp credit window? (the 3D credits viewer when you click on "Nullsoft Winamp..." in the context menu).
Anyone seen some code for doing this in .NET?
Thank's in advance,
Stevie
|
|
|
|
|
SCENARIO
I have been learing to use C# and DirectX via small programs using the Express edition of c# 2005.
To take what I have learn't further I have decided to develop a small engine, it is nothing fancy and so far it is only Direct Draw, just developing my skills.
I have developed the engine as a class library that has methods such as
Graphics2D=sets up direct draw and creates 2 surfaces for double buffering
LoadImage=loads a file into an offscreen surface array and returns the index
LoadAnimImage=same but creates a frame array and color key for transparency
DrawImage(Index,etc)=Draws the indicated image from the surface array.
there is also an overloaded DrawImage which has a frame parameter added for drawing animations.
I also have a testing project that references the dll and uses its methods to show a scrolling background and an animated walking character with music.
MY PROBLEM
OK, all is working well, except that my surface array is static in the number of elements it has.
Here is the code that relates to my question
private Surface[] ImgList = new Surface[2];
public int LoadImage(string FileName)
{
sDesc.Clear();
sDesc.SurfaceCaps.OffScreenPlain = true;
ImgList[NumImages] = new Surface(FileName, sDesc, dddevice);
NumImages+= 1;
return NumImages;
}
public void DrawImage(int Image,int x,int y)
{
ssurf.DrawFast(0, 0, ImgList[Image-1],ImageRect,DrawFastFlags.DoNotWait);
}
As I said, the above works fine, but I now want to make the surface array dynamic using the ArrayList from the system.collection namespace
and here is my attempt
ArrayList al = new ArrayList();
public int LoadImage(string FileName)
{
sDesc.Clear();
sDesc.SurfaceCaps.OffScreenPlain = true;
al.Add(new Surface(FileName, sDesc, dddevice));Add a surface to the array
NumImages+= 1;
return NumImages;
}
public void DrawImage(int Image, int x, int y)
{
ssurf.DrawFast(0,0,al[Image-1],ImageRect,DrawFastFlags.DoNotWait);
}
When I build that I get
cannot convert from system.array to microsoft.directx.directdraw.surface
error, among others which are related to the above error.
The error occurs in the DrawImage method
From the article I read about ArrayList collections I got the impression that the elements added to in an ArrayList could be of any type. Obviously I am mistaken, I only have a vague understanding of collections.
Can someone please tell me
What am I doing wrong ?
and more importantly for me, how can I make the above work?
Any help would be much appreciated.
-- modified at 17:23 Sunday 3rd June, 2007
|
|
|
|
|
In case anyone is interested in a solution I have figured out a workaround by modifying my static array solution.
I changed the array definition and the LoadImage method to use a new method called GrowImageArray.
This new method
Creates a new array to the new dimension
Copies all the surfaces from the old array into the new
Adds the new surface to the new array
Returns the new array to the LoadImage Method
I realize that this is probably not the best way to achieve my goal, but the 'best way' is not important to me at this stage because this is an experience gaining exercise
private Surface[] ImgList = null;
...
public int LoadImage(string FileName)
{
sDesc.Clear();
sDesc.SurfaceCaps.OffScreenPlain = true;
NumImages+= 1;
ImgList= GrowImageArray(FileName,ImgList, NumImages);
return NumImages;
}
private Surface[] GrowImageArray(string FileName,Surface[] pOldArray, Int32 pNewSize)
{
Int32 counter = 0;
Surface[] newArray = new Surface[pNewSize];
if (pNewSize > 1)
{
foreach (Surface item in pOldArray)
{
newArray[counter] = item;
counter += 1;
}
}
newArray[counter] = new Surface(FileName, sdesc, dddevice);
return newArray;
}
public void DrawImage(int Image,int x,int y)
{
ssurf.DrawFast(0, 0, ImgList[Image-1],ImageRect,DrawFastFlags.DoNotWait);
}
PS
I am still interested to find out how to achieve this with ArrayList?
|
|
|
|
|
What you are doing there is basically what a vector does. The C++ standard library has a vector class which is an array that grows. It uses a template to take a type, that is, you declare it like this:
vector<int> v = new vector<int>();
where int is the type. Now i don't know any C# but i had a look and found that indeed you can add any type to your ArrayList and that this is the C# equivalent to a vector. I think you function is quite good and if it works then that's even better
----------------------------------
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
Thanks to VizCoder providing confirmation that ArrayList's are indeed any type I looked at my orriginal attempt again.
All I needed to do was change the DrawImage method to..
public void DrawImage(int Image, int x, int y)
{
ssurf.DrawFast(0,0,(Surface)al[Image-1],ImageRect,DrawFastFlags.DoNotWait);
}
Because the ArrayList object can be of any type I had to cast it as type surface when using it
(Surface)al[Image-1]
|
|
|
|
|
Saludos:
I will greatly appreciate any help you can provide with the following:
Currently I'm working on project to do zonal OCR on scanned images.
I'm in need to find a way to dectect blank images in order to exclude
them from the OCR process. I'm using CImage and CxImage to process
my images.Any suggestions?
Thanks Again;
Joe Gonzalez
|
|
|
|
|
Hi, i posted a question a few days ago about using SwapBuffers(). Well what i want to do it draw an image, warp it (using a grid of points and texture mapping the image to quads at each point), then copy that image and repeat. In other words, i want to continually copy the screen and render it back to the screen. Now i was doing that just fine by rendering straight to the screen but someone told me i should use pbuffers with shared lists. So i am, but how would i do the above? Here is some psudocode of what i think i should do
select pbuffer
draw warped texture of image
draw image on top of warped one
copy to texture
Now how do i get that to the screen? Just draw a quad textured with the image to fill the screen? If that is the case, why do i need the pbuffer.
I hope i have explained it well. Can anyone help
EDIT: by the way, i can't render directly to a texture since my hardware doesn't support it. I have to render to a scene (off screen) then copy to texture
-- modified at 21:05 Friday 1st June, 2007
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
I am trying to understand the Math of a Camera in Computer Graphics.
Here is the question
If i have a camera a point a, How do I compute the view matrix so the camera looks at point b?
|
|
|
|
|
I am building a image cropper that should automatically detect the image boundry surrounded by white area and then crop it.
The question is:
how to detect the boundry of image surrounded by white area?
I have tried the following code with little success.
for (int j = 0; j < (height/2); j++)
{
count = 0;
for (i = 0; i < (width/2); i++)
{
color = grays.GetPixel(j,i);
if ((color.R == 255) && (color.B == 255) && (color.G == 255))
{
height_top = i;
width_left = j;
}
else
break;
}
}
This code should provide the upper left corner co-orninates but it does not.
Thanks in Advance.
Z.A
|
|
|
|
|
I think it would be easier to scan top-down horizontally until you find a non-white pixel. That
gives you the top. Then scan left-right vertically until you find a non-white pixel. That gives
you the left.
I think the code you've shown is just to get the top - maybe - unless there's colored pixels
higher on the right half of the image
Also, did you mean to put these arguments in this order? GetPixel(j,i);
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|