bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / convwatch / ImageHelper.java
blob1114a8d6aea837398ffc112ac26d1c0fc2f41e7e
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 java.awt.image.PixelGrabber;
23 import java.awt.image.ImageObserver;
24 import java.io.File;
25 //import javax.imageio.ImageIO;
26 import java.lang.reflect.Method;
28 class ImageHelper
30 Image m_aImage;
31 int[] m_aPixels;
32 int m_w = 0;
33 int m_h = 0;
34 boolean m_bGrabbed = false;
36 public ImageHelper(Image _aImage)
38 m_aImage = _aImage;
40 // grab all (consume much memory)
41 m_w = getWidth();
42 m_h = getHeight();
43 int x = 0;
44 int y = 0;
45 m_aPixels = new int[m_w * m_h];
46 PixelGrabber pg = new PixelGrabber(m_aImage, x, y, m_w, m_h, m_aPixels, 0, m_w);
47 try {
48 pg.grabPixels();
49 } catch (InterruptedException e) {
50 System.err.println("interrupted waiting for pixels!");
51 return;
53 if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
54 System.err.println("image fetch aborted or errored");
55 return;
57 m_bGrabbed = true;
59 public int getWidth() {return m_aImage.getWidth(null);}
60 public int getHeight() {return m_aImage.getHeight(null);}
61 // direct access to a pixel
62 public int getPixel(int x, int y)
64 return m_aPixels[y * m_w + x];
67 // Write down the current image to a file.
68 // public void storeImage(String _sFilename)
69 // {
70 // }
72 public static ImageHelper createImageHelper(String _sFilename)
73 throws java.io.IOException
75 Image aImage = null;
76 File aFile = new File(_sFilename);
77 Exception ex = null;
78 try {
79 Class<?> imageIOClass = Class.forName("javax.imageio.ImageIO");
80 Method readMethod = imageIOClass.getDeclaredMethod("read", new Class[]{java.io.File.class});
81 Object retValue = readMethod.invoke(imageIOClass, new Object[]{aFile});
82 aImage = (Image)retValue;
84 catch(java.lang.ClassNotFoundException e) {
85 ex = e;
87 catch(java.lang.NoSuchMethodException e) {
88 ex = e;
90 catch(java.lang.IllegalAccessException e) {
91 ex = e;
93 catch(java.lang.reflect.InvocationTargetException e) {
94 ex = e;
97 if (ex != null) {
98 // get Java version:
99 String javaVersion = System.getProperty("java.version");
100 throw new java.io.IOException(
101 "Cannot construct object with current Java version " +
102 javaVersion + ": " + ex.getMessage());
104 // aImage = ImageIO.read(aFile);
105 return new ImageHelper(aImage);