Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.scene.effect; 027 028import javafx.beans.property.BooleanProperty; 029import javafx.beans.property.IntegerProperty; 030import javafx.beans.property.IntegerPropertyBase; 031import javafx.beans.property.SimpleBooleanProperty; 032 033import com.sun.javafx.Utils; 034 035 036/** 037 * A buffer that contains floating point data, intended for use as a parameter 038 * to effects such as {@link DisplacementMap}. 039 */ 040public class FloatMap { 041 private com.sun.scenario.effect.FloatMap map; 042 private float[] buf; 043 private boolean mapBufferDirty = true; 044 045 com.sun.scenario.effect.FloatMap getImpl() { 046 return map; 047 } 048 049 private void updateBuffer() { 050 if (getWidth() > 0 && getHeight() > 0) { 051 int w = Utils.clampMax(getWidth(), 4096); 052 int h = Utils.clampMax(getHeight(), 4096); 053 int size = w * h * 4; 054 buf = new float[size]; 055 mapBufferDirty = true; 056 } 057 } 058 059 private void impl_update() { 060 if (mapBufferDirty) { 061 map = new com.sun.scenario.effect.FloatMap( 062 Utils.clamp(1, getWidth(), 4096), 063 Utils.clamp(1, getHeight(), 4096)); 064 mapBufferDirty = false; 065 } 066 map.put(buf); 067 } 068 069 void impl_sync() { 070 if (impl_isEffectDirty()) { 071 impl_update(); 072 impl_clearDirty(); 073 } 074 } 075 private BooleanProperty effectDirty; 076 077 078 private void setEffectDirty(boolean value) { 079 effectDirtyProperty().set(value); 080 } 081 082 final BooleanProperty effectDirtyProperty() { 083 if (effectDirty == null) { 084 effectDirty = new SimpleBooleanProperty(this, "effectDirty"); 085 } 086 return effectDirty; 087 } 088 089 /** 090 * @treatAsPrivate implementation detail 091 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 092 */ 093 @Deprecated 094 boolean impl_isEffectDirty() { 095 return effectDirty == null ? false : effectDirty.get(); 096 } 097 098 private void impl_markDirty() { 099 setEffectDirty(true); 100 } 101 102 private void impl_clearDirty() { 103 setEffectDirty(false); 104 } 105 106 /** 107 * Creates a new instance of FloatMap with default parameters. 108 */ 109 public FloatMap() { 110 updateBuffer(); 111 impl_markDirty(); 112 } 113 114 /** 115 * Creates a new instance of FloatMap with the specified width and height. 116 * @param width the width of the map, in pixels 117 * @param height the height of the map, in pixels 118 */ 119 public FloatMap(int width, int height) { 120 setWidth(width); 121 setHeight(height); 122 updateBuffer(); 123 impl_markDirty(); 124 } 125 126 /** 127 * The width of the map, in pixels. 128 * <pre> 129 * Min: 1 130 * Max: 4096 131 * Default: 1 132 * Identity: n/a 133 * </pre> 134 * @defaultValue 1 135 */ 136 private IntegerProperty width; 137 138 139 public final void setWidth(int value) { 140 widthProperty().set(value); 141 } 142 143 public final int getWidth() { 144 return width == null ? 1 : width.get(); 145 } 146 147 public final IntegerProperty widthProperty() { 148 if (width == null) { 149 width = new IntegerPropertyBase(1) { 150 151 @Override 152 public void invalidated() { 153 updateBuffer(); 154 impl_markDirty(); 155 } 156 157 @Override 158 public Object getBean() { 159 return FloatMap.this; 160 } 161 162 @Override 163 public String getName() { 164 return "width"; 165 } 166 }; 167 } 168 return width; 169 } 170 171 /** 172 * The height of the map, in pixels. 173 * <pre> 174 * Min: 1 175 * Max: 4096 176 * Default: 1 177 * Identity: n/a 178 * </pre> 179 * @defaultValue 1 180 */ 181 private IntegerProperty height; 182 183 184 public final void setHeight(int value) { 185 heightProperty().set(value); 186 } 187 188 public final int getHeight() { 189 return height == null ? 1 : height.get(); 190 } 191 192 public final IntegerProperty heightProperty() { 193 if (height == null) { 194 height = new IntegerPropertyBase(1) { 195 196 @Override 197 public void invalidated() { 198 updateBuffer(); 199 impl_markDirty(); 200 } 201 202 @Override 203 public Object getBean() { 204 return FloatMap.this; 205 } 206 207 @Override 208 public String getName() { 209 return "height"; 210 } 211 }; 212 } 213 return height; 214 } 215 216 /** 217 * Sets the sample for a specific band at the given (x,y) location. 218 * 219 * @param x the x location 220 * @param y the y location 221 * @param band the band to set (must be 0, 1, 2, or 3) 222 * @param s the sample value to set 223 */ 224 public void setSample(int x, int y, int band, float s) { 225 buf[((x+(y*getWidth()))*4) + band] = s; 226 impl_markDirty(); 227 } 228 229 /** 230 * Sets the sample for the first band at the given (x,y) location. 231 * 232 * @param x the x location 233 * @param y the y location 234 * @param s0 the sample value to set for the first band 235 */ 236 public void setSamples(int x, int y, float s0) 237 { 238 int index = (x+(y*getWidth()))*4; 239 buf[index + 0] = s0; 240 impl_markDirty(); 241 } 242 243 /** 244 * Sets the sample for the first two bands at the given (x,y) location. 245 * 246 * @param x the x location 247 * @param y the y location 248 * @param s0 the sample value to set for the first band 249 * @param s1 the sample value to set for the second band 250 */ 251 public void setSamples(int x, int y, float s0, float s1) 252 { 253 int index = (x+(y*getWidth()))*4; 254 buf[index + 0] = s0; 255 buf[index + 1] = s1; 256 impl_markDirty(); 257 } 258 259 /** 260 * Sets the sample for the first three bands at the given (x,y) location. 261 * 262 * @param x the x location 263 * @param y the y location 264 * @param s0 the sample value to set for the first band 265 * @param s1 the sample value to set for the second band 266 * @param s2 the sample value to set for the third band 267 */ 268 public void setSamples(int x, int y, float s0, float s1, float s2) 269 { 270 int index = (x+(y*getWidth()))*4; 271 buf[index + 0] = s0; 272 buf[index + 1] = s1; 273 buf[index + 2] = s2; 274 impl_markDirty(); 275 } 276 277 /** 278 * Sets the sample for each of the four bands at the given (x,y) location. 279 * 280 * @param x the x location 281 * @param y the y location 282 * @param s0 the sample value to set for the first band 283 * @param s1 the sample value to set for the second band 284 * @param s2 the sample value to set for the third band 285 * @param s3 the sample value to set for the fourth band 286 */ 287 public void setSamples(int x, int y, 288 float s0, float s1, float s2, float s3) 289 { 290 int index = (x+(y*getWidth()))*4; 291 buf[index + 0] = s0; 292 buf[index + 1] = s1; 293 buf[index + 2] = s2; 294 buf[index + 3] = s3; 295 impl_markDirty(); 296 } 297 298 /** 299 * @treatAsPrivate implementation detail 300 * @deprecated This is an internal API that is not intended for use and will be removed in the next version 301 */ 302 @Deprecated 303 public FloatMap impl_copy() { 304 FloatMap dest = new FloatMap(this.getWidth(), this.getHeight()); 305 System.arraycopy(buf, 0, dest.buf, 0, buf.length); 306 return dest; 307 } 308}