Updated copyright. Prefer HTTPS in documentation. Switched to LGPLv3 or later.
[imagesqueeze.git] / src / main / java / eu / svjatoslav / imagesqueeze / codec / Channel.java
1 /*
2  * Imagesqueeze - Image codec. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  */
8
9 package eu.svjatoslav.imagesqueeze.codec;
10
11 class Channel {
12
13     final byte[] rangeMap;
14     final byte[] map;
15
16     final byte[] decodedRangeMap;
17     final byte[] decodedMap;
18
19     int bitCount;
20
21     public Channel(final int width, final int height) {
22         rangeMap = new byte[width * height];
23
24         map = new byte[width * height];
25
26         decodedRangeMap = new byte[width * height];
27         decodedRangeMap[0] = (byte) 255;
28
29         decodedMap = new byte[width * height];
30     }
31
32     public void printStatistics() {
33         final float bitsPerPixel = (float) bitCount / (float) rangeMap.length;
34         System.out.println((bitCount / 8) + " bytes. " + bitsPerPixel
35                 + " bits per pixel.");
36     }
37
38     public void reset() {
39
40         for (int i = 0; i < decodedMap.length; i++) {
41             decodedMap[i] = 0;
42         }
43
44         for (int i = 0; i < decodedRangeMap.length; i++) {
45             decodedRangeMap[i] = 0;
46         }
47         decodedRangeMap[0] = (byte) 255;
48
49         for (int i = 0; i < map.length; i++) {
50             map[i] = 0;
51         }
52
53         for (int i = 0; i < rangeMap.length; i++) {
54             rangeMap[i] = 0;
55         }
56
57         bitCount = 0;
58     }
59
60 }