/* and draw the resulting triangles */ void subdividet(GLfloat u1[2], GLfloat u2[2], GLfloat u3[2], float cutoff, int depth) { GLfloat v1[3], v2[3], v3[3], n1[3], n2[3], n3[3]; GLfloat u12[2], u23[2], u31[2]; int i; if(depth == MAXDEPTH || (curv(u1) < cutoff && curv(u2) < cutoff && curv(u3) < cutoff)){ surf(u1,v1,n1); surf(u2,v2,n2); surf(u3,v3,n3); glBegin(GL_TRIANGLES); glNormal3fv(n1); glVertex3fv(v1); //glNormal3fv(n2); glVertex3fv(v2); //glNormal3fv(n3); glVertex3fv(v3); glEnd(); return; } for(i=0;i<2;i++){ u12[i]=(u1[i]+u2[i])/2.0; u23[i]=(u2[i]+u3[i])/2.0; u31[i]=(u1[i]+u3[i])/2.0; } subdividet(u1,u12,u31,cutoff,depth+1); subdividet(u2,u23,u12,cutoff,depth+1); subdividet(u3,u31,u23,cutoff,depth+1); subdividet(u12,u23,u31,cutoff,depth+1); }
void* nsThebesRenderingContext::GetNativeGraphicData(GraphicDataType aType) { if (aType == NATIVE_GDK_DRAWABLE) { if (mWidget) return mWidget->GetNativeData(NS_NATIVE_WIDGET); } if (aType == NATIVE_THEBES_CONTEXT) return mThebes; if (aType == NATIVE_CAIRO_CONTEXT) return mThebes->GetCairo(); #ifdef XP_WIN if (aType == NATIVE_WINDOWS_DC) { nsRefPtr<gfxASurface> surf(mThebes->CurrentSurface()); if (!surf || surf->CairoStatus()) return nsnull; return static_cast<gfxWindowsSurface*>(static_cast<gfxASurface*>(surf.get()))->GetDC(); } #endif #ifdef XP_OS2 if (aType == NATIVE_OS2_PS) { nsRefPtr<gfxASurface> surf(mThebes->CurrentSurface()); if (!surf || surf->CairoStatus()) return nsnull; return (void*)(static_cast<gfxOS2Surface*>(static_cast<gfxASurface*>(surf.get()))->GetPS()); } #endif return nsnull; }
// main int main( int argc, char** argv ) { cv::Mat img_1 = cv::imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE ); cv::Mat img_2 = cv::imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE ); if( !img_1.data || !img_2.data ) { return -1; } //-- Step 1: Detect the keypoints and generate their descriptors using SURF int minHessian = 400; cv::SURF surf( minHessian ); std::vector<cv::KeyPoint> keypoints_1, keypoints_2; cv::Mat descriptors_1, descriptors_2; surf( img_1, cv::Mat(), keypoints_1, descriptors_1, false ); surf( img_2, cv::Mat(), keypoints_2, descriptors_2, false ); //-- Step 3: Matching descriptor vectors with a brute force matcher cv::BFMatcher matcher( cv::NORM_L2, false ); std::vector< cv::DMatch > matches; matcher.match( descriptors_1, descriptors_2, matches ); //-- Draw matches cv::Mat img_matches; cv::drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches ); //-- Show detected matches imshow("Matches", img_matches ); cv::waitKey(0); return 0; }
void process( FrameData &frameData ) { for( int i=0; i<(int)frameData.images.size(); i++) { Image *image = frameData.images[i].get(); vector<FrameData::DetectedFeature> &detectedFeatures = frameData.detectedFeatures[_stepName]; IplImage* gs = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1); for (int y = 0; y < image->height; y++) memcpy( &gs->imageData[y*gs->widthStep], &image->data[y*image->width], image->width ); cv::SURF surf(Threshold); vector<float> descriptors; vector<cv::KeyPoint> keypoints; surf( cv::Mat(cv::Ptr<IplImage>(gs)), cv::Mat(), keypoints, descriptors); int nDesc = detectedFeatures.size(); detectedFeatures.resize(detectedFeatures.size() + keypoints.size()); for(int j=0; j<(int)keypoints.size(); j++) { detectedFeatures[nDesc].imageIdx = i; detectedFeatures[nDesc].descriptor.resize(64); for (int x=0; x<64; x++) detectedFeatures[nDesc].descriptor[x] = descriptors[j*64+x]; detectedFeatures[nDesc].coord2D[0] = keypoints[j].pt.x; detectedFeatures[nDesc].coord2D[1] = keypoints[j].pt.y; nDesc++; } } }
int detectSURFPoints(const ImgG& img, Mat_d& surfPts, std::vector<float>& surfDesc, double hessianThreshold) { KpVec surfPtsVec; cv::SURF surf(hessianThreshold, 4, 2, false); cv::Mat cvImg(img.rows, img.cols, CV_8UC1, img.data); surf(cvImg, cv::Mat(), surfPtsVec, surfDesc); KpVec2Mat(surfPtsVec, surfPts); return surf.descriptorSize(); }
void Texture2dData::store(const util::Path& file) const { log::log(MSG(info) << "Saving texture data to " << file); if (this->info.get_format() != pixel_format::rgba8) { throw Error(MSG(err) << "Storing 2D textures into files is unimplemented. PRs welcome :D"); } auto size = this->info.get_size(); // If an older SDL2 is used, we have to specify the format manually. #ifndef SDL_PIXELFORMAT_RGBA32 uint32_t rmask, gmask, bmask, amask; #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else // little endian, like x86 rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif std::unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)> surf( SDL_CreateRGBSurfaceFrom( // const_cast is okay, because the surface doesn't modify data const_cast<void*>(static_cast<void const*>(this->data.data())), size.first, size.second, 32, this->info.get_row_size(), rmask, gmask, bmask, amask ), &SDL_FreeSurface ); #else std::unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)> surf( SDL_CreateRGBSurfaceWithFormatFrom( // const_cast is okay, because the surface doesn't modify data const_cast<void*>(static_cast<void const*>(this->data.data())), size.first, size.second, 32, this->info.get_row_size(), SDL_PIXELFORMAT_RGBA32 ), &SDL_FreeSurface ); #endif // Call sdl_image for saving the screenshot to PNG std::string path = file.resolve_native_path_w(); IMG_SavePNG(surf.get(), path.c_str()); }
TEST_P(SURF, Descriptor) { cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(image.empty()); cv::gpu::SURF_GPU surf; surf.hessianThreshold = hessianThreshold; surf.nOctaves = nOctaves; surf.nOctaveLayers = nOctaveLayers; surf.extended = extended; surf.upright = upright; surf.keypointsRatio = 0.05f; cv::SURF surf_gold; surf_gold.hessianThreshold = hessianThreshold; surf_gold.nOctaves = nOctaves; surf_gold.nOctaveLayers = nOctaveLayers; surf_gold.extended = extended; surf_gold.upright = upright; if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS)) { try { std::vector<cv::KeyPoint> keypoints; cv::gpu::GpuMat descriptors; surf(loadMat(image), cv::gpu::GpuMat(), keypoints, descriptors); } catch (const cv::Exception& e) { ASSERT_EQ(CV_StsNotImplemented, e.code); } } else { std::vector<cv::KeyPoint> keypoints; surf_gold(image, cv::noArray(), keypoints); cv::gpu::GpuMat descriptors; surf(loadMat(image), cv::gpu::GpuMat(), keypoints, descriptors, true); cv::Mat descriptors_gold; surf_gold(image, cv::noArray(), keypoints, descriptors_gold, true); cv::BFMatcher matcher(cv::NORM_L2); std::vector<cv::DMatch> matches; matcher.match(descriptors_gold, cv::Mat(descriptors), matches); int matchedCount = getMatchedPointsCount(keypoints, keypoints, matches); double matchedRatio = static_cast<double>(matchedCount) / keypoints.size(); EXPECT_GT(matchedRatio, 0.35); } }
int main() { curve::NURBS<3> cur; cur.pushControlPoint( geom::Vector3f( 0, 0, 0 ) ); cur.pushControlPoint( geom::Vector3f( 1, 0, 0 ) ); cur.pushControlPoint( geom::Vector3f( 1, 1, 0 ) ); cur.pushControlPoint( geom::Vector3f( 0, 1, 0 ) ); std::cout << cur( 0.5 ) << std::endl; surface::Tube<float> surf( cur, frame::Frenet<float>() ); std::cout << surf( 0.5, 0 ) << std::endl; return 0; }
TEST_P(SURF, Detector_Masked) { cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(image.empty()); cv::Mat mask(image.size(), CV_8UC1, cv::Scalar::all(1)); mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0)); cv::gpu::SURF_GPU surf; surf.hessianThreshold = hessianThreshold; surf.nOctaves = nOctaves; surf.nOctaveLayers = nOctaveLayers; surf.extended = extended; surf.upright = upright; surf.keypointsRatio = 0.05f; if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS)) { try { std::vector<cv::KeyPoint> keypoints; surf(loadMat(image), loadMat(mask), keypoints); } catch (const cv::Exception& e) { ASSERT_EQ(CV_StsNotImplemented, e.code); } } else { std::vector<cv::KeyPoint> keypoints; surf(loadMat(image), loadMat(mask), keypoints); cv::SURF surf_gold; surf_gold.hessianThreshold = hessianThreshold; surf_gold.nOctaves = nOctaves; surf_gold.nOctaveLayers = nOctaveLayers; surf_gold.extended = extended; surf_gold.upright = upright; std::vector<cv::KeyPoint> keypoints_gold; surf_gold(image, mask, keypoints_gold); ASSERT_EQ(keypoints_gold.size(), keypoints.size()); int matchedCount = getMatchedPointsCount(keypoints_gold, keypoints); double matchedRatio = static_cast<double>(matchedCount) / keypoints_gold.size(); EXPECT_GT(matchedRatio, 0.95); } }
void Feature::SURFExtractor_GPU(vector<cv::KeyPoint> &feature_pts, vector_eigen_vector3f &feature_pts_3d, cv::Mat &feature_descriptors, const cv::Mat &imgRGB, const cv::Mat &imgDepth) { cv::Mat grey; cv::cvtColor(imgRGB, grey, CV_BGR2GRAY); //cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice()); cv::gpu::GpuMat gpuRGB, gpuKeypoints, gpuDescriptors; gpuRGB.upload(grey); cv::gpu::SURF_GPU surf; surf(gpuRGB, cv::gpu::GpuMat(), gpuKeypoints, gpuDescriptors); vector<cv::KeyPoint> fpts; cv::Mat descriptors; surf.downloadKeypoints(gpuKeypoints, fpts); gpuDescriptors.download(descriptors); for (int i = 0; i < fpts.size(); i++) { if (imgDepth.at<ushort>(cvRound(fpts[i].pt.y), cvRound(fpts[i].pt.x)) == 0) continue; feature_pts.push_back(fpts[i]); Eigen::Vector3f pt = ConvertPointTo3D(fpts[i].pt.x, fpts[i].pt.y, imgDepth); feature_pts_3d.push_back(pt); feature_descriptors.push_back(descriptors.row(i)); } }
void Installer<UserData>::install(DetElement component, PlacedVolume pv) { Volume comp_vol = pv.volume(); if ( comp_vol.isSensitive() ) { Volume mod_vol = parentVolume(component); DD4hep::Geometry::PolyhedraRegular comp_shape(comp_vol.solid()), mod_shape(mod_vol.solid()); if ( !comp_shape.isValid() || !mod_shape.isValid() ) { invalidInstaller("Components and/or modules are not Trapezoid -- invalid shapes"); } else if ( !handleUsingCache(component,comp_vol) ) { DetElement par = component.parent(); const TGeoHMatrix& m = par.worldTransformation(); double dz = m.GetTranslation()[2]; const double* trans = placementTranslation(component); double half_mod_thickness = (mod_shape->GetZ(1)-mod_shape->GetZ(0))/2.0; double half_comp_thickness = (comp_shape->GetZ(1)-comp_shape->GetZ(0))/2.0; double si_position = trans[2]+half_mod_thickness; double outer_thickness = half_mod_thickness - si_position; double inner_thickness = half_mod_thickness + si_position; Vector3D u(1.,0.,0.), v(0.,1.,0.), n(0.,0.,1.), o(100.,100.,0.); std::cout << " Module: " << mod_shape.toString() << std::endl; std::cout << " Component: " << comp_shape.toString() << std::endl; std::cout << "dz:" << dz << " Si-pos:" << si_position << " Mod-thickness:" << half_mod_thickness << " Comp-thickness:" << half_comp_thickness << std::endl; VolPlane surf(comp_vol,Type(Type::Sensitive,Type::Measurement1D), inner_thickness, outer_thickness, u, v, n, o); addSurface(component,surf); } } }
DEF_TEST(PremulAlphaRoundTrip, reporter) { const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); sk_sp<SkSurface> surf(SkSurface::MakeRaster(info)); test_premul_alpha_roundtrip(reporter, surf.get()); }
static void surfpcs_addlc(surfpcs *s,const char *x,unsigned int n) /* modified from Dan's surfpcs_add by skipping ' ' & '\t' and */ /* case-independence */ { unsigned char ch; int i; while (n--) { ch = *x++; if (ch == ' ' || ch == '\t') continue; if (ch >= 'A' && ch <= 'Z') data[end[s->todo++]] = ch - 'A' + 'a'; else data[end[s->todo++]] = ch; if (s->todo == 32) { s->todo = 0; if (!++s->in[8]) if (!++s->in[9]) if (!++s->in[10]) ++s->in[11]; surf(s->out,s->in,s->seed); for (i = 0;i < 8;++i) s->sum[i] += s->out[i]; } } }
void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const { cpuTime timer; triSurface surf(surfName_); Info<< " Read surface from " << surfName_ << " in = "<< timer.cpuTimeIncrement() << " s" << endl << endl; // Construct search engine on surface triSurfaceSearch querySurf(surf); if (includeInside_ || includeOutside_) { boolList pointInside(querySurf.calcInside(mesh_.points())); forAll(pointInside, pointI) { bool isInside = pointInside[pointI]; if ((isInside && includeInside_) || (!isInside && includeOutside_)) { addOrDelete(set, pointI, add); } }
Mm ex() { begin_scope #line 1 "d:/matcom45/ex.m" call_stack_begin; #line 1 "d:/matcom45/ex.m" // nargin, nargout entry code double old_nargin=nargin_val; if (!nargin_set) nargin_val=0.0; nargin_set=0; double old_nargout=nargout_val; if (!nargout_set) nargout_val=0.0; nargout_set=0; // translated code #line 2 "d:/matcom45/ex.m" _ subplot(121.0); #line 3 "d:/matcom45/ex.m" _ surf((CL(peaks(25.0)))); #line 4 "d:/matcom45/ex.m" _ subplot(122.0); #line 5 "d:/matcom45/ex.m" _ pcolor((CL(peaks(25.0)))); call_stack_end; // nargin, nargout exit code nargin_val=old_nargin; nargout_val=old_nargout; // function exit code return x_M; end_scope }
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, ctxInfo) { sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRenderTarget(ctxInfo.grContext(), kSmallerSize, kSmallerSize, kSkia8888_GrPixelConfig)); test_surface(surf, reporter, 0); }
virtual void onDraw(SkCanvas* canvas) { SkAutoTUnref<SkSurface> surf(compat_surface(canvas, this->getISize(), this->isCanvasDeferred())); surf->getCanvas()->drawColor(SK_ColorWHITE); this->drawContent(surf->getCanvas()); surf->draw(canvas, 0, 0, NULL); }
DEF_TEST(SpecialSurface_Raster, reporter) { SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_SkAlphaType); sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRaster(info)); test_surface(surf, reporter, 0); }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PremulAlphaRoundTrip_Gpu, reporter, ctxInfo) { const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info)); test_premul_alpha_roundtrip(reporter, surf.get()); }
Foam::autoPtr< Foam::UnsortedMeshedSurface<Face> > Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext) { if (debug) { Info<< "UnsortedMeshedSurface::New(const fileName&, const word&) : " "constructing UnsortedMeshedSurface" << endl; } typename fileExtensionConstructorTable::iterator cstrIter = fileExtensionConstructorTablePtr_->find(ext); if (cstrIter == fileExtensionConstructorTablePtr_->end()) { // no direct reader, use the parent if possible wordHashSet supported = ParentType::readTypes(); if (supported.found(ext)) { // create indirectly autoPtr<UnsortedMeshedSurface<Face> > surf ( new UnsortedMeshedSurface<Face> ); surf().transfer(ParentType::New(name, ext)()); return surf; } // nothing left but to issue an error supported += readTypes(); FatalErrorIn ( "UnsortedMeshedSurface<Face>::New" "(const fileName&, const word&) : " "constructing UnsortedMeshedSurface" ) << "Unknown file extension " << ext << nl << nl << "Valid types are:" << nl << supported << exit(FatalError); } return autoPtr<UnsortedMeshedSurface<Face> >(cstrIter()(name)); }
int msh::ApplicationSession::configure_surface(mf::SurfaceId id, MirSurfaceAttrib attrib, int value) { std::unique_lock<std::mutex> lock(surfaces_mutex); std::shared_ptr<mf::Surface> surf(checked_find(id)->second); return surf->configure(attrib, value); }
int main(int argc, char* argv[]) { try { const toptions& options = toptions::parse(argc, argv); surface surf(make_neutral_surface( IMG_Load(options.input_filename.c_str()))); if(!surf) { std::cerr << "Error: Failed to load input file »" << options.input_filename << "«.\n"; return EXIT_FAILURE; } std::vector<surface> surfaces; if(options.count != 1) { for(int i = 1; i < options.count; ++i) { // make_neutral_surface make a deep-copy of the image. surfaces.push_back(make_neutral_surface(surf)); } } surfaces.push_back(surf); const clock_t begin = options.time ? get_begin_time() : 0; for(int i = 0; i < options.count; ++i) { BOOST_FOREACH(const std::string& filter, options.filters) { filter_apply(surfaces[i], filter); } } if(options.time) { const clock_t end = std::clock(); std::cout << "Applying the filters took " << end - begin << " ticks, " << static_cast<double>(end - begin) / CLOCKS_PER_SEC << " seconds.\n"; } if(!options.output_filename.empty()) { save_image(surfaces[0], options.output_filename); } } catch(const texit& exit) { return exit.status; } catch(exploder_failure& err) { std::cerr << "Error: Failed with error »" << err.message << "«.\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; }
static void surfpcs_out(surfpcs *s,unsigned char h[32]) { int i; surfpcs_addlc(s,".",1); while (s->todo) surfpcs_addlc(s,"",1); for (i = 0;i < 8;++i) s->in[i] = s->sum[i]; for (;i < 12;++i) s->in[i] = 0; surf(s->out,s->in,s->seed); for (i = 0;i < 32;++i) h[i] = outdata[end[i]]; }
void surfpcs_out(surfpcs *s,unsigned char h[32]) { int i; uint32 out[8]; surfpcs_add(s,".",1); while (s->todo) surfpcs_add(s,"",1); for (i = 0;i < 8;++i) s->in[i] = s->sum[i]; for (;i < 12;++i) s->in[i] = 0; surf(out,s->in,s->seed); for (i = 0;i < 32;++i) h[i] = ((unsigned char*)out)[end[i]]; }
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface ( const Time& t, const word& surfName ) : ParentType() { MeshedSurface<Face> surf(t, surfName); transfer(surf); }
void loadFeaturesRGB(BoWFeatures &features) { features.clear(); features.reserve(files_list_rgb.size()); cv::SURF surf(500, 4, 2, true); double acc_media = 0,media=0,scarti=0,varianza=0; DUtilsCV::GUI::tWinHandler win = "SURF"; for (int i = 0; i < files_list_rgb.size(); ++i) { cout << "Estrazione SURF: " << files_list_rgb[i]; clock_t begin = clock(); cv::Mat image = cv::imread(files_list_rgb[i]); cv::Mat mask,outImg; vector<cv::KeyPoint> keypoints; vector<float> descriptors; surf(image, mask, keypoints, descriptors); drawKeypoints(image, keypoints, outImg ); DUtilsCV::GUI::showImage(outImg, true, &win, 10); features.push_back(vector<vector<float> >()); changeStructure(descriptors, features.back(), surf.descriptorSize()); clock_t end = clock(); double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; media = media + elapsed_secs; acc_media = media / (i+1); cout << "media: " << acc_media<<endl; scarti += pow(elapsed_secs-acc_media,2); varianza = sqrt(scarti/(i+1)); cout << "varianza: " << varianza<<endl; cout << ". Estratti " << features[i].size() << " descrittori." << endl; descriptors.clear(); keypoints.clear(); mask.release(); image.release(); } cout << "Estrazione terminata." << endl; }
void ObjectRecognition::loadFeatures(Mat& inImage, vector< KeyPoint >& keypoints, vector< std::vector< float > >& features, Mat& descriptors) { features.clear(); keypoints.clear(); if(input_type==0) //input_type = 0 camera cvtColor(inImage, inImage, CV_RGB2GRAY); #if FEATURE_EXTRATION //---------------using SIFT to get features descriptors------------------------- //cout<< "...Extracting SIFT features..." << endl; initModule_nonfree(); SIFT sift(1, 3, 0.04, 10, 1.0); sift(inImage, noArray(), keypoints, descriptors); // vector<vector<float> > vdesc; // vdesc.reserve(descriptors.rows); for (int i=0; i<descriptors.rows; i++) { features.push_back(descriptors.row(i)); } // cout<< "descriptors: " << vdesc.size() << " " << vdesc[0].size() << endl; #else //-----------using SURF to get features descriptors------------------------ vector<float> descriptors; cv::Mat mask; cv::SURF surf(400, 4, 2, EXTENDED_SURF); surf(inimage, mask, keypoints, descriptors); features.push_back(vector<vector<float> >()); changeStructure(descriptors, features.back(), surf.descriptorSize()); #endif //----------------------------display keypoints-------------------------- // drawKeypoints(image, keypoints, image, Scalar(255,0,0)); // imshow("clusters", image); // waitKey(); }
sk_sp<SkSpecialImage> SkDropShadowImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx, SkIPoint* offset) const { SkIPoint inputOffset = SkIPoint::Make(0, 0); sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)); if (!input) { return nullptr; } const SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y(), input->width(), input->height()); SkIRect bounds; if (!this->applyCropRect(ctx, inputBounds, &bounds)) { return nullptr; } const SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), kPremul_SkAlphaType); sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } SkCanvas* canvas = surf->getCanvas(); SkASSERT(canvas); canvas->clear(0x0); SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); ctx.ctm().mapVectors(&sigma, 1); sigma.fX = SkMaxScalar(0, sigma.fX); sigma.fY = SkMaxScalar(0, sigma.fY); SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, sigma.fY)); SkPaint paint; paint.setImageFilter(blurFilter.get()); paint.setColorFilter(SkColorFilter::MakeModeFilter(fColor, SkXfermode::kSrcIn_Mode)); paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); SkVector offsetVec = SkVector::Make(fDx, fDy); ctx.ctm().mapVectors(&offsetVec, 1); canvas->translate(SkIntToScalar(inputOffset.fX - bounds.fLeft), SkIntToScalar(inputOffset.fY - bounds.fTop)); input->draw(canvas, offsetVec.fX, offsetVec.fY, &paint); if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { input->draw(canvas, 0, 0, nullptr); } offset->fX = bounds.fLeft; offset->fY = bounds.fTop; return surf->makeImageSnapshot(); }
sk_sp<SkSpecialImage> SkImageSource::onFilterImage(SkSpecialImage* source, const Context& ctx, SkIPoint* offset) const { SkRect dstRect; ctx.ctm().mapRect(&dstRect, fDstRect); SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height()); if (fSrcRect == bounds) { int iLeft = dstRect.fLeft; int iTop = dstRect.fTop; // TODO: this seems to be a very noise-prone way to determine this (esp. the floating-point // widths & heights). if (dstRect.width() == bounds.width() && dstRect.height() == bounds.height() && iLeft == dstRect.fLeft && iTop == dstRect.fTop) { // The dest is just an un-scaled integer translation of the entire image; return it offset->fX = iLeft; offset->fY = iTop; return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(fImage->width(), fImage->height()), fImage, ctx.outputProperties().colorSpace(), &source->props()); } } const SkIRect dstIRect = dstRect.roundOut(); sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), dstIRect.size())); if (!surf) { return nullptr; } SkCanvas* canvas = surf->getCanvas(); SkASSERT(canvas); // TODO: it seems like this clear shouldn't be necessary (see skbug.com/5075) canvas->clear(0x0); SkPaint paint; // Subtract off the integer component of the translation (will be applied in offset, below). dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop)); paint.setBlendMode(SkBlendMode::kSrc); // FIXME: this probably shouldn't be necessary, but drawImageRect asserts // None filtering when it's translate-only paint.setFilterQuality( fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ? kNone_SkFilterQuality : fFilterQuality); canvas->drawImageRect(fImage.get(), fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint); offset->fX = dstIRect.fLeft; offset->fY = dstIRect.fTop; return surf->makeImageSnapshot(); }
RegularSurface<A> RegularSurfaceRotated<A>::ResampleSurface() const { double dx = surface_.GetDX()*cos(angle_); double dy = surface_.GetDY()*cos(angle_); int nx = int((x_max_-x_min_)/dx) + 1; int ny = int((y_max_-y_min_)/dy) +1; RegularSurface<A> surf(x_min_, y_min_, x_max_-x_min_, y_max_-y_min_, nx, ny, 0.0); surf.SetMissingValue(GetMissingValue()); A value; double x,y; int i,j; for(i=0;i<nx;i++) for(j=0;j<ny;j++) { x = x_min_ + i*dx; y = y_min_ + j*dy; value = GetZ(x,y); surf(i,j) = value; } return surf; }