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