Solved

Fast access to bitmap data

Posted on 1997-06-20
8
443 Views
Last Modified: 2013-12-03
I need to grab the colour data from a bitmap, manipulate it then write it back to the bitmap.  This needs to compile in D1.0 (without Win32.API) but needs to run reliably under W3.1 and W95.  I really need to treat the data I get from the bitmap as 24BBP information, even if the bitmap was actually palettised.  Pixels property and WinAPI GetPixels are WAY TOO SLOW.  Speed is of the essence!
0
Comment
Question by:csmikeb
8 Comments
 
LVL 1

Expert Comment

by:ywoedta
ID: 1337289
The two functions (API) that you need are GetBitmapBits and SetBitmapBits.  Both use an array of pixel information, which you can then write your own access routines for (seeing as how you are so concerned with speed, that's the only way to make sure.)
Hope this is what you were looking for.
0
 

Author Comment

by:csmikeb
ID: 1337290
I am aware of the Get and Set bitmap bits API functions, but there is also a getDIB and setDIB function, what I really need to know is not what functions are there, (this much I already know) but how those functions should correctly and portably be used so that they work with at least the vast majority of graphics cards.
0
 
LVL 1

Expert Comment

by:millerw
ID: 1337291
What is the file, bmp, dif, etc?
0
 

Author Comment

by:csmikeb
ID: 1337292
Errr, not sure that it makes any difference does it?  I'm not working on the raw data of the file, (in fact currently they are a mixture of different file types, GIF, JPG and BMP, loaded through the medium of the Image Lib TPMulitImage component. But surely that makes no difference?  By the time I am at the stage of wanting to edit, the image is held in an internal bitmap format, whatever the source type WAS.  All I want is to have rapid access to the data...  This was all SOOOOOOooo easy under Unix....
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:millerw
ID: 1337293
If you are programming in Delphi, TBitmap is the best way to edit and display etc files in memory.  It handles all of the features needed and even has a TCanvas so you can draw on the bitmap.  Also it will display the image in any windows form etc with just one call.  You can access individual pixels and such.  I'm not sure how many colors it will handle (the built in object that is) but it can be redefined to handle more with a new object.  You will have to handle all conversion of files into the Bitmap format but once that is done, the access will be quite fast.  Additionally, there are routines that are out there to do the conversion for you.  

If you are more familiar with C++ also, you can use C++ Builder instead of Delphi.  With Unix as your background, you will probably feel more confortable with C++ Builder.  It has the TBitmap also built in.
0
 
LVL 1

Expert Comment

by:millerw
ID: 1337294
Unfortunately, C++ Builder will not satisfy your condition of No WIN32.  Sorry about that.
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 150 total points
ID: 1337295
If You need fast code to work on bitmap then try this:
1.Make new project and on MainForm place TPicture and TButton then load any picture (first not very big) to Picture1.
2.In OnClicked for button write this code :

procedure TForm1.Button1Click(Sender: TObject);
type
  LongArray    = array[0..0] of word;
var Bmp     : TBitmap;
    BmpInfo : WinTypes.TBitmap;
    Len     : Longint;
    BitData : Pointer;
    i, j    : Longint;
begin
{$R-}
  { Get the Bitmap Bits }
  Bmp := Image1.Picture.Bitmap;
  GetObject( Bmp.Handle, SizeOf(WinTypes.TBitmap), @BmpInfo);
  Len := BmpInfo.bmWidthBytes;
  Len := Len * BmpInfo.bmHeight;
  Len := Len * BmpInfo.bmPlanes;
  BitData := MemAlloc(Len*2);
  GetBitmapBits( Bmp.Handle, Len, BitData );
  { Make Changes
    here is my example (it is not correct this is only example!) }
  for j:=1 to 10 do
  begin
    for i:=0 to Len-2 do
      LongArray(BitData^)[i] := LongArray(BitData^)[i+1];
    SetBitmapBits( Bmp.Handle, Len, BitData );
    Image1.Repaint;  { repaint Image1 }
  end;
  FreeMem(BitData, Len*2);
end;


I know that this is on GetBitmapBits but this is very fast.
0
 

Author Comment

by:csmikeb
ID: 1337296
Thanks Mirek, this has the potential to do what I want it to, although it will need adapting for different colour resolutions I think...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now