Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

Copy 2D array to 1D array and for-loop traversal

$
0
0
--- SORRY posted in WRONG PLACE ---
Please Move to Visual Basic 6 and earlier

In the app I am dedicated to (image processing) I make intensive use of 2D arrays of "singles" representing RGB values.
So to prcess them I am used to use 2 "for" loops in X and Y
Code:

For X = 0 to Width
For Y = 0 to Height

I wonder:
1) Instead of having 2 for cycles, would it be faster to have only one and operate like this:?
Single for-loop traversal over 2D/3D arrays

Code:

For I = 0 to (W+1)*(H+1)-1
            X = I Mod (W+1)
            Y = I \ (W+1)
            ...
Next I

2) Is it possible to (fast) copy the contents of a 2D array to a 1D array ?
For example like this ?
Code:

Private Declare Function vbaCopyBytes Lib "msvbvm60.dll" Alias "__vbaCopyBytes" (ByVal Length As Long, Dst As Long, Src As Long) As Long

vbaCopyBytes Size, ByVal VarPtr(Dest(0)), ByVal VarPtr(Src(0, 0))

where
Src is a 2D array of Singles and
Dest is a 1D array of Singles already correctly resized
and Size is the number of Bytes of the 2D array.


In short, the purpose is to speed up the traversal of 2D arrays.
If that of using a single loop was too little gain in speed maybe I could try transforming it to 1D.

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>