View Javadoc
1   /*
2    *  Licensed under the Apache License, Version 2.0 (the "License");
3    *  you may not use this file except in compliance with the License.
4    *  You may obtain a copy of the License at
5    *
6    *       http://www.apache.org/licenses/LICENSE-2.0
7    *
8    *  Unless required by applicable law or agreed to in writing, software
9    *  distributed under the License is distributed on an "AS IS" BASIS,
10   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   *  See the License for the specific language governing permissions and
12   *  limitations under the License.
13   *  under the License.
14   */
15  
16  package org.apache.commons.imaging.formats.jpeg.decoder;
17  
18  final class ZigZag {
19      private static final int[] ZIG_ZAG = { 0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44, 53,
20              10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63 };
21  
22      public static void blockToZigZag(final int[] block, final int[] zz) {
23          for (int i = 0; i < ZIG_ZAG.length; i++) {
24              zz[ZIG_ZAG[i]] = block[i];
25          }
26      }
27  
28      public static void zigZagToBlock(final int[] zz, final int[] block) {
29          for (int i = 0; i < ZIG_ZAG.length; i++) {
30              block[i] = zz[ZIG_ZAG[i]];
31          }
32      }
33  
34      private ZigZag() {
35      }
36  }