就是这条语句:new ConvolveOp(new Kernel(width, height, data), ConvolveOp.EDGE_NO_OP, null).filter(imageCopy, image);正在做一个单片机上的图片滤镜程序,是用C写的,想参考JAVA上的java.awt.image.ConvolveOp,
可是跟踪起来不太顺利,始终没能跟进其实现部分,已经耗了3天时间了,还是没有进展。有三点问题:
一、我用的是eclipse加jdk debug版和openjdk来进行调试跟踪JDK的,这套能跟入内部实现部分吗?
二、想了解ConvolveOp.filter的原理及实现。
三、想最终自己能用C代码实现这条语句,但还是希望有能力的朋友提供一个C程序供我参考一下,再研究怕时间不够 :-(PS:平时爱集些开发类的书籍,愿拿出几本赠给热心的朋友,只要是市面上能见到的都可以。
可是跟踪起来不太顺利,始终没能跟进其实现部分,已经耗了3天时间了,还是没有进展。有三点问题:
一、我用的是eclipse加jdk debug版和openjdk来进行调试跟踪JDK的,这套能跟入内部实现部分吗?
二、想了解ConvolveOp.filter的原理及实现。
三、想最终自己能用C代码实现这条语句,但还是希望有能力的朋友提供一个C程序供我参考一下,再研究怕时间不够 :-(PS:平时爱集些开发类的书籍,愿拿出几本赠给热心的朋友,只要是市面上能见到的都可以。
{
-1,0,1,
-1,0,1,
-1,0,1
};
检测水平边沿的float data[] =
{
-1,-1,-1,
0, 0, 0,
1, 1, 1
};
谢谢meneil的回复。本以为难度不大,所以就边看java基础书边研究,临阵磨枪是不行呀 :-(
if (src == null) {
throw new NullPointerException("src image is null");
}
if (src == dst) {
throw new IllegalArgumentException("src image cannot be the "+
"same as the dst image");
} boolean needToConvert = false;
ColorModel srcCM = src.getColorModel();
ColorModel dstCM;
BufferedImage origDst = dst; // Can't convolve an IndexColorModel. Need to expand it
if (srcCM instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel) srcCM;
src = icm.convertToIntDiscrete(src.getRaster(), false);
srcCM = src.getColorModel();
}
if (dst == null) {
dst = createCompatibleDestImage(src, null);
dstCM = srcCM;
origDst = dst;
}
else {
dstCM = dst.getColorModel();
if (srcCM.getColorSpace().getType() !=
dstCM.getColorSpace().getType())
{
needToConvert = true;
dst = createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
}
else if (dstCM instanceof IndexColorModel) {
dst = createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
}
} if (ImagingLib.filter(this, src, dst) == null) {
throw new ImagingOpException ("Unable to convolve src image");
} if (needToConvert) {
ColorConvertOp ccop = new ColorConvertOp(hints);
ccop.filter(dst, origDst);
}
else if (origDst != dst) {
java.awt.Graphics2D g = origDst.createGraphics();
try {
g.drawImage(dst, 0, 0, null);
} finally {
g.dispose();
}
} return origDst;
}这一段是过滤器的源代码. 当然里面还包含了许多其他的其他的对象. 但是一般来说都是可以在源代码里面找到的. 按图索骥下去应该就可以了.
this.width = width;
this.height = height;
this.xOrigin = (width-1)>>1;
this.yOrigin = (height-1)>>1;
int len = width*height;
if (data.length < len) {
throw new IllegalArgumentException("Data array too small "+
"(is "+data.length+
" and should be "+len);
}
this.data = new float[len];
System.arraycopy(data, 0, this.data, 0, len); }Kernel是这样的. 我觉得好像很容易得到. 不知道是不是我 理解错误了?
首先多谢 cydp007 的热心回复。上面这2段我也看到了,但到了这段就终止了,但其核心算法并没有在这2段中。
if (ImagingLib.filter(this, src, dst) == null) { //感觉算法应该是在这里
throw new ImagingOpException ("Unable to convolve src image");
}
能不能再进一步调试跟踪进去呀?
public static BufferedImage filter(BufferedImageOp op, BufferedImage src,
BufferedImage dst)
{
if (verbose) {
System.out.println("in filter and op is "+op
+ "bufimage is "+src+" and "+dst);
}
if (useLib == false) {
return null;
}
// Create the destination image
if (dst == null) {
dst = op.createCompatibleDestImage(src, null);
}
BufferedImage retBI = null;
switch (getNativeOpIndex(op.getClass())) {
case LOOKUP_OP:
// REMIND: Fix this!
LookupTable table = ((LookupOp)op).getTable();
if (table.getOffset() != 0) {
// Right now the native code doesn't support offsets
return null;
}
if (table instanceof ByteLookupTable) {
ByteLookupTable bt = (ByteLookupTable) table;
if (lookupByteBI(src, dst, bt.getTable()) > 0) {
retBI = dst;
}
}
break;
case AFFINE_OP:
AffineTransformOp bOp = (AffineTransformOp) op;
double[] matrix = new double[6];
AffineTransform xform = bOp.getTransform();
bOp.getTransform().getMatrix(matrix);
if (transformBI(src, dst, matrix,
bOp.getInterpolationType())>0) {
retBI = dst;
}
break;
case CONVOLVE_OP:
ConvolveOp cOp = (ConvolveOp) op;
if (convolveBI(src, dst, cOp.getKernel(), //这句没有找到具体的实现
cOp.getEdgeCondition()) > 0) {
retBI = dst;
}
break;
default:
break;
} if (retBI != null) {
SurfaceManager sm = SurfaceManager.getManager(retBI);
SurfaceData sd = sm.getDestSurfaceData();
sd.setNeedsBackup(true);
}
return retBI;
}
最后提供一点 我的搜索资料. google jdk native code 第一个除外..2~4个是解析native code的..如果实在找不到源码.可以看一下. 是英文的.我没看完.呵呵.
# after -XX: or in .hotspotrc: SuppressErrorAt=\stackValue.hpp:58
#
# An unexpected error has been detected by Java Runtime Environment:
#
# Internal Error (C:\BUILD_AREA\jdk6_12\hotspot\src\share\vm\runtime\stackValue.hpp:58), pid=3420, tid=3064
# Error: assert(type() == T_OBJECT,"type check")
#
# Java VM: Java HotSpot(TM) Client VM (11.2-b01-fastdebug mixed mode windows-x86)
# An error report file with more information is saved as:
# D:\workspace\javaanpr\hs_err_pid3420.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
答:JAVA中的Image类库包是基于SUN公司有名的开源的多媒体库mediaLib(C语言版),目前最新的版本是2.5。Image的处理只是其中的一个组成部分(即:mlib_image源代码 含所有的*.c与*.h文件)
你要自己参考写一个,则mlib_image源代码肯定要看的了:
下载地址:http://www.sun.com/processors/vis/mlibfiles.html
在openjdk中jdk\src\share\native\sun\awt\medialib\mlib_ImageConvMxN_Fp.c,疑似正在研究中....多谢提醒,呵呵