Any Other Image formats/Routines for supporting?

Everything else that doesn't fall into one of the other PB categories.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

All i can type is thank you. i went to a rock wall climbing gym for the first time today, and i can't move my fingers.

thank you!!!!

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

localmotion34 wrote:i went to a rock wall climbing gym for the first time today, and i can't move my fingers.
heheh :D

yeah i tried that. Also i was just having a hard session of weight lifting yesterday and my muscles are not too keen on being used
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

@thefool

FastImage routines:

Code: Select all

; Fast Image Routines

;- Procedures

Procedure CopyImageToMemory(ImageNo, Memory) 
  
  Protected TemporaryDC.l, TemporaryBitmap.BITMAP, TemporaryBitmapInfo.BITMAPINFO 
  
  TemporaryDC = CreateDC_("DISPLAY", #Null, #Null, #Null) 
  
  GetObject_(ImageID(ImageNo), SizeOf(BITMAP), TemporaryBitmap.BITMAP) 
  
  TemporaryBitmapInfo\bmiHeader\biSize        = SizeOf(BITMAPINFOHEADER) 
  TemporaryBitmapInfo\bmiHeader\biWidth       = TemporaryBitmap\bmWidth 
  TemporaryBitmapInfo\bmiHeader\biHeight      = -TemporaryBitmap\bmHeight 
  TemporaryBitmapInfo\bmiHeader\biPlanes      = 1
  TemporaryBitmapInfo\bmiHeader\biBitCount    = 32 
  TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB
  
  GetDIBits_(TemporaryDC, ImageID(ImageNo), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo, #DIB_RGB_COLORS)
  
  DeleteDC_(TemporaryDC) 
  
EndProcedure

Procedure CopyMemoryToImage(Memory, ImageNo) 
  
  Protected TemporaryDC.l, TemporaryBitmap.BITMAP, TemporaryBitmapInfo.BITMAPINFO 
  
  TemporaryDC = CreateDC_("DISPLAY", #Null, #Null, #Null) 
  
  GetObject_(ImageID(ImageNo), SizeOf(BITMAP), TemporaryBitmap.BITMAP) 
  
  TemporaryBitmapInfo\bmiHeader\biSize        = SizeOf(BITMAPINFOHEADER) 
  TemporaryBitmapInfo\bmiHeader\biWidth       = TemporaryBitmap\bmWidth 
  TemporaryBitmapInfo\bmiHeader\biHeight      = -TemporaryBitmap\bmHeight 
  TemporaryBitmapInfo\bmiHeader\biPlanes      = 1 
  TemporaryBitmapInfo\bmiHeader\biBitCount    = 32 
  TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB 
  
  SetDIBits_(TemporaryDC, ImageID(ImageNo), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo, #DIB_RGB_COLORS) 
  
  DeleteDC_(TemporaryDC) 
  
EndProcedure

Procedure SwapRGB(Color)
  
  ProcedureReturn ((Color & $FF) << 16) | (Color & $FF00) | ((Color & $FF0000) >> 16)
  
EndProcedure

;- Macros

Macro RGB(Red, Green, Blue)
  
  (((Blue << 8 + Green) << 8 ) + Red )
  
EndMacro 

Macro FastRed(Color)
  
  Color & 255
  
EndMacro 

Macro FastGreen(Color)
  
  (Color & 65535) >> 8
  
EndMacro 

Macro FastBlue(Color)
  
  (Color & 16777215) >> 16
  
EndMacro 

Macro FastPlot(x, y, Color)
  
  PokeL(*Memory + (x + ImageWidth * (y)) << 2, SwapRGB(Color))
  
EndMacro

Macro FastPoint(x, y)
  
  SwapRGB(PeekL(*Memory + (x + ImageWidth * (y)) << 2))
  
EndMacro
Kind regards,

Francis
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Thanks!
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re:

Post by MachineCode »

This standalone snippet doesn't seem to work anymore; I get square blocks of color in the converted image, in some places. Does it need something new since the latest PureBasic? (I know I can use the other Invert code in this thread, but I prefer to use this shorter code, and besides, I'm interested to know why it suddenly doesn't work anymore).

Code: Select all

ProcedureDLL imgm_InvertColors(image)
  ;Invert the colors
  hBmp=ImageID(image)

  If hBmp

    imageWidth=ImageWidth(image)
    imageHeight=ImageHeight(image)

    mem=AllocateMemory(imageWidth*imageHeight*4)
    bmi.myBITMAPINFO
    bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
    bmi\bmiHeader\biWidth = imageWidth
    bmi\bmiHeader\biHeight = imageHeight
    bmi\bmiHeader\biPlanes = 1
    bmi\bmiHeader\biBitCount = 32
    bmi\bmiHeader\biCompression = #BI_RGB

    hdc = StartDrawing(ImageOutput(image))
    Debug hdc
    GetDIBits_(hdc,hBmp,0,imageHeight,mem,bmi,#DIB_RGB_COLORS)

    *pixels.LONG = mem
    For A = 1 To imageWidth*(imageHeight)
      *pixels\l - *pixels\l - *pixels\l
      *pixels + 4
    Next A

  SetDIBits_(hdc,hBmp,0,imageHeight,mem,bmi,#DIB_RGB_COLORS) ;<> 0
  StopDrawing()
  ProcedureReturn 1
EndIf

EndProcedure
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Any Other Image formats/Routines for supporting?

Post by c4s »

You don't need those old hacks anymore!

First of all because Point()/Plot() got a lot faster in PB 4.40(?), and second because you can use DrawingBuffer() for direct access to the image pixels.


To answer your question: I think it doesn't work anymore because of this: http://www.purebasic.fr/blog/?p=196
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Post Reply