Normand Briere
2019-07-21 d32f24f147068e6cbecb31c7f98047f68bc8b58a
CameraPane.java
....@@ -2405,6 +2405,45 @@
24052405 return currentGL;
24062406 }
24072407
2408
+ private BufferedImage CreateBim(TextureData texturedata)
2409
+ {
2410
+ // cache to disk
2411
+ Buffer buffer = texturedata.getBuffer(); // getMipmapData();
2412
+ //buffers[0].
2413
+ ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
2414
+ int[] pixels = new int[bytebuf.capacity()/3];
2415
+ int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared
2416
+ int height = width;
2417
+ for (int i=pixels.length; --i>=0;)
2418
+ {
2419
+ int i3 = i*3;
2420
+ pixels[i] = 0xFF;
2421
+ pixels[i] <<= 8;
2422
+ pixels[i] |= bytebuf.get(i3+2) & 0xFF;
2423
+ pixels[i] <<= 8;
2424
+ pixels[i] |= bytebuf.get(i3+1) & 0xFF;
2425
+ pixels[i] <<= 8;
2426
+ pixels[i] |= bytebuf.get(i3) & 0xFF;
2427
+ }
2428
+ /*
2429
+ int r=0,g=0,b=0,a=0;
2430
+ for (int i=0; i<width; i++)
2431
+ for (int j=0; j<height; j++)
2432
+ {
2433
+ int index = j*width+i;
2434
+ int p = pixels[index];
2435
+ a = ((p>>24) & 0xFF);
2436
+ r = ((p>>16) & 0xFF);
2437
+ g = ((p>>8) & 0xFF);
2438
+ b = (p & 0xFF);
2439
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
2440
+ }
2441
+ /**/
2442
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
2443
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
2444
+ return rendImage;
2445
+ }
2446
+
24082447 /**/
24092448 class CacheTexture
24102449 {
....@@ -8308,9 +8347,9 @@
83088347 {
83098348 TextureData texturedata = null;
83108349
8311
- if (bim == null)
8350
+ if (bim != null)
83128351 {
8313
-
8352
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
83148353 }
83158354 else
83168355 if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
....@@ -8329,6 +8368,8 @@
83298368 {
83308369 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83318370 }
8371
+ else
8372
+ new Exception().printStackTrace();
83328373 // }
83338374 } else
83348375 if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
....@@ -8337,6 +8378,8 @@
83378378 texturecache = textures.get(tex);
83388379 if (texturecache == null)
83398380 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8381
+ else
8382
+ new Exception().printStackTrace();
83408383 } else
83418384 {
83428385 //if (tex.equals("IMMORTAL"))
....@@ -8349,6 +8392,8 @@
83498392 texturecache = textures.get(tex);
83508393 if (texturecache == null)
83518394 texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8395
+ else
8396
+ new Exception().printStackTrace();
83528397 } else
83538398 {
83548399 if (textureon)
....@@ -8417,6 +8462,7 @@
84178462 if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
84188463 {
84198464 //return false;
8465
+ assert(bim == null);
84208466
84218467 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
84228468 if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
....@@ -8436,52 +8482,17 @@
84368482 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
84378483 if (!cachefile.exists())
84388484 {
8439
- // cache to disk
8440
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8441
- //buffers[0].
8442
-
8443
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8444
- int[] pixels = new int[bytebuf.capacity()/3];
8445
-
8446
- // squared size heuristic...
8447
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8485
+ //if (texturedata.getWidth() == texturedata.getHeight())
84488486 {
8449
- for (int i=pixels.length; --i>=0;)
8450
- {
8451
- int i3 = i*3;
8452
- pixels[i] = 0xFF;
8453
- pixels[i] <<= 8;
8454
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8455
- pixels[i] <<= 8;
8456
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8457
- pixels[i] <<= 8;
8458
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8459
- }
8460
-
8461
- /*
8462
- int r=0,g=0,b=0,a=0;
8463
- for (int i=0; i<width; i++)
8464
- for (int j=0; j<height; j++)
8465
- {
8466
- int index = j*width+i;
8467
- int p = pixels[index];
8468
- a = ((p>>24) & 0xFF);
8469
- r = ((p>>16) & 0xFF);
8470
- g = ((p>>8) & 0xFF);
8471
- b = (p & 0xFF);
8472
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8473
- }
8474
- /**/
8475
- int width = (int)Math.sqrt(pixels.length); // squared
8476
- int height = width;
8477
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8478
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8487
+ BufferedImage rendImage = CreateBim(texturedata);
8488
+
84798489 ImageWriter writer = null;
84808490 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84818491 if (iter.hasNext()) {
84828492 writer = (ImageWriter)iter.next();
84838493 }
8484
- float compressionQuality = 0.9f;
8494
+
8495
+ float compressionQuality = 0.85f;
84858496 try
84868497 {
84878498 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8528,6 +8539,11 @@
85288539 return texturecache;
85298540 }
85308541
8542
+ static void EmbedTextures(cTexture tex)
8543
+ {
8544
+
8545
+ }
8546
+
85318547 com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
85328548 {
85338549 CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);