/** * Project: simpleimage-1.1 * * File Created at 2010-9-3 * $Id$ * * Copyright 2008 Alibaba.com Croporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * Alibaba Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Alibaba.com. */ package com.alibaba.simpleimage; import java.awt.color.ColorSpace; import java.awt.color.ICC_ColorSpace; import java.awt.color.ICC_Profile; import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicLong; import junit.framework.TestCase; /** * This TestCase used to proof memleak exists in ICC_ColorSpace.toRGB() * * @author wendell */ public class ICCProfileTest extends TestCase { static byte[] ICC_data1 = new byte[] { 0, 0, 2, 48, 65, 68, 66, 69, 2, 16, 0, 0, 109, 110, 116, 114, 82, 71, 66, 32, 88, 89, 90, 32, 7, -49, 0, 6, 0, 3, 0, 0, 0, 0, 0, 0, 97, 99, 115, 112, 65, 80, 80, 76, 0, 0, 0, 0, 110, 111, 110, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10, -42, 0, 1, 0, 0, 0, 0, -45, 45, 65, 68, 66, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 99, 112, 114, 116, 0, 0, 0, -4, 0, 0, 0, 50, 100, 101, 115, 99, 0, 0, 1, 48, 0, 0, 0, 107, 119, 116, 112, 116, 0, 0, 1, -100, 0, 0, 0, 20, 98, 107, 112, 116, 0, 0, 1, -80, 0, 0, 0, 20, 114, 84, 82, 67, 0, 0, 1, -60, 0, 0, 0, 14, 103, 84, 82, 67, 0, 0, 1, -44, 0, 0, 0, 14, 98, 84, 82, 67, 0, 0, 1, -28, 0, 0, 0, 14, 114, 88, 89, 90, 0, 0, 1, -12, 0, 0, 0, 20, 103, 88, 89, 90, 0, 0, 2, 8, 0, 0, 0, 20, 98, 88, 89, 90, 0, 0, 2, 28, 0, 0, 0, 20, 116, 101, 120, 116, 0, 0, 0, 0, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 49, 57, 57, 57, 32, 65, 100, 111, 98, 101, 32, 83, 121, 115, 116, 101, 109, 115, 32, 73, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 0, 0, 0, 100, 101, 115, 99, 0, 0, 0, 0, 0, 0, 0, 17, 65, 100, 111, 98, 101, 32, 82, 71, 66, 32, 40, 49, 57, 57, 56, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, -13, 81, 0, 1, 0, 0, 0, 1, 22, -52, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 2, 51, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 2, 51, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 2, 51, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, -100, 24, 0, 0, 79, -91, 0, 0, 4, -4, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 52, -115, 0, 0, -96, 44, 0, 0, 15, -107, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 38, 49, 0, 0, 16, 47, 0, 0, -66, -100 }; static byte[] ICC_data2 = new byte[] { 0, 0, 2, 40, 65, 68, 66, 69, 2, 16, 0, 0, 109, 110, 116, 114, 82, 71, 66, 32, 88, 89, 90, 32, 7, -49, 0, 6, 0, 3, 0, 0, 0, 0, 0, 0, 97, 99, 115, 112, 65, 80, 80, 76, 0, 0, 0, 0, 110, 111, 110, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10, -42, 0, 1, 0, 0, 0, 0, -45, 45, 65, 68, 66, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 99, 112, 114, 116, 0, 0, 0, -4, 0, 0, 0, 50, 100, 101, 115, 99, 0, 0, 1, 48, 0, 0, 0, 100, 119, 116, 112, 116, 0, 0, 1, -108, 0, 0, 0, 20, 98, 107, 112, 116, 0, 0, 1, -88, 0, 0, 0, 20, 114, 84, 82, 67, 0, 0, 1, -68, 0, 0, 0, 14, 103, 84, 82, 67, 0, 0, 1, -52, 0, 0, 0, 14, 98, 84, 82, 67, 0, 0, 1, -36, 0, 0, 0, 14, 114, 88, 89, 90, 0, 0, 1, -20, 0, 0, 0, 20, 103, 88, 89, 90, 0, 0, 2, 0, 0, 0, 0, 20, 98, 88, 89, 90, 0, 0, 2, 20, 0, 0, 0, 20, 116, 101, 120, 116, 0, 0, 0, 0, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 49, 57, 57, 57, 32, 65, 100, 111, 98, 101, 32, 83, 121, 115, 116, 101, 109, 115, 32, 73, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 0, 0, 0, 100, 101, 115, 99, 0, 0, 0, 0, 0, 0, 0, 10, 65, 112, 112, 108, 101, 32, 82, 71, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, -13, 81, 0, 1, 0, 0, 0, 1, 22, -52, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 1, -51, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 1, -51, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 1, -51, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 121, -67, 0, 0, 65, 82, 0, 0, 4, -71, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 86, -8, 0, 0, -84, 47, 0, 0, 29, 3, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 38, 34, 0, 0, 18, 127, 0, 0, -79, 112 }; static byte[] ICC_data3 = new byte[] { 0, 0, 2, 40, 65, 68, 66, 69, 2, 16, 0, 0, 109, 110, 116, 114, 82, 71, 66, 32, 88, 89, 90, 32, 7, -48, 0, 8, 0, 11, 0, 19, 0, 52, 0, 59, 97, 99, 115, 112, 65, 80, 80, 76, 0, 0, 0, 0, 110, 111, 110, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10, -42, 0, 1, 0, 0, 0, 0, -45, 45, 65, 68, 66, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 99, 112, 114, 116, 0, 0, 0, -4, 0, 0, 0, 50, 100, 101, 115, 99, 0, 0, 1, 48, 0, 0, 0, 98, 119, 116, 112, 116, 0, 0, 1, -108, 0, 0, 0, 20, 98, 107, 112, 116, 0, 0, 1, -88, 0, 0, 0, 20, 114, 84, 82, 67, 0, 0, 1, -68, 0, 0, 0, 14, 103, 84, 82, 67, 0, 0, 1, -52, 0, 0, 0, 14, 98, 84, 82, 67, 0, 0, 1, -36, 0, 0, 0, 14, 114, 88, 89, 90, 0, 0, 1, -20, 0, 0, 0, 20, 103, 88, 89, 90, 0, 0, 2, 0, 0, 0, 0, 20, 98, 88, 89, 90, 0, 0, 2, 20, 0, 0, 0, 20, 116, 101, 120, 116, 0, 0, 0, 0, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 50, 48, 48, 48, 32, 65, 100, 111, 98, 101, 32, 83, 121, 115, 116, 101, 109, 115, 32, 73, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 0, 0, 0, 100, 101, 115, 99, 0, 0, 0, 0, 0, 0, 0, 8, 67, 73, 69, 32, 82, 71, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 20, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 2, 51, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 2, 51, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 2, 51, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 124, -93, 0, 0, 44, -74, -1, -1, -1, -83, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 78, 109, 0, 0, -45, 37, 0, 0, 4, 90, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 43, -58, 0, 0, 0, 37, 0, 0, -49, 37 }; static byte[] ICC_data4 = new byte[] { 0, 0, 2, 48, 65, 68, 66, 69, 2, 16, 0, 0, 109, 110, 116, 114, 82, 71, 66, 32, 88, 89, 90, 32, 7, -49, 0, 6, 0, 3, 0, 0, 0, 0, 0, 0, 97, 99, 115, 112, 65, 80, 80, 76, 0, 0, 0, 0, 110, 111, 110, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10, -42, 0, 1, 0, 0, 0, 0, -45, 45, 65, 68, 66, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 99, 112, 114, 116, 0, 0, 0, -4, 0, 0, 0, 50, 100, 101, 115, 99, 0, 0, 1, 48, 0, 0, 0, 105, 119, 116, 112, 116, 0, 0, 1, -100, 0, 0, 0, 20, 98, 107, 112, 116, 0, 0, 1, -80, 0, 0, 0, 20, 114, 84, 82, 67, 0, 0, 1, -60, 0, 0, 0, 14, 103, 84, 82, 67, 0, 0, 1, -44, 0, 0, 0, 14, 98, 84, 82, 67, 0, 0, 1, -28, 0, 0, 0, 14, 114, 88, 89, 90, 0, 0, 1, -12, 0, 0, 0, 20, 103, 88, 89, 90, 0, 0, 2, 8, 0, 0, 0, 20, 98, 88, 89, 90, 0, 0, 2, 28, 0, 0, 0, 20, 116, 101, 120, 116, 0, 0, 0, 0, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 49, 57, 57, 57, 32, 65, 100, 111, 98, 101, 32, 83, 121, 115, 116, 101, 109, 115, 32, 73, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 0, 0, 0, 100, 101, 115, 99, 0, 0, 0, 0, 0, 0, 0, 15, 67, 111, 108, 111, 114, 77, 97, 116, 99, 104, 32, 82, 71, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, -10, -36, 0, 1, 0, 0, 0, 0, -45, 58, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 1, -51, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 1, -51, 0, 0, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 0, 1, 1, -51, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, -126, 107, 0, 0, 70, 99, 0, 0, 6, 54, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 82, 35, 0, 0, -88, 121, 0, 0, 27, -41, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 34, 72, 0, 0, 17, 37, 0, 0, -79, 32 }; public void doParse(byte[] src) throws Exception { byte[] dest = new byte[src.length]; System.arraycopy(src, 0, dest, 0, src.length); ICC_Profile profile = ICC_Profile.getInstance(dest); ColorSpace cs = new ICC_ColorSpace(profile); Random rand = new Random(); float[] color = new float[3]; color[0] = rand.nextFloat(); color[1] = rand.nextFloat(); color[2] = rand.nextFloat(); float[] res = cs.toRGB(color); System.out.println(res[0] + ", " + res[1] + ", " + res[2]); } public void testNull() { } public static void main(String[] args) throws Exception { int th = 16; long t = 9999999; if (args.length > 0) { th = Integer.parseInt(args[0]); } if (args.length > 1) { t = Long.parseLong(args[1]); } System.out.println("------------------ICC_Profile Test--------------------"); ICCProfileTest instance = new ICCProfileTest(th, t); instance.doWork(); } int threadsNum; AtomicLong total; CountDownLatch countDownLatch; public ICCProfileTest(int threadsNum, long total) { this.threadsNum = threadsNum; this.total = new AtomicLong(total); this.countDownLatch = new CountDownLatch(threadsNum); } public ICCProfileTest() { this.threadsNum = 1; this.total = new AtomicLong(1L); this.countDownLatch = new CountDownLatch(1); } public void doWork() throws Exception { Thread[] threads = new Thread[threadsNum]; for (int i = 0; i < threadsNum; i++) { threads[i] = new Thread(new ProfileParser("Thread-" + i), "Thread-" + i); } for (int i = 0; i < threadsNum; i++) { threads[i].start(); } countDownLatch.await(); } class ProfileParser implements Runnable { private String name; public ProfileParser(String name) { this.name = name; } /* * (non-Javadoc) * @see java.lang.Runnable#run() */ public void run() { try { for (;;) { if (total.getAndDecrement() <= 0) { return; } System.out.println(name + " working"); doParse(ICC_data1); doParse(ICC_data2); doParse(ICC_data3); doParse(ICC_data4); } } catch (Exception e) { e.printStackTrace(); } finally { countDownLatch.countDown(); } } } }