-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.monkey
73 lines (58 loc) · 1.58 KB
/
header.monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Strict
Public
' Imports (Public):
Import config
' Imports (Private):
Private
Import util
Public
' Classes:
' The contents of an IHDR chunk; PNG header information.
Class PNGHeader Implements PNGEntity Final
' Methods:
Method Read:Void(input:Stream)
Self.width = input.ReadInt()
Self.height = input.ReadInt()
Self.depth = input.ReadByte()
Self.color_type = input.ReadByte()
Self.compression_method = input.ReadByte()
Self.filter_method = input.ReadByte()
Self.interlace_method = input.ReadByte()
End
' Properties:
' This specifies the accumulative color-depth of a pixel.
' For bits-per-pixel, use the 'depth' field.
Method TotalDepth:Int() Property
Return (depth * ColorChannels)
End
' This specifies how many bytes are needed to store a pixel.
Method ByteDepth:Int() Property ' PixelLength
Return BitDepthInBytes(TotalDepth)
End
' This specifies how many bytes are required to store a line of pixels.
Method LineLength:Int() Property
Return BitDepthInBytes((depth * ColorChannels) * width) ' (width * ByteDepth)
End
Method ColorChannels:Int() Property
Select (color_type)
Case PNG_COLOR_TYPE_GRAYSCALE
Return 1
Case PNG_COLOR_TYPE_TRUECOLOR
Return 3
Case PNG_COLOR_TYPE_INDEXED
Return 1
Case PNG_COLOR_TYPE_GRAYSCALE_ALPHA
Return 2
Case PNG_COLOR_TYPE_TRUECOLOR_ALPHA
Return 4
End Select
Return 0
End
' Fields:
Field width:Int, height:Int ' UInt, UInt
Field depth:Int ' Byte
Field color_type:Int ' Byte
Field compression_method:Int ' Byte
Field filter_method:Int ' Byte
Field interlace_method:Int ' Byte
End