February 27, 2021, 03:44:25 AM

Author Topic: [bmx] PNG Header by FlameDuck [ 1+ years ago ]  (Read 627 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] PNG Header by FlameDuck [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : PNG Header
Author : FlameDuck
Posted : 1+ years ago

Description : Provides methods to determine if a given file is a PNG file, and which dimensions it has without loading the entire file into memory.

Code :
Code: BlitzMax
  1. Strict
  2.  
  3. Import BRL.Stream
  4. Import BRL.EndianStream
  5.  
  6. Type PNGHeader
  7.  
  8.         Field signiture:String
  9.         Field chunksize:Int
  10.         Field chunkID:String
  11.         Field width:Int
  12.         Field height:Int
  13.         Const PNG_ID:String = Chr($89) + Chr($50) + Chr($4E) + Chr($47) + Chr($0D) + Chr($0A) + Chr($1A) + Chr($0A)
  14.  
  15.         Function fromFile:PNGHeader( url:Object )
  16.                 Local myStream:TStream = ReadStream( url )
  17.                 Local temp:PNGHeader
  18.                 If StreamSize (myStream) > 24
  19.                         temp = New PNGHeader
  20.                         Local eStream:TStream = BigEndianStream(myStream)
  21.                         temp.signiture = ReadString (eStream , 8)
  22.                         temp.chunksize = Readint (eStream)
  23.                         temp.chunkID = ReadString (eStream , 4)
  24.                         temp.width = Readint (eStream)
  25.                         temp.height = Readint (eStream)
  26.                         CloseStream eStream
  27.                 EndIf
  28.                 CloseStream myStream
  29.                 Return temp
  30.         EndFunction    
  31.  
  32.         Method isPNG:Int()
  33.                 If signiture = PNG_ID
  34.                         Return True
  35.                 EndIf
  36.                 Return False
  37.         EndMethod
  38.        
  39.         Method toString:String()
  40.                 Local temp:String = "isPng: "
  41.                 If isPNG()
  42.                         temp:+"True "
  43.                 Else
  44.                         temp:+"False "
  45.                 EndIf
  46.                 temp:+"Width: " + width + " Height: " + height
  47.                
  48.                 Return temp
  49.         EndMethod
  50. EndType


Comments :


VP(Posted 1+ years ago)

 This would be for max, rather than b3d ;)


VP(Posted 1+ years ago)

 Ignore me, I've got a cold.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal