Android Question Anaglyph 3D Image - Replace only Red component of Pixels

I am working on a project of showing 3D images where we have two images one for left eye and another for right eye. For those who don't have VR devices, I am planning the show the image as Anaglyph images, where Right eye Red is replaced with Left Eye Red.

It works great. However, the For Next loop which goes through each pixel to get RGB from Left image and set RGB in Right Image takes minimum 10 seconds for an image of 1920 by 1080 pixels.

Any suggestions please?

B4X:
    Dim Bc As BitmapCreator
    Dim bcleft As BitmapCreator
    Dim bcright As BitmapCreator
    Dim bmp As B4XBitmap = xui.LoadBitmap(File.DirAssets, "fractal0001.jpg")
    Dim nWidth As Int
    Dim nHalf As Int
    Dim r As B4XRect
    Dim i As Int = 0
    Dim j As Int = 0
    Dim leftrgb As ARGBColor
    Dim rightrgb As ARGBColor
    Dim nHeight As Int = bmp.Height
  
    nWidth = bmp.Width
    nHalf = nWidth / 2
    Bc.Initialize( nHalf, nHeight )
    bcleft.Initialize(nHalf, nHeight )
    bcright.Initialize( nHalf, nHeight)
    Dim right1 As BCBrush = Bc.CreateBrushFromBitmap(bmp.Crop(nHalf, 0, nHalf, nHeight))
    Dim left1 As BCBrush = Bc.CreateBrushFromBitmap(bmp.Crop(0, 0, nHalf, nHeight))
    r.Initialize(0,0,nHalf, nHeight )
    bcleft.DrawRect2( r, left1, True,1)
    bcright.DrawRect2( r, right1, True, 1 )
    For i = 0 To nHalf - 1
        For j = 0 To nHeight - 1
            bcleft.GetARGB( i,j,leftrgb )
            bcright.GetARGB( i, j, rightrgb)
            rightrgb.r = leftrgb.r
            bcright.SetARGB( i, j, rightrgb )
        Next
    Next
    Return FillImageToView( bcright.Bitmap,Root)
 
Thanks a lot for your attention @Erel. I have never seen an admin answering to a new member for his first post!

No. I am testing in Debug mode only.

The original image is 1920 X 540. It contains two images as a tile. Left half is for left eye and right half is for right eye. So, effectively the image is 960 x 540 and when shown in full screen of 1920 x 1080 it looks good. It is already down sized.

So, the answer for your question is nHeight when logged it shows 540. nHalf is 960.

For your kind information, I have tried getPixels and setPixels from the forum. It does the job fast.

But getting the RGB value from the array of pixels in colorint using sub getARGB as mentioned here takes much time for each pixel. I am wondering, when xui.Color_ARGB method is so fast in converting ARGB to colorint, why the reverse (converting from colorint to ARGB) takes this much time.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top