void	ImageBaseTest::testAccessors() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testAccessors() begin");
	CPPUNIT_ASSERT(i1->size() == ImageSize(640,480));
	CPPUNIT_ASSERT(i2->size() == ImageSize(640,480));
	CPPUNIT_ASSERT(i3->size() == ImageSize(1024,768));
	CPPUNIT_ASSERT(i4->size() == ImageSize(1024,768));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testAccessors() end");
}
kpCommandSize::SizeType kpTransformAutoCropCommand::size () const
{
    return d->leftBorder.size () +
           d->rightBorder.size () +
           d->topBorder.size () +
           d->botBorder.size () +
           ImageSize (d->leftImage) +
           ImageSize (d->rightImage) +
           ImageSize (d->topImage) +
           ImageSize (d->botImage) +
           SelectionSize (d->oldSelectionPtr);
}
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");
}
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");
}
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");
}
Residual	Analyzer::translation(const ConstImageAdapter<double>&image,
	const ImagePoint& where, int _patchsize) const {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "get translation at %s",
		std::string(where).c_str());
	// create the subwindow we want to lock at
	int	xoffset = where.x() - _patchsize / 2;
	int	yoffset = where.y() - _patchsize / 2;
	ImagePoint	patchcorner(xoffset, yoffset);
	ImageRectangle	window(patchcorner,
			ImageSize(patchsize, _patchsize));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "window: %s",
		window.toString().c_str());

	// we need a phase correlator to measure the transform
	transform::PhaseCorrelator	pc(false);

	// compute the translation between the windows
	WindowAdapter<double>	frompatch(image, window);
	WindowAdapter<double>	topatch(baseimage, window);
	std::pair<Point, double>	delta
		= pc(frompatch, topatch);
	Point	translation = delta.first;
	double	weight = delta.second;
	debug(LOG_DEBUG, DEBUG_LOG, 0, "%s -> %s",
		where.toString().c_str(),
		translation.toString().c_str());

	// add the residual to the result set
	Residual	residual(where, translation, weight);
	return residual;
}
// Hack for AutoSizeRowEx()...
CSize CGridCellMultiLine::GetCellExtentEx(int width, CDC*pDC)
{
	CSize ImageSize(0,0);
	
	int nImage = GetImage();
	if (nImage >= 0) 
	{
		CGridCtrl* pGrid = GetGrid();
		ASSERT(pGrid);
		
		if (pGrid->GetImageList()) 
		{
			IMAGEINFO Info;
			if (pGrid->GetImageList()->GetImageInfo(nImage, &Info))
				ImageSize = CSize(Info.rcImage.right-Info.rcImage.left+1, 
				Info.rcImage.bottom-Info.rcImage.top+1);
		}
	}
	
	
	CSize size = GetTextExtentEx(width - ImageSize.cx, GetText(), pDC);

	CSize retSize(size.cx + ImageSize.cx, max(size.cy, ImageSize.cy));

	return retSize;
}
Mock1Camera::Mock1Camera(int _id) : astro::camera::Camera(cameraname(_id)), id(_id) {

	CcdInfo	ccd0(DeviceName(name(), DeviceName::Ccd, "primary ccd"),
		ImageSize(1024, 768), 0);
	ccd0.addMode(Binning(1,1));
	ccd0.pixelwidth(0.00001);
	ccd0.pixelheight(0.00001);
	ccdinfo.push_back(ccd0);

	CcdInfo	ccd1(DeviceName(name(), DeviceName::Ccd, "secondary ccd"),
		ImageSize(640, 480), 1);
	ccd1.addMode(Binning(1,1));
	ccd1.pixelwidth(0.00001);
	ccd1.pixelheight(0.00001);
	ccdinfo.push_back(ccd1);

	debug(LOG_DEBUG, DEBUG_LOG, 0, "mock1 has %d ccds", this->nCcds());
}
/**
 * \brief Create a work object
 *
 * The constructor sets up the devices used for task execution. This should
 * not take any noticable time, in particular this can be done synchronously.
 */
ExposureWork::ExposureWork(TaskQueueEntry& task) : _task(task) {
	// create a repository, we are always using the default
	// repository
	astro::module::Repository	repository;
	
	// get camera and ccd
	debug(LOG_DEBUG, DEBUG_LOG, 0, "get camera '%s' and ccd %s",
		_task.camera().c_str(), _task.ccd().c_str());
	{
		astro::device::DeviceAccessor<astro::camera::CameraPtr>
			dc(repository);
		camera = dc.get(_task.camera());
	}
	{
		astro::device::DeviceAccessor<astro::camera::CcdPtr>
			dc(repository);
		ccd = camera->getCcd(_task.ccd());
	}

	// turn on the cooler
	debug(LOG_DEBUG, DEBUG_LOG, 0, "get cooler '%s', temperature %.2f ",
		_task.cooler().c_str(), _task.ccdtemperature());
	if ((_task.cooler().size() > 0) && (_task.ccdtemperature() > 0)) {
		astro::device::DeviceAccessor<astro::camera::CoolerPtr>
			df(repository);
		cooler = df.get(_task.cooler());
	}

	// get the filterwheel
	debug(LOG_DEBUG, DEBUG_LOG, 0, "get filter '%s' of wheel '%s'",
		_task.filter().c_str(), _task.filterwheel().c_str());
	if (_task.filterwheel().size() > 0) {
		astro::device::DeviceAccessor<astro::camera::FilterWheelPtr>
			df(repository);
		filterwheel = df.get(_task.filterwheel());
	}

	// get the mount
	debug(LOG_DEBUG, DEBUG_LOG, 0, "get mount %s", _task.mount().c_str());
	if (_task.mount().size() > 0) {
		astro::device::DeviceAccessor<astro::device::MountPtr>
			df(repository);
		mount = df.get(_task.mount());
	}

	// if the task does not have a frame size, then take the one from the
	// the CCD
	if (_task.size() == ImageSize()) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "using the full chip");
		_task.frame(ccd->getInfo().getFrame());
	}

	// that's it, the task is constructed
	debug(LOG_DEBUG, DEBUG_LOG, 0, "ExposureWork created");
}
/**
 * \brief Simulator camera construction
 *
 * The simulator camera supports two binning modes and has a shutter
 */
SimCamera::SimCamera(SimLocator& locator)
	: Camera("camera:simulator/camera"), _locator(locator) {
	DeviceName	ccdname = CcdInfo::defaultname(name(), "ccd");
	CcdInfo	ccdi(ccdname, ImageSize(640, 480), 0);
	ccdi.addMode(Binning(1,1));
	ccdi.addMode(Binning(2,2));
	ccdi.shutter(true);
	ccdi.pixelwidth(0.00001);
	ccdi.pixelheight(0.00001);
	ccdinfo.push_back(ccdi);
}
Exemple #11
0
 virtual std::ostream& Print (std::ostream& os) const {
     Operator<T>::Print(os);
     os << "    image size: rank(" << Rank() << ") side(" <<
        ImageSize() << ") nodes(" << KSpaceSize() << ")" << std::endl;
     os << "    nfft: maxit(" << Maxit() << ") eps(" << Epsilon() <<	") alpha("
        << Alpha() << ") m("<< m_m <<") sigma(" << Sigma() << ")" << std::endl;
     os << "    have_kspace(" << m_have_kspace << ") have_weights(" <<
        m_have_weights << ") have_b0(" << m_have_b0 << ")" << std::endl;
     os << "    ft-threads(" << m_np << ")";
     if (m_3rd_dim_cart)
         os << " 3rd dimension (" << m_ncart << ") is Cartesian.";
     return os;
 }
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;
}
Exemple #13
0
size_t ImageDecoder::frameBytesAtIndex(size_t index) const {
  if (index >= m_frameBufferCache.size() ||
      m_frameBufferCache[index].getStatus() == ImageFrame::FrameEmpty)
    return 0;

  struct ImageSize {
    explicit ImageSize(IntSize size) {
      area = static_cast<uint64_t>(size.width()) * size.height();
    }

    uint64_t area;
  };

  return ImageSize(frameSizeAtIndex(index)).area *
         sizeof(ImageFrame::PixelData);
}
FSlateTextureDataPtr FTileThumbnail::ToSlateTextureData(const FObjectThumbnail* ObjectThumbnail) const
{
	FSlateTextureDataPtr Result;
	
	if (ObjectThumbnail)
	{
		FIntPoint ImageSize(ObjectThumbnail->GetImageWidth(), ObjectThumbnail->GetImageHeight());
		FIntPoint TargetSize = ThumbnailRenderTarget->GetSizeXY();
		if (TargetSize == ImageSize)
		{
			const TArray<uint8>& ImageData = ObjectThumbnail->GetUncompressedImageData();
			if (ImageData.Num())
			{
				Result = MakeShareable(new FSlateTextureData(ImageData.GetData(), ImageSize.X, ImageSize.Y, 4));
			}
		}
	}

	return Result;
}
SimCamera::SimCamera() : Camera(cameraname("guidesim")) {
	DeviceName	ccdname(name(), DeviceName::Ccd, "primary ccd");
	CcdInfo	ccd0(ccdname, ImageSize(640, 480));
	ccd0.addMode(Binning(1, 1));
	ccdinfo.push_back(ccd0);

	// initial star position
	x = 320;
	y = 240;

	// movement definition
	vx = 0.1;
	vy = 0.2;
	delta = 10;
	ra.clear();
	dec.clear();
	ra.alpha = 1;
	dec.alpha = ra.alpha + M_PI / 2;

	// neither movement nor exposures are active
	exposurestart = -1;
	lastexposure = Timer::gettime();
}
Bitmap * ImageItem::LoadImageFromFile(ATL::CString& strFilename, int nWidth, int nHeight)
{
	if ( !m_strFilename.CompareNoCase(strFilename) && nHeight==m_nHeight )
	{
		m_nRef++;
		return m_pBitmap;
	}
	else if ( m_pBitmap==NULL && m_nRef==0)
	{
		Size ImageSize(nWidth, nHeight);
		if (GetBitmapFromFile(m_pBitmap, strFilename, m_nFrameCount, m_FrameSize, ImageSize, m_pFrameDelays ))
		{
			m_nHeight = nHeight;
			m_nRef++;
			m_strFilename=strFilename;
			return m_pBitmap;
		}
		return NULL;

	}
	//NOT REACHABLE
	DebugBreak();
	return NULL;
}
Exemple #17
0
void PopRect(int *err)
{
	*err = 1;
	if (savetail)
	{
		savelist *prev = savetail->prev;

		if (savetail->im)
		{
			WriteImage(savetail->R, savetail->im);
			if (putz)
				heapwalker();
			farfree(savetail->im);
			savetail->im = NULL;
			if (putz)
				heapwalker();

			*err = 0;
		}
		else
		{
			if (savetail->filename)
			{
				rect R = *(savetail->R);
				rect R1 = R;

				FILE *fd = fopen(savetail->filename, "rb");
				long savesize;
				image *tmp;
				int i;

				if (fd)
				{
					R1.Ymax = R1.Ymin;
					R1.Ymax = R1.Ymin + savetail->lines - 1;
					savesize = ImageSize(&R1);
					safe_alloc = 1;
					if ((tmp = farmalloc(savesize)) == NULL)
					{
#ifdef AXTDEBUG
						printf("\nNot enough memory to do pop!!");
#endif
						ErrorBox("Not enough memory to restore screen.");
					}
					else
						//setvbuf(fd, (char *) tmp, _IOFBF, (size_t) savesize);
					for (i = R.Ymin; i <= R.Ymax; i += savetail->lines)
					{
						R1.Ymax = min(R1.Ymax, R.Ymax);
						fread(tmp, 1, (int) ImageSize(&R1), fd);
						WriteImage(&R1, tmp);
						OffsetRect(&R1, 0, savetail->lines);
					}
					fclose(fd);
					if (tmp)
						farfree(tmp);
					*err = 0;
				}
				remove(savetail->filename);
				free(savetail->filename);
				savetail->filename = NULL;

			}
		}
		farfree(savetail->R);
		savetail->R = NULL;
		farfree(savetail);
		savetail = NULL;
		savetail = prev;
	}
}
Exemple #18
0
// public virtual [base kpCommand]
kpCommandSize::SizeType kpToolFlowCommand::size () const
{
    return ImageSize (d->image);
}
void	ImageRectangleTest::testConstructor() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testEquality() begin");
	CPPUNIT_ASSERT(*r3 == ImageRectangle(ImageSize(640, 480)));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testEquality() end");
}
// public virtual [base kpCommand]
kpCommandSize::SizeType kpEffectClearCommand::size () const
{
    return ImageSize (m_oldImagePtr);
}
ImageSize       operator/(const ImageSize& size, const Binning& binning) {
    return ImageSize(size.width() / binning.x(),
                     size.height() / binning.y());
}
ImageSize	ImageSize::operator*(const double l) const {
	unsigned int	x = _width * l;
	unsigned int	y = _height * l;
	return ImageSize(x, y);
}
// public virtual [base kpCommand]
kpCommandSize::SizeType kpToolRectangularCommand::size () const
{
    return ImageSize (d->oldImage);
}
/**
 * \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;
}
Exemple #25
0
// (Re)Open the Script File
int/*error*/ VapourSynther::Import(const wchar_t* wszScriptName)
{
    char szScriptName[MAX_PATH*2];
    WideCharToMultiByte(CP_UTF8, 0, wszScriptName, -1, szScriptName, sizeof(szScriptName), NULL, NULL); 
    if(*szScriptName)
    {

		std::string script = get_file_contents(szScriptName);
		if (script.empty())
			goto vpyerror;

		if (!vseval_evaluateScript(&se, script.c_str(), szScriptName)) {
			
			node = vseval_getOutput(se, 0);
			if (!node)
				goto vpyerror;
			vi = vsapi->getVideoInfo(node);

            if (vi->width == 0 || vi->height == 0 || vi->format == NULL || vi->numFrames == 0) {
                setError("Cannot open clips with varying dimensions or format in VSFS");
                return ERROR_ACCESS_DENIED;
            }

            int id = vi->format->id;
            if (id != pfCompatBGR32
                && id != pfCompatYUY2
                && id != pfYUV420P8
                && id != pfGray8
                && id != pfYUV444P8
                && id != pfYUV422P8
                && id != pfYUV411P8
                && id != pfYUV410P8
                && id != pfYUV420P10
                && id != pfYUV420P16
                && id != pfYUV422P10
                && id != pfYUV422P16) {
                    std::string error_msg = "VSFS module doesn't support ";
                    error_msg += vi->format->name;
                    error_msg += " output";
                    setError(error_msg.c_str());
                    return ERROR_ACCESS_DENIED;
            }

			// set the special options hidden in global variables
			int error;
			int64_t val;
			VSMap *options = vsapi->createMap();
			vseval_getVariable(se, "enable_v210", options);
			val = vsapi->propGetInt(options, "enable_v210", 0, &error);
			if (!error)
				enable_v210 = !!val;
			else
				enable_v210 = false;
			vseval_getVariable(se, "pad_scanlines", options);
			val = vsapi->propGetInt(options, "pad_scanlines", 0, &error);
			if (!error)
				pad_scanlines = !!val;
			else
				pad_scanlines = false;
			vsapi->freeMap(options);

			const VSCoreInfo *info = vsapi->getCoreInfo(vseval_getCore(se));
			num_threads = info->numThreads;

            if (vi->format->id == pfYUV422P10 && enable_v210) {
                packedPlane1 = new uint16_t[ImageSize()];
            } else if (vi->format->id == pfYUV420P16 || vi->format->id == pfYUV422P16) {
                packedPlane2 = new uint16_t[vi->format->subSamplingH == 1 ? (vi->width*vi->height)/2 : vi->width*vi->height];
            } else if (vi->format->id == pfYUV420P10 || vi->format->id == pfYUV422P10) {
                packedPlane1 = new uint16_t[vi->width*vi->height];
                packedPlane2 = new uint16_t[vi->format->subSamplingH == 1 ? (vi->width*vi->height)/2 : vi->width*vi->height];
            }

            return 0;
        } else {
			vpyerror:
            setError(vseval_getError(se));
			return ERROR_ACCESS_DENIED;
        }
    } 
    return ERROR_ACCESS_DENIED;
}
Exemple #26
0
void PushRect(rect * R, int *err)
{
	/* We don't really use ERR, but its for compatibility */
	savelist *lastsave = savetail;
	long savesize = ImageSize(R);

	/* And we don't give a shit about size. */

	savetail = farcalloc(sizeof(savelist), 1L);
	savetail->prev = lastsave;
	savetail->im = NULL;
	if (memok(savesize))
	{
		safe_alloc = 1;
		savetail->im = (image far *) farcalloc(savesize, 1L);
	}
	savetail->R = farmalloc(sizeof(rect));
	*(savetail->R) = *R;

	if (!savetail->im)
	{
		char tbuf[128];
		char tbuf2[128];
		FILE *fd;
		image *tmp;
		char *pathname = getenv("TMP");
		unsigned char drive;
		struct dfree dtable;
		long dfree;

#ifdef AXTDEBUG
		printf("\nLook out, I'm pushing to disk.");
#endif

		/* Find out if there is enough space left on the thing */
      if (pathname && access(pathname,0))
         pathname = NULL;
		if (pathname && pathname[1] == ':')
			drive = toupper(pathname[0]) - 'A' + 1;
		else
			drive = 0;

		getdfree(drive, &dtable);

		if (dtable.df_sclus == 0xffff && drive)
		{
			drive = 0;
			getdfree(drive, &dtable);
			pathname = NULL;
			/* and so this doesn't happen again */
			putenv("TMP=");
		}

		dfree = (long) dtable.df_avail
		 * (long) dtable.df_bsec * (long) dtable.df_sclus;

		if (dfree > savesize)
		{
			rect R1;

			sprintf(tbuf, "%lx.dat", savetail);
			TempFileName(tbuf2, tbuf);
			fd = fopen(tbuf2, "wb");

			if (fd)
			{
				int i;
				unsigned long cl = farcoreleft();
				int lines;
				long n;

				if (cl > 2048L)
					cl -= 2048L;	/* Safety margin */

				R1 = *R;
				R1.Ymax = R1.Ymin;

				i = 1;
				while (i < R->Ymax)
				{
					R1.Ymax = R1.Ymin + i;
					n = ImageSize(&R1);
					if (n < cl)
					{
						savesize = n;
						lines = i;
					}
					i *= 2;
				}




				/*
				 * Let's see how many rows at a time we can
				 * save
				 */
				savetail->lines = lines;
				savetail->blocks = (R->Ymax - R->Ymin + 1) / lines;

				tmp = farmalloc(savesize);
				//setvbuf(fd, (char *) tmp, _IOFBF, (size_t) savesize);
				R1 = *R;
				R1.Ymax = R1.Ymin + lines - 1;
				for (i = R->Ymin; i <= R->Ymax; i += lines)
				{
					R1.Ymax = min(R1.Ymax, R->Ymax);
					ReadImage(&R1, tmp);
					fwrite(tmp, 1, (int) ImageSize(&R1), fd);
					OffsetRect(&R1, 0, lines);
				}
				fclose(fd);
				farfree(tmp);
				tmp = NULL;
				savetail->filename = strdup(tbuf2);
				*err = 0;
				return;
			}
		}

		sprintf(tbuf, "Can't allocate %ld bytes", savesize);
		ErrorBox(tbuf);
		*err = 1;
		farfree(savetail->R);
		savetail->R = NULL;
		farfree(savetail);
		savetail = NULL;
		savetail = lastsave;
	}
	else
	{
		ReadImage(savetail->R, savetail->im);
		*err = 0;
	}
}
void	ImageBaseTest::setUp() {
	i1 = new ImageBase(ImageSize(640,480));
	i2 = new ImageBase(ImageSize(640,480));
	i3 = new ImageBase(ImageSize(1024,768));
	i4 = new ImageBase(ImageSize(1024,768));
}