Skip to content

Commit f9b38d4

Browse files
committed
Reject input image with incorrect dimensions - everything gets screwy and I don't want to deal with it
1 parent 51fcb2e commit f9b38d4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Types/GraphicsOutput.bmx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ Type GraphicsOutput
3838
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3939

4040
Method LoadFile:Int(fileToLoad:String)
41-
m_SourceImage = LoadImage(fileToLoad, 0)
42-
43-
If m_SourceImage <> Null Then
44-
m_SourceImageSize = New SVec2I(m_SourceImage.Width, m_SourceImage.Height)
45-
DrawImageRect(m_SourceImage, 0, 0, m_SourceImageSize[0] * m_InputZoom, m_SourceImageSize[1] * m_InputZoom) 'Draw the source image to the backbuffer so limb tiles can be created
46-
m_LimbManager.CreateLimbParts(m_InputZoom, m_TileSize)
47-
Return True
41+
Local loadedImage:TImage = LoadImage(fileToLoad, 0)
42+
43+
If loadedImage <> Null Then
44+
If loadedImage.Width = 192 And loadedImage.Height = 24 Then
45+
m_SourceImage = loadedImage
46+
m_SourceImageSize = New SVec2I(m_SourceImage.Width, m_SourceImage.Height)
47+
DrawImageRect(m_SourceImage, 0, 0, m_SourceImageSize[0] * m_InputZoom, m_SourceImageSize[1] * m_InputZoom) 'Draw the source image to the backbuffer so limb tiles can be created
48+
m_LimbManager.CreateLimbParts(m_InputZoom, m_TileSize)
49+
Return True
50+
Else
51+
Notify("Attempting to load image with incorrect dimensions!~n~nMake sure the dimensions are exactly 192x24px!~nUse ~qInputTemplate~q for reference.", True)
52+
EndIf
4853
EndIf
4954
Return False
5055
EndMethod

Types/IndexedImageWriter.bmx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ Type IndexedImageWriter
158158
Local convertingPixmap:IndexedPixmap = New IndexedPixmap(sourcePixmap.Width, sourcePixmap.Height)
159159
For Local pixelY:Int = 0 Until sourcePixmap.Height
160160
For Local pixelX:Int = 0 Until sourcePixmap.Width
161-
'Convert the 32bit RGBA color value from the source pixmap to a 8bit index value and write it to the converting bitmap
161+
'Convert the 32bit RGBA color value from the source pixmap to a 8bit index value and write it to the converting pixmap
162162
convertingPixmap.WritePixel(pixelX, pixelY, ConvertColorToClosestIndex(ReadPixel(sourcePixmap, pixelX, pixelY)))
163163
Next
164164
Next
165165

166166
Local rows:Byte Ptr[sourcePixmap.Height]
167167
For Local i = 0 Until sourcePixmap.Height
168-
rows[i] = convertingPixmap.PixelPtr(0, i) 'Get row pointers from the converting bitmap (1 byte aligned so won't be spaghettified)
168+
rows[i] = convertingPixmap.PixelPtr(0, i) 'Get row pointers from the converting pixmap (1 byte aligned so won't be spaghettified)
169169
Next
170170
png_set_rows(pngPtr, pngInfoPtr, rows)
171171

0 commit comments

Comments
 (0)