Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.graphics.predictor » [javadoc | source]

    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    * We can use raw on the right hand side of
   21    * the decoding formula because it is already decoded.
   22    *
   23    * <code>average(i,j) = raw(i,j) + (raw(i-1,j)+raw(i,j-1)/2</code>
   24    *
   25    * decoding
   26    *
   27    * <code>raw(i,j) = avarage(i,j) - (raw(i-1,j)+raw(i,j-1)/2</code>
   28    *
   29    * @author xylifyx@yahoo.co.uk
   30    * @version $Revision: 1.3 $
   31    */
   32   public class Average extends PredictorAlgorithm
   33   {
   34       /**
   35        * Not an optimal version, but close to the def.
   36        *
   37        * {@inheritDoc}
   38        */
   39       public void encodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset,
   40               int destDy, int destOffset)
   41       {
   42           int bpl = getWidth() * getBpp();
   43           for (int x = 0; x < bpl; x++)
   44           {
   45               dest[x + destOffset] = (byte) (src[x + srcOffset] - ((leftPixel(
   46                       src, srcOffset, srcDy, x) + abovePixel(src, srcOffset,
   47                       srcDy, x)) >>> 2));
   48           }
   49       }
   50   
   51       /**
   52        * {@inheritDoc}
   53        */
   54       public void decodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset,
   55               int destDy, int destOffset)
   56       {
   57           int bpl = getWidth() * getBpp();
   58           for (int x = 0; x < bpl; x++)
   59           {
   60               dest[x + destOffset] = (byte) (src[x + srcOffset] + ((leftPixel(
   61                       dest, destOffset, destDy, x) + abovePixel(dest,
   62                       destOffset, destDy, x)) >>> 2));
   63           }
   64       }
   65   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.graphics.predictor » [javadoc | source]