1 31 package org.pdfbox.pdmodel.graphics.predictor; 32 33 42 public class Uptimum extends PredictorAlgorithm 43 { 44 47 public void checkBufsiz(byte[] filtered, byte[] raw) 48 { 49 if (filtered.length != (getWidth() * getBpp() + 1) * getHeight()) 50 { 51 52 throw new IllegalArgumentException ( 53 "filtered.length != (width*bpp + 1) * height, " 54 + filtered.length + " " 55 + (getWidth() * getBpp() + 1) * getHeight() 56 + "w,h,bpp=" + getWidth() + "," + getHeight() + "," 57 + getBpp()); 58 } 59 if (raw.length != getWidth() * getHeight() * getBpp()) 60 { 61 throw new IllegalArgumentException ( 62 "raw.length != width * height * bpp, raw.length=" 63 + raw.length + " w,h,bpp=" + getWidth() + "," 64 + getHeight() + "," + getBpp()); 65 } 66 } 67 68 71 public void encodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset, 72 int destDy, int destOffset) 73 { 74 throw new UnsupportedOperationException ("encodeLine"); 75 } 76 77 80 public void decodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset, 81 int destDy, int destOffset) 82 { 83 throw new UnsupportedOperationException ("decodeLine"); 84 } 85 86 89 public void encode(byte[] src, byte[] dest) 90 { 91 checkBufsiz(dest, src); 92 throw new UnsupportedOperationException ("encode"); 93 } 94 95 98 PredictorAlgorithm[] filter = { new None(), new Sub(), new Up(), new Average(), 99 new Paeth() }; 100 101 104 public void setBpp(int bpp) 105 { 106 super.setBpp(bpp); 107 for (int i = 0; i < filter.length; i++) 108 { 109 filter[i].setBpp(bpp); 110 } 111 } 112 115 public void setHeight(int height) 116 { 117 super.setHeight(height); 118 for (int i = 0; i < filter.length; i++) 119 { 120 filter[i].setHeight(height); 121 } 122 } 123 124 127 public void setWidth(int width) 128 { 129 super.setWidth(width); 130 for (int i = 0; i < filter.length; i++) 131 { 132 filter[i].setWidth(width); 133 } 134 } 135 136 139 public void decode(byte[] src, byte[] dest) 140 { 141 checkBufsiz(src, dest); 142 int bpl = getWidth() * getBpp(); 143 int srcDy = bpl + 1; 144 for (int y = 0; y < getHeight(); y++) 145 { 146 PredictorAlgorithm f = filter[src[y * srcDy]]; 147 int srcOffset = y * srcDy + 1; 148 f.decodeLine(src, dest, srcDy, srcOffset, bpl, y * bpl); 149 } 150 } 151 } | Popular Tags |