Solved

SuperSpeed access to pixels by DirectX

Posted on 2004-04-25
7
507 Views
Last Modified: 2010-04-05
Hi experts,
I want to get about 500 squares with different size from a bitmap and stretch them into 40 x 40 squares. and also READ and WRITE pixels very fast. count them and so (Access them snappy ;)
Can you give me some code to do it using DirectX because I need to know this fast method very fast too. Much faster than Scanline. at least converting a 320 x 240 bitmap to grayscale in less than 50 milliseconds (converting 100 times in 50 ms).
Look at this code:

var
bitmap:tbitmap;
p:pbytearray;
x,y,q,w,i:integer;
begin
bitmap:=tbitmap.Create;
bitmap.Assign(image1.Picture.Bitmap);
q:=gettickcount;
for i:=0 to 100 do begin
for x:=0 to bitmap.Height-1 do begin
p:=bitmap.ScanLine[x];
for y:=0 to bitmap.Width-1 do begin
if (p[y*3+2]>200) and (p[y*3+2]<255) then begin
p[y*3+0]:=255;
p[y*3+1]:=255;
p[y*3+2]:=255;
end;
end;
end;
end;
w:=gettickcount;
image1.Picture.Bitmap.Assign(bitmap);
showmessage:=(inttostr(w-q));
end;

In this code I looked for 200<redvalue<255 for 100 times. it takes about 32~47 milliseconds by an ATi Radeon 7000 64MB. and 450 milliseconds for 1000 scans.
I want it more than 50 times faster. DirectX can do this for sure. but how. I use DirectX to capture images from a ccd, now I have a bitmap assigned to the current frame. how can I access bitmap.pixels? (Please answer with codes, I don't want to be lazy but ...)
Thank U,

Comboy
0
Comment
Question by:Comboy
  • 2
7 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 10913545
As far as I know DirectX won't be much faster. But you can still optimize that code you posted. E.g. get rid of the "*3" and replace it by adding "3" after each pixel.

What is your final aim? Is it fast grayscaling?
0
 
LVL 11

Accepted Solution

by:
ZhaawZ earned 100 total points
ID: 10913702
You can also use this to optimize code:

type
  TLine = array [0..32767] of TRGBTriple;
  PLine = ^TLine;
var
  p : PLine; {not pbytearray}
..
for y := 0 to bitmap.Height - 1 do begin
  p := bitmap.ScanLine[y];
  for x := 0 to bitmap.Width - 1 do with p[x] do begin
    if (rgbtRed > 200) and (rgbtRed < 255) then begin
      rgbtRed   := 255;
      rgbtGreen := 255;
      rgbtBlue  := 255;
    end;
  end;
end;

p[y].rgbtRed, p[y].rgbtGreen, p[y].rgbtBlue will be the red, green and blue values of the pixel now (not p[y*3+0], p[y*3+1], p[y*3+2]).
0
 
LVL 1

Author Comment

by:Comboy
ID: 10916939
Hi,
to Madshi > Final aim is an object detection software.
to ZhaawZ > It's faster, but not fast enough :(

to Madshi > DirectX is not faster - this codes make the process 4 times faster, they're in GR32_Filters.pas

procedure ColorToGrayscale(Dst, Src: TBitmap32);
var
  I: Integer;
  D, S: PColor32;
begin
  CheckParams(Dst, Src);
  Dst.SetSize(Src.Width, Src.Height);
  D := @Dst.Bits[0];
  S := @Src.Bits[0];
  for I := 0 to Src.Width * Src.Height - 1 do
  begin
    D^ := Gray32(Intensity(S^));
    Inc(S); Inc(D);
  end;
  Dst.Changed;
end;

DirectDraw must be faster, if it's not then how can games be created, while moving in a scene, it's drawing many textures using many filters and rotating them, but it's still smooth.
0
 
LVL 20

Assisted Solution

by:Madshi
Madshi earned 100 total points
ID: 10917136
That code above is not much different to the scanline code, it's just a bit more optimated. That's why I said: "But you can still optimize that code you posted" in my first comment.

DirectX is mainly meant to DRAW graphics, not to read and analyze them. DirectX games are so fast, because the graphics card is optimized for games. It does most of the work, while the CPU only tells the graphics card what to do.

In contrast what you're doing has not much to do with games programming or with writing into the graphics card. You simply want to manipulate some pixels in a bitmap. The graphics card has nothing to do with that. It's a CPU and system RAM only operation. And so DirectX will not be able to speed it up much - if at all.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question