/*
- * Imagesqueeze - Image codec optimized for photos.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ * Imagesqueeze - Image codec. Copyright ©2012-2019, 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.
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
*/
package eu.svjatoslav.imagesqueeze.codec;
-public class OperatingContext {
-
- Image image;
- byte[] yMap;
- byte[] uMap;
- byte[] vMap;
- ColorStats colorStats = new ColorStats();
-
- public OperatingContext() {
- }
-
- public int getURange(final int index) {
- final int colorness = ImageEncoder.byteToInt(uMap[index]);
- return Math.abs(colorness - colorStats.getAverageU());
- }
-
- public int getVRange(final int index) {
- final int color = ImageEncoder.byteToInt(vMap[index]);
- return Math.abs(color - colorStats.getAverageV());
- }
-
- public int getYRange(final int index) {
- final int brightness = ImageEncoder.byteToInt(yMap[index]);
- return Math.abs(brightness - colorStats.getAverageY());
- }
-
- 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 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++;
- }
- }
+class OperatingContext {
+
+ final ColorStats colorStats = new ColorStats();
+ private Image image;
+ private byte[] yMap;
+ private byte[] uMap;
+ private byte[] vMap;
+
+ public OperatingContext() {
+ }
+
+ public int getURange(final int index) {
+ final int colorness = ImageEncoder.byteToInt(uMap[index]);
+ return Math.abs(colorness - colorStats.getAverageU());
+ }
+
+ public int getVRange(final int index) {
+ final int color = ImageEncoder.byteToInt(vMap[index]);
+ return Math.abs(color - colorStats.getAverageV());
+ }
+
+ public int getYRange(final int index) {
+ final int brightness = ImageEncoder.byteToInt(yMap[index]);
+ return Math.abs(brightness - colorStats.getAverageY());
+ }
+
+ 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 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++;
+ }
+ }
}