-
Notifications
You must be signed in to change notification settings - Fork 10
/
IconImage.php
131 lines (114 loc) · 2.79 KB
/
IconImage.php
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
namespace Elphin\IcoFileLoader;
/**
* Holds data on an image within an Icon
*/
class IconImage
{
/**
* @var integer Width, in pixels, of the image
*/
public $width;
/**
* @var integer Height, in pixels, of the image
*/
public $height;
/**
* @var integer Number of colors in image
*/
public $colorCount;
/**
* @var integer Reserved ( must be 0)
*/
public $reserved;
/**
* @var integer Color Planes
*/
public $planes;
/**
* @var integer bits per pixel
*/
public $bitCount;
/**
* @var integer How many bytes in this resource?
*/
public $sizeInBytes;
/**
* @var integer Where in the file is this image?
*/
public $fileOffset;
/**
* @var integer size of BITMAPINFOHEADER structure
*/
public $bmpHeaderSize;
/**
* @var integer image width from BITMAPINFOHEADER
*/
public $bmpHeaderWidth;
/**
* @var integer image height from BITMAPINFOHEADER
*/
public $bmpHeaderHeight;
/**
* @var string PNG file for icon images which use PNG
*/
public $pngData = null;
/**
* @var string BMP bitmap data for images which use BMP
*/
public $bmpData = null;
public $palette = [];
/**
* IconEntry constructor.
* @param array $data array of data extracted from a ICONDIRENTRY binary structure
*/
public function __construct($data)
{
foreach ($data as $name => $value) {
$this->$name = $value;
}
}
public function getDescription()
{
return sprintf(
'%dx%d pixel %s @ %d bits/pixel',
$this->width,
$this->height,
$this->isPng() ? 'PNG' : 'BMP',
$this->bitCount
);
}
/**
* Stores binary PNG file for the icon
* @param string $pngData
*/
public function setPngFile($pngData)
{
$this->pngData = $pngData;
}
public function isPng()
{
return !empty($this->pngData);
}
public function isBmp()
{
return empty($this->pngData);
}
public function setBitmapInfoHeader($bmpInfo)
{
//bit depth can be zero in the ICONDIRENTRY, we trust the bitmap header more...
$this->bitCount = $bmpInfo['BitCount'];
//we need this to calculate offsets when rendering
$this->bmpHeaderWidth = $bmpInfo['Width'];
$this->bmpHeaderHeight = $bmpInfo['Height'];
$this->bmpHeaderSize = $bmpInfo['Size'];
}
public function setBitmapData($bmpData)
{
$this->bmpData = $bmpData;
}
public function addToBmpPalette($r, $g, $b, $reserved)
{
$this->palette[] = ['red' => $r, 'green' => $g, 'blue' => $b, 'reserved' => $reserved];
}
}