This is a fast native jpeg loader. Well battle tested, thread-safe. We have versions for linux and os x.
| 7 | * This is a fast native jpeg loader. Well battle tested, thread-safe. We have versions for linux and os x. |
| 8 | */ |
| 9 | public class FastJPEG implements JPEGLoader { |
| 10 | |
| 11 | static public boolean available; |
| 12 | |
| 13 | static { |
| 14 | available = false; |
| 15 | try { |
| 16 | System.loadLibrary("fieldjpegturb"); |
| 17 | available = true; |
| 18 | } catch (Throwable t) { |
| 19 | // t.printStackTrace(); |
| 20 | } |
| 21 | if (!available) try { |
| 22 | System.loadLibrary("turbojpegF"); |
| 23 | available = true; |
| 24 | } catch (Throwable t) { |
| 25 | // t.printStackTrace(); |
| 26 | } |
| 27 | if (!available) System.out.println(" Fast jpeg loading is not available. This isn't typically going to be a problem."); |
| 28 | else |
| 29 | System.out.println(" Fast jpeg loading is available"); |
| 30 | } |
| 31 | |
| 32 | static public final JPEGLoader j; |
| 33 | |
| 34 | static { |
| 35 | if (available) j = new FastJPEG(); |
| 36 | else j = new SlowJPEG(); |
| 37 | } |
| 38 | |
| 39 | public native void decompress(String filename, Buffer dest, int width, int height); |
| 40 | |
| 41 | public native void decompress4(String filename, Buffer dest, int width, int height); |
| 42 | |
| 43 | public native void decompressFlipped(String filename, Buffer dest, int width, int height); |
| 44 | |
| 45 | public native void decompressGrey(String filename, Buffer dest, int width, int height); |
| 46 | |
| 47 | public native void compress(String filename, Buffer dest, int width, int height); |
| 48 | |
| 49 | public native long dimensionsFor(String filename); |
| 50 | |
| 51 | public int[] dimensions(String filename) { |
| 52 | long dim = dimensionsFor(filename); |
| 53 | if (dim == 0) return null; |
| 54 | return new int[]{(int) (dim >> 16), (int) (dim & 0xffff)}; |
| 55 | } |
| 56 | |
| 57 | public Texture.TextureSpecification loadTexture(int unit, boolean mips, String filename) { |
| 58 | |
| 59 | int[] d = dimensions(filename); |
| 60 | if (d == null) return null; |
| 61 | |
| 62 | ByteBuffer b = ByteBuffer.allocateDirect(3 * d[0] * d[1]); |
| 63 | decompress(filename, b, d[0], d[1]); |
| 64 | b.rewind(); |
| 65 | |
| 66 | return Texture.TextureSpecification.byte3(unit, d[0], d[1], b, mips); |
no test coverage detected