@@ -15,7 +15,7 @@ class TileRenderer
15
15
* Changing this will affect all generated hashes. You should increment it
16
16
* whenever you alter anything in the drawing algorithm.
17
17
*/
18
- private static $ VERSION = 61 ;
18
+ private static $ VERSION = 62 ;
19
19
20
20
/**
21
21
* Should be always true. You may temporarily set it to false, when you're
@@ -115,13 +115,13 @@ private static function get_image($name, $opacity=1, $brightness=0,
115
115
try
116
116
{
117
117
$ cache_key = "tilesrc/ " .Okapi::getGitRevision ()."/ " .self ::$ VERSION ."/ " .$ key ;
118
- $ gd2_path = self ::$ USE_STATIC_IMAGE_CACHE
118
+ $ img_path = self ::$ USE_STATIC_IMAGE_CACHE
119
119
? FileCache::get_file_path ($ cache_key ) : null ;
120
- if ($ gd2_path === null )
120
+ if ($ img_path === null )
121
121
throw new Exception ("Not in cache " );
122
122
# File cache hit. GD2 files are much faster to read than PNGs.
123
123
# This can throw an Exception (see bug#160).
124
- $ locmem_cache [$ key ] = imagecreatefromgd2 ( $ gd2_path );
124
+ $ locmem_cache [$ key ] = imagecreatefrompng ( $ img_path );
125
125
}
126
126
catch (Exception $ e )
127
127
{
@@ -132,7 +132,12 @@ private static function get_image($name, $opacity=1, $brightness=0,
132
132
# Apply all wanted effects.
133
133
134
134
if ($ opacity != 1 )
135
- self ::change_opacity ($ locmem_cache [$ key ], $ opacity );
135
+ {
136
+ imagealphablending ($ locmem_cache [$ key ], false );
137
+ imagesavealpha ($ locmem_cache [$ key ], true );
138
+ imagefilter ($ locmem_cache [$ key ], IMG_FILTER_COLORIZE , 0 ,0 ,0 ,127 *$ opacity );
139
+ imagealphablending ($ locmem_cache [$ key ], true );
140
+ }
136
141
if ($ contrast != 0 )
137
142
imagefilter ($ locmem_cache [$ key ], IMG_FILTER_CONTRAST , $ contrast );
138
143
if ($ brightness != 0 )
@@ -146,37 +151,15 @@ private static function get_image($name, $opacity=1, $brightness=0,
146
151
# Cache the result.
147
152
148
153
ob_start ();
149
- imagegd2 ($ locmem_cache [$ key ]);
150
- $ gd2 = ob_get_clean ();
151
- FileCache::set ($ cache_key , $ gd2 );
154
+ imagesavealpha ($ locmem_cache [$ key ], true );
155
+ imagepng ($ locmem_cache [$ key ]);
156
+ $ png_img = ob_get_clean ();
157
+ FileCache::set ($ cache_key , $ png_img );
152
158
}
153
159
}
154
160
return $ locmem_cache [$ key ];
155
161
}
156
162
157
- /**
158
- * Extremely slow! Remember to cache the result!
159
- */
160
- private static function change_opacity ($ im , $ ratio )
161
- {
162
- imagealphablending ($ im , false );
163
-
164
- $ w = imagesx ($ im );
165
- $ h = imagesy ($ im );
166
-
167
- for ($ x = 0 ; $ x < $ w ; $ x ++)
168
- {
169
- for ($ y = 0 ; $ y < $ h ; $ y ++)
170
- {
171
- $ color = imagecolorat ($ im , $ x , $ y );
172
- $ new_color = ((max (0 , floor (127 - ((127 - (($ color >> 24 ) & 0x7f )) * $ ratio ))) & 0x7f ) << 24 ) | ($ color & 0x80ffffff );
173
- imagesetpixel ($ im , $ x , $ y , $ new_color );
174
- }
175
- }
176
-
177
- imagealphablending ($ im , true );
178
- }
179
-
180
163
private function draw_cache (&$ cache_struct )
181
164
{
182
165
$ capt = ($ cache_struct [6 ] & TileTree::$ FLAG_DRAW_CAPTION );
@@ -345,8 +328,8 @@ private function get_caption($cache_id, $name_crc)
345
328
# Check cache.
346
329
347
330
$ cache_key = "tilecaption/ " .self ::$ VERSION ."/ " .$ cache_id ."/ " .$ name_crc ;
348
- $ gd2 = self ::$ USE_CAPTIONS_CACHE ? Cache::get ($ cache_key ) : null ;
349
- if ($ gd2 === null )
331
+ $ caption_png = self ::$ USE_CAPTIONS_CACHE ? Cache::get ($ cache_key ) : null ;
332
+ if ($ caption_png === null )
350
333
{
351
334
# We'll work with 16x bigger image to get smoother interpolation.
352
335
@@ -419,12 +402,13 @@ private function get_caption($cache_id, $name_crc)
419
402
# Cache it!
420
403
421
404
ob_start ();
422
- imagegd2 ($ small );
423
- $ gd2 = ob_get_clean ();
424
- Cache::set_scored ($ cache_key , $ gd2 );
405
+ imagesavealpha ($ small , true );
406
+ imagepng ($ small );
407
+ $ caption_png = ob_get_clean ();
408
+ Cache::set_scored ($ cache_key , $ caption_png );
425
409
}
426
410
427
- return imagecreatefromstring ($ gd2 );
411
+ return imagecreatefromstring ($ caption_png );
428
412
}
429
413
430
414
private function draw_cache_medium (&$ cache_struct )
@@ -564,8 +548,7 @@ private function draw_cache_tiny(&$cache_struct)
564
548
565
549
if (($ status != 1 ) && ($ count == 1 ))
566
550
{
567
- $ icon = self ::get_image (($ status == 2 ) ? "status_unavailable "
568
- : "status_archived " );
551
+ $ icon = self ::get_image (($ status == 2 ) ? "status_unavailable " : "status_archived " );
569
552
imagecopy ($ this ->im , $ icon , $ px - ($ center_x - $ markercenter_x ) - 6 ,
570
553
$ py - ($ center_y - $ markercenter_y ) - 8 , 0 , 0 , 16 , 16 );
571
554
}
0 commit comments