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    * The up algorithm.
   21    *
   22    * <code>Up(i,j) = Raw(i,j) - Raw(i,j-1)</code>
   23    *
   24    * <code>Raw(i,j) = Up(i,j) + Raw(i,j-1)</code>
   25    *
   26    * @author xylifyx@yahoo.co.uk
   27    * @version $Revision: 1.3 $
   28    */
   29   public class Up 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           // case: y = 0;
   39           if (srcOffset - srcDy < 0)
   40           {
   41               if (0 < getHeight())
   42               {
   43                   for (int x = 0; x < bpl; x++)
   44                   {
   45                       dest[destOffset + x] = src[srcOffset + x];
   46                   }
   47               }
   48           }
   49           else
   50           {
   51               for (int x = 0; x < bpl; x++)
   52               {
   53                   dest[destOffset + x] = (byte) (src[srcOffset + x] - src[srcOffset
   54                           + x - srcDy]);
   55               }
   56           }
   57       }
   58   
   59       /**
   60        * {@inheritDoc}
   61        */
   62       public void decodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset,
   63               int destDy, int destOffset)
   64       {
   65           // case: y = 0;
   66           int bpl = getWidth()*getBpp();
   67           if (destOffset - destDy < 0)
   68           {
   69               if (0 < getHeight())
   70               {
   71                   for (int x = 0; x < bpl; x++)
   72                   {
   73                       dest[destOffset + x] = src[srcOffset + x];
   74                   }
   75               }
   76           }
   77           else
   78           {
   79               for (int x = 0; x < bpl; x++)
   80               {
   81                   dest[destOffset + x] = (byte) (src[srcOffset + x] + dest[destOffset
   82                           + x - destDy]);
   83               }
   84           }
   85       }
   86   }

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