33
33
import java .util .zip .ZipEntry ;
34
34
import java .util .zip .ZipFile ;
35
35
36
+ import org .dynmap .MapType .ImageEncoding ;
36
37
import org .dynmap .common .DynmapCommandSender ;
37
38
import org .dynmap .common .DynmapListenerManager ;
38
39
import org .dynmap .common .DynmapListenerManager .EventType ;
@@ -138,6 +139,12 @@ public static abstract class EnableCoreCallbacks {
138
139
139
140
private boolean loginRequired ;
140
141
142
+ // WEBP support
143
+ private String cwebpPath ;
144
+ private String dwebpPath ;
145
+ private boolean did_cwebpPath_warn = false ;
146
+ private boolean did_dwebpPath_warn = false ;
147
+
141
148
/* Flag to let code know that we're doing reload - make sure we don't double-register event handlers */
142
149
public boolean is_reload = false ;
143
150
public static boolean ignore_chunk_loads = false ; /* Flag keep us from processing our own chunk loads */
@@ -200,7 +207,6 @@ public final File getExportFolder() {
200
207
public void setMinecraftVersion (String mcver ) {
201
208
this .platformVersion = mcver ;
202
209
}
203
-
204
210
public void setServer (DynmapServerInterface srv ) {
205
211
server = srv ;
206
212
}
@@ -213,6 +219,21 @@ public final void setBiomeNames(String[] names) {
213
219
public static final boolean migrateChunks () {
214
220
return migrate_chunks ;
215
221
}
222
+
223
+ public String getCWEBPPath () {
224
+ if ((cwebpPath == null ) && (!did_cwebpPath_warn )) {
225
+ Log .severe ("ERROR: trying to use WEBP without cwebp tool installed or cwebpPath set properly" );
226
+ did_cwebpPath_warn = true ;
227
+ }
228
+ return cwebpPath ;
229
+ }
230
+ public String getDWEBPPath () {
231
+ if ((dwebpPath == null ) && (!did_dwebpPath_warn )) {
232
+ Log .severe ("ERROR: trying to use WEBP without dwebp tool installed or dwebpPath set properly" );
233
+ did_dwebpPath_warn = true ;
234
+ }
235
+ return dwebpPath ;
236
+ }
216
237
217
238
public final String getBiomeName (int biomeid ) {
218
239
String n = null ;
@@ -416,6 +437,20 @@ else if (storetype.equals("postgres") || storetype.equals("postgresql")) {
416
437
return true ;
417
438
}
418
439
440
+ private String findExecutableOnPath (String fname ) {
441
+ for (String dirname : System .getenv ("PATH" ).split (File .pathSeparator )) {
442
+ File file = new File (dirname , fname );
443
+ if (file .isFile () && file .canExecute ()) {
444
+ return file .getAbsolutePath ();
445
+ }
446
+ file = new File (dirname , fname + ".exe" );
447
+ if (file .isFile () && file .canExecute ()) {
448
+ return file .getAbsolutePath ();
449
+ }
450
+ }
451
+ return null ;
452
+ }
453
+
419
454
public boolean enableCore (EnableCoreCallbacks cb ) {
420
455
/* Update extracted files, if needed */
421
456
updateExtractedFiles ();
@@ -427,14 +462,47 @@ public boolean enableCore(EnableCoreCallbacks cb) {
427
462
428
463
/* Load control for leaf transparency (spout lighting bug workaround) */
429
464
transparentLeaves = configuration .getBoolean ("transparent-leaves" , true );
465
+
466
+ // Inject core instance
467
+ ImageIOManager .core = this ;
468
+ // Check for webp support
469
+ cwebpPath = configuration .getString ("cwebpPath" , null );
470
+ dwebpPath = configuration .getString ("dwebpPath" , null );
471
+ if (cwebpPath == null ) {
472
+ cwebpPath = findExecutableOnPath ("cwebp" );
473
+ }
474
+ if (dwebpPath == null ) {
475
+ dwebpPath = findExecutableOnPath ("dwebp" );
476
+ }
477
+ if (cwebpPath != null ) {
478
+ File file = new File (cwebpPath );
479
+ if (!file .isFile () || !file .canExecute ()) {
480
+ cwebpPath = null ;
481
+ }
482
+ }
483
+ if (dwebpPath != null ) {
484
+ File file = new File (dwebpPath );
485
+ if (!file .isFile () || !file .canExecute ()) {
486
+ dwebpPath = null ;
487
+ }
488
+ }
489
+ if ((cwebpPath != null ) && (dwebpPath != null )) {
490
+ Log .info ("Found cwebp at " + cwebpPath + " and dwebp at " + dwebpPath + ": webp format enabled" );
491
+ }
492
+ else {
493
+ Log .warning ("cwebp or dwebp not found, or cwebpPath or dwebpPath is invalid: webp format disabled" );
494
+ cwebpPath = dwebpPath = null ;
495
+ }
430
496
/* Get default image format */
431
497
def_image_format = configuration .getString ("image-format" , "png" );
432
498
MapType .ImageFormat fmt = MapType .ImageFormat .fromID (def_image_format );
433
- if ( fmt == null ) {
499
+ if (( fmt == null ) || (( fmt . enc == ImageEncoding . WEBP ) && ( cwebpPath == null )) ) {
434
500
Log .severe ("Invalid image-format: " + def_image_format );
435
501
def_image_format = "png" ;
502
+ fmt = MapType .ImageFormat .fromID (def_image_format );
436
503
}
437
504
505
+
438
506
DynmapWorld .doInitialScan (configuration .getBoolean ("initial-zoomout-validate" , true ));
439
507
440
508
smoothlighting = configuration .getBoolean ("smooth-lighting" , false );
0 commit comments