1 30 package org.pdfbox.pdmodel.graphics.predictor; 31 32 50 public class Paeth extends PredictorAlgorithm 51 { 52 66 public int paethPredictor(int a, int b, int c) 67 { 68 int p = a + b - c; int pa = Math.abs(p - a); int pb = Math.abs(p - b); 71 int pc = Math.abs(p - c); 72 if (pa <= pb && pa <= pc) 75 { 76 return a; 77 } 78 else if (pb <= pc) 79 { 80 return b; 81 } 82 else 83 { 84 return c; 85 } 86 } 87 88 91 public void encodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset, 92 int destDy, int destOffset) 93 { 94 int bpl = getWidth() * getBpp(); 95 for (int x = 0; x < bpl; x++) 96 { 97 dest[x + destOffset] = (byte) (src[x + srcOffset] - paethPredictor( 98 leftPixel(src, srcOffset, srcDy, x), abovePixel(src, 99 srcOffset, srcDy, x), aboveLeftPixel(src, 100 srcOffset, srcDy, x))); 101 } 102 } 103 104 107 public void decodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset, 108 int destDy, int destOffset) 109 { 110 int bpl = getWidth() * getBpp(); 111 for (int x = 0; x < bpl; x++) 112 { 113 dest[x + destOffset] = (byte) (src[x + srcOffset] + paethPredictor( 114 leftPixel(dest, destOffset, destDy, x), abovePixel(dest, 115 destOffset, destDy, x), aboveLeftPixel(dest, 116 destOffset, destDy, x))); 117 } 118 } 119 } 120 | Popular Tags |