1 18 package org.apache.batik.ext.awt.image; 19 20 import java.awt.Color ; 21 22 28 public abstract class AbstractLight implements Light { 29 32 public static final double sRGBToLsRGB(double value) { 33 if(value <= 0.003928) 34 return value/12.92; 35 return Math.pow((value+0.055)/1.055, 2.4); 36 } 37 38 41 private double[] color; 42 43 49 public double[] getColor(boolean linear){ 50 double [] ret = new double[3]; 51 if (linear) { 52 ret[0] = sRGBToLsRGB(color[0]); 53 ret[1] = sRGBToLsRGB(color[1]); 54 ret[2] = sRGBToLsRGB(color[2]); 55 } else { 56 ret[0] = color[0]; 57 ret[1] = color[1]; 58 ret[2] = color[2]; 59 } 60 return ret; 61 } 62 63 public AbstractLight(Color color){ 64 setColor(color); 65 } 66 67 70 public void setColor(Color newColor){ 71 color = new double[3]; 72 color[0] = newColor.getRed() /255.; 73 color[1] = newColor.getGreen()/255.; 74 color[2] = newColor.getBlue() /255.; 75 } 76 77 80 public boolean isConstant(){ 81 return true; 82 } 83 84 97 public double[][][] getLightMap(double x, double y, 98 final double dx, final double dy, 99 final int width, final int height, 100 final double[][][] z) 101 { 102 double[][][] L = new double[height][][]; 103 104 for(int i=0; i<height; i++){ 105 L[i] = getLightRow(x, y, dx, width, z[i], null); 106 y += dy; 107 } 108 109 return L; 110 } 111 112 128 public double[][] getLightRow(double x, double y, 129 final double dx, final int width, 130 final double[][] z, 131 final double[][] lightRow) { 132 double [][] ret = lightRow; 133 if (ret == null) 134 ret = new double[width][3]; 135 136 for(int i=0; i<width; i++){ 137 getLight(x, y, z[i][3], ret[i]); 138 x += dx; 139 } 140 141 return ret; 142 } 143 } 144 145 146 | Popular Tags |