We've been holding onto FastJPEG and it's our only Created by marc on 2/19/16.
| 18 | public class SlowJPEG implements JPEGLoader{ |
| 19 | |
| 20 | @Override |
| 21 | public void decompress(String filename, Buffer dest, int width, int height) { |
| 22 | byte[] f = bytes(filename); |
| 23 | |
| 24 | if(f==null) |
| 25 | { |
| 26 | throw new IllegalArgumentException(" failed to load :"+filename); |
| 27 | } |
| 28 | // 4 or 3? |
| 29 | dest.rewind(); |
| 30 | ((ByteBuffer)dest).put(f); |
| 31 | dest.rewind(); |
| 32 | |
| 33 | } |
| 34 | |
| 35 | public void decompressRaw(String filename, Buffer dest, int width, int height) { |
| 36 | byte[] f = bytes(filename); |
| 37 | |
| 38 | if(f==null) |
| 39 | { |
| 40 | throw new IllegalArgumentException(" failed to load :"+filename); |
| 41 | } |
| 42 | ((ByteBuffer)dest).put(f); |
| 43 | } |
| 44 | |
| 45 | protected byte[] bytes(String filename) { |
| 46 | try { |
| 47 | BufferedImage originalImage = ImageIO.read(new File(filename)); |
| 48 | |
| 49 | byte[] pixels = ((DataBufferByte) originalImage.getRaster().getDataBuffer()).getData(); |
| 50 | |
| 51 | return pixels; |
| 52 | } catch (Exception e) { |
| 53 | e.printStackTrace(); |
| 54 | return null; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public void decompressFlipped(String filename, Buffer dest, int width, int height) |
| 59 | { |
| 60 | throw new IllegalArgumentException("not implemented"); |
| 61 | } |
| 62 | |
| 63 | public void decompressGrey(String filename, Buffer dest, int width, int height) |
| 64 | { |
| 65 | throw new IllegalArgumentException("not implemented"); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | public void compress(String filename, Buffer dest, int width, int height) |
| 70 | { |
| 71 | // throw new IllegalArgumentException("not implemented"); |
| 72 | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); |
| 73 | |
| 74 | ByteBuffer t = ByteBuffer.allocate(dest.limit()); |
| 75 | dest.rewind(); |
| 76 | t.put((ByteBuffer)dest); |
| 77 | t.rewind(); |
no outgoing calls
no test coverage detected