bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / graphical / PixelCounter.java
blobb7e1b6464bfb10b4ddfae16e1b5e792c6f77e54a
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 graphical;
22 // -----------------------------------------------------------------------------
23 abstract class CountPixel
25 protected int m_nCount = 0;
26 public int getCount() {return m_nCount;}
27 public abstract void count(int _nRGB);
30 // -----------------------------------------------------------------------------
31 class CountNotWhite extends CountPixel
33 public CountNotWhite()
35 // System.out.println("CountWhite()");
38 public void countold(final int pixel)
40 // final int alpha = (pixel >> 24) & 0xff;
41 final int red = (pixel >> 16) & 0xff;
42 final int green = (pixel >> 8) & 0xff;
43 final int blue = (pixel ) & 0xff;
45 // System.out.println(String.valueOf(red) + ":" + String.valueOf(green) + ":" + String.valueOf(blue));
46 if (red == 0xff && green == 0xff && blue == 0xff)
48 return;
50 ++m_nCount;
52 public void count(final int pixel)
54 // final int alpha = (pixel >> 24) & 0xff;
55 final int blue = (pixel ) & 0xff;
56 if (blue != 0xff)
58 ++m_nCount;
59 return;
61 final int green = (pixel >> 8) & 0xff;
62 if (green != 0xff)
64 ++m_nCount;
65 return;
67 final int red = (pixel >> 16) & 0xff;
68 if (red != 0xff)
70 ++m_nCount;
71 return;
76 // -----------------------------------------------------------------------------
77 class CountNotBlack extends CountPixel
79 public CountNotBlack()
81 // System.out.println("CountBlack()");
84 public void countold(final int pixel)
86 // final int alpha = (pixel >> 24) & 0xff;
87 final int red = (pixel >> 16) & 0xff;
88 final int green = (pixel >> 8) & 0xff;
89 final int blue = (pixel ) & 0xff;
91 if (red == 0x00 && green == 0x00 && blue == 0x00)
93 return;
95 ++m_nCount;
97 public void count(final int pixel)
99 // final int alpha = (pixel >> 24) & 0xff;
100 final int blue = (pixel ) & 0xff;
101 if (blue != 0x00)
103 ++m_nCount;
104 return;
106 final int green = (pixel >> 8) & 0xff;
107 if (green != 0x00)
109 ++m_nCount;
110 return;
112 final int red = (pixel >> 16) & 0xff;
113 if (red != 0x00)
115 ++m_nCount;
116 return;
121 // -----------------------------------------------------------------------------
122 class graphics_stuff
124 // public int stuff()
125 // {
126 //// (1) decoding
127 // int rgba = 0; // ...; // comes from PixelGrabber, BufferedImage.getRGB etc.
128 // int red = (rgba >> 16) & 0xff;
129 // int green = (rgba >> 8) & 0xff;
130 // int blue = rgba & 0xff;
131 // int alpha = (rgba >> 24) & 0xff;
132 //// (2) now modify red, green, blue and alpha as you like;
133 //// make sure that each of the four values stays in the
134 //// interval 0 to 255
135 //// ...
136 //// (3) and encode back to an int, e.g. to give it to MemoryImageSource or
137 //// BufferedImage.setRGB
138 // rgba = (alpha << 24) | (red << 16) | (green << 8) | blue;
139 // return 0;
140 // }
142 // public static void handlesinglepixel(int x, int y, int pixel)
143 // {
144 // int alpha = (pixel >> 24) & 0xff;
145 // int red = (pixel >> 16) & 0xff;
146 // int green = (pixel >> 8) & 0xff;
147 // int blue = (pixel ) & 0xff;
148 // // Deal with the pixel as necessary...
149 // }
151 public static void countPixel(ImageHelper img, int _x, int _y, int _w, int _h, CountPixel _aPixelCounter)
153 for (int y = 0; y < _h; y++) {
154 for (int x = 0; x < _w; x++) {
155 // handlesinglepixel(x+i, y+j, pixels[j * w + i]);
156 _aPixelCounter.count(img.getPixel(x,y));
160 public static int countNotWhitePixel(ImageHelper _aImage)
162 final int w = _aImage.getWidth();
163 final int h = _aImage.getHeight();
165 CountPixel aCountNotWhite = new CountNotWhite();
166 countPixel(_aImage, 0, 0, w, h, aCountNotWhite);
167 return aCountNotWhite.getCount();
170 public static int countNotBlackPixel(ImageHelper _aImage)
172 final int w = _aImage.getWidth();
173 final int h = _aImage.getHeight();
175 CountPixel aCountNotBlack = new CountNotBlack();
176 countPixel(_aImage, 0, 0, w, h, aCountNotBlack);
177 return aCountNotBlack.getCount();
181 // -----------------------------------------------------------------------------
183 public class PixelCounter {
184 // private Image m_aImage;
185 // ImageHelper m_aImage;
188 public int countNotWhitePixel(String _sFile)
189 throws java.io.IOException
191 ImageHelper aImage = ImageHelper.createImageHelper(_sFile);
192 final int nw = graphics_stuff.countNotWhitePixel(aImage);
193 return nw;
196 public int countNotBlackPixel(String _sFile)
197 throws java.io.IOException
199 ImageHelper aImage = ImageHelper.createImageHelper(_sFile);
200 final int nw = graphics_stuff.countNotBlackPixel(aImage);
201 return nw;
204 public static int countNotWhitePixelsFromImage(String _sFile)
205 throws java.io.IOException
207 PixelCounter a = new PixelCounter();
208 return a.countNotWhitePixel(_sFile);
211 public static int countNotBlackPixelsFromImage(String _sFile)
212 throws java.io.IOException
214 PixelCounter a = new PixelCounter();
215 return a.countNotBlackPixel(_sFile);
218 // -----------------------------------------------------------------------------
220 // public static void main(String[] args) {
222 // String a = helper.StringHelper.createValueString(10, 4);
223 // int dummy = 1;
224 ///*
225 // BorderRemover a = new BorderRemover();
226 // try
227 // {
228 // a.createNewImageWithoutBorder(args[0], args[1]);
229 // }
230 // catch(java.io.IOException e)
231 // {
232 // System.out.println("Exception caught.");
233 // }
234 // */
235 // }