void LinearFunctionTest::testBase() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testBase() begin"); LinearFunction l(ImagePoint(500, 500), false); l[0] = 0.1; l[1] = 0.2; l[2] = 0.3; std::vector<FunctionBase::doublevaluepair> values; for (int x = 0; x < 1000; x += 10) { for (int y = 0; y < 1000; y += 10) { double e = -0.5 + random() / (double)2147483647; ImagePoint p(x, y); double value = l.evaluate(Point(p)) + e; values.push_back(std::make_pair(p, value)); } } LinearFunction l2(ImagePoint(500, 500), false, values); for (int x = 0; x < 1000; x += 50) { for (int y = 0; y < 1000; y += 50) { ImagePoint p(x, y); double delta = fabs(l.evaluate(Point(p)) - l2.evaluate(Point(p))); CPPUNIT_ASSERT(delta < 2); } } debug(LOG_DEBUG, DEBUG_LOG, 0, "testBase() end"); }
void ImageRectangleTest::testTranslation() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testTranslation() begin"); ImageRectangle r(*r1, ImagePoint(17, 4)); CPPUNIT_ASSERT(r.size() == r1->size()); CPPUNIT_ASSERT(r.origin() == ImagePoint(20, 9)); debug(LOG_DEBUG, DEBUG_LOG, 0, "testTranslation() end"); }
void ImageRectangleTest::testCorners() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testCorners() begin"); CPPUNIT_ASSERT(ImagePoint(3, 5) == r1->lowerLeftCorner()); CPPUNIT_ASSERT(ImagePoint(642, 5) == r1->lowerRightCorner()); CPPUNIT_ASSERT(ImagePoint(3, 484) == r1->upperLeftCorner()); CPPUNIT_ASSERT(ImagePoint(642, 484) == r1->upperRightCorner()); debug(LOG_DEBUG, DEBUG_LOG, 0, "testCorners() end"); }
/** * \brief main function for the convolve program */ int main(int argc, char *argv[]) { // parse command line int c; int longindex; while (EOF != (c = getopt_long(argc, argv, "dh?", longopts, &longindex))) switch (c) { case 'd': debuglevel = LOG_DEBUG; break; case 'h': case '?': usage(argv[0]); return EXIT_SUCCESS; default: throw std::runtime_error("unknown option"); } // next two arguments must be filenames if ((argc - optind) != 3) { std::cerr << "need exactly three file name arguments" << std::endl; return EXIT_FAILURE; } const char *in1filename = argv[optind++]; const char *in2filename = argv[optind++]; const char *outfilename = argv[optind++]; // read the image from the file FITSin in1file(in1filename); ImagePtr image1 = in1file.read(); Image<double> *img1 = dynamic_cast<Image<double> *>(&*image1); if (NULL == img1) { debug(LOG_ERR, DEBUG_LOG, 0, "can only convolve double images"); } ConvolutionResult factor1(*img1, ImagePoint(0, 0)); FITSin in2file(in2filename); ImagePtr image2 = in2file.read(); Image<double> *img2 = dynamic_cast<Image<double> *>(&*image2); if (NULL == img2) { debug(LOG_ERR, DEBUG_LOG, 0, "can only convolve double images"); } ConvolutionResult factor2(*img2, ImagePoint(0, 0)); // compute the convolution ConvolutionResultPtr result = factor1 * factor2; // write the result image FITSout outfile(outfilename); outfile.setPrecious(false); outfile.write(result->image()); // that's it return EXIT_SUCCESS; }
void MinRadiusTest::testMin() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testMin() begin"); std::list<ImagePoint> points; points.push_back(ImagePoint(0, 0)); points.push_back(ImagePoint(1, 0)); points.push_back(ImagePoint(0, 1)); points.push_back(ImagePoint(1, 1)); double radius = MinRadius(points); CPPUNIT_ASSERT(fabs(radius - sqrt(2)/2) < 0.0001); debug(LOG_DEBUG, DEBUG_LOG, 0, "testMin() end"); }
void DeconvolveTest::testDisk() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testDisk() begin"); DiskImage image1(ImageSize(256,256), ImagePoint(47,62), 1, 1); ImagePtr iptr = ImagePtr(new Image<double>(image1)); DiskImage image2(ImageSize(256,256), ImagePoint(128,111), 1, 1); BasicDeconvolutionOperator decon(image2); ImagePtr fq = decon(iptr); io::FITSout out("tmp/deconvolve-disk.fits"); out.setPrecious(false); out.write(fq); debug(LOG_DEBUG, DEBUG_LOG, 0, "testDisk() end"); }
ImagePtr Calibrator::operator()(const ImagePtr image) const { unsigned int floatlimit = std::numeric_limits<float>::digits; // find the appropriate frame to use for the correction images ImageRectangle frame; if (rectangle == ImageRectangle()) { frame = ImageRectangle(ImagePoint(), image->size()); } // use pixel size to decide which type to use for the result image if (image->bitsPerPixel() <= floatlimit) { // create adapters for darks and flats with float values ConstPixelValueAdapter<float> pvdark(dark); WindowAdapter<float> wdark(pvdark, frame); ConstPixelValueAdapter<float> pvflat(flat); WindowAdapter<float> wflat(pvflat, frame); TypedCalibrator<float> calibrator(wdark, wflat); return calibrator(image); } ConstPixelValueAdapter<double> pvdark(dark); WindowAdapter<double> wdark(pvdark, frame); ConstPixelValueAdapter<double> pvflat(flat); WindowAdapter<double> wflat(pvflat, frame); TypedCalibrator<double> calibrator(wdark, wflat); return calibrator(image); }
void WindowAdapterTest::testWindowAdapter() { debug(LOG_DEBUG, DEBUG_LOG, 0, "window adapter test"); // create an image Image<unsigned char> image(16, 16); for (unsigned int x = 0; x < 16; x++) { for (unsigned int y = 0; y < 16; y++) { image.pixel(x, y) = x * y; } } // create the subframe ImageRectangle frame(ImagePoint(4, 4), ImageSize(8, 8)); debug(LOG_DEBUG, DEBUG_LOG, 0, "frame: %s", frame.toString().c_str()); // create an adapter for a subframe WindowAdapter<unsigned char> adapter(image, frame); // access the subframe ImageSize size = adapter.getSize(); debug(LOG_DEBUG, DEBUG_LOG, 0, "adapter size: %s", size.toString().c_str()); for (int x = 0; x < size.width(); x++) { for (int y = 0; y < size.height(); y++) { unsigned char value = adapter.pixel(x, y); unsigned char v = (frame.origin().x() + x) * (frame.origin().y() + y); if (v != value) { debug(LOG_DEBUG, DEBUG_LOG, 0, "expected %d != %d found", (int)v, (int)value); } CPPUNIT_ASSERT(value == v); } } debug(LOG_DEBUG, DEBUG_LOG, 0, "window adapter test complete"); }
void ImageRectangleTest::testSubrectangle() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testSubrectangle() begin"); ImageRectangle r(*r2, *r1); CPPUNIT_ASSERT(r.size() == r1->size()); CPPUNIT_ASSERT(r.origin() == ImagePoint(6, 10)); debug(LOG_DEBUG, DEBUG_LOG, 0, "testSubrectangle() end"); }
void SimpleSurface::applyFilter (Surface *inSrc, const Rect &inRect, ImagePoint inOffset, Filter *inFilter) { if (!mBase) return; FilterList f; f.push_back (inFilter); Rect src_rect (inRect.w, inRect.h); Rect dest = GetFilteredObjectRect (f, src_rect); inSrc->IncRef (); Surface *result = FilterBitmap (f, inSrc, src_rect, dest, false, ImagePoint (inRect.x, inRect.y)); dest.Translate (inOffset.x, inOffset.y); src_rect = Rect (0, 0, result->Width (), result->Height ()); int dx = dest.x; int dy = dest.y; dest = dest.Intersect (Rect (0, 0, mWidth, mHeight)); dest.Translate (-dx, -dy); dest = dest.Intersect (src_rect); dest.Translate (dx, dy); int bpp = BytesPP (); RenderTarget t = BeginRender (dest, false); //printf("Copy back @ %d,%d %dx%d + (%d,%d)\n", dest.x, dest.y, t.Width(), t.Height(), dx, dy); for (int y = 0; y < t.Height (); y++) memcpy ((void *)(t.Row (y + dest.y) + ((dest.x) * bpp)), result->Row (y - dy) - (dx * bpp), dest.w * bpp); EndRender (); result->DecRef (); }
void LinearFunctionTest::testAsymmetric() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testAsymmetric() begin"); ImageSize size(1000, 1000); LinearFunction l(size.center(), false); l[0] = 0.1; l[1] = 0.2; l[2] = 200; std::vector<FunctionBase::doublevaluepair> values; for (int x = 0; x < size.width(); x++) { for (int y = 0; y < size.height(); y++) { float e = -0.5 + random() / (double)2147483647; ImagePoint p(x, y); float value = l(p) + e; values.push_back(std::make_pair(p, value)); } } ImageFunctionAdapter<LinearFunction> lfa(size, l, ImagePoint(0, 0)); MinimumEstimator<LinearFunction> me(lfa, 100); FunctionPtr l2 = me(size.center(), false); for (int x = 0; x < size.width(); x++) { for (int y = 0; y < size.height(); y++) { ImagePoint p(x, y); double delta = fabs(l(p) - l2->evaluate(p)); CPPUNIT_ASSERT(delta < 2); } } debug(LOG_DEBUG, DEBUG_LOG, 0, "testAsymmetric() end"); }
void ImageBaseTest::testPixeloffset() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testPixelOffset() begin"); CPPUNIT_ASSERT(i1->pixeloffset(4, 11) == (4 + 11 * 640)); CPPUNIT_ASSERT(i1->pixeloffset(ImagePoint(4, 11)) == (4 + 11 * 640)); CPPUNIT_ASSERT(i4->pixeloffset(4, 11) == (4 + 1024 * (11))); debug(LOG_DEBUG, DEBUG_LOG, 0, "testPixelOffset() end"); }
void Mock1Test::testMock1() { debug(LOG_DEBUG, DEBUG_LOG, 0, "Mock1Test begin"); ModulePtr module = repository->getModule("mock1"); debug(LOG_DEBUG, DEBUG_LOG, 0, "got module"); module->open(); debug(LOG_DEBUG, DEBUG_LOG, 0, "module open"); DeviceLocatorPtr cl = module->getDeviceLocator(); debug(LOG_DEBUG, DEBUG_LOG, 0, "get DeviceLocator"); std::vector<std::string> cameras = cl->getDevicelist(); debug(LOG_DEBUG, DEBUG_LOG, 0, "get %d devices", cameras.size()); CPPUNIT_ASSERT(cameras.size() == 10); CameraPtr camera = cl->getCamera("camera:mock1/5"); // for every CCD, take an image for (unsigned int i = 0; i < camera->nCcds(); i++) { CcdPtr ccd = camera->getCcd(i); Exposure exposure; ImageRectangle frame(ImagePoint(1,1), ImageSize(ccd->getSize().width() - 2, ccd->getSize().height() - 2)); exposure.frame(frame); ccd->startExposure(exposure); while (ccd->exposureStatus() == Exposure::exposing) { sleep(1); } if (ccd->exposureStatus() == Exposure::exposed) { ImagePtr image = ccd->getImage(); debug(LOG_DEBUG, DEBUG_LOG, 0, "result image size: %d x %d", image->size().width(), image->size().height()); } } debug(LOG_DEBUG, DEBUG_LOG, 0, "Mock1Test end"); }
/** * \brief Find out whether a rectangle is contained in the rectangle * defined by a size ojbect. */ bool ImageSize::bounds(const ImageRectangle& rect) const { if (!bounds(rect.origin())) { debug(LOG_DEBUG, DEBUG_LOG, 0, "origin outside"); return false; } return bounds(ImagePoint(rect.origin().x() + rect.size().width() - 1, rect.origin().y() + rect.size().height() - 1)); }
ImagePtr dark(const ImageSequence& images, bool gridded = false) { debug(LOG_DEBUG, DEBUG_LOG, 0, "gridded: %s", (gridded) ? "YES" : "NO"); if (!gridded) { return dark_plain<T>(images); } debug(LOG_DEBUG, DEBUG_LOG, 0, "gridded dark processing"); ImageMean<T> im(images, true); // perform the dark computation for each individual subgrid size_t badpixels = 0; ImageSize step(2, 2); badpixels += subdark<T>(images, im, Subgrid(ImagePoint(0, 0), step)); badpixels += subdark<T>(images, im, Subgrid(ImagePoint(1, 0), step)); badpixels += subdark<T>(images, im, Subgrid(ImagePoint(0, 1), step)); badpixels += subdark<T>(images, im, Subgrid(ImagePoint(1, 1), step)); debug(LOG_DEBUG, DEBUG_LOG, 0, "total bad pixels: %d", badpixels); ImagePtr darkimg = im.getImagePtr(); darkimg->setMetadata(FITSKeywords::meta("BADPIXEL", (long)badpixels)); return darkimg; }
int main(int argc, char *argv[]) { // parse command line arguments int c; while (EOF != (c = getopt(argc, argv, "d"))) switch (c) { case 'd': debuglevel = LOG_DEBUG; break; } // create a camera instance SimCamera camera; CcdPtr ccd = camera.getCcd(0); GuiderPortPtr guiderport = camera.getGuiderPort(); // we will always use 1 sec exposures Exposure exposure(ImageRectangle(ImagePoint(160,120), ImageSize(320, 240)), 1); // make 10 images 1 second appart (should give small drift) counter = 0; while (counter < 10) { ccd->startExposure(exposure); ImagePtr image = ccd->getImage(); writeimage(image); } // now move for 5 seconds guiderport->activate(5, 0, 0, 0); sleep(5); ccd->startExposure(exposure); writeimage(ccd->getImage()); guiderport->activate(0, 5, 0, 0); sleep(5); ccd->startExposure(exposure); writeimage(ccd->getImage()); guiderport->activate(0, 0, 5, 0); sleep(5); ccd->startExposure(exposure); writeimage(ccd->getImage()); guiderport->activate(0, 0, 0, 5); sleep(5); ccd->startExposure(exposure); writeimage(ccd->getImage()); return EXIT_SUCCESS; }
void ImageRectangleTest::testContainsPoint() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testContainsPoint() begin"); CPPUNIT_ASSERT(r1->contains(r1->lowerLeftCorner())); CPPUNIT_ASSERT(r1->contains(r1->lowerRightCorner())); CPPUNIT_ASSERT(r1->contains(r1->upperLeftCorner())); CPPUNIT_ASSERT(r1->contains(r1->upperRightCorner())); CPPUNIT_ASSERT(!r1->contains(ImagePoint(2, 5))); CPPUNIT_ASSERT(!r1->contains(ImagePoint(3, 4))); CPPUNIT_ASSERT(!r1->contains(ImagePoint(643, 5))); CPPUNIT_ASSERT(!r1->contains(ImagePoint(642, 4))); CPPUNIT_ASSERT(!r1->contains(ImagePoint(2, 484))); CPPUNIT_ASSERT(!r1->contains(ImagePoint(3, 485))); CPPUNIT_ASSERT(!r1->contains(ImagePoint(643, 484))); CPPUNIT_ASSERT(!r1->contains(ImagePoint(642, 485))); debug(LOG_DEBUG, DEBUG_LOG, 0, "testContainsPoint() end"); }
//设置区域 VOID CLayeredWindow::InitLayeredArea(CDC * pDCImage, BYTE cbAlpha, CRect & rcUnLayered, CPoint & PointRound, bool bUnLayeredChild) { //效验参数 ASSERT((pDCImage!=NULL)&&(pDCImage->m_hDC!=NULL)); if ((pDCImage==NULL)||(pDCImage->m_hDC==NULL)) return; //变量定义 BITMAP Bitmap; ZeroMemory(&Bitmap,sizeof(Bitmap)); //获取图像 CBitmap * pBitmap=pDCImage->GetCurrentBitmap(); if (pBitmap!=NULL) pBitmap->GetBitmap(&Bitmap); //获取大小 CSize SizeImage; SizeImage.SetSize(Bitmap.bmWidth,Bitmap.bmHeight); //效验大小 ASSERT((SizeImage.cx>0)&&(SizeImage.cy>0)); if ((SizeImage.cx==0)||(SizeImage.cy==0)) return; //变量定义 BLENDFUNCTION BlendFunction; ZeroMemory(&BlendFunction,sizeof(BlendFunction)); //设置参数 BlendFunction.BlendOp=0; BlendFunction.BlendFlags=0; BlendFunction.AlphaFormat=AC_SRC_ALPHA; BlendFunction.SourceConstantAlpha=cbAlpha; //设置分层 CPoint ImagePoint(0,0); CClientDC ClientDC(this); UpdateLayeredWindow(&ClientDC,NULL,&SizeImage,pDCImage,&ImagePoint,0L,&BlendFunction,ULW_ALPHA); //创建区域 CRgn RegionResult; RegionResult.CreateRectRgn(0,0,SizeImage.cx,SizeImage.cy); //窗口排除 if (bUnLayeredChild==true) { //变量定义 tagEnumChildInfo EnumChildInfo; ZeroMemory(&EnumChildInfo,sizeof(EnumChildInfo)); //设置变量 EnumChildInfo.pWndLayered=this; EnumChildInfo.pWndControl=m_pWndControl; EnumChildInfo.pRegionResult=&RegionResult; //枚举窗口 ASSERT(m_pWndControl->GetSafeHwnd()!=NULL); EnumChildWindows(m_pWndControl->m_hWnd,EnumChildProc,(LPARAM)&EnumChildInfo); } //区域排除 if (rcUnLayered.IsRectEmpty()==FALSE) { //创建区域 CRgn RegionUnLayered; RegionUnLayered.CreateRoundRectRgn(rcUnLayered.left,rcUnLayered.top,rcUnLayered.right+1,rcUnLayered.bottom+1,PointRound.x,PointRound.y); //合并区域 RegionResult.CombineRgn(&RegionResult,&RegionUnLayered,RGN_DIFF); } //设置区域 SetWindowRgn(RegionResult,TRUE); return; }
//绘画函数 VOID CFlashWnd::Draw(HDC hdcDraw, LPCRECT rcDraw, BOOL bErase) { //效验状态 ASSERT(m_pIControl!=NULL); if (m_pIControl==NULL) return; //获取位置 CRect rcRect; GetClientRect(m_hWnd,&rcRect); //绘画判断 if (rcRect.Width()==0) return; if (rcRect.Height()==0) return; //接口变量 IOleObject * pIOleObject=m_pIOleObject; IViewObject * pIViewObject=(m_pIViewObjectEx!=NULL)?m_pIViewObjectEx:m_pIViewObject; if (m_hdcBack) ::DeleteDC(m_hdcBack); if (m_bmpBack) ::DeleteObject(m_bmpBack); //绘画对象 /*if ((pIOleObject!=NULL)&&(pIViewObject!=NULL)) { //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(rcRect.Width(),rcRect.Height(),32); //绘画对象 CImageDC ImageDC(ImageBuffer); OleDraw(pIViewObject,DVASPECT_TRANSPARENT,ImageDC,&rcRect); }*/ //变量定义 BITMAPINFOHEADER BitmapInfoHeader; ZeroMemory(&BitmapInfoHeader,sizeof(BitmapInfoHeader)); //设置变量 BitmapInfoHeader.biSize=sizeof(BITMAPINFOHEADER); BitmapInfoHeader.biBitCount=32; BitmapInfoHeader.biCompression=BI_RGB; BitmapInfoHeader.biPlanes=1; BitmapInfoHeader.biWidth=rcRect.Width(); BitmapInfoHeader.biHeight=-rcRect.Height(); HDC hdc=::GetDC(m_hWnd); m_hdcBack=CreateCompatibleDC(hdc); m_bmpBack=CreateDIBSection(hdc, (BITMAPINFO *)&BitmapInfoHeader, DIB_RGB_COLORS, (VOID **)&m_lpBitsOnly, NULL, 0x0); SelectObject(m_hdcBack, m_bmpBack); ::ReleaseDC(m_hWnd,hdc); if (m_iBPP==0) m_iBPP=GetDeviceCaps(m_hdcBack,BITSPIXEL); CPoint Point(rcRect.left, rcRect.top); CSize Size(rcRect.Width(),rcRect.Height()); //绘画对象 if ((pIOleObject!=NULL)&&(pIViewObject!=NULL)) { CRect rcTotal; ::GetClientRect(m_hWnd,&rcTotal); if (m_iBPP==32) { ZeroMemory(m_lpBitsOnly,Size.cx*Size.cy*sizeof(DWORD)); OleDraw(pIViewObject,DVASPECT_TRANSPARENT,m_hdcBack,&rcTotal); } else //in 8/16/24 bit screen depth UpdateLayeredWindow produces wrong results - we use underlaying DC to paint to { //HWND hwndParent=::GetParent(hwnd); HWND hwndParent=::GetDesktopWindow(); HDC hdcParent=::GetWindowDC(hwndParent); CRect rcClient; GetClientRect(m_hWnd,rcClient); CPoint pt; pt.x=rcClient.left; pt.y=rcClient.top; ClientToScreen(m_hWnd,&pt); BitBlt(m_hdcBack, 0, 0, rcTotal.right, rcTotal.bottom, hdcParent, pt.x, pt.y, SRCCOPY); ::ReleaseDC(hwndParent, hdcParent); OleDraw(pIViewObject, DVASPECT_TRANSPARENT, m_hdcBack, &rcTotal); } } /* CPoint Point(rcRect.left, rcRect.top); CSize Size(rcRect.Width(),rcRect.Height());*/ //变量定义 BLENDFUNCTION BlendFunction; ZeroMemory(&BlendFunction,sizeof(BlendFunction)); //设置变量 BlendFunction.BlendOp=AC_SRC_OVER; BlendFunction.AlphaFormat=AC_SRC_ALPHA; BlendFunction.SourceConstantAlpha=255; return; //当前帧数 LONG lCurrentFrame=-1; if (m_pIControl!=NULL) { lCurrentFrame=m_pIControl->CurrentFrame(); } //完成判断 if ((m_pIControl!=NULL)&&(((m_lCurrentFrame+1)==m_lTotalFrames)||(m_lCurrentFrame>lCurrentFrame))) { //停止播放 m_pIControl->Stop(); //事件通知 if (m_pIFlashControlSink!=NULL) { m_pIFlashControlSink->OnEventFlashPlayFinish(); } } //设置变量 if (m_bStop) BlendFunction.SourceConstantAlpha=0; m_lCurrentFrame=lCurrentFrame; CPoint ImagePoint(0,0); UpdateLayeredWindow(m_hWnd, NULL, &Point, &Size, m_hdcBack, &ImagePoint, 0, &BlendFunction, m_iBPP==32 ? ULW_ALPHA : ULW_OPAQUE); return; }
void ImageSizeTest::testBounds() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testBounds() begin"); CPPUNIT_ASSERT(i1->bounds(ImagePoint(0, 0))); CPPUNIT_ASSERT(i1->bounds(ImagePoint(6, 0))); CPPUNIT_ASSERT(i1->bounds(ImagePoint(0, 10))); CPPUNIT_ASSERT(i1->bounds(ImagePoint(6, 10))); CPPUNIT_ASSERT(!i1->bounds(ImagePoint(0, -1))); CPPUNIT_ASSERT(!i1->bounds(ImagePoint(6, -1))); CPPUNIT_ASSERT(!i1->bounds(ImagePoint(0, 11))); CPPUNIT_ASSERT(!i1->bounds(ImagePoint(6, 11))); CPPUNIT_ASSERT(!i1->bounds(ImagePoint(-1, 0))); CPPUNIT_ASSERT(!i1->bounds(ImagePoint(-1, 10))); CPPUNIT_ASSERT(!i1->bounds(ImagePoint(7, 0))); CPPUNIT_ASSERT(!i1->bounds(ImagePoint(7, 10))); debug(LOG_DEBUG, DEBUG_LOG, 0, "testBounds() end"); }
ImagePoint MosaicType::greenr() const { ImagePoint r = red(); int bluex = 0x1 ^ r.x(); return ImagePoint(bluex, r.y()); }
ImagePoint ImageSize::lowerright() const { return ImagePoint(_width - 1, 0); }
ImagePoint ImageSize::upperleft() const { return ImagePoint(0, _height - 1); }
ImagePoint MosaicType::greenb() const { ImagePoint r = red(); int bluey = 0x1 ^ r.y(); return ImagePoint(r.x(), bluey); }
ImagePoint ImageSize::upperright() const { return ImagePoint(_width - 1, _height - 1); }
ImagePoint operator/(const ImagePoint& point, const Binning& binning) { return ImagePoint(point.x() / binning.x(), point.y() / binning.y()); }
ImagePoint ImageSize::lowerleft() const { return ImagePoint(0, 0); }
/** * \brief main function for the focus program */ int main(int argc, char *argv[]) { int c; double exposuretime = 0.1; unsigned int cameraid = 0; unsigned int ccdid = 0; int length = 512; std::string cameratype("uvc"); while (EOF != (c = getopt(argc, argv, "de:m:c:C:l:"))) switch (c) { case 'd': debuglevel = LOG_DEBUG; break; case 'm': cameratype = std::string(optarg); break; case 'C': cameraid = atoi(optarg); break; case 'c': ccdid = atoi(optarg); break; case 'e': exposuretime = atof(optarg); break; case 'l': length = atoi(optarg); break; } // get the camera Repository repository; debug(LOG_DEBUG, DEBUG_LOG, 0, "loading module %s", cameratype.c_str()); ModulePtr module = repository.getModule(cameratype); module->open(); // get the camera DeviceLocatorPtr locator = module->getDeviceLocator(); std::vector<std::string> cameras = locator->getDevicelist(); if (0 == cameras.size()) { std::cerr << "no cameras found" << std::endl; return EXIT_FAILURE; } if (cameraid >= cameras.size()) { std::string msg = stringprintf("camera %d out of range", cameraid); debug(LOG_ERR, DEBUG_LOG, 0, "%s\n", msg.c_str()); throw std::range_error(msg); } std::string cameraname = cameras[cameraid]; CameraPtr camera = locator->getCamera(cameraname); debug(LOG_DEBUG, DEBUG_LOG, 0, "camera loaded: %s", cameraname.c_str()); // get the ccd CcdPtr ccd = camera->getCcd(ccdid); debug(LOG_DEBUG, DEBUG_LOG, 0, "get a ccd: %s", ccd->getInfo().toString().c_str()); // get a centerd length x length frame ImageSize framesize(length, length); ImageRectangle frame = ccd->getInfo().centeredRectangle(framesize); Exposure exposure(frame, exposuretime); debug(LOG_DEBUG, DEBUG_LOG, 0, "exposure prepared: %s", exposure.toString().c_str()); // retrieve an image ccd->startExposure(exposure); ImagePtr image = ccd->getImage(); // write image unlink("test.fits"); FITSout out("test.fits"); out.write(image); // apply a mask to keep the border out CircleFunction circle(ImagePoint(length/2, length/2), length/2, 0.8); mask(circle, image); unlink("masked.fits"); FITSout maskout("masked.fits"); maskout.write(image); #if 0 // compute the FOM double fom = focusFOM(image, true, Subgrid(ImagePoint(1, 0), ImageSize(1, 1))); std::cout << "FOM: " << fom << std::endl; #endif return EXIT_SUCCESS; }
ImagePoint ImageSize::center() const { return ImagePoint(_width / 2, _height / 2); }
//绘画函数 VOID CFlashActiveX::DrawControl(HDC hdcDraw, LPCRECT rcDraw, BOOL bErase) { //效验状态 if (m_hWnd==NULL) return; if (m_lTotalFrames==0L) return; if (m_pIFalshControl==NULL) return; //获取位置 CRect rcRect; GetClientRect(m_hWnd,&rcRect); //绘画判断 if (rcRect.Width()==0) return; if (rcRect.Height()==0) return; //接口变量 IOleObject * pIOleObject=m_pIOleObject; IViewObject * pIViewObject=(m_pIViewObjectEx!=NULL)?m_pIViewObjectEx:m_pIViewObject; //绘画对象 if ((pIOleObject!=NULL)&&(pIViewObject!=NULL)) { //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(rcRect.Width(),rcRect.Height(),32); //绘画对象 CImageDC ImageDC(ImageBuffer); OleDraw(pIViewObject,DVASPECT_TRANSPARENT,ImageDC,&rcRect); //变量定义 BLENDFUNCTION BlendFunction; ZeroMemory(&BlendFunction,sizeof(BlendFunction)); //设置变量 BlendFunction.BlendOp=AC_SRC_OVER; BlendFunction.AlphaFormat=AC_SRC_ALPHA; BlendFunction.SourceConstantAlpha=0xFF; //帧数统计 LONG lCurFrame = m_pIFalshControl->CurrentFrame(); if(m_lLastFrames != lCurFrame) { m_lLastFrames = lCurFrame; m_lLastFrameCount = 0L; } else m_lLastFrameCount++; //完成判断 if ((lCurFrame+1L)>=m_lTotalFrames || m_lLastFrameCount>=20) { //停止播放 m_pIFalshControl->StopPlay(); //设置变量 BlendFunction.SourceConstantAlpha=0x00; //事件通知 if (m_pIFlashControlSink!=NULL) { m_pIFlashControlSink->OnEventFlashFinish(); } } //变量定义 CPoint ImagePoint(0,0); CSize SizeImage(ImageBuffer.GetWidth(),ImageBuffer.GetHeight()); //设置窗口 UpdateLayeredWindow(m_hWnd,NULL,NULL,&SizeImage,ImageDC,&ImagePoint,RGB(0,0,0),&BlendFunction,ULW_ALPHA); } return; }