| .. | .. | 
|---|
| 18 | 18 |  import javax.imageio.ImageIO; | 
|---|
| 19 | 19 |  import javax.imageio.ImageWriteParam; | 
|---|
| 20 | 20 |  import javax.imageio.ImageWriter; | 
|---|
 | 21 | +import javax.imageio.ImageReadParam;  | 
|---|
 | 22 | +import javax.imageio.ImageReader;  | 
|---|
| 21 | 23 |  import javax.imageio.plugins.jpeg.JPEGImageWriteParam; | 
|---|
 | 24 | +import javax.imageio.stream.ImageInputStream;  | 
|---|
| 22 | 25 |  import javax.imageio.stream.ImageOutputStream; | 
|---|
| 23 | 26 |  import javax.imageio.ImageWriteParam; | 
|---|
| 24 | 27 |   | 
|---|
| .. | .. | 
|---|
| 30 | 33 |  import java.nio.*; | 
|---|
| 31 | 34 |   | 
|---|
| 32 | 35 |  import gleem.linalg.Mat4f; | 
|---|
 | 36 | +import javax.imageio.ImageTypeSpecifier;  | 
|---|
| 33 | 37 |   | 
|---|
| 34 | 38 |  class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener | 
|---|
| 35 | 39 |  { | 
|---|
| .. | .. | 
|---|
| 93 | 97 |      //boolean REDUCETEXTURE = true; | 
|---|
| 94 | 98 |      boolean CACHETEXTURE = true; | 
|---|
| 95 | 99 |      boolean CLEANCACHE = false; // true; | 
|---|
| 96 |  | -    boolean MIPMAP = true; // false; // true;  | 
|---|
 | 100 | +    boolean MIPMAP = false; // true; // never works...  | 
|---|
| 97 | 101 |      boolean COMPRESSTEXTURE = false; | 
|---|
| 98 | 102 |      boolean KOMPACTTEXTURE = false; // true; | 
|---|
| 99 | 103 |      boolean RESIZETEXTURE = false; | 
|---|
| .. | .. | 
|---|
| 8358 | 8362 |              { | 
|---|
| 8359 | 8363 |                  TextureData texturedata = null; | 
|---|
| 8360 | 8364 |               | 
|---|
| 8361 |  | -                if (texdata != null)  | 
|---|
 | 8365 | +                if (texdata != null && textureon)  | 
|---|
| 8362 | 8366 |                  { | 
|---|
| 8363 |  | -                    BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);  | 
|---|
 | 8367 | +                    BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);  | 
|---|
| 8364 | 8368 |                       | 
|---|
| 8365 |  | -                         CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);  | 
|---|
 | 8369 | +                            try  | 
|---|
 | 8370 | +                            {  | 
|---|
 | 8371 | +                                bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);                                  | 
|---|
 | 8372 | +                            }  | 
|---|
 | 8373 | +                            catch (Exception e)  | 
|---|
 | 8374 | +                            {  | 
|---|
 | 8375 | +                                bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);  | 
|---|
 | 8376 | +                            }  | 
|---|
| 8366 | 8377 |                       | 
|---|
| 8367 | 8378 |                      texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); | 
|---|
| 8368 | 8379 |                      bimtextures.put(texdata, texturecache); | 
|---|
 | 8380 | +                      | 
|---|
 | 8381 | +                    //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);  | 
|---|
 | 8382 | +                              | 
|---|
 | 8383 | +                    //Object bim2 = CreateBim(texturecache.texturedata);  | 
|---|
 | 8384 | +                    //bim2 = bim;  | 
|---|
| 8369 | 8385 |                  } | 
|---|
| 8370 | 8386 |                  else | 
|---|
| 8371 | 8387 |                  if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) | 
|---|
| .. | .. | 
|---|
| 8560 | 8576 |      { | 
|---|
| 8561 | 8577 |          if (tex.pigmentdata == null) | 
|---|
| 8562 | 8578 |          { | 
|---|
| 8563 |  | -            String texname = Object3D.GetPigment(tex);  | 
|---|
 | 8579 | +            //String texname = Object3D.GetPigment(tex);  | 
|---|
| 8564 | 8580 |               | 
|---|
| 8565 | 8581 |              CacheTexture texturecache = texturepigment.get(tex); | 
|---|
| 8566 | 8582 |               | 
|---|
| 8567 | 8583 |              if (texturecache != null) | 
|---|
| 8568 | 8584 |              { | 
|---|
| 8569 |  | -                tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();  | 
|---|
| 8570 | 8585 |                  tex.pw = texturecache.texturedata.getWidth(); | 
|---|
| 8571 | 8586 |                  tex.ph = texturecache.texturedata.getHeight(); | 
|---|
 | 8587 | +                tex.pigmentdata = //CompressJPEG(CreateBim  | 
|---|
 | 8588 | +                        ((ByteBuffer)texturecache.texturedata.getBuffer()).array()  | 
|---|
 | 8589 | +                        ;  | 
|---|
 | 8590 | +                        //, tex.pw, tex.ph), 0.5f);  | 
|---|
| 8572 | 8591 |              } | 
|---|
| 8573 | 8592 |          } | 
|---|
| 8574 | 8593 |           | 
|---|
| 8575 | 8594 |          if (tex.bumpdata == null) | 
|---|
| 8576 | 8595 |          { | 
|---|
| 8577 |  | -            String texname = Object3D.GetBump(tex);  | 
|---|
 | 8596 | +            //String texname = Object3D.GetBump(tex);  | 
|---|
| 8578 | 8597 |               | 
|---|
| 8579 | 8598 |              CacheTexture texturecache = texturebump.get(tex); | 
|---|
| 8580 | 8599 |               | 
|---|
| 8581 | 8600 |              if (texturecache != null) | 
|---|
| 8582 | 8601 |              { | 
|---|
| 8583 |  | -                tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();  | 
|---|
| 8584 | 8602 |                  tex.bw = texturecache.texturedata.getWidth(); | 
|---|
| 8585 | 8603 |                  tex.bh = texturecache.texturedata.getHeight(); | 
|---|
 | 8604 | +                tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);  | 
|---|
| 8586 | 8605 |              } | 
|---|
| 8587 | 8606 |          } | 
|---|
| 8588 | 8607 |      } | 
|---|
| .. | .. | 
|---|
| 8654 | 8673 |          return true; // Warning: not used. | 
|---|
| 8655 | 8674 |      } | 
|---|
| 8656 | 8675 |       | 
|---|
 | 8676 | +    public static byte[] CompressJPEG(BufferedImage image, float quality)  | 
|---|
 | 8677 | +    {  | 
|---|
 | 8678 | +        try  | 
|---|
 | 8679 | +        {  | 
|---|
 | 8680 | +            ByteArrayOutputStream baos = new ByteArrayOutputStream();  | 
|---|
 | 8681 | +            Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");  | 
|---|
 | 8682 | +            ImageWriter writer = writers.next();  | 
|---|
 | 8683 | +  | 
|---|
 | 8684 | +            ImageWriteParam param = writer.getDefaultWriteParam();  | 
|---|
 | 8685 | +            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);  | 
|---|
 | 8686 | +            param.setCompressionQuality(quality);  | 
|---|
 | 8687 | +  | 
|---|
 | 8688 | +            ImageOutputStream ios = ImageIO.createImageOutputStream(baos);  | 
|---|
 | 8689 | +            writer.setOutput(ios);  | 
|---|
 | 8690 | +            writer.write(null, new IIOImage(image, null, null), param);  | 
|---|
 | 8691 | +  | 
|---|
 | 8692 | +            byte[] data = baos.toByteArray();  | 
|---|
 | 8693 | +            writer.dispose();  | 
|---|
 | 8694 | +            return data;  | 
|---|
 | 8695 | +        }  | 
|---|
 | 8696 | +        catch (Exception e)  | 
|---|
 | 8697 | +        {  | 
|---|
 | 8698 | +            e.printStackTrace();  | 
|---|
 | 8699 | +            return null;  | 
|---|
 | 8700 | +        }  | 
|---|
 | 8701 | +    }  | 
|---|
 | 8702 | +  | 
|---|
 | 8703 | +    public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException  | 
|---|
 | 8704 | +    {  | 
|---|
 | 8705 | +        ByteArrayInputStream baos = new ByteArrayInputStream(image);  | 
|---|
 | 8706 | +        Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");  | 
|---|
 | 8707 | +        ImageReader reader = writers.next();  | 
|---|
 | 8708 | +          | 
|---|
 | 8709 | +        BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);  | 
|---|
 | 8710 | +          | 
|---|
 | 8711 | +        ImageReadParam param = reader.getDefaultReadParam();  | 
|---|
 | 8712 | +        param.setDestination(bim);  | 
|---|
 | 8713 | +        //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));  | 
|---|
 | 8714 | +  | 
|---|
 | 8715 | +        ImageInputStream ios = ImageIO.createImageInputStream(baos);  | 
|---|
 | 8716 | +        reader.setInput(ios);  | 
|---|
 | 8717 | +        BufferedImage bim2 = reader.read(0, param);  | 
|---|
 | 8718 | +        reader.dispose();  | 
|---|
 | 8719 | +          | 
|---|
 | 8720 | +//        WritableRaster raster = bim2.getRaster();  | 
|---|
 | 8721 | +//        DataBufferByte data   = (DataBufferByte) raster.getDataBuffer();  | 
|---|
 | 8722 | +//        byte[] bytes = data.getData();  | 
|---|
 | 8723 | +//          | 
|---|
 | 8724 | +//        int[] pixels = new int[bytes.length/3];  | 
|---|
 | 8725 | +//        for (int i=pixels.length; --i>=0;)  | 
|---|
 | 8726 | +//        {  | 
|---|
 | 8727 | +//            int i3 = i*3;  | 
|---|
 | 8728 | +//            pixels[i] = 0xFF;  | 
|---|
 | 8729 | +//            pixels[i] <<= 8;  | 
|---|
 | 8730 | +//            pixels[i] |= bytes[i3+2] & 0xFF;  | 
|---|
 | 8731 | +//            pixels[i] <<= 8;  | 
|---|
 | 8732 | +//            pixels[i] |= bytes[i3+1] & 0xFF;  | 
|---|
 | 8733 | +//            pixels[i] <<= 8;  | 
|---|
 | 8734 | +//            pixels[i] |= bytes[i3] & 0xFF;  | 
|---|
 | 8735 | +//        }  | 
|---|
 | 8736 | +//          | 
|---|
 | 8737 | +//        bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);  | 
|---|
 | 8738 | +          | 
|---|
 | 8739 | +        return bim;  | 
|---|
 | 8740 | +    }  | 
|---|
 | 8741 | +  | 
|---|
| 8657 | 8742 |      ShadowBuffer shadowPBuf; | 
|---|
| 8658 | 8743 |      AntialiasBuffer antialiasPBuf; | 
|---|
| 8659 | 8744 |      int MAXSTACK; | 
|---|
| .. | .. | 
|---|
| 11399 | 11484 |              } | 
|---|
| 11400 | 11485 |          } | 
|---|
| 11401 | 11486 |   | 
|---|
| 11402 |  | -        if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)  | 
|---|
 | 11487 | +        if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)  | 
|---|
| 11403 | 11488 |          { | 
|---|
| 11404 | 11489 |              //gl.glDepthFunc(GL.GL_LEQUAL); | 
|---|
| 11405 | 11490 |              //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); | 
|---|
| .. | .. | 
|---|
| 11407 | 11492 |   | 
|---|
| 11408 | 11493 |              boolean texon = textureon; | 
|---|
| 11409 | 11494 |   | 
|---|
| 11410 |  | -            if (RENDERPROGRAM > 0)  | 
|---|
| 11411 |  | -            {  | 
|---|
| 11412 |  | -                gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);  | 
|---|
| 11413 |  | -                textureon = false;  | 
|---|
| 11414 |  | -            }  | 
|---|
 | 11495 | +            gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);  | 
|---|
 | 11496 | +            textureon = false;  | 
|---|
 | 11497 | +              | 
|---|
| 11415 | 11498 |              //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); | 
|---|
| 11416 | 11499 |              //System.out.println("ALLO"); | 
|---|
| 11417 | 11500 |              gl.glColorMask(false, false, false, false); | 
|---|
| 11418 | 11501 |              DrawObject(gl); | 
|---|
| 11419 |  | -            if (RENDERPROGRAM > 0)  | 
|---|
| 11420 |  | -            {  | 
|---|
| 11421 |  | -                gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);  | 
|---|
| 11422 |  | -                textureon = texon;  | 
|---|
| 11423 |  | -            }  | 
|---|
 | 11502 | +              | 
|---|
 | 11503 | +            gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);  | 
|---|
 | 11504 | +            textureon = texon;  | 
|---|
 | 11505 | +  | 
|---|
| 11424 | 11506 |              gl.glColorMask(true, true, true, true); | 
|---|
| 11425 | 11507 |   | 
|---|
| 11426 | 11508 |              gl.glDepthFunc(GL.GL_EQUAL); | 
|---|
| 11427 |  | -        //gl.glDepthMask(false);  | 
|---|
 | 11509 | +            gl.glDepthMask(false);  | 
|---|
| 11428 | 11510 |          } | 
|---|
| 11429 | 11511 |   | 
|---|
| 11430 | 11512 |          if (false) // DrawMode() == SHADOW) | 
|---|