int main()
{
	BinPackingProblem bpp("10.BPP");
	BppSolver solver;
	solver.bestFitUpperBound(bpp);
	system("pause");
	return 0;
}
Exemple #2
0
 string str() const
 {
     stringstream buffer;
     buffer << width << "x" << height << "x" << (int)bpp();
     buffer << " VSync(" << (vsync ? "ON" : "OFF") << ") FSAA(";
     buffer << (int)FSAA << ")\n: Buffers: Depth " << (int)depth_bits;
     buffer << "-bit, Stencil " << (int)stencil_bits << "-bit";
     return (buffer.str());
 }
Exemple #3
0
V BPlusSegment<K,V>::lookup(const K &key) const
{
    BufferFrame& targetPage = *fixLeafFor(key, false);

    BPlusPage<K,V> bpp(targetPage.getData(), pageSize, cmp);
    V value = bpp.lookup(key);
    bm.unfixPage(targetPage, false);

    return value;
}
PImage::PImage(const puint8 *data, puint32 width, puint32 height, 
    PImagePixelFormatEnum pixelFormat)
{
    puint32 b = bpp(pixelFormat);
    puint32 size = width * height * b;
    m_data = PNEWARRAY(puint8, size);
    if (data != P_NULL)
    {
        pmemcpy(m_data, data, size);
    }

    m_width = width;
    m_height = height;
    m_pixelFormat = pixelFormat;
}
PImage::PImage(const PImage& other)
{
    m_width = other.m_width;
    m_height = other.m_height;
    m_pixelFormat = other.m_pixelFormat;
    m_data = P_NULL;

    if (other.m_data != P_NULL)
    {
        puint32 b = bpp(m_pixelFormat);
        puint32 size = m_width * m_height * b;
        m_data = PNEWARRAY(puint8, size);
        pmemcpy(m_data, other.m_data, size);
    }
}
const PImage& PImage::operator=(const PImage& other)
{
    if (this != &other)
    {
        m_width = other.m_width;
        m_height = other.m_height;
        m_pixelFormat = other.m_pixelFormat;
        m_data = P_NULL;

        if (other.m_data != P_NULL)
        {
            puint32 b = bpp(m_pixelFormat);
            puint32 size = m_width * m_height * b;
            m_data = PNEWARRAY(puint8, size);
            pmemcpy(m_data, other.m_data, size);
        }
    }

    return *this;
}
Exemple #7
0
	void Image::copyRect( int x, int y, const Image& img, const Recti & rect )
	{
		checkFormat( img, __PRETTY_FUNCTION__, __LINE__, _mem->_format );
		int tx, ty;

		tx = -x + rect.x;
		ty = -y + rect.y;
		Recti rdst( 0, 0, ( int ) _mem->_width, ( int ) _mem->_height );
		rdst.translate( tx, ty );
		Recti rsrc( 0, 0, ( int ) img._mem->_width, ( int ) img._mem->_height );
		rsrc.intersect( rect );
		rsrc.intersect( rdst );
		if( rsrc.isEmpty() )
			return;
		rdst.copy( rsrc );
		rdst.translate( -tx, -ty );

		SIMD* simd = SIMD::instance();
		size_t dstride;
		uint8_t* dst = map( &dstride );
		uint8_t* dbase = dst;
		dst += rdst.y * dstride + bpp() * rdst.x;

		size_t sstride;
		const uint8_t* src = img.map( &sstride );
		const uint8_t* sbase = src;
		src += rsrc.y * sstride + rsrc.x * img.bpp();

		size_t n = rsrc.width * img.bpp();
		size_t i = rsrc.height;

		while( i-- ) {
			simd->Memcpy( dst, src, n );
			src += sstride;
			dst += dstride;
		}
		img.unmap( sbase );
		unmap( dbase );
	}
Exemple #8
0
void BPlusSegment<K,V>::insert(const K &key, const V &value)
{
    //TODO: (optional) locate without X lock
    //locate page
    try{
        BufferFrame& targetPage = *fixLeafFor(key, true);

        BPlusPage<K,V> bpp(targetPage.getData(), pageSize, cmp);

        //check if insert possible
        if (bpp.hasAdditionalSpace()){
            bpp.insert(key, value);
            bm.unfixPage(targetPage, true);
            return;
        }
        bm.unfixPage(targetPage, false);

    }catch(NotFoundException e){
        //couldn't locate page because all keys are bigger than given key and upper
        //doesn't exist, thus we continue with insertion case
    }

    insertAndSplit(key, value);
}
void grab_cb(const ImgBase *img) {

	BENCHMARK_THIS_FUNCTION;

	int roi_percent = gui["roi_size"].as<int>();

	canny.setThresholds(gui["canny_low_th"].as<int>(),gui["canny_high_th"].as<int>());

	Img<T> color_original = *img->asImg<T>();

	Size size = color_original.getSize();

	size.width = std::floor(size.width*((float)roi_percent/100.0));
	size.height = std::floor(size.height*((float)roi_percent)/100.0);

	size.width = size.width%2+size.width;
	size.height = size.height%2+size.height;

	Point offset(color_original.getWidth()/2.0-size.width/2.0,color_original.getHeight()/2.0-size.height/2.0);

	color_original.setROI(offset,size);

	Img<T> color_median(color_original.getParams());
	MedianOp median(utils::Size(gui["median_radius"].as<int>(),gui["median_radius"].as<int>()));

	bool use_gray = gui["to_gray"].as<bool>();
	Img<T> gray_image(color_original.getSize(),core::formatGray);
	//color_original.setFormat(core::formatRGB);
	Img8u edge_;
	if (use_gray) {
		core::cc(&color_original,&gray_image);
		canny.apply(&gray_image,bpp(edge_));
	} else {
		canny.apply(&color_original,bpp(edge_));
	}

	{
		BENCHMARK_THIS_SECTION(median_call);
		if (use_gray)
			median.apply(&gray_image,bpp(color_median));
		else
			median.apply(&color_original,bpp(color_median));

	}
	Img8u edge_median;//(color_median.getSize(),core::formatGray);
	canny.apply(&color_median,bpp(edge_median));

	bi_filter->setRadius(gui["bi_radius"].as<int>());
	bi_filter->setSigmaR(gui["sigma_r"].as<float>());
	bi_filter->setSigmaS(gui["sigma_s"].as<float>());
	bi_filter->setUseLAB(gui["use_lab"].as<bool>());
	Img<T> color_bilateral(color_median.getParams());
	{
		BENCHMARK_THIS_SECTION(bilateral_filter_call);
		if (use_gray)
			bi_filter->apply(&color_median,bpp(color_bilateral));
		else
			bi_filter->apply(&color_median,bpp(color_bilateral));
	}

	Img8u edge_bi_filtered;//(edge_bi_filtered.getSize(),core::formatGray);
	canny.apply(&color_bilateral,bpp(edge_bi_filtered));

	// set images
	if (use_gray)
		gui["view1"] = &gray_image;
	else
		gui["view1"] = &color_original;
	gui["view2"] = &color_median;
	gui["view3"] = &color_bilateral;

	gui["viewedge1"] = &edge_;
	gui["viewedge2"] = &edge_median;
	gui["viewedge3"] = &edge_bi_filtered;

	// update view:
	gui["view1"].render();
	gui["view2"].render();
	gui["view3"].render();

	gui["viewedge1"].render();
	gui["viewedge2"].render();
	gui["viewedge3"].render();

}
bool ImageLoader::
load(const std::string& imageName, bool isNormalMap)
{
	// 载入图片
	FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(imageName.c_str());
	if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif))
	{
		if (mDIB)
			FreeImage_Unload(mDIB);
		mDIB = FreeImage_Load(fif, imageName.c_str());
		mFormat = fif;

		bool needScale = !oiram::fequal(config.imageScale, 1.0f);
		unsigned int newWidth = width(), newHeight = height(), newBpp = bpp();
		bool imagePowerOfTwo = config.imagePowerOfTwo;
		unsigned int imageMaxSize = config.imageMaxSize;

		// PVRTCII支持non-POT; ETC1和ETC2必须是POT, 最大尺寸限定在2048, 而且必须是正方形
		if (config.imageCompressionType == CT_ETC1 ||
			config.imageCompressionType == CT_ETC2)
		{
			imagePowerOfTwo = true;
			imageMaxSize = 2048;
		}

		// DXTC/PVRTC/ETCI有最小尺寸限制
		switch (config.imageCompressionType)
		{
		case CT_DXTC:
			if (newWidth < DXT_MIN_TEXWIDTH)
			{
				newWidth = DXT_MIN_TEXWIDTH;
				needScale = true;
			}
			if (newHeight < DXT_MIN_TEXHEIGHT)
			{
				newHeight = DXT_MIN_TEXHEIGHT;
				needScale = true;
			}
			// DXTC的尺寸必须是4的倍数
			{
				unsigned int	multiplesOfFourWidth = nearestMultiplesOfFour(newWidth),
								multiplesOfFourHeight = nearestMultiplesOfFour(newHeight);
				if (newWidth != multiplesOfFourWidth)
				{
					newWidth = multiplesOfFourWidth;
					needScale = true;
				}
				if (newHeight != multiplesOfFourHeight)
				{
					newHeight = multiplesOfFourHeight;
					needScale = true;
				}
			}
			break;

		case CT_ETC1:
		case CT_ETC2:
			if (newWidth < ETC_MIN_TEXWIDTH)
			{
				newWidth = ETC_MIN_TEXWIDTH;
				needScale = true;
			}
			if (newHeight < ETC_MIN_TEXHEIGHT)
			{
				newHeight = ETC_MIN_TEXHEIGHT;
				needScale = true;
			}
			break;

		case CT_PVRTC2_4BPP:
			if (newWidth < PVRTC4_MIN_TEXWIDTH)
			{
				newWidth = PVRTC4_MIN_TEXWIDTH;
				needScale = true;
			}
			if (newHeight < PVRTC4_MIN_TEXHEIGHT)
			{
				newHeight = PVRTC4_MIN_TEXHEIGHT;
				needScale = true;
			}
			break;
		}

		// 超出最大尺寸则按比例缩放
		if (imageMaxSize > 0 &&
			(newWidth > imageMaxSize || newHeight > imageMaxSize))
		{
			if (newWidth > newHeight)
			{
				float scale = static_cast<float>(newWidth) / newHeight;
				newWidth = imageMaxSize;
				newHeight = static_cast<unsigned int>(newWidth / scale);
			}
			else
			{
				float scale = static_cast<float>(newHeight) / newWidth;
				newHeight = imageMaxSize;
				newWidth = static_cast<unsigned int>(newHeight / scale);
			}
			needScale = true;
		}

		newWidth = static_cast<unsigned int>(newWidth * config.imageScale);
		newHeight = static_cast<unsigned int>(newHeight * config.imageScale);

		if (imagePowerOfTwo)
		{
			unsigned int potWidth = nearestPowerOfTwo(newWidth), potHeight = nearestPowerOfTwo(newHeight);
			if (newWidth != potWidth || newHeight != potHeight)
			{
				newWidth = potWidth;
				newHeight = potHeight;
				needScale = true;
			}
		}

		if (needScale)
		{
			FIBITMAP* rescaleDIB = FreeImage_Rescale(mDIB, newWidth, newHeight, FILTER_LANCZOS3);
			FreeImage_Unload(mDIB);
			mDIB = rescaleDIB;
		}

		return true;
	}

	return false;
}
Exemple #11
0
void BPlusSegment<K,V>::erase(const K &key) {
    BufferFrame& targetFrame = *fixLeafFor(key, true);
    BPlusPage<K,V> bpp(targetFrame.getData(), pageSize, cmp);
    bool removed = bpp.remove(key);
    bm.unfixPage(targetFrame, removed);
}
void ObjectEdgeDetectorCPU::applyMedianFilter() {
	m_data->medianFilter->adaptSize(Size(m_data->params.medianFilterSize,m_data->params.medianFilterSize));
	m_data->medianFilter->apply(&m_data->rawImage, bpp(m_data->filteredImage));
}