1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.pdfbox.pdmodel.graphics.predictor;
18
19 /**
20 * The sub algorithm.
21 *
22 * <code>Sub(i,j) = Raw(i,j) - Raw(i-1,j)</code>
23 *
24 * <code>Raw(i,j) = Sub(i,j) + Raw(i-1,j)</code>
25 *
26 * @author xylifyx@yahoo.co.uk
27 * @version $Revision: 1.3 $
28 */
29 public class Sub extends PredictorAlgorithm
30 {
31 /**
32 * {@inheritDoc}
33 */
34 public void encodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset,
35 int destDy, int destOffset)
36 {
37 int bpl = getWidth()*getBpp();
38 int bpp = getBpp();
39 // case: x < bpp
40 for (int x = 0; x < bpl && x < bpp; x++)
41 {
42 dest[x + destOffset] = src[x + srcOffset];
43 }
44 // otherwise
45 for (int x = getBpp(); x < bpl; x++)
46 {
47 dest[x + destOffset] = (byte) (src[x + srcOffset] - src[x
48 + srcOffset - bpp]);
49 }
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 public void decodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset,
56 int destDy, int destOffset)
57 {
58 int bpl = getWidth()*getBpp();
59 int bpp = getBpp();
60 // case: x < bpp
61 for (int x = 0; x < bpl && x < bpp; x++)
62 {
63 dest[x + destOffset] = src[x + srcOffset];
64 }
65 // otherwise
66 for (int x = getBpp(); x < bpl; x++)
67 {
68 dest[x + destOffset] = (byte) (src[x + srcOffset] + dest[x
69 + destOffset - bpp]);
70 }
71 }
72 }