Skip to content

Commit

Permalink
first release of Marlin 0.8 including efficient & proper path clippin…
Browse files Browse the repository at this point in the history
…g in Stroker (100% working)
  • Loading branch information
bourgesl committed Aug 16, 2017
1 parent fe5dab9 commit 22bc856
Show file tree
Hide file tree
Showing 16 changed files with 2,814 additions and 470 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>org.marlin</groupId>
<artifactId>marlin</artifactId>
<packaging>jar</packaging>
<version>0.7.5-Unsafe-OpenJDK</version>
<version>0.8.0-Unsafe-OpenJDK</version>
<name>Marlin software rasterizer</name>

<url>https://github.com/bourgesl/marlin-renderer</url>
Expand Down Expand Up @@ -87,7 +87,7 @@
<classifier>sun-java2d</classifier>
<includes>
<include>com/sun/imageio/**</include>
<include>java/awt/geom/Path2D*</include>
<include>java/awt/**</include>
<include>sun/java2d/pipe/**</include>
</includes>
</configuration>
Expand Down
152 changes: 152 additions & 0 deletions src/main/java/java/awt/TexturePaint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/

package java.awt;

import java.awt.geom.Rectangle2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;

/**
* The <code>TexturePaint</code> class provides a way to fill a
* {@link Shape} with a texture that is specified as
* a {@link BufferedImage}. The size of the <code>BufferedImage</code>
* object should be small because the <code>BufferedImage</code> data
* is copied by the <code>TexturePaint</code> object.
* At construction time, the texture is anchored to the upper
* left corner of a {@link Rectangle2D} that is
* specified in user space. Texture is computed for
* locations in the device space by conceptually replicating the
* specified <code>Rectangle2D</code> infinitely in all directions
* in user space and mapping the <code>BufferedImage</code> to each
* replicated <code>Rectangle2D</code>.
* @see Paint
* @see Graphics2D#setPaint
* @version 1.48, 06/05/07
*/

public class TexturePaint implements Paint {

BufferedImage bufImg;
double tx;
double ty;
double sx;
double sy;

/**
* Constructs a <code>TexturePaint</code> object.
* @param txtr the <code>BufferedImage</code> object with the texture
* used for painting
* @param anchor the <code>Rectangle2D</code> in user space used to
* anchor and replicate the texture
*/
public TexturePaint(BufferedImage txtr,
Rectangle2D anchor) {
this.bufImg = txtr;
this.tx = anchor.getX();
this.ty = anchor.getY();
this.sx = anchor.getWidth() / bufImg.getWidth();
this.sy = anchor.getHeight() / bufImg.getHeight();
}

/**
* Returns the <code>BufferedImage</code> texture used to
* fill the shapes.
* @return a <code>BufferedImage</code>.
*/
public BufferedImage getImage() {
return bufImg;
}

/**
* Returns a copy of the anchor rectangle which positions and
* sizes the textured image.
* @return the <code>Rectangle2D</code> used to anchor and
* size this <code>TexturePaint</code>.
*/
public Rectangle2D getAnchorRect() {
return new Rectangle2D.Double(tx, ty,
sx * bufImg.getWidth(),
sy * bufImg.getHeight());
}

/**
* Creates and returns a {@link PaintContext} used to
* generate a tiled image pattern.
* See the {@link Paint#createContext specification} of the
* method in the {@link Paint} interface for information
* on null parameter handling.
*
* @param cm the preferred {@link ColorModel} which represents the most convenient
* format for the caller to receive the pixel data, or {@code null}
* if there is no preference.
* @param deviceBounds the device space bounding box
* of the graphics primitive being rendered.
* @param userBounds the user space bounding box
* of the graphics primitive being rendered.
* @param xform the {@link AffineTransform} from user
* space into device space.
* @param hints the set of hints that the context object can use to
* choose between rendering alternatives.
* @return the {@code PaintContext} for
* generating color patterns.
* @see Paint
* @see PaintContext
* @see ColorModel
* @see Rectangle
* @see Rectangle2D
* @see AffineTransform
* @see RenderingHints
*/
public PaintContext createContext(ColorModel cm,
Rectangle deviceBounds,
Rectangle2D userBounds,
AffineTransform xform,
RenderingHints hints) {
// TODO: avoid allocating new transform for Identity !
if (xform == null) {
xform = new AffineTransform();
} else {
xform = (AffineTransform) xform.clone();
}
xform.translate(tx, ty);
xform.scale(sx, sy);

return TexturePaintContext.getContext(bufImg, xform, hints,
deviceBounds);
}

/**
* Returns the transparency mode for this <code>TexturePaint</code>.
* @return the transparency mode for this <code>TexturePaint</code>
* as an integer value.
* @see Transparency
*/
public int getTransparency() {
return (bufImg.getColorModel()).getTransparency();
}

}
Loading

0 comments on commit 22bc856

Please sign in to comment.