瀏覽代碼

Added GIF image loader. Resolves #6.

Brucey 3 年之前
父節點
當前提交
86ed1c70a9
共有 4 個文件被更改,包括 81 次插入0 次删除
  1. 二進制
      gif.mod/examples/bali.gif
  2. 53 0
      gif.mod/examples/example_01.bmx
  3. 二進制
      gif.mod/examples/fractal_tree.gif
  4. 28 0
      gif.mod/gif.bmx

二進制
gif.mod/examples/bali.gif


+ 53 - 0
gif.mod/examples/example_01.bmx

@@ -0,0 +1,53 @@
+SuperStrict
+
+Framework SDL.SDLRenderMax2D
+Import Image.GIF
+
+Local w:Int = DesktopWidth() * .75
+Local h:Int = DeskTopHeight() * .75
+
+Graphics w, h, 0
+
+AutoMidHandle(True)
+
+Local img1:TImage = Loader("bali.gif", w, h)
+Local img2:TImage = Loader("fractal_tree.gif", w, h)
+
+If Not img1 Or Not img2 Then
+	Print "Failed to load image"
+	End
+End If
+
+Local image:Int
+Local img:TImage = img1
+
+While Not KeyDown(Key_ESCAPE)
+
+	Cls
+
+	If KeyHit(KEY_SPACE) Then
+		image = Not image
+		If image Then
+			img = img2
+		Else
+			img = img1
+		End If
+	End If
+
+	DrawImage img, w / 2, h / 2
+
+	Flip
+
+Wend
+
+Function Loader:TImage(path:String, maxWidth:Int, maxHeight:Int)
+	Local pix:TPixmap = LoadPixmap( path )
+	If pix Then
+		If pix.width > maxWidth Or pix.height > maxHeight Then
+			Local ratio:Float = Min(maxWidth / Float(pix.width), maxHeight / Float(pix.height))
+			pix = ResizePixmap(pix, Int(pix.width * ratio), Int(pix.height * ratio))
+		End If
+		Return LoadImage(pix)
+	End If
+End Function
+

二進制
gif.mod/examples/fractal_tree.gif


+ 28 - 0
gif.mod/gif.bmx

@@ -0,0 +1,28 @@
+' Copyright (c) 2022 Bruce A Henderson
+' 
+' This software is provided 'as-is', without any express or implied
+' warranty. In no event will the authors be held liable for any damages
+' arising from the use of this software.
+' 
+' Permission is granted to anyone to use this software for any purpose,
+' including commercial applications, and to alter it and redistribute it
+' freely, subject to the following restrictions:
+' 
+' 1. The origin of this software must not be misrepresented; you must not
+'    claim that you wrote the original software. If you use this software
+'    in a product, an acknowledgment in the product documentation would be
+'    appreciated but is not required.
+' 2. Altered source versions must be plainly marked as such, and must not be
+'    misrepresented as being the original software.
+' 3. This notice may not be removed or altered from any source distribution.
+' 
+SuperStrict
+
+Rem
+bbdoc: Image/GIF loader
+about:
+The GIF loader module provides the ability to load GIF format #pixmaps.
+End Rem
+Module Image.GIF
+
+Import Image.Stb