see these 'for' loop:

Public Function SetTransparentColor(color As Long)
    Dim X As Integer
    Dim Y As Integer
    Dim c As Long
    Dim h As Long
    Dim w As Long
    Dim temp As BGRAQUAD ' substitua BGRColor pelo tipo de dado correto usado em bDibBGRA


    h = Height - 1
    w = Width - 1


    For c = 0 To h * w ' movendo as operações fora do loop for
        X = c Mod (w + 1)
        Y = Int(c / (w + 1))
        temp = bDibBGRA(c)


        ' modificando apenas a propriedade necessária
        If (RGB(temp.B, temp.G, temp.R) = color) Then
            temp.B = 255
            bDibBGRA(c) = temp
        End If


Next c


End Function

even i comment all the code, inside the 'for', i lose more than 50% of performance\optimization :(
in these case the image is 330X330.

  1. Line 15 calculates X but I don't see where X is used.
  2. Same for line 16 and Y.
  3. The function or possibly array bDibBGRA is not native to VB6 so I can't tell what you are doing on lines 17 and 23
  4. Why is optimizing needed today? That is this would run in a split second on the usual hardware we have at the office.
  5. You never explained what this code's purpose is so it's a roll of the dice if I could optimize it.
  6. VB6. It's dead. Move on.

i need optimization, because i only have 200FPS for change 1 color.. these is a test for change the Alpha values... i can share all code

commented: The code provided shows it is not optimized. See my comments. +17

I don't know what it is you are trying to do but is it possible to use ffmpeg to do the changes? If you can tell us what your intentions are perhaps I can suggest an ffmpeg command line that will do it.

commented: "Open command line." Today's users hate that? +17

To improve the performance of your code, have a look at the following code - keep in mind that this code has been dead for 20 years+... To get overall performance you will have to start looking at switching over to new standards or your code will keep on lagging in performance...

Public Function SetTransparentColor(color As Long)
    Dim X As Integer
    Dim Y As Integer
    Dim c As Long
    Dim h As Long
    Dim w As Long
    Dim temp As BGRAQUAD ' I am guessing that 'BGRAQUAD' is a structure type for your image data...

    h = Height - 1
    w = Width - 1

    'Move your operations outside the loop if they are not dependent on the loop variable to improve performance...
    For c = 0 To h * w
        X = c Mod (w + 1)
        Y = Int(c / (w + 1))
        temp = bDibBGRA(c)

        'Here you need to use a faster comparison without converting to RGB...
        If (temp.R + (temp.G * 256) + (temp.B * 65536) = color) Then
            'Set your blue channel to 255 I am guessing you want to make it transparent...)
            temp.B = 255
            'Update the pixel in the array...
            bDibBGRA(c) = temp
        End If
    Next c
End Function

The steps taken is -

  1. Instead of converting temp to RGB for each comparison, compare the individual color channels.

  2. If you are doing calculations that do not depend on your loop variable, it is better to perform them outside the loop to reduce redundant computations.

  3. You need to access the color channels directly for comparison and modification.

  4. This should be a pointer in the right direction...

"Open command line." Today's users hate that?

Could always use something like Handbrake which is basically a GUI built on top of ffmpeg.

commented: Still old tech that we are trying to support, the OP really need to look at moving on in life to increase what he needs to achieve... +15
commented: +1 +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.