+/*
+ * Imagesqueeze - Image codec optimized for photos.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
package eu.svjatoslav.imagesqueeze.codec;
public class OperatingContext {
byte[] uMap;
byte[] vMap;
ColorStats colorStats = new ColorStats();
-
- public OperatingContext(){
+
+ public OperatingContext() {
}
- public void initialize(Image image, byte [] brightnessMap, byte [] colornessMap, byte [] colorMap){
- this.image = image;
- this.yMap = brightnessMap;
- this.uMap = colornessMap;
- this.vMap = colorMap;
-
- colorStats.reset();
+ public int getURange(final int index) {
+ final int colorness = ImageEncoder.byteToInt(uMap[index]);
+ return Math.abs(colorness - colorStats.getAverageU());
}
-
- public void measureNeighborEncode(int x, int y){
- if ((y >= 0) && (y < image.metaData.height) && (x >= 0) && (x < image.metaData.width)){
-
- int neighborIndex = y * image.metaData.width + x;
-
- colorStats.ySum = colorStats.ySum + ImageEncoder.byteToInt(yMap[neighborIndex]);
- colorStats.uSum = colorStats.uSum + ImageEncoder.byteToInt(uMap[neighborIndex]);
- colorStats.vSum = colorStats.vSum + ImageEncoder.byteToInt(vMap[neighborIndex]);
- colorStats.pixelCount++;
- }
+
+ public int getVRange(final int index) {
+ final int color = ImageEncoder.byteToInt(vMap[index]);
+ return Math.abs(color - colorStats.getAverageV());
}
- public int getYRange(int index){
- int brightness = ImageEncoder.byteToInt(yMap[index]);
- return Math.abs(brightness - colorStats.getAverageY());
+ public int getYRange(final int index) {
+ final int brightness = ImageEncoder.byteToInt(yMap[index]);
+ return Math.abs(brightness - colorStats.getAverageY());
}
- public int getURange(int index){
- int colorness = ImageEncoder.byteToInt(uMap[index]);
- return Math.abs(colorness - colorStats.getAverageU());
+ public void initialize(final Image image, final byte[] brightnessMap,
+ final byte[] colornessMap, final byte[] colorMap) {
+ this.image = image;
+ yMap = brightnessMap;
+ uMap = colornessMap;
+ vMap = colorMap;
+
+ colorStats.reset();
}
- public int getVRange(int index){
- int color = ImageEncoder.byteToInt(vMap[index]);
- return Math.abs(color - colorStats.getAverageV());
+ public void measureNeighborEncode(final int x, final int y) {
+ if ((y >= 0) && (y < image.metaData.height) && (x >= 0)
+ && (x < image.metaData.width)) {
+
+ final int neighborIndex = (y * image.metaData.width) + x;
+
+ colorStats.ySum = colorStats.ySum
+ + ImageEncoder.byteToInt(yMap[neighborIndex]);
+ colorStats.uSum = colorStats.uSum
+ + ImageEncoder.byteToInt(uMap[neighborIndex]);
+ colorStats.vSum = colorStats.vSum
+ + ImageEncoder.byteToInt(vMap[neighborIndex]);
+ colorStats.pixelCount++;
+ }
}
-
}