1 /*
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
264 * @param fx fx,fy defines focal point of the gradient. ie. 0% gradient stop is mapped to fx,fy point. If cx == fx and cy == fy, then gradient consists of homocentric circles. If these relations are not met, gradient field is deformed and eccentric ovals can be observed.
265 * @param fy
266 * @param radius @see cx
267 * @param gradientColorMap @see setLinearGradient
268 * @param gradientTransform @see setLinearGradient
269 *
270 * As Pisces Gradient support was added to support features introduced in SVG, see e.g. http://www.w3.org/TR/SVG11/pservers.html for more information and examples.
271 */
272
273 public void setRadialGradient(int cx, int cy, int fx, int fy,
274 int radius,
275 GradientColorMap gradientColorMap,
276 Transform6 gradientTransform) {
277 setRadialGradientImpl(cx, cy, fx, fy, radius,
278 gradientColorMap.colors,
279 gradientColorMap.cycleMethod,
280 gradientTransform == null ? new Transform6(1 << 16, 0, 0, 1 << 16, 0, 0) : gradientTransform);
281 }
282
283 public void setTexture(int imageType, int data[], int width, int height, int stride,
284 Transform6 textureTransform, boolean repeat, boolean hasAlpha)
285 {
286 this.inputImageCheck(width, height, 0, stride, data.length);
287 this.setTextureImpl(imageType, data, width, height, stride, textureTransform, repeat, hasAlpha);
288 }
289
290 private native void setTextureImpl(int imageType, int data[], int width, int height, int stride,
291 Transform6 textureTransform, boolean repeat, boolean hasAlpha);
292
293 /**
294 * Sets a clip rectangle for all primitives. Each primitive will be
295 * clipped to the intersection of this rectangle and the destination
296 * image bounds.
297 */
298 public void setClip(int minX, int minY, int width, int height) {
299 final int x1 = Math.max(minX, 0);
300 final int y1 = Math.max(minY, 0);
301 final int x2 = Math.min(minX + width, surface.getWidth());
302 final int y2 = Math.min(minY + height, surface.getHeight());
303 this.setClipImpl(x1, y1, x2 - x1, y2 - y1);
304 }
305
306 private native void setClipImpl(int minX, int minY, int width, int height);
307
308 /**
309 * Resets the clip rectangle. Each primitive will be clipped only
310 * to the destination image bounds.
311 */
372 if (gamma <= 0) {
373 throw new IllegalArgumentException("Gamma must be greater than zero");
374 }
375 this.setLCDGammaCorrectionImpl(gamma);
376 }
377
378 private native void setLCDGammaCorrectionImpl(float gamma);
379
380 public void fillLCDAlphaMask(byte[] mask, int x, int y, int width, int height, int offset, int stride)
381 {
382 if (mask == null) {
383 throw new NullPointerException("Mask is NULL");
384 }
385 this.inputImageCheck(width, height, offset, stride, mask.length);
386 this.fillLCDAlphaMaskImpl(mask, x, y, width, height, offset, stride);
387 }
388
389 private native void fillLCDAlphaMaskImpl(byte[] mask, int x, int y, int width, int height, int offset, int stride);
390
391 public void drawImage(int imageType, int imageMode, int data[], int width, int height, int offset, int stride,
392 Transform6 textureTransform, boolean repeat,
393 int bboxX, int bboxY, int bboxW, int bboxH,
394 int lEdge, int rEdge, int tEdge, int bEdge,
395 int txMin, int tyMin, int txMax, int tyMax,
396 boolean hasAlpha)
397 {
398 this.inputImageCheck(width, height, offset, stride, data.length);
399 this.drawImageImpl(imageType, imageMode, data, width, height, offset, stride,
400 textureTransform, repeat,
401 bboxX, bboxY, bboxW, bboxH,
402 lEdge, rEdge, tEdge, bEdge,
403 txMin, tyMin, txMax, tyMax,
404 hasAlpha);
405 }
406
407 private native void drawImageImpl(int imageType, int imageMode, int data[], int width, int height, int offset, int stride,
408 Transform6 textureTransform, boolean repeat,
409 int bboxX, int bboxY, int bboxW, int bboxH,
410 int lEdge, int rEdge, int tEdge, int bEdge,
411 int txMin, int tyMin, int txMax, int tyMax,
412 boolean hasAlpha);
413
414 private void inputImageCheck(int width, int height, int offset, int stride, int data_length) {
415 if (width < 0) {
416 throw new IllegalArgumentException("WIDTH must be positive");
417 }
418 if (height < 0) {
419 throw new IllegalArgumentException("HEIGHT must be positive");
420 }
421 if (offset < 0) {
422 throw new IllegalArgumentException("OFFSET must be positive");
423 }
424 if (stride < 0) {
425 throw new IllegalArgumentException("STRIDE must be positive");
426 }
427 if (stride < width) {
428 throw new IllegalArgumentException("STRIDE must be >= WIDTH");
|
1 /*
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
264 * @param fx fx,fy defines focal point of the gradient. ie. 0% gradient stop is mapped to fx,fy point. If cx == fx and cy == fy, then gradient consists of homocentric circles. If these relations are not met, gradient field is deformed and eccentric ovals can be observed.
265 * @param fy
266 * @param radius @see cx
267 * @param gradientColorMap @see setLinearGradient
268 * @param gradientTransform @see setLinearGradient
269 *
270 * As Pisces Gradient support was added to support features introduced in SVG, see e.g. http://www.w3.org/TR/SVG11/pservers.html for more information and examples.
271 */
272
273 public void setRadialGradient(int cx, int cy, int fx, int fy,
274 int radius,
275 GradientColorMap gradientColorMap,
276 Transform6 gradientTransform) {
277 setRadialGradientImpl(cx, cy, fx, fy, radius,
278 gradientColorMap.colors,
279 gradientColorMap.cycleMethod,
280 gradientTransform == null ? new Transform6(1 << 16, 0, 0, 1 << 16, 0, 0) : gradientTransform);
281 }
282
283 public void setTexture(int imageType, int data[], int width, int height, int stride,
284 Transform6 textureTransform, boolean repeat, boolean linearFiltering, boolean hasAlpha)
285 {
286 this.inputImageCheck(width, height, 0, stride, data.length);
287 this.setTextureImpl(imageType, data, width, height, stride, textureTransform, repeat, linearFiltering, hasAlpha);
288 }
289
290 private native void setTextureImpl(int imageType, int data[], int width, int height, int stride,
291 Transform6 textureTransform, boolean repeat, boolean linearFiltering, boolean hasAlpha);
292
293 /**
294 * Sets a clip rectangle for all primitives. Each primitive will be
295 * clipped to the intersection of this rectangle and the destination
296 * image bounds.
297 */
298 public void setClip(int minX, int minY, int width, int height) {
299 final int x1 = Math.max(minX, 0);
300 final int y1 = Math.max(minY, 0);
301 final int x2 = Math.min(minX + width, surface.getWidth());
302 final int y2 = Math.min(minY + height, surface.getHeight());
303 this.setClipImpl(x1, y1, x2 - x1, y2 - y1);
304 }
305
306 private native void setClipImpl(int minX, int minY, int width, int height);
307
308 /**
309 * Resets the clip rectangle. Each primitive will be clipped only
310 * to the destination image bounds.
311 */
372 if (gamma <= 0) {
373 throw new IllegalArgumentException("Gamma must be greater than zero");
374 }
375 this.setLCDGammaCorrectionImpl(gamma);
376 }
377
378 private native void setLCDGammaCorrectionImpl(float gamma);
379
380 public void fillLCDAlphaMask(byte[] mask, int x, int y, int width, int height, int offset, int stride)
381 {
382 if (mask == null) {
383 throw new NullPointerException("Mask is NULL");
384 }
385 this.inputImageCheck(width, height, offset, stride, mask.length);
386 this.fillLCDAlphaMaskImpl(mask, x, y, width, height, offset, stride);
387 }
388
389 private native void fillLCDAlphaMaskImpl(byte[] mask, int x, int y, int width, int height, int offset, int stride);
390
391 public void drawImage(int imageType, int imageMode, int data[], int width, int height, int offset, int stride,
392 Transform6 textureTransform, boolean repeat, boolean linearFiltering,
393 int bboxX, int bboxY, int bboxW, int bboxH,
394 int lEdge, int rEdge, int tEdge, int bEdge,
395 int txMin, int tyMin, int txMax, int tyMax,
396 boolean hasAlpha)
397 {
398 this.inputImageCheck(width, height, offset, stride, data.length);
399 this.drawImageImpl(imageType, imageMode, data, width, height, offset, stride,
400 textureTransform, repeat, linearFiltering,
401 bboxX, bboxY, bboxW, bboxH,
402 lEdge, rEdge, tEdge, bEdge,
403 txMin, tyMin, txMax, tyMax,
404 hasAlpha);
405 }
406
407 private native void drawImageImpl(int imageType, int imageMode, int data[], int width, int height, int offset, int stride,
408 Transform6 textureTransform, boolean repeat, boolean linearFiltering,
409 int bboxX, int bboxY, int bboxW, int bboxH,
410 int lEdge, int rEdge, int tEdge, int bEdge,
411 int txMin, int tyMin, int txMax, int tyMax,
412 boolean hasAlpha);
413
414 private void inputImageCheck(int width, int height, int offset, int stride, int data_length) {
415 if (width < 0) {
416 throw new IllegalArgumentException("WIDTH must be positive");
417 }
418 if (height < 0) {
419 throw new IllegalArgumentException("HEIGHT must be positive");
420 }
421 if (offset < 0) {
422 throw new IllegalArgumentException("OFFSET must be positive");
423 }
424 if (stride < 0) {
425 throw new IllegalArgumentException("STRIDE must be positive");
426 }
427 if (stride < width) {
428 throw new IllegalArgumentException("STRIDE must be >= WIDTH");
|