javauis/eswt_qt/s60utils/java/src/com/nokia/mj/impl/uitestutils/ImageTestUtils.java
changeset 35 85266cc22c7f
parent 26 dc7c549001d5
child 40 c6043ea9b06a
child 44 0105bdca6f9c
child 47 f40128debb5d
child 49 35baca0e7a2e
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 package com.nokia.mj.impl.uitestutils;
       
    18 
       
    19 import org.eclipse.swt.internal.qt.graphics.Image;
       
    20 import java.util.Arrays;
       
    21 
       
    22 /**
       
    23  * Image utils for verifying image pixels against mask
       
    24  * plus some other helpers for verifying image properties. 
       
    25  * 
       
    26  * NOTE. Currently only CGFX images are supported however eSWT images 
       
    27  * can be verified by using org.eclipse.swt.internal.qt.graphics.Image internal_getImage()
       
    28  * to obtain wrapped CGFX image.
       
    29  * 
       
    30  * Usage example
       
    31  * 
       
    32  * create a mask from mask data and then mask by giving data and scanlenght.
       
    33  * <code>
       
    34  * int[] maskData = {
       
    35  *   	0,0,0,0,0,0,0,0,0,
       
    36  * 		0,0,0,0,1,0,0,0,0,
       
    37  * 		0,0,0,0,1,0,0,0,0,
       
    38  * 		0,0,0,0,1,0,0,0,0,
       
    39  * 		0,0,0,0,1,0,0,0,0,
       
    40  * 		0,0,0,0,1,0,0,0,0,
       
    41  * 		0,0,0,0,1,0,0,0,0,
       
    42  * 		0,0,0,0,0,0,0,0,0
       
    43  * };
       
    44  * 
       
    45  * Mask mask = new Mask(maskData, 9);
       
    46  * </code>
       
    47  * 
       
    48  * Then image pixels can be validated with ImageTestUtils. That is where there is 1 in mask it is
       
    49  * compared against maskArgb and all where there is 0 in mask it is compared against bgArgb.
       
    50  * <code>
       
    51  * ImageTestUtils.validatePixels(imageToValidate, mask, maskArgb, bgArgb); 
       
    52  * </code>
       
    53  * 
       
    54  * @author sampkaar
       
    55  *
       
    56  */
       
    57 public class ImageTestUtils {
       
    58 
       
    59 	/** 
       
    60 	 * This pixel is rendering target image background color.
       
    61 	 */
       
    62 	public static final int IMAGE_BACKGROUND_COLOR = 0;
       
    63 
       
    64 	/** 
       
    65 	 * This pixel is foreground color set to GC.
       
    66 	 */
       
    67 	public static final int GC_FOREGROUND_COLOR = 1;
       
    68 
       
    69 	/**
       
    70 	 * This pixel is either foreground or image background color.
       
    71 	 * Used for example in drawRoundRect and drawEllipse tests.
       
    72 	 */
       
    73 	public static final int FOREGROUND_OR_IMAGE_BACKGROUND_COLOR = 2;
       
    74 	
       
    75 	/** 
       
    76 	 * This pixel is background color set to GC.
       
    77 	 * Used for example in fillGradientRect test.
       
    78 	 */
       
    79 	public static final int GC_BACKGROUND_COLOR = 3;
       
    80 
       
    81 	/**
       
    82 	 * This pixel is neither foreground nor gc background color. 
       
    83 	 * Used for example in fillGradientRect test. 
       
    84 	 */
       
    85 	public static final int NEITHER_FOREGROUND_NOR_GC_BACKGROUND_COLOR = 4;
       
    86 
       
    87 	/** 
       
    88 	 * This pixel can be ignored.
       
    89 	 * Used for example in fillGradientRect test.
       
    90 	 */
       
    91 	public static final int IGNORE_COLOR = 5;
       
    92 	
       
    93 	/**
       
    94 	 * Validates image dimensions against reference width and height.
       
    95 	 * Prints possible problems to System.out.
       
    96 	 * 
       
    97 	 * @param img - The image to check
       
    98 	 * @param refWidth - The reference width
       
    99 	 * @param refHeight - The reference height
       
   100 	 */
       
   101 	public static final boolean validateImageDimensions(Image img, int refWidth, int refHeight) {
       
   102 		if ((refWidth != img.getWidth()) || (refHeight != img.getHeight())) {
       
   103 			System.out.println("Image size should be ("+refWidth+","+refHeight+"), "+
       
   104 							   "but is ("+img.getWidth()+","+img.getHeight()+")");
       
   105 			return false;
       
   106 		}
       
   107 		return true;
       
   108 	}
       
   109 	
       
   110 	/**
       
   111 	 * Validates image pixels which are outside specified rectangle ingoreRect against given reference color.
       
   112 	 * 
       
   113 	 * @param ignoreRect The area that is to be ingnored
       
   114 	 * @param img Image to validate
       
   115 	 * @param argb The reference color
       
   116 	 * @return true if all pixels outside ingoreRect have reference color orherwise false 
       
   117 	 */
       
   118 	public static final boolean validatePixels(Rect ignoreRect, Image img, int argb) {
       
   119 		final int width = img.getWidth();
       
   120 		final int height = img.getHeight();
       
   121 		final int pixels =  width * height;
       
   122 		final int scanlength = img.getWidth();
       
   123 		
       
   124 		// data array for image data
       
   125 		int[] imageData = new int[pixels];
       
   126 		
       
   127 		// get data for whole image
       
   128 		img.getRGB(imageData, 0, width, 0, 0, width, height);
       
   129 
       
   130 		// calculate start index
       
   131 		int start = scanlength*ignoreRect.y();
       
   132 		for(int y = 0; y<ignoreRect.height();y++) {
       
   133 			Arrays.fill(imageData, start+ignoreRect.x(), start+ignoreRect.width()+ignoreRect.x(), argb);
       
   134 			// move start to next line
       
   135 			start += scanlength;
       
   136 		}
       
   137 		
       
   138 		// validate array
       
   139 		for(int i=0; i < pixels; i++) {
       
   140 			if(!(imageData[i] == argb)) {
       
   141 				return false;
       
   142 			}
       
   143 		}
       
   144 		return true;
       
   145 	}
       
   146 	
       
   147 	/**
       
   148 	 * Validates that there is at least one pixel with foreground color inside the specified rectangle
       
   149 	 * and that image pixels which are outside specified rectangle has background color.
       
   150 	 * 
       
   151 	 * @param rect The area that is to be checked
       
   152 	 * @param img Image to validate
       
   153 	 * @param fgColor The color that must exist inside the rect
       
   154 	 * @param bgColor The color which must be outside the rect
       
   155 	 * @return true if all pixels outside rect have background color and at least one pixel inside the rect has foreground color 
       
   156 	 *         orherwise false 
       
   157 	 */
       
   158 	public static final boolean validatePixels(Rect rect, Image img, int fgColor, int bgColor) {
       
   159 		final int width = img.getWidth();
       
   160 		final int height = img.getHeight();
       
   161 		final int pixels =  width * height;
       
   162 		final int scanlength = img.getWidth();
       
   163 		boolean foundFgColor = false;
       
   164 				
       
   165 		// data array for image data
       
   166 		int[] imageData = new int[pixels];
       
   167 		
       
   168 		// get data for whole image
       
   169 		img.getRGB(imageData, 0, width, 0, 0, width, height);
       
   170 
       
   171 		Rect imageRect = new Rect(0,0,width, height);
       
   172 		rect = rect.intersection(imageRect);
       
   173 
       
   174 		// Check that foreground color was found inside the rect
       
   175 		foundFgColor = isAtleastOnePixelWithRefColor(img, rect, fgColor);		
       
   176 		if(!foundFgColor){
       
   177 			return false;
       
   178 		}
       
   179 		
       
   180 		int start = scanlength*rect.y();
       
   181 		// Fill the rect with background color
       
   182 		for(int y = 0; y<rect.height();y++) {
       
   183 			Arrays.fill(imageData, start+rect.x(), start+rect.width()+rect.x(), bgColor);
       
   184 			// move start to next line
       
   185 			start += scanlength;
       
   186 		}
       
   187 		
       
   188 		// validate array, now all pixels should have background color
       
   189 		for(int i=0; i < pixels; i++) {
       
   190 			if(!(imageData[i] == bgColor)) {
       
   191 				return false;
       
   192 			}
       
   193 		}
       
   194 		return true;
       
   195 	}
       
   196 
       
   197 	/**
       
   198 	 * Validates that there is at least one pixel with foreground color inside the specified rectangle
       
   199 	 * and that image pixels which are outside specified rectangle has background color.
       
   200 	 * 
       
   201 	 * @param rect The area that is to be checked
       
   202 	 * @param img Image to validate
       
   203 	 * @param fgColor The color that must exist inside the rect
       
   204 	 * @param textRectColor The background color of the rect 
       
   205 	 * @param bgColor The color which must be outside the rect
       
   206 	 * @param textRectColorOn true if textRectColor must exist inside the rect, false if textRectColor shouldn't be found inside the rect 
       
   207 	 * @return true if all pixels outside rect have background color and at least one pixel inside the rect has foreground color 
       
   208 	 *         orherwise false 
       
   209 	 */
       
   210 	public static final boolean validatePixels(Rect rect, Image img, int fgColor, int textRectColor, int bgColor, boolean textRectColorOn) {
       
   211 
       
   212 		if(textRectColorOn){
       
   213 			// Check that text background color was found inside the rect
       
   214 			if(!isAtleastOnePixelWithRefColor(img, rect, textRectColor)){
       
   215 				return false;
       
   216 			}
       
   217 		} else {
       
   218 			// Check that text background color is not found inside the rect		
       
   219 			if(isAtleastOnePixelWithRefColor(img, rect, textRectColor)){
       
   220 				return false;
       
   221 			}
       
   222 		}
       
   223 		
       
   224 		return validatePixels(rect, img, fgColor, bgColor);
       
   225 	}
       
   226 
       
   227 	/**
       
   228 	 * Validates that there is at least one pixel with foreground color inside the specified rectangles
       
   229 	 * and that image pixels which are outside specified rectangles has background color.
       
   230 	 * 
       
   231 	 * @param rects The areas that is to be checked
       
   232 	 * @param img Image to validate
       
   233 	 * @param fgColor The color that must exist inside the rects
       
   234 	 * @param bgColor The color which must be outside the rects
       
   235 	 * @return true if all pixels outside rects have background color and at least one pixel inside the rects has foreground color 
       
   236 	 *         orherwise false 
       
   237 	 */
       
   238 	public static final boolean validatePixels(Rect[] rects, Image img, int fgColor, int bgColor) {
       
   239 		final int width = img.getWidth();
       
   240 		final int height = img.getHeight();
       
   241 		final int pixels =  width * height;
       
   242 		final int scanlength = img.getWidth();
       
   243 		boolean foundFgColor = false;
       
   244 		final int rectCount = rects.length;
       
   245 
       
   246 		Rect imageRect = new Rect(0,0,width, height);
       
   247 		// Check that foreground color is found inside each rect
       
   248 		for(int i=0; i<rectCount; i++){
       
   249 			rects[i] = rects[i].intersection(imageRect);
       
   250 			foundFgColor = isAtleastOnePixelWithRefColor(img, rects[i], fgColor);		
       
   251 			if(!foundFgColor){
       
   252 				return false;
       
   253 			}
       
   254 		}
       
   255 		
       
   256 		// Check that background color is found outside the rects
       
   257 
       
   258 		// data array for image data
       
   259 		int[] imageData = new int[pixels];
       
   260 		// get data for whole image
       
   261 		img.getRGB(imageData, 0, width, 0, 0, width, height);
       
   262 
       
   263 		int start;
       
   264 		// Fill the rects with background color
       
   265 		for(int i=0; i<rectCount; i++){
       
   266 			start = scanlength*rects[i].y();
       
   267 			for(int y = 0; y<rects[i].height();y++) {
       
   268 				Arrays.fill(imageData, start+rects[i].x(), start+rects[i].width()+rects[i].x(), bgColor);
       
   269 				// move start to next line
       
   270 				start += scanlength;
       
   271 			}
       
   272 		}
       
   273 		
       
   274 		// validate array, now all pixels should have background color
       
   275 		for(int i=0; i < pixels; i++) {
       
   276 			if(!(imageData[i] == bgColor)) {
       
   277 				return false;
       
   278 			}
       
   279 		}
       
   280 		return true;
       
   281 	}
       
   282 
       
   283 	/**
       
   284 	 * Checks is there at least one pixel with reference color inside the specified rectangle in Image.
       
   285 	 * 
       
   286 	 * @param rect The area that is to be checked
       
   287 	 * @param refColor The color that must exist inside the rect
       
   288 	 * @return true if at least one pixel inside the rect has reference color orherwise false 
       
   289 	 */
       
   290 	public static final boolean isAtleastOnePixelWithRefColor(Image img, Rect rect, int refColor) {
       
   291 		
       
   292 		final int width = img.getWidth();
       
   293 		final int height = img.getHeight();
       
   294 		final int pixels =  width * height;
       
   295 		final int scanlength = img.getWidth();
       
   296 
       
   297 		// data array for image data
       
   298 		int[] imageData = new int[pixels];
       
   299 		
       
   300 		// get data for whole image
       
   301 		img.getRGB(imageData, 0, width, 0, 0, width, height);
       
   302 
       
   303 		// calculate start index
       
   304 		int start = scanlength*rect.y();
       
   305 
       
   306 		// Check that is at least one pixel has foreground color inside the rect
       
   307 		for(int y = 0; y<rect.height();y++) {
       
   308 			for(int i=start+rect.x(); i < start+rect.width()+rect.x(); i++) {			
       
   309 				if((imageData[i] == refColor)) {
       
   310 					return true;
       
   311 				}
       
   312 			}
       
   313 			// move start to next line
       
   314 			start += scanlength;
       
   315 		}	
       
   316 		return false;
       
   317 	}
       
   318 	
       
   319 	/**
       
   320 	 * Validates that every pixel in given image has
       
   321 	 * given referense color value argb. 
       
   322 	 * 
       
   323 	 * @param img - The image to check
       
   324 	 * @param argb - The referece color to compare
       
   325 	 */
       
   326 	public static final boolean validatePixels(Image img, int argb) {
       
   327 		
       
   328 		final int width = img.getWidth();
       
   329 		final int height = img.getHeight();
       
   330 		final int pixels =  width * height;
       
   331 		
       
   332 		// get color components from reference
       
   333 		final int refAlpha 	= (argb >> 24) 	& 0xff;
       
   334 		final int refRed   	= (argb >> 16) 	& 0xff;
       
   335 		final int refGreen 	= (argb >> 8) 	& 0xff;
       
   336 		final int refBlue 	= (argb) 		& 0xff;
       
   337 		
       
   338 		// data array for image data
       
   339 		int[] imageData = new int[pixels];
       
   340 		
       
   341 		// get data for whole image
       
   342 		img.getRGB(imageData, 0, width, 0, 0, width, height);
       
   343 	
       
   344 		// check each pixel in image, break if pixel does not match
       
   345 		for(int i=0; i < pixels; i++) {
       
   346 			if (refAlpha != ((imageData[i] >> 24) & 0xff)) return false;
       
   347 			if (refRed 	 != ((imageData[i] >> 16) & 0xff)) return false; 
       
   348 			if (refGreen != ((imageData[i] >> 8 ) & 0xff)) return false;
       
   349 			if (refBlue  != ( imageData[i]        & 0xff)) return false;
       
   350 		}
       
   351 		return true;
       
   352 	}
       
   353 	
       
   354 	/**
       
   355 	 * Validates that given pixels are equal to 
       
   356 	 * reference pixel color (argb) and background color in given rgb data
       
   357 	 * 
       
   358 	 * @param rgbdata - The image data to be checked
       
   359 	 * @param mask - the reference mask
       
   360 	 * @param maskArgb - The reference color for pixels with value 1 in mask
       
   361 	 * @param bgArgb - The reference color for pixels with value 0 in mask
       
   362 	 * 
       
   363 	 */
       
   364 	public static final boolean validatePixels(int[] rgbdata, Mask mask, int maskArgb, int bgArgb) {
       
   365 		return doCheckPixels(rgbdata, mask, maskArgb, bgArgb, 0, false);
       
   366 	}
       
   367 	
       
   368 	/**
       
   369 	 * Validates that given pixels are equal to 
       
   370 	 * reference pixel color (argb) and background color in given rgb data
       
   371 	 * 
       
   372 	 * @param rgbdata - The image data to be checked
       
   373 	 * @param dataOffset The offset from beginning of rgbdata where image data starts
       
   374 	 * @param dataLength The lenght of image data after offset
       
   375 	 * @param mask - the reference mask
       
   376 	 * @param maskArgb - The reference color for pixels with value 1 in mask
       
   377 	 * @param bgArgb - The reference color for pixels with value 0 in mask
       
   378 	 * 
       
   379 	 */
       
   380 	public static final boolean validatePixels(int[] rgbdata, int dataOffset, int dataLength, Mask mask, int maskArgb, int bgArgb) {
       
   381 		
       
   382 		// create array for data 
       
   383 		int[] data = new int[dataLength];
       
   384 		
       
   385 		// copy from rgbdata to data
       
   386 		for(int i=dataOffset; i < rgbdata.length; i++) {
       
   387 			data[i-dataOffset] = rgbdata[i];
       
   388 		}
       
   389 		
       
   390 		//System.out.println("\n mask size: " + mask.getData().length+", dataSize: " + rgbdata.length);
       
   391 		return doCheckPixels(data, mask, maskArgb, bgArgb, 0, false);
       
   392 	}
       
   393 	
       
   394 	/**
       
   395 	 * Validates that given pixels are equal to 
       
   396 	 * reference pixel color (argb) and background color in image
       
   397 	 * 
       
   398 	 * @param img - The image to check
       
   399 	 * @param mask - the reference mask
       
   400 	 * @param maskArgb - The reference color for pixels with value 1 in mask
       
   401 	 * @param bgArgb - The reference color for pixels with value 0 in mask
       
   402 	 * 
       
   403 	 */
       
   404 	public static final boolean validatePixels(Image img, Mask mask, int maskArgb, int bgArgb) {
       
   405 		
       
   406 		// data array for image data
       
   407 		int[] imageData = new int[img.getWidth()*img.getHeight()];
       
   408 		
       
   409 		// get data for whole image
       
   410 		img.getRGB(imageData, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
       
   411 		
       
   412 		// check pixels
       
   413 		return doCheckPixels(imageData, mask, maskArgb, bgArgb, 0, false);
       
   414 	}
       
   415 	
       
   416 	/**
       
   417 	 * Validates that given pixels are equal to 
       
   418 	 * reference pixel color (argb) and background color in image
       
   419 	 * 
       
   420 	 * @param img - The image to check
       
   421 	 * @param mask - the reference mask
       
   422 	 * @param maskArgb - The reference color for pixels with value 1 in mask
       
   423 	 * @param bgArgb - The reference color for pixels with value 0 in mask
       
   424 	 * @param ingoreAlpha If true alpha value is not validated
       
   425 	 * @return true if mask and image match otherwise false
       
   426 	 */
       
   427 	public static final boolean validatePixels(Image img, Mask mask, int maskArgb, int bgArgb, boolean ignoreAlpha) {
       
   428 		
       
   429 		// data array for image data
       
   430 		int[] imageData = new int[img.getWidth()*img.getHeight()];
       
   431 		
       
   432 		// get data for whole image
       
   433 		img.getRGB(imageData, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
       
   434 		
       
   435 		// check pixels
       
   436 		return doCheckPixels(imageData, mask, maskArgb, bgArgb, 0, ignoreAlpha);
       
   437 	}
       
   438 
       
   439 	/**
       
   440 	 * Validates that given pixels are equal to 
       
   441 	 * foreground color (argb), image background color and gc background color in image
       
   442 	 * 
       
   443 	 * @param img - The image to check
       
   444 	 * @param mask - the reference mask
       
   445 	 * @param fgArgb - The reference color for pixels with value 1 GC_FOREGROUND_COLOR in mask
       
   446 	 * @param gcBgArgb - The reference color for pixels with value 3 GC_BACKGROUND_COLOR in mask
       
   447 	 * @param imgBgArgb - The reference color for pixels with value 0 IMAGE_BACKGROUND_COLOR in mask
       
   448 	 * @param ingoreAlpha If true alpha value is not validated
       
   449 	 * @return true if mask and image match otherwise false
       
   450 	 */
       
   451 	public static final boolean validatePixels(Image img, Mask mask, int fgArgb, int gcBgArgb, int imgBgArgb, boolean ignoreAlpha) {
       
   452 		
       
   453 		// data array for image data
       
   454 		int[] imageData = new int[img.getWidth()*img.getHeight()];
       
   455 		
       
   456 		// get data for whole image
       
   457 		img.getRGB(imageData, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
       
   458 		
       
   459 		// check pixels
       
   460 		return doCheckPixels(imageData, mask, fgArgb, imgBgArgb, gcBgArgb, ignoreAlpha);
       
   461 	}
       
   462 
       
   463 	/*
       
   464 	 * method for checking pixels against mask
       
   465 	 * The imageData and the data in mask must be same size.  
       
   466 	 */
       
   467 	private static final boolean doCheckPixels(int[] imageData, Mask mask, int fgColorArgb, int imgBgColorArgb, int gcBgColorArgb, boolean ignoreAlpha ) {
       
   468 		
       
   469 		// get color components for GC foreground color
       
   470 		final int fgAlpha 	= (fgColorArgb >> 24) 	& 0xff;
       
   471 		final int fgRed   	= (fgColorArgb >> 16) 	& 0xff;
       
   472 		final int fgGreen 	= (fgColorArgb >> 8) 	& 0xff;
       
   473 		final int fgBlue 	= (fgColorArgb) 		& 0xff;
       
   474 		
       
   475 		// get color components for image background color
       
   476 		final int imgBgAlpha 	= (imgBgColorArgb  >> 24) 	& 0xff;
       
   477 		final int imgBgRed   	= (imgBgColorArgb  >> 16) 	& 0xff;
       
   478 		final int imgBgGreen 	= (imgBgColorArgb  >> 8) 	& 0xff;
       
   479 		final int imgBgBlue 	= (imgBgColorArgb) 			& 0xff;
       
   480 		
       
   481 		// get color components for GC background color
       
   482 		int gcBgAlpha 	= 0;
       
   483 		int gcBgRed   	= 0;
       
   484 		int gcBgGreen 	= 0;
       
   485 		int gcBgBlue 	= 0;
       
   486 		if (gcBgColorArgb != 0){ // GC Background color is defined
       
   487 			gcBgAlpha 	= (gcBgColorArgb  >> 24) 	& 0xff;
       
   488 			gcBgRed   	= (gcBgColorArgb  >> 16) 	& 0xff;
       
   489 			gcBgGreen 	= (gcBgColorArgb  >> 8) 	& 0xff;
       
   490 			gcBgBlue 	= (gcBgColorArgb) 			& 0xff;
       
   491 		}
       
   492 		
       
   493 		// get mask data
       
   494 		int[] maskdata = mask.getData();
       
   495 		
       
   496 		// verify background & pixels
       
   497 		for(int i=0; i < imageData.length; i++) {
       
   498 
       
   499 			// if mask pixel is GC_FOREGROUND_COLOR (1), check against fgArgb
       
   500 			if(maskdata[i] == GC_FOREGROUND_COLOR) {	
       
   501 				if (!ignoreAlpha) {
       
   502 				    if (fgAlpha != ((imageData[i] >> 24) & 0xff)) return false;
       
   503 				}
       
   504 				if (fgRed	!= ((imageData[i] >> 16) & 0xff)) return false; 
       
   505 				if (fgGreen != ((imageData[i] >> 8 ) & 0xff)) return false;
       
   506 				if (fgBlue  != ( imageData[i]        & 0xff)) return false;
       
   507 			} 
       
   508 			// if mask pixel is FOREGROUND_OR_IMAGE_BACKGROUND_COLOR (2), this pixel is either 
       
   509 			// foreground or image background color. 
       
   510 			// Used for example in drawRoundRect and drawEllipse tests.
       
   511 			else if(maskdata[i] == FOREGROUND_OR_IMAGE_BACKGROUND_COLOR) {	
       
   512 				if (!ignoreAlpha) {
       
   513 					if (fgAlpha 	!= ((imageData[i] >> 24) & 0xff) && 
       
   514 						imgBgAlpha 	!= ((imageData[i] >> 24) & 0xff)) return false;
       
   515 				}				
       
   516 				if (fgRed 	 	!= ((imageData[i] >> 16) & 0xff) && 
       
   517 					imgBgRed 	!= ((imageData[i] >> 16) & 0xff)) return false; 
       
   518 
       
   519 				if (fgGreen 	!= ((imageData[i] >> 8 ) & 0xff) && 
       
   520 					imgBgGreen 	!= ((imageData[i] >> 8 ) & 0xff)) return false;
       
   521 	
       
   522 				if (fgBlue  	!= ( imageData[i]        & 0xff) && 
       
   523 					imgBgBlue	!= ( imageData[i]         & 0xff)) return false;
       
   524 			} 
       
   525 			// if mask pixel is GC_BACKGROUND_COLOR (3), this pixel is background color set to GC. 
       
   526 			// Used for example in fillGradientRect test.
       
   527 			else if(maskdata[i] == GC_BACKGROUND_COLOR) {	
       
   528 				if (!ignoreAlpha) {
       
   529 					if (gcBgAlpha != ((imageData[i] >> 24) & 0xff)) return false;
       
   530 				}
       
   531 				if (gcBgRed 	!= ((imageData[i] >> 16) & 0xff)) return false; 
       
   532 				if (gcBgGreen 	!= ((imageData[i] >> 8 ) & 0xff)) return false;
       
   533 				if (gcBgBlue  	!= ( imageData[i]        & 0xff)) return false;
       
   534 			} 
       
   535 			// if mask pixel is NEITHER_FOREGROUND_NOR_GC_BACKGROUND_COLOR (4), this pixel is neither 
       
   536 			// foreground nor gc background color. 
       
   537 			// Used for example in fillGradientRect test.
       
   538 			else if(maskdata[i] == NEITHER_FOREGROUND_NOR_GC_BACKGROUND_COLOR) {	
       
   539 				if (!ignoreAlpha) {
       
   540 					if (fgAlpha != gcBgAlpha){
       
   541 						if (fgAlpha 	== ((imageData[i] >> 24) & 0xff) || 
       
   542 							gcBgAlpha 	== ((imageData[i] >> 24) & 0xff)) return false;
       
   543 					}
       
   544 				}
       
   545 				
       
   546 				if (fgRed != gcBgRed){
       
   547 					if (fgRed 	 	== ((imageData[i] >> 16) & 0xff) || 
       
   548 						gcBgRed  	== ((imageData[i] >> 16) & 0xff)) return false; 
       
   549 				}
       
   550 				if (fgGreen != gcBgGreen){
       
   551 					if (fgGreen 	== ((imageData[i] >> 8 ) & 0xff) || 
       
   552 						gcBgGreen	== ((imageData[i] >> 8 ) & 0xff)) return false;
       
   553 				}
       
   554 				if (fgBlue != gcBgBlue){
       
   555 					if (fgBlue  	== ( imageData[i]        & 0xff) || 
       
   556 						gcBgBlue 	== ( imageData[i]         & 0xff)) return false;
       
   557 				}
       
   558 			} 
       
   559 			else if(maskdata[i] == IGNORE_COLOR) {	
       
   560 				// skip the pixel
       
   561 			} 
       
   562 			// if mask pixel is IMAGE_BACKGROUND_COLOR (1), check against imgBg
       
   563 			else  if(maskdata[i] == IMAGE_BACKGROUND_COLOR) {
       
   564 				if (!ignoreAlpha) {
       
   565 				    if (imgBgAlpha != ((imageData[i] >> 24) & 0xff)) return false;
       
   566 				}
       
   567 				if (imgBgRed 	!= ((imageData[i] >> 16) & 0xff)) return false; 
       
   568 				if (imgBgGreen 	!= ((imageData[i] >> 8 ) & 0xff)) return false;
       
   569 				if (imgBgBlue 	!= ( imageData[i]         & 0xff)) return false;
       
   570 			}
       
   571 			// If mask pixel is something else that's error
       
   572 			else {
       
   573 				return false;
       
   574 			}
       
   575 		}
       
   576 		return true;
       
   577 	}
       
   578 	
       
   579 	/**
       
   580 	 * prints black & white image to console.
       
   581 	 * black is printed as 1 and white as 0.
       
   582 	 */
       
   583 	public static final void print(Image img) {
       
   584 
       
   585 		final int width = img.getWidth();
       
   586 		final int height = img.getHeight();
       
   587 		final int pixels =  img.getWidth() * img.getHeight();
       
   588 		
       
   589 		// data array for image data
       
   590 		int[] imageData = new int[pixels];
       
   591 		
       
   592 		// get data for whole image
       
   593 		img.getRGB(imageData, 0, width, 0, 0, width, height);
       
   594 		
       
   595 		String output = "Image("+img.getWidth()+","+img.getHeight()+"):\n";
       
   596 		int y = 0;
       
   597 		for(int i = 0; i < imageData.length; i++) {
       
   598 			
       
   599 			int a = ((imageData[i] >> 24) & 0xff);
       
   600 			int r = ((imageData[i] >> 16) & 0xff); 
       
   601 			int b = ((imageData[i] >> 8 ) & 0xff);
       
   602 			int g = ( imageData[i] & 0xff);
       
   603 			
       
   604 			if (a == 255 && r == 0 && g == 0 && b == 0) {
       
   605 				output += "1,";
       
   606 			} else if (a == 255 && r == 255 && g == 255 && b == 255) {
       
   607 				output += "0,";
       
   608 			}
       
   609 			else {
       
   610 				output += "("+a+","+r+","+b+","+g+")";
       
   611 			}
       
   612 			
       
   613 			if(i==((y*width) + (width-1))) {
       
   614 				output += "\n";
       
   615 				y++;
       
   616 			}
       
   617 		}
       
   618 		System.out.println(output);
       
   619 	}
       
   620 	
       
   621 	public static final void print(int[] array, int scanlength) {
       
   622 		final int width = scanlength;
       
   623 		String output = "";
       
   624 		
       
   625 		int y = 0;
       
   626 		for(int i = 0; i < array.length; i++) {
       
   627 			
       
   628 			int a = ((array[i] >> 24) & 0xff);
       
   629 			int r = ((array[i] >> 16) & 0xff); 
       
   630 			int b = ((array[i] >> 8 ) & 0xff);
       
   631 			int g = ( array[i] & 0xff);
       
   632 			
       
   633 			if (a == 255 && r == 0 && g == 0 && b == 0) {
       
   634 				output += "1,";
       
   635 			} else if (a == 255 && r == 255 && g == 255 && b == 255) {
       
   636 				output += "0,";
       
   637 			}
       
   638 			else {
       
   639 				output += "x,";
       
   640 			}
       
   641 			
       
   642 			if(i==((y*width) + (width-1))) {
       
   643 				output += "\n";
       
   644 				y++;
       
   645 			}
       
   646 		}
       
   647 		System.out.println(output);
       
   648 	}
       
   649 
       
   650 	private int getIndexForPoint(int scanlength, int x, int y) {
       
   651 		return y*scanlength+x;
       
   652 	}
       
   653 	
       
   654 	
       
   655 }