Seite 1 von 2

Problem mit dem Handle von images bei 32 Bit images

Verfasst: 28.04.2009 17:34
von Dostej
Hallo

Ich habe folgenden Code aus einem anderen Beispiel aus dem (englischen?) Forum zusammengestöpselt.
Er vergleicht 2 Bilder, die mit PB erstellt wurden, indem er den Bilderspeicher per CompareMemory bergleicht.

Seltsamerweise geht das mit 24-bit Bildern, nicht aber mit 32 bit Bildern?
(BITMAP)\bmBits gibt dann immer 0 zurück.

Kann mir jemand sagen warum? Und wie man das mit 32 bit Images zu laufen bekommt?

Vielen Dank schon mal...

Code: Alles auswählen

Procedure.i CompareImage(Image1, Image2) ; compares two images  - returns -1: error  0: identically   1: different size   2: different content
  Back_I.i = -1
  Protected bmp1.BITMAP, bmp2.BITMAP, Size1, Size2, *Memory1, *Memory2
  
  If GetObject_(Image1, SizeOf(BITMAP), @bmp1) 
    Size1 = (bmp1\bmWidth * bmp1\bmHeight)
    *Memory1 = bmp1\bmBits 
    Debug *Memory1
    If GetObject_(Image2, SizeOf(BITMAP), @bmp2) 
      Size2 = (bmp2\bmWidth * bmp2\bmHeight)
      *Memory2 = bmp2\bmBits 
      Debug *Memory2
      If Size1 <> Size2
        Back_I = 1
      Else
        If CompareMemory(*Memory1, *Memory2, Size1) = 1 ; identically
          Back_I = 0
        Else
          Back_I = 2
        EndIf
      EndIf
    EndIf
  EndIf 
  
  ProcedureReturn Back_I
EndProcedure


CreateImage(1, 128, 128, 24)
CreateImage(2, 128, 128, 24)
CreateImage(3, 128, 128, 24)

; try this insted, it wont work
; CreateImage(1, 128, 128)
; CreateImage(2, 128, 128)
; CreateImage(3, 128, 128)

If StartDrawing(ImageOutput(1))
    Box(0, 0, 128, 128, $000002)
  StopDrawing()
EndIf

If StartDrawing(ImageOutput(2))
    Box(0, 0, 128, 128, $000002)
  StopDrawing()
EndIf

If StartDrawing(ImageOutput(3))
    Box(0, 0, 128, 128, $000001)
  StopDrawing()
EndIf
Debug CompareImage(ImageID(1), ImageID(2))
Debug CompareImage(ImageID(1), ImageID(3))


End



Re: Problem mit dem Handle von images bei 32 Bit images

Verfasst: 28.04.2009 18:06
von Fluid Byte
Dostej hat geschrieben:Kann mir jemand sagen warum? Und wie man das mit 32 bit Images zu laufen bekommt?
Ja, RTFM. <)
If 'Depth' is omitted or set to #PB_Image_DisplayFormat, the image format is taken from the desktop format. Valid 'Depth' values can be: 1, 2, 4, 8, 16, 24 and 32 bits. When manipulating true colors formats, and want save back the modifications without color information loss, it's advised to use the 24 or 32 bits values. If the images are only used for displaying on the screen, #PB_Image_DisplayFormat will provide faster performances.
Du musst die Bittiefe explizit angeben damit es für 32-Bit funktioniert.

Verfasst: 28.04.2009 20:13
von Dostej
@Fluidbyte

Das mit dem Manual habe ich schon gelesen... bin aber nicht schau draus geworden, was das damit zu tun hat...

Hm, ehrlich gesagt komm ich leider immer noch nicht draus, warum das in dem Beispiel mit GetObject nicht geht...

Verfasst: 28.04.2009 20:34
von Fluid Byte
Wo ist jetzt das Problem? Du erstellst das Image mit CreateImage(1, 128, 128, 32) und gut ist.

Verfasst: 29.04.2009 09:01
von Dostej
Jetzt hab ichs... klasssicher Fall von aneinander vorbei...

Ich hab kein Problem damit, wie ich Bilder mit 32 bit erstelle. Da bei mir 32 Standard eingestellt ist, macht auch createimage(0, 100, 100) 32 bit-images.

Mein Problem ist, das der Beispielcode, den ich angefügt habe, mit 24-bit images läuft, wenn ich aber den gleichen Code mit 32-bit images laufen lassen, bringt
BITMAP\bmBits immer nur 0 <- das ist mein Problem (nicht wie ich 32 bit images erstelle :lol: )

Dazu hätte ich gerne ne Hilfe

Verfasst: 29.04.2009 09:39
von alter Mann
änder mal

Code: Alles auswählen

Box(0, 0, 128, 128, $000002)
in

Code: Alles auswählen

Box(0, 0, 127, 127, $000002) 
aber frag mich nicht warum der Speicher anders belegt ist, wenn man über den Imagerand zeichnet

Verfasst: 29.04.2009 09:51
von dige
Sehr merkwürdig! Hier gehts auch nicht, obwohl das Display mit 32Bit Farbtiefe läuft, scheint ein Bild das mit #PB_Image_DisplayFormat erstellt
wird, nicht das gleiche zu sein. Da muss Fred irgendwas vergessen haben..

Was meint Ihr - Eintrag in BugSection?

Verfasst: 29.04.2009 10:15
von dige
Ich poste mal folgenden Code im englischen Forum:

Code: Alles auswählen

; No Pointer to DIB-Section available for Images created with #PB_Image_DisplayFormat

Procedure.l GetDIBSection (ImgID.i)
  If GetObject_(ImageID(ImgID), SizeOf(DIBSECTION), ds.DIBSECTION )
    Debug ""
    Debug "Image Nr: " + Str(ImgID) 
    Debug "Width x Height: " + StrU(ds\dsBm\bmWidth, #PB_Long) + ", " + StrU(ds\dsBm\bmHeight, #PB_Long)
    Debug "BitsPixel: " + Hex(ds\dsBm\bmBitsPixel)
    Debug "ImageSize: " + StrU(ds\dsBmih\biSizeImage, #PB_Long)
    Debug "-> BitmapPixel Location: " + Hex(ds\dsBm\bmBits)
  EndIf
EndProcedure

If ExamineDesktops()
  Debug "DesktopDepth  : " + Str(DesktopDepth(0))
EndIf

CreateImage(1, 64, 64, 24)
CreateImage(2, 64, 64, 32)
CreateImage(3, 64, 64, #PB_Image_DisplayFormat)

Debug "ImageDepth 1: " + Str(ImageDepth(1)) + " bit"
Debug "ImageDepth 2: " + Str(ImageDepth(2)) + " bit"
Debug "ImageDepth 3: " + Str(ImageDepth(3)) + " bit"

GetDIBSection(1)
GetDIBSection(2)
GetDIBSection(3)

Verfasst: 29.04.2009 21:32
von Dostej
@ old man

Geht beimir trotzdem nicht.

@dige

hab den Thread im engl. Forum gesehen. Thx. Mal sehn was da kommt.

Verfasst: 29.04.2009 22:18
von alter Mann
bei mir ergibt

Code: Alles auswählen

Procedure.i CompareImage(Image1, Image2) ; compares two images  - returns -1: error  0: identically   1: different size   2: different content
  Back_I.i = -1
  Protected bmp1.BITMAP, bmp2.BITMAP, Size1, Size2, *Memory1, *Memory2
 
  If GetObject_(Image1, SizeOf(BITMAP), @bmp1)
    Size1 = (bmp1\bmWidth * bmp1\bmHeight)
    *Memory1 = bmp1\bmBits
    Debug *Memory1
    If GetObject_(Image2, SizeOf(BITMAP), @bmp2)
      Size2 = (bmp2\bmWidth * bmp2\bmHeight)
      *Memory2 = bmp2\bmBits
      Debug *Memory2
      If Size1 <> Size2
        Back_I = 1
      Else
        If CompareMemory(*Memory1, *Memory2, Size1) = 1 ; identically
          Back_I = 0
        Else
          Back_I = 2
        EndIf
      EndIf
    EndIf
  EndIf
 
  ProcedureReturn Back_I
EndProcedure


CreateImage(1, 128, 128, 32)
CreateImage(2, 128, 128, 32)
CreateImage(3, 128, 128, 32)

; try this insted, it wont work
; CreateImage(1, 128, 128)
; CreateImage(2, 128, 128)
; CreateImage(3, 128, 128)

If StartDrawing(ImageOutput(1))
    Box(0, 0, 127, 127, $000002)
  StopDrawing()
EndIf

If StartDrawing(ImageOutput(2))
    Box(0, 0, 127, 127, $000002)
  StopDrawing()
EndIf

If StartDrawing(ImageOutput(3))
    Box(0, 0, 127, 127, $000001)
  StopDrawing()
EndIf
Debug CompareImage(ImageID(1), ImageID(2))
Debug CompareImage(ImageID(1), ImageID(3))

End
in der Debugger-Ausgabe

3932160
3997696
0
3932160
4063232
2