bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / convwatch / PixelCounter.java
blobbf110ebba3ed8574457fad790b6fd507013e73a4
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package convwatch;
21 // import java.awt.Image;
22 import convwatch.ImageHelper;
24 // -----------------------------------------------------------------------------
25 abstract class CountPixel
27 int m_nCount = 0;
28 public int getCount() {return m_nCount;}
29 public abstract void count(int _nRGB);
32 // -----------------------------------------------------------------------------
33 class CountNotWhite extends CountPixel
35 public CountNotWhite()
37 // System.out.println("CountWhite()");
40 public void count(int pixel)
42 int red = (pixel >> 16) & 0xff;
43 int green = (pixel >> 8) & 0xff;
44 int blue = (pixel ) & 0xff;
46 // System.out.println(String.valueOf(red) + ":" + String.valueOf(green) + ":" + String.valueOf(blue));
47 if (red == 0xff && green == 0xff && blue == 0xff)
49 return;
51 m_nCount++;
55 // -----------------------------------------------------------------------------
56 class CountNotBlack extends CountPixel
58 public CountNotBlack()
60 // System.out.println("CountBlack()");
63 public void count(int pixel)
65 int red = (pixel >> 16) & 0xff;
66 int green = (pixel >> 8) & 0xff;
67 int blue = (pixel ) & 0xff;
69 if (red == 0x00 && green == 0x00 && blue == 0x00)
71 return;
73 m_nCount++;
77 // -----------------------------------------------------------------------------
78 class graphics_stuff
80 public int stuff()
82 // (1) decoding
83 int rgba = 0; // ...; // comes from PixelGrabber, BufferedImage.getRGB etc.
84 int red = (rgba >> 16) & 0xff;
85 int green = (rgba >> 8) & 0xff;
86 int blue = rgba & 0xff;
87 int alpha = (rgba >> 24) & 0xff;
88 // (2) now modify red, green, blue and alpha as you like;
89 // make sure that each of the four values stays in the
90 // interval 0 to 255
91 // ...
92 // (3) and encode back to an int, e.g. to give it to MemoryImageSource or
93 // BufferedImage.setRGB
94 rgba = (alpha << 24) | (red << 16) | (green << 8) | blue;
95 return 0;
98 public static void handlesinglepixel(int x, int y, int pixel)
102 public static void countPixel(ImageHelper img, int _x, int _y, int _w, int _h, CountPixel _aPixelCounter)
104 for (int y = 0; y < _h; y++) {
105 for (int x = 0; x < _w; x++) {
106 // handlesinglepixel(x+i, y+j, pixels[j * w + i]);
107 _aPixelCounter.count(img.getPixel(x,y));
111 public static int countNotWhitePixel(ImageHelper _aImage)
113 int w = _aImage.getWidth();
114 int h = _aImage.getHeight();
116 CountPixel aCountNotWhite = new CountNotWhite();
117 countPixel(_aImage, 0, 0, w, h, aCountNotWhite);
118 return aCountNotWhite.getCount();
121 public static int countNotBlackPixel(ImageHelper _aImage)
123 int w = _aImage.getWidth();
124 int h = _aImage.getHeight();
126 CountPixel aCountNotBlack = new CountNotBlack();
127 countPixel(_aImage, 0, 0, w, h, aCountNotBlack);
128 return aCountNotBlack.getCount();
132 // -----------------------------------------------------------------------------
134 public class PixelCounter {
135 // private Image m_aImage;
136 ImageHelper m_aImage;
139 public int countNotWhitePixel(String _sFile)
140 throws java.io.IOException
142 m_aImage = ImageHelper.createImageHelper(_sFile);
143 int nw = graphics_stuff.countNotWhitePixel(m_aImage);
144 return nw;
147 public int countNotBlackPixel(String _sFile)
148 throws java.io.IOException
150 m_aImage = ImageHelper.createImageHelper(_sFile);
151 int nw = graphics_stuff.countNotBlackPixel(m_aImage);
152 return nw;
155 public static int countNotWhitePixelsFromImage(String _sFile)
156 throws java.io.IOException
158 PixelCounter a = new PixelCounter();
159 return a.countNotWhitePixel(_sFile);
162 public static int countNotBlackPixelsFromImage(String _sFile)
163 throws java.io.IOException
165 PixelCounter a = new PixelCounter();
166 return a.countNotBlackPixel(_sFile);
169 // -----------------------------------------------------------------------------
171 // public static void main(String[] args) {
173 // String a = helper.StringHelper.createValueString(10, 4);
174 // int dummy = 1;
175 ///*
176 // BorderRemover a = new BorderRemover();
177 // try
178 // {
179 // a.createNewImageWithoutBorder(args[0], args[1]);
180 // }
181 // catch(java.io.IOException e)
182 // {
183 // System.out.println("Exception caught.");
184 // }
185 // */
186 // }