Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ON ERROR question
#6
(08-16-2024, 09:38 PM)Pete Wrote:
Code: (Select All)
Dim Shared erh As Integer
i = -1
pete = IMG_ColorDepth%(i)
Print pete

handler:
erh = Err
Resume Next
Function IMG_ColorDepth% (i As Long)
    '+------------------------------------------------+
    '| Returns the color depth of an image passed in. |
    '|                                                |
    '| i - the image handle                          |
    '|                                                |
    '| Returns:  0 : not an image                    |
    '|          32 : 32 bit color image              |
    '|          256 : 256 color image                |
    '|          16 : 16 color image (or text only)  |
    '|                                                |
    '| Note: this function will fail if an image      |
    '|      handle value passed in is less than -1  |
    '|      but does not belong to an actual image.  |
    '+------------------------------------------------+
    Dim c As Integer ' color counter
    Dim p As Integer ' palette counter
    On Error GoTo handler
    If _PixelSize(i) = 4 Then '                                  4 bytes per pixel?
        If erh Then i = 0: Exit Function
        IMG_ColorDepth% = 32 '                                    yes, 32 bit color image
    Else '                                                        no, 1 byte per pixel
        p = 0 '                                                  reset palette counter
        c = 0 '                                                  reset color counter
        Do '                                                      begin palette search
            If _PaletteColor(p, i) <> &HFF000000 Then c = c + 1 ' increment color counter if color found
            p = p + 1 '                                          increment palette counter
        Loop Until p = 256 '                                      leave when entire palette searched
        If c <= 16 Then '                                        16 colors or less?
            IMG_ColorDepth% = 16 '                                yes, 16 color image
        Else '                                                    no, greater than 16
            IMG_ColorDepth% = 256 '                              256 color image
        End If
    End If
End Function

So i starts in at -1, triggers the error, exits as 0.

Edit: To turn the call to handler off at some point, just place: ON ERROR GOTO 0 in the program flow.

Pete
Oh I completely understand how to implement this like you showed. The problem is the function above is a .BM library file.

My code would error out when:

'$INCLUDE:'.\lib\image\LIB_IMG_Contrast.BM'
'$INCLUDE:'.\lib\image\LIB_IMG_ColorDepth.BM'

The code outside of the function in the second .BM file will trigger an error. I could create an accompanying .BI file that contains the code outside. I'll experiment with that.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
ON ERROR question - by TerryRitchie - 08-16-2024, 07:16 PM
RE: ON ERROR question - by RhoSigma - 08-16-2024, 07:51 PM
RE: ON ERROR question - by Pete - 08-16-2024, 08:29 PM
RE: ON ERROR question - by TerryRitchie - 08-16-2024, 09:16 PM
RE: ON ERROR question - by Pete - 08-16-2024, 09:38 PM
RE: ON ERROR question - by TerryRitchie - 08-16-2024, 09:43 PM
RE: ON ERROR question - by Pete - 08-16-2024, 09:54 PM
RE: ON ERROR question - by TerryRitchie - 08-16-2024, 10:00 PM
RE: ON ERROR question - by Pete - 08-16-2024, 10:19 PM
RE: ON ERROR question - by SMcNeill - 08-16-2024, 10:41 PM
RE: ON ERROR question - by RhoSigma - 08-16-2024, 10:58 PM
RE: ON ERROR question - by TerryRitchie - 08-17-2024, 02:53 AM
RE: ON ERROR question - by RhoSigma - 08-17-2024, 02:10 PM
RE: ON ERROR question - by TerryRitchie - 08-17-2024, 06:59 PM
RE: ON ERROR question - by Pete - 08-16-2024, 11:23 PM
RE: ON ERROR question - by Pete - 08-17-2024, 04:24 AM
RE: ON ERROR question - by luke - 08-17-2024, 11:58 AM
RE: ON ERROR question - by eoredson - 09-02-2024, 04:39 AM
RE: ON ERROR question - by Pete - 08-19-2024, 03:15 AM



Users browsing this thread: 3 Guest(s)