2
0
Эх сурвалжийг харах

Added PNM image loader. Resolves #7.

Brucey 3 жил өмнө
parent
commit
8b1c1d7474

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

@@ -0,0 +1,53 @@
+SuperStrict
+
+Framework SDL.SDLRenderMax2D
+Import Image.PNM
+
+Local w:Int = DesktopWidth() * .75
+Local h:Int = DeskTopHeight() * .75
+
+Graphics w, h, 0
+
+AutoMidHandle(True)
+
+Local img1:TImage = Loader("rays2.pnm", w, h)
+Local img2:TImage = Loader("snail2.pnm", 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
+

BIN
pnm.mod/examples/rays2.pnm


BIN
pnm.mod/examples/snail2.pnm


+ 29 - 0
pnm.mod/pnm.bmx

@@ -0,0 +1,29 @@
+' 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/PNM loader
+about:
+The PNM loader module provides the ability to load PNM format #pixmaps.
+End Rem
+Module Image.PNM
+
+Import Image.STB
+