.. | .. |
---|
2405 | 2405 | return currentGL; |
---|
2406 | 2406 | } |
---|
2407 | 2407 | |
---|
| 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 | + |
---|
2408 | 2447 | /**/ |
---|
2409 | 2448 | class CacheTexture |
---|
2410 | 2449 | { |
---|
.. | .. |
---|
8308 | 8347 | { |
---|
8309 | 8348 | TextureData texturedata = null; |
---|
8310 | 8349 | |
---|
8311 | | - if (bim == null) |
---|
| 8350 | + if (bim != null) |
---|
8312 | 8351 | { |
---|
8313 | | - |
---|
| 8352 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
8314 | 8353 | } |
---|
8315 | 8354 | else |
---|
8316 | 8355 | if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
.. | .. |
---|
8329 | 8368 | { |
---|
8330 | 8369 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8331 | 8370 | } |
---|
| 8371 | + else |
---|
| 8372 | + new Exception().printStackTrace(); |
---|
8332 | 8373 | // } |
---|
8333 | 8374 | } else |
---|
8334 | 8375 | if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
.. | .. |
---|
8337 | 8378 | texturecache = textures.get(tex); |
---|
8338 | 8379 | if (texturecache == null) |
---|
8339 | 8380 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8381 | + else |
---|
| 8382 | + new Exception().printStackTrace(); |
---|
8340 | 8383 | } else |
---|
8341 | 8384 | { |
---|
8342 | 8385 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8349 | 8392 | texturecache = textures.get(tex); |
---|
8350 | 8393 | if (texturecache == null) |
---|
8351 | 8394 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8395 | + else |
---|
| 8396 | + new Exception().printStackTrace(); |
---|
8352 | 8397 | } else |
---|
8353 | 8398 | { |
---|
8354 | 8399 | if (textureon) |
---|
.. | .. |
---|
8417 | 8462 | if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8418 | 8463 | { |
---|
8419 | 8464 | //return false; |
---|
| 8465 | + assert(bim == null); |
---|
8420 | 8466 | |
---|
8421 | 8467 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8422 | 8468 | if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
.. | .. |
---|
8436 | 8482 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8437 | 8483 | if (!cachefile.exists()) |
---|
8438 | 8484 | { |
---|
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()) |
---|
8448 | 8486 | { |
---|
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 | + |
---|
8479 | 8489 | ImageWriter writer = null; |
---|
8480 | 8490 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8481 | 8491 | if (iter.hasNext()) { |
---|
8482 | 8492 | writer = (ImageWriter)iter.next(); |
---|
8483 | 8493 | } |
---|
8484 | | - float compressionQuality = 0.9f; |
---|
| 8494 | + |
---|
| 8495 | + float compressionQuality = 0.85f; |
---|
8485 | 8496 | try |
---|
8486 | 8497 | { |
---|
8487 | 8498 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8528 | 8539 | return texturecache; |
---|
8529 | 8540 | } |
---|
8530 | 8541 | |
---|
| 8542 | + static void EmbedTextures(cTexture tex) |
---|
| 8543 | + { |
---|
| 8544 | + |
---|
| 8545 | + } |
---|
| 8546 | + |
---|
8531 | 8547 | com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
8532 | 8548 | { |
---|
8533 | 8549 | CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|