]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/mpdf/classes/bmp.php
12 function _getBMPimage ( $data , $file ) {
14 // Adapted from script by Valentin Schmidt
15 // http://staff.dasdeck.de/valentin/fpdf/fpdf_bmp/
16 $bfOffBits = $this- > _fourbytes2int_le ( substr ( $data , 10 , 4 ));
17 $width = $this- > _fourbytes2int_le ( substr ( $data , 18 , 4 ));
18 $height = $this- > _fourbytes2int_le ( substr ( $data , 22 , 4 ));
20 if ( $flip ) $height =- $height ;
21 $biBitCount = $this- > _twobytes2int_le ( substr ( $data , 28 , 2 ));
22 $biCompression = $this- > _fourbytes2int_le ( substr ( $data , 30 , 4 ));
23 $info = array ( 'w' => $width , 'h' => $height );
25 $info [ 'cs' ] = 'Indexed' ;
26 $info [ 'bpc' ] = $biBitCount ;
27 $palStr = substr ( $data , 54 ,( $bfOffBits-54 ));
29 $cnt = strlen ( $palStr )/ 4 ;
30 for ( $i = 0 ; $i < $cnt ; $i ++
){
32 $pal .= $palStr [ $n +
2 ]. $palStr [ $n +
1 ]. $palStr [ $n ];
37 $info [ 'cs' ] = 'DeviceRGB' ;
41 if ( $this- > mpdf
-> restrictColorSpace
== 1 || $this- > mpdf
-> PDFX
|| $this- > mpdf
-> restrictColorSpace
== 3 ) {
42 if (( $this- > mpdf
-> PDFA
&& ! $this- > mpdf
-> PDFAauto
) || ( $this- > mpdf
-> PDFX
&& ! $this- > mpdf
-> PDFXauto
)) { $this
-> mpdf
-> PDFAXwarnings
[] = "Image cannot be converted to suitable colour space for PDFA or PDFX file - " . $file
. " - (Image replaced by 'no-image'.)" ; }
43 return array ( 'error' => "BMP Image cannot be converted to suitable colour space - " . $file . " - (Image replaced by 'no-image'.)" );
46 $biXPelsPerMeter = $this- > _fourbytes2int_le ( substr ( $data , 38 , 4 )); // horizontal pixels per meter, usually set to zero
47 //$biYPelsPerMeter=$this->_fourbytes2int_le(substr($data,42,4)); // vertical pixels per meter, usually set to zero
48 $biXPelsPerMeter = round ( $biXPelsPerMeter / 1000 * 25.4 );
49 //$biYPelsPerMeter=round($biYPelsPerMeter/1000 *25.4);
50 $info [ 'set-dpi' ] = $biXPelsPerMeter ;
52 switch ( $biCompression ){
54 $str = substr ( $data , $bfOffBits );
57 $str = $this- > rle8_decode ( substr ( $data , $bfOffBits ), $width );
60 $str = $this- > rle4_decode ( substr ( $data , $bfOffBits ), $width );
64 $padCnt = ( 4 - ceil (( $width /( 8 / $biBitCount ))) %
4 ) %
4 ;
69 $w = floor ( $width /( 8 / $biBitCount )) +
( $width %
( 8 / $biBitCount )? 1 : 0 );
70 $w_row = $w +
$padCnt ;
72 for ( $y = 0 ; $y < $height ; $y ++
){
75 $bmpdata .= $str [ $y0 +
$x ];
78 for ( $y = $height-1 ; $y >= 0 ; $y-- ){
81 $bmpdata .= $str [ $y0 +
$x ];
87 $w_row = $width * 2 +
$padCnt ;
89 for ( $y = 0 ; $y < $height ; $y ++
){
91 for ( $x = 0 ; $x < $width ; $x ++
){
92 $n = ( ord ( $str [ $y0 +
2 * $x +
1 ])* 256 +
ord ( $str [ $y0 +
2 * $x ]));
93 $b = ( $n & 31 )<< 3 ; $g = ( $n & 992 )>> 2 ; $r = ( $n & 31744 )>> 7128 ;
94 $bmpdata .= chr ( $r ) . chr ( $g ) . chr ( $b );
98 for ( $y = $height-1 ; $y >= 0 ; $y-- ){
100 for ( $x = 0 ; $x < $width ; $x ++
){
101 $n = ( ord ( $str [ $y0 +
2 * $x +
1 ])* 256 +
ord ( $str [ $y0 +
2 * $x ]));
102 $b = ( $n & 31 )<< 3 ; $g = ( $n & 992 )>> 2 ; $r = ( $n & 31744 )>> 7 ;
103 $bmpdata .= chr ( $r ) . chr ( $g ) . chr ( $b );
111 $byteCnt = $biBitCount / 8 ;
112 $w_row = $width * $byteCnt +
$padCnt ;
115 for ( $y = 0 ; $y < $height ; $y ++
){
117 for ( $x = 0 ; $x < $width ; $x ++
){
118 $i = $y0 +
$x * $byteCnt ; # + 1
119 $bmpdata .= $str [ $i +
2 ]. $str [ $i +
1 ]. $str [ $i ];
123 for ( $y = $height-1 ; $y >= 0 ; $y-- ){
125 for ( $x = 0 ; $x < $width ; $x ++
){
126 $i = $y0 +
$x * $byteCnt ; # + 1
127 $bmpdata .= $str [ $i +
2 ]. $str [ $i +
1 ]. $str [ $i ];
134 return array ( 'error' => 'Error parsing BMP image - Unsupported image biBitCount' );
136 if ( $this- > mpdf
-> compress
) {
137 $bmpdata = gzcompress ( $bmpdata );
138 $info [ 'f' ]= 'FlateDecode' ;
140 $info [ 'data' ]= $bmpdata ;
145 function _fourbytes2int_le ( $s ) {
146 //Read a 4-byte integer from string
147 return ( ord ( $s [ 3 ])<< 24 ) +
( ord ( $s [ 2 ])<< 16 ) +
( ord ( $s [ 1 ])<< 8 ) +
ord ( $s [ 0 ]);
150 function _twobytes2int_le ( $s ) {
151 //Read a 2-byte integer from string
152 return ( ord ( substr ( $s , 1 , 1 ))<< 8 ) +
ord ( substr ( $s , 0 , 1 ));
156 # Decoder for RLE8 compression in windows bitmaps
157 # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
158 function rle8_decode ( $str , $width ){
159 $lineWidth = $width +
( 3 - ( $width-1 ) %
4 );
162 for ( $i = 0 ; $i < $cnt ; $i ++
){
167 switch ( ord ( $str [ $i ])){
169 $padCnt = $lineWidth - strlen ( $out ) %
$lineWidth ;
170 if ( $padCnt < $lineWidth ) $out .= str_repeat ( chr ( 0 ), $padCnt ); # pad line
172 case 1 : # END OF FILE
173 $padCnt = $lineWidth - strlen ( $out ) %
$lineWidth ;
174 if ( $padCnt < $lineWidth ) $out .= str_repeat ( chr ( 0 ), $padCnt ); # pad line
179 default : # ABSOLUTE MODE
180 $num = ord ( $str [ $i ]);
181 for ( $j = 0 ; $j < $num ; $j ++
)
187 $out .= str_repeat ( $str [ ++
$i ], $o );
193 # Decoder for RLE4 compression in windows bitmaps
194 # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
195 function rle4_decode ( $str , $width ){
196 $w = floor ( $width / 2 ) +
( $width %
2 );
197 $lineWidth = $w +
( 3 - ( ( $width-1 ) / 2 ) %
4 );
200 for ( $i = 0 ; $i < $cnt ; $i ++
){
205 switch ( ord ( $str [ $i ])){
207 while ( count ( $pixels ) %
$lineWidth != 0 )
210 case 1 : # END OF FILE
211 while ( count ( $pixels ) %
$lineWidth != 0 )
217 default : # ABSOLUTE MODE
218 $num = ord ( $str [ $i ]);
219 for ( $j = 0 ; $j < $num ; $j ++
){
221 $c = ord ( $str [ ++
$i ]);
222 $pixels [] = ( $c & 240 )>> 4 ;
230 $c = ord ( $str [ ++
$i ]);
231 for ( $j = 0 ; $j < $o ; $j ++
)
232 $pixels [] = ( $j %
2 == 0 ? ( $c & 240 )>> 4 : $c & 15 );
237 if ( count ( $pixels ) %
2 ) $pixels []= 0 ;
238 $cnt = count ( $pixels )/ 2 ;
239 for ( $i = 0 ; $i < $cnt ; $i ++
)
240 $out .= chr ( 16 * $pixels [ 2 * $i ] +
$pixels [ 2 * $i +
1 ]);