[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SuperSpeed access to pixels by DirectX

Posted on 2004-04-25
7
Medium Priority
?
515 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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 400 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

656 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