/*
Copyright 2006 Jerry Huxtable
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.jhlabs.image;
import java.awt.image.*;
import com.jhlabs.math.*;
import com.jhlabs.vecmath.*;
import java.awt.*;
import java.io.*;
import java.util.*;
/**
* A filter which produces lighting and embossing effects.
*/
public class LightFilter extends WholeImageFilter {
/**
* Take the output colors from the input image.
*/
public final static int COLORS_FROM_IMAGE = 0;
/**
* Use constant material color.
*/
public final static int COLORS_CONSTANT = 1;
/**
* Use the input image brightness as the bump map.
*/
public final static int BUMPS_FROM_IMAGE = 0;
/**
* Use the input image alpha as the bump map.
*/
public final static int BUMPS_FROM_IMAGE_ALPHA = 1;
/**
* Use a separate image alpha channel as the bump map.
*/
public final static int BUMPS_FROM_MAP = 2;
/**
* Use a custom function as the bump map.
*/
public final static int BUMPS_FROM_BEVEL = 3;
private float bumpHeight;
private float bumpSoftness;
private int bumpShape;
private float viewDistance = 10000.0f;
Material material;
private Vector lights;
private int colorSource = COLORS_FROM_IMAGE;
private int bumpSource = BUMPS_FROM_IMAGE;
private Function2D bumpFunction;
private Image environmentMap;
private int[] envPixels;
private int envWidth = 1, envHeight = 1;
// Temporary variables used to avoid per-pixel memory allocation while filtering
private Vector3f l;
private Vector3f v;
private Vector3f n;
private Color4f shadedColor;
private Color4f diffuse_color;
private Color4f specular_color;
private Vector3f tmpv, tmpv2;
public LightFilter() {
lights = new Vector();
addLight(new DistantLight());
bumpHeight = 1.0f;
bumpSoftness = 5.0f;
bumpShape = 0;
material = new Material();
l = new Vector3f();
v = new Vector3f();
n = new Vector3f();
shadedColor = new Color4f();
diffuse_color = new Color4f();
specular_color = new Color4f();
tmpv = new Vector3f();
tmpv2 = new Vector3f();
}
public void setMaterial( Material material ) {
this.material = material;
}
public Material getMaterial() {
return material;
}
public void setBumpFunction(Function2D bumpFunction) {
this.bumpFunction = bumpFunction;
}
public Function2D getBumpFunction() {
return bumpFunction;
}
public void setBumpHeight(float bumpHeight) {
this.bumpHeight = bumpHeight;
}
public float getBumpHeight() {
return bumpHeight;
}
public void setBumpSoftness(float bumpSoftness) {
this.bumpSoftness = bumpSoftness;
}
public float getBumpSoftness() {
return bumpSoftness;
}
public void setBumpShape(int bumpShape) {
this.bumpShape = bumpShape;
}
public int getBumpShape() {
return bumpShape;
}
public void setViewDistance(float viewDistance) {
this.viewDistance = viewDistance;
}
public float getViewDistance() {
return viewDistance;
}
public void setEnvironmentMap(BufferedImage environmentMap) {
this.environmentMap = environmentMap;
if (environmentMap != null) {
envWidth = environmentMap.getWidth();
envHeight = environmentMap.getHeight();
envPixels = getRGB( environmentMap, 0, 0, envWidth, envHeight, null );
} else {
envWidth = envHeight = 1;
envPixels = null;
}
}
public Image getEnvironmentMap() {
return environmentMap;
}
public void setColorSource(int colorSource) {
this.colorSource = colorSource;
}
public int getColorSource() {
return colorSource;
}
public void setBumpSource(int bumpSource) {
this.bumpSource = bumpSource;
}
public int getBumpSource() {
return bumpSource;
}
public void setDiffuseColor(int diffuseColor) {
material.diffuseColor = diffuseColor;
}
public int getDiffuseColor() {
return material.diffuseColor;
}
public void addLight(Light light) {
lights.addElement(light);
}
public void removeLight(Light light) {
lights.removeElement(light);
}
public Vector getLights() {
return lights;
}
protected final static float r255 = 1.0f/255.0f;
protected void setFromRGB( Color4f c, int argb ) {
c.set( ((argb >> 16) & 0xff) * r255, ((argb >> 8) & 0xff) * r255, (argb & 0xff) * r255, ((argb >> 24) & 0xff) * r255 );
}
protected int[] filterPixels( int width, int height, int[] inPixels, Rectangle transformedSpace ) {
int index = 0;
int[] outPixels = new int[width * height];
float width45 = Math.abs(6.0f * bumpHeight);
boolean invertBumps = bumpHeight < 0;
Vector3f position = new Vector3f(0.0f, 0.0f, 0.0f);
Vector3f viewpoint = new Vector3f((float)width / 2.0f, (float)height / 2.0f, viewDistance);
Vector3f normal = new Vector3f();
Color4f envColor = new Color4f();
Color4f diffuseColor = new Color4f( new Color(material.diffuseColor) );
Color4f specularColor = new Color4f( new Color(material.specularColor) );
Function2D bump = bumpFunction;
// Apply the bump softness
if (bumpSource == BUMPS_FROM_IMAGE || bumpSource == BUMPS_FROM_IMAGE_ALPHA || bumpSource == BUMPS_FROM_MAP || bump == null) {
if ( bumpSoftness != 0 ) {
int bumpWidth = width;
int bumpHeight = height;
int[] bumpPixels = inPixels;
if ( bumpSource == BUMPS_FROM_MAP && bumpFunction instanceof ImageFunction2D ) {
ImageFunction2D if2d = (ImageFunction2D)bumpFunction;
bumpWidth = if2d.getWidth();
bumpHeight = if2d.getHeight();
bumpPixels = if2d.getPixels();
}
int [] tmpPixels = new int[bumpWidth * bumpHeight];
int [] softPixels = new int[bumpWidth * bumpHeight];
/*
for (int i = 0; i < 3; i++ ) {
BoxBlurFilter.blur( bumpPixels, tmpPixels, bumpWidth, bumpHeight, (int)bumpSoftness );
BoxBlurFilter.blur( tmpPixels, softPixels, bumpHeight, bumpWidth, (int)bumpSoftness );
}
*/
Kernel kernel = GaussianFilter.makeKernel( bumpSoftness );
GaussianFilter.convolveAndTranspose( kernel, bumpPixels, tmpPixels, bumpWidth, bumpHeight, true, false, false, GaussianFilter.WRAP_EDGES );
GaussianFilter.convolveAndTranspose( kernel, tmpPixels, softPixels, bumpHeight, bumpWidth, true, false, false, GaussianFilter.WRAP_EDGES );
bump = new ImageFunction2D(softPixels, bumpWidth, bumpHeight, ImageFunction2D.CLAMP, bumpSource == BUMPS_FROM_IMAGE_ALPHA);
final Function2D bbump = bump;
if ( bumpShape != 0 ) {
bump = new Function2D() {
private Function2D original = bbump;
public float evaluate(float x, float y) {
float v = original.evaluate( x, y );
switch ( bumpShape ) {
case 1:
// v = v > 0.5f ? 0.5f : v;
v *= ImageMath.smoothStep( 0.45f, 0.55f, v );
break;
case 2:
v = v < 0.5f ? 0.5f : v;
break;
case 3:
v = ImageMath.triangle( v );
break;
case 4:
v = ImageMath.circleDown( v );
break;
case 5:
v = ImageMath.gain( v, 0.75f );
break;
}
return v;
}
};
}
} else if ( bumpSource != BUMPS_FROM_MAP )
bump = new ImageFunction2D(inPixels, width, height, ImageFunction2D.CLAMP, bumpSource == BUMPS_FROM_IMAGE_ALPHA);
}
float reflectivity = material.reflectivity;
float areflectivity = (1-reflectivity);
Vector3f v1 = new Vector3f();
Vector3f v2 = new Vector3f();
Vector3f n = new Vector3f();
Light[] lightsArray = new Light[lights.size()];
lights.copyInto(lightsArray);
for (int i = 0; i < lightsArray.length; i++)
lightsArray[i].prepare(width, height);
float[][] heightWindow = new float[3][width];
for (int x = 0; x < width; x++)
heightWindow[1][x] = width45*bump.evaluate(x, 0);
没有合适的资源?快使用搜索试试~ 我知道了~
强大的Java图像滤镜特效类库Java Image Filters
共222个文件
java:219个
xml:1个
manifest:1个
5星 · 超过95%的资源 需积分: 50 90 下载量 50 浏览量
2016-01-14
18:09:39
上传
评论 4
收藏 604KB ZIP 举报
温馨提示
Java Image Filters是一款基于Java的图像处理类库,特别是在图像滤镜特效方面,Java Image Filters简直就是强大到天衣无缝。它几乎提供了PS上大部分的图像特效。比如反色特效、图像扭曲、水波和纹理等效果。
资源推荐
资源详情
资源评论
收起资源包目录
强大的Java图像滤镜特效类库Java Image Filters (222个子文件)
Filters.jar 330KB
LightFilter.java 19KB
ImageMath.java 18KB
Gradient.java 13KB
CellularFilter.java 12KB
ConvolveFilter.java 12KB
LensBlurFilter.java 10KB
SkyFilter.java 9KB
ImageUtils.java 9KB
PerspectiveFilter.java 9KB
ShadeFilter.java 9KB
MiscCompositeContext.java 9KB
WarpGrid.java 9KB
GradientFilter.java 8KB
ShapeFilter.java 8KB
CurlFilter.java 8KB
BoxBlurFilter.java 8KB
CausticsFilter.java 8KB
BrushedMetalFilter.java 8KB
VariableBlurFilter.java 8KB
TransformFilter.java 8KB
GlintFilter.java 7KB
DitherFilter.java 7KB
Noise.java 7KB
FeedbackFilter.java 7KB
ShadowFilter.java 7KB
OctTreeQuantizer.java 7KB
SmearFilter.java 7KB
Matrix4f.java 6KB
PlasmaFilter.java 6KB
MotionBlurOp.java 6KB
MotionBlurFilter.java 6KB
ColorHalftoneFilter.java 6KB
ShatterFilter.java 6KB
FBMFilter.java 6KB
PixelUtils.java 6KB
SmartBlurFilter.java 6KB
GaussianFilter.java 5KB
WoodFilter.java 5KB
KeyFilter.java 5KB
MiscComposite.java 5KB
PolarFilter.java 5KB
SCNoise.java 5KB
TransitionFilter.java 5KB
QuantizeFilter.java 5KB
RaysFilter.java 5KB
FFT.java 5KB
WaterFilter.java 5KB
KaleidoscopeFilter.java 5KB
BorderFilter.java 5KB
TextureFilter.java 5KB
DiffusionFilter.java 5KB
FieldWarpFilter.java 4KB
CircleFilter.java 4KB
PinchFilter.java 4KB
FlipFilter.java 4KB
WarpFilter.java 4KB
QuiltFilter.java 4KB
RippleFilter.java 4KB
Histogram.java 4KB
DoGFilter.java 4KB
SphereFilter.java 4KB
HalftoneFilter.java 4KB
SwimFilter.java 4KB
TwirlFilter.java 4KB
RenderTextFilter.java 4KB
ArrayColormap.java 4KB
WeaveFilter.java 4KB
LaplaceFilter.java 4KB
ApplyMaskFilter.java 4KB
MarbleTexFilter.java 4KB
CheckFilter.java 4KB
FlareFilter.java 4KB
ShineFilter.java 4KB
Quat4f.java 4KB
StampFilter.java 4KB
ImageFunction2D.java 4KB
ContourFilter.java 4KB
SkeletonFilter.java 4KB
EmbossFilter.java 3KB
SplineColormap.java 3KB
DisplaceFilter.java 3KB
AbstractBufferedImageOp.java 3KB
NoiseFilter.java 3KB
CellularFunction2D.java 3KB
CropFilter.java 3KB
EdgeFilter.java 3KB
OilFilter.java 3KB
InterpolateFilter.java 3KB
UnsharpFilter.java 3KB
MarbleFilter.java 3KB
ShearFilter.java 3KB
ChromaKeyFilter.java 3KB
DeinterlaceFilter.java 3KB
ScratchFilter.java 3KB
MirrorFilter.java 3KB
FadeFilter.java 3KB
SparkleFilter.java 3KB
BlockFilter.java 3KB
DespeckleFilter.java 3KB
共 222 条
- 1
- 2
- 3
资源评论
- biaoshi482018-12-07资源确实能用,我现在只拿CircleFilter作了测试,谢谢分享
- bbcwest2019-05-28很不错的效果,虽然不是自己想要的,但是效果蛮好
oSayMissyou0
- 粉丝: 31
- 资源: 67
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功