1 /* 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * - Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * - Neither the name of Oracle nor the names of its 16 * contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * This source code is provided to illustrate the usage of a given feature 34 * or technique and has been deliberately simplified. Additional steps 35 * required for a production-quality application, such as security checks, 36 * input validation and proper error handling, might not be present in 37 * this sample code. 38 */ 39 package j2dbench.tests.cmm; 40 41 import j2dbench.Group; 42 import j2dbench.Result; 43 import j2dbench.TestEnvironment; 44 import java.awt.color.ColorSpace; 45 import java.awt.color.ICC_ColorSpace; 46 import java.awt.color.ICC_Profile; 47 48 public class ProfileTests extends CMMTests { 49 50 protected static Group profileRoot; 51 52 public static void init() { 53 profileRoot = new Group(cmmRoot, "profiles", "Profile Handling Benchmarks"); 54 55 new ReadHeaderTest(); 56 new GetNumComponentsTest(); 57 } 58 59 protected ProfileTests(Group parent, String nodeName, String description) { 60 super(parent, nodeName, description); 61 } 62 63 protected static class Context { 64 65 ICC_Profile profile; 66 TestEnvironment env; 67 Result res; 68 69 public Context(ICC_Profile profile, TestEnvironment env, Result res) { 70 this.profile = profile; 71 this.env = env; 72 this.res = res; 73 } 74 } 75 76 @Override 77 public Object initTest(TestEnvironment env, Result res) { 78 ICC_ColorSpace cs = (ICC_ColorSpace) getColorSpace(env); 79 return new Context(cs.getProfile(), env, res); 80 } 81 82 @Override 83 public void cleanupTest(TestEnvironment env, Object o) { 84 } 85 86 private static class ReadHeaderTest extends ProfileTests { 87 88 public ReadHeaderTest() { 89 super(profileRoot, 90 "getHeader", 91 "getData(icSigHead)"); 92 } 93 94 @Override 95 public void runTest(Object ctx, int numReps) { 96 final Context ictx = (Context) ctx; 97 final ICC_Profile profile = ictx.profile; 98 99 byte[] data = null; 100 do { 101 try { 102 data = profile.getData(ICC_Profile.icSigHead); 103 } catch (Exception e) { 104 e.printStackTrace(); 105 } 106 } while (--numReps >= 0); 107 } 108 } 109 110 private static class GetNumComponentsTest extends ProfileTests { 111 112 public GetNumComponentsTest() { 113 super(profileRoot, 114 "getNumComponents", 115 "getNumComponents"); 116 } 117 118 @Override 119 public void runTest(Object ctx, int numReps) { 120 final Context ictx = (Context) ctx; 121 final ICC_Profile profile = ictx.profile; 122 123 do { 124 try { 125 int num = profile.getNumComponents(); 126 } catch (Exception e) { 127 e.printStackTrace(); 128 } 129 } while (--numReps >= 0); 130 } 131 } 132 }