Board index » delphi » Access an array of trgbtriple like bitmap by scanline
?
![]() Delphi Developer |
Thu, 19 Jun 2003 03:27:06 GMT
|
?
![]() Delphi Developer |
Thu, 19 Jun 2003 03:27:06 GMT
Access an array of trgbtriple like bitmap by scanline
Hi all ,
My question is : Can i access with a pointer the rows of a N x M array in a similar way like i do using scanline with bitmaps : For example when handling bitmaps i write something like : procedure modifybitmap(var bitmap:tbitmap); how can i do the same for an array of integer or any other type (trgbtriple |
Earl F. Glyn
![]() Delphi Developer |
Thu, 19 Jun 2003 05:41:00 GMT
Re:Access an array of trgbtriple like bitmap by scanlineHi, Francescosava: Sorry for first sending this by private E-mail. I hit "Reply" instead of Quote> My question is : Can i access with a pointer the rows of a N x M array in a a TBitmap as a 2D array and store objects other than pixels in each array element? Using pf24bit will not work well, since you have an array of The "Raw Image" in this Lab Report shows how to use a pf32bit The "Raw Image" in this Lab Report shows how to use a pf32bit A pf32bit TBitmap can be used like a 2D Matrix of 4-byte values, If this didn't answer your question, feel free to clarify Find other details of working with Scanline here: Happy New Year, -- Earl F. Glynn E-mail: e...@efg2.com efg's Computer Lab: http://www.efg2.com/Lab |
Peter Haa
![]() Delphi Developer |
Thu, 19 Jun 2003 07:03:48 GMT
Re:Access an array of trgbtriple like bitmap by scanlineHi Francesco?, ? schrieb in <92lec6$6...@bornews.inprise.com>: Quote> My question is : Can i access with a pointer the rows of a N x M array in a Note, that the compiler generate code for calculation the adress of a Preparing (for 24 bit): var function GetPixelAdress(X, Y : Integer): PRGBTriple; Please note, LineSize is negativ in the most cases (Bottom-Top-Bitmaps). This is a rational method for a random access of the pixels, similar to In your example you use a sequential access. You can optimize the procedure ModifyBitmap(var Bitmap: TBitmap); LineStart := PByte(FirstLine); By Peter. I wish all a happy new millenium. |
ยค
![]() Delphi Developer |
Thu, 19 Jun 2003 08:17:44 GMT
Re:Access an array of trgbtriple like bitmap by scanlineQuote> I'm not sure I understand your question. Are you trying to use I want to use a 2D array in which i want to store trgbtriple or bytes values (taking them from a bitmap of course ) , but i want fast access to this array like i have with bitmap.scanline . The problem is this : i want to put in a 2d array a copy of a bitmap because i want to use it as a "brush" to paint in my photoretouch program . I have already done this but i 'm convinced that accessing each element of the array ( ex. brusharray[i,j] ) is slower than if i could have a pointer to each row of the array (like scanline) and then accessing each element of the row ( example Prow[i] ) . In other words what i'm questioning is if there is a way to access 2D array values using pointers ( note that i'm able to do it with a 1D array ) . Please do not hesitate to tell me if neither now my question is clear enough . Thx , Francesco , Happy Millennium . |
Jens Grusche
![]() Delphi Developer |
Thu, 19 Jun 2003 09:36:26 GMT
Re:Access an array of trgbtriple like bitmap by scanlineI don't think accessing an array is slower, at least if you use powers of 2 (2,4,8,16...) as "width" of your array. Of course you can store a pointer to each row of the array, too: Var But I do not quite understand why you use an 2dim array instead of a Type The disadvantage of this: you need some extra space to store some Var Okay, you are right, that one's very similar to the code you posted. Oh... one more thing: I have not tested the code. If you have problems Jens |
<francescos..
![]() Delphi Developer |
Thu, 19 Jun 2003 21:05:50 GMT
Re:Access an array of trgbtriple like bitmap by scanlineQuoteJens Gruschel <j...@pegtop.de> wrote in message Quote> I don't think accessing an array is slower, at least if you use powers Quote> But I do not quite understand why you use an 2dim array instead of a So i think it's better to save the values to a 2d array the first time i load the bitmap and then read the array (faster) instead of the bitmap (slower ? !) . I need any speed that is possible to read the brush gray values because i'm painting (and showing in real time ) with the brush on an other bitmap ! From other side i thought that reading the elements of the brush array in the standard way ( grayvalue:=brusharray[i , j] ) was slower than having many pointers that point to each j row of the array and access the elements of that row by prow[ i ] . Francesco |
Jens Grusche
![]() Delphi Developer |
Sun, 29 Jun 2003 08:33:55 GMT
Re:Access an array of trgbtriple like bitmap by scanlineQuote> I don't need to modify the brush bitmap but only to read its values once : grayvalue:=brusharray[x,y] is slower, because to access the element, Delphi has to calculate y * ElelmentsPerRow + x. If you use a pointer to each row, Delphi just has to calculate RowPointer[y] + x. Using powers of 2 should also be a solution, because y SHL 8 + x is much faster than y * 256 + x and does the same. Delphi optimizes * to SHL automatically if you multiply by a power of 2 (only constants of course). But I really think if you use a bitmap and scanline, it should be about as fast as the array technique, especially if you store the scanlines in an array first. Jens |
<francescos..
![]() Delphi Developer |
Sun, 29 Jun 2003 17:18:21 GMT
Re:Access an array of trgbtriple like bitmap by scanlineQuoteJens Gruschel <j...@pegtop.de> wrote in message Quote> > I don't need to modify the brush bitmap but only to read its values once |