bool SkDilateImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, const SkMatrix& ctm, SkBitmap* dst, SkIPoint* offset) { SkBitmap src = this->getInputResult(proxy, source, ctm, offset); if (src.config() != SkBitmap::kARGB_8888_Config) { return false; } SkAutoLockPixels alp(src); if (!src.getPixels()) { return false; } dst->setConfig(src.config(), src.width(), src.height()); dst->allocPixels(); int width = radius().width(); int height = radius().height(); if (width < 0 || height < 0) { return false; } if (width == 0 && height == 0) { src.copyTo(dst, dst->config()); return true; } SkBitmap temp; temp.setConfig(dst->config(), dst->width(), dst->height()); if (!temp.allocPixels()) { return false; } if (width > 0 && height > 0) { dilateX(src, &temp, width); dilateY(temp, dst, height); } else if (width > 0) { dilateX(src, dst, width); } else if (height > 0) { dilateY(src, dst, height); } return true; }
int DilationXY(densityDataType* data, int range, densityDataType* dilation) { int height=(*data).sizeY; int width=(*data).sizeX; int imagesize=height*width+1; densityDataType help; (help).sizeX=width; (help).sizeY=height; (help).data=(float*) malloc( sizeof(float) * imagesize); int n=range/2; int x,y; for ( y=n+10;y<(*data).sizeY-(n+10);y++) { for ( x=n+10;x<(*data).sizeX-(n+10);x++) { //printf("hello\n"); intVectorType x0; x0.x=x; x0.y=y; ACCESSDATAATPOINT(help,x,y) = dilateX(data,x0,range); //printf("x=%d y=%d diletate=%f\n",x,y,value); }; }; for ( y=n+10;y<(*data).sizeY-(n+10);y++) { for ( x=n+10;x<(*data).sizeX-(n+10);x++) { //printf("hello\n"); intVectorType x0; x0.x=x; x0.y=y; ACCESSDATAATPOINT((*dilation),x,y) = dilateY(&help,x0,range); //printf("x=%d y=%d diletate=%f\n",x,y,value); }; }; free(help.data); return 0; };
bool SkDilateImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, const SkMatrix& ctm, SkBitmap* dst, SkIPoint* offset) { SkBitmap src = source; if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offset)) { return false; } if (src.config() != SkBitmap::kARGB_8888_Config) { return false; } SkIRect bounds; src.getBounds(&bounds); if (!this->applyCropRect(&bounds, ctm)) { return false; } SkAutoLockPixels alp(src); if (!src.getPixels()) { return false; } dst->setConfig(src.config(), bounds.width(), bounds.height()); dst->allocPixels(); if (!dst->getPixels()) { return false; } int width = radius().width(); int height = radius().height(); if (width < 0 || height < 0) { return false; } if (width == 0 && height == 0) { src.extractSubset(dst, bounds); offset->fX += bounds.left(); offset->fY += bounds.top(); return true; } SkBitmap temp; temp.setConfig(dst->config(), dst->width(), dst->height()); if (!temp.allocPixels()) { return false; } if (width > 0 && height > 0) { dilateX(src, &temp, width, bounds); SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height()); dilateY(temp, dst, height, tmpBounds); } else if (width > 0) { dilateX(src, dst, width, bounds); } else if (height > 0) { dilateY(src, dst, height, bounds); } offset->fX += bounds.left(); offset->fY += bounds.top(); return true; }