当前位置: 首页>>代码示例>>C++>>正文


C++ ImageBuf::clear方法代码示例

本文整理汇总了C++中ImageBuf::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageBuf::clear方法的具体用法?C++ ImageBuf::clear怎么用?C++ ImageBuf::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageBuf的用法示例。


在下文中一共展示了ImageBuf::clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: IBAprep

bool 
ImageBufAlgo::crop (ImageBuf &dst, const ImageBuf &src,
                    ROI roi, int nthreads)
{
    dst.clear ();
    roi.chend = std::min (roi.chend, src.nchannels());
    IBAprep (roi, &dst, &src);
    OIIO_DISPATCH_TYPES2 ("crop", crop_, dst.spec().format, src.spec().format,
                          dst, src, roi, nthreads);
    return false;
}
开发者ID:jcrogel,项目名称:oiio,代码行数:11,代码来源:imagebufalgo_copy.cpp

示例2: tileSpec


//.........这里部分代码省略.........

    // Loop vars
    unsigned int currentTile;

    // Comparison vars
    bool match;
    unsigned int i;
    string hash;
    vector<string> hashTable;
    TileBufListEntry *listEntry;
    deque<TileBufListEntry *> tileList;

    if( verbose ){
        cout << "\tSource: " << sourceSpec.width << "x" << sourceSpec.height << endl;
        cout << "\ttileRes: " << tileSpec.width << "x" << tileSpec.height << endl;
        cout << "\ttilemap: " << mapSpec.width << "x" << mapSpec.height << endl;
        cout << "\tmaxTiles: " << mapSpec.image_pixels() << endl;
        cout << "  Processing tiles:\n";
    }

    for( ImageBuf::Iterator<unsigned int, unsigned int> it(mapBuf); ! it.done(); ++it ){
        currentTile = it.y() * mapSpec.width + it.x();

        // define the cropping region.
        roi.xbegin = it.x() * tileSpec.width;
        roi.xend = it.x() * tileSpec.width + tileSpec.width;
        roi.ybegin = it.y() * tileSpec.height;
        roi.yend = it.y() * tileSpec.height + tileSpec.height;

        // crop out tile.
        ImageBufAlgo::cut( tileBuf, *sourceBuf, roi );

#ifdef DEBUG_IMG
        tileBuf.save("SMTool::imageToSMT_tileBuf_" + to_string( currentTile + 1 ) + ".tif", "tif");
#endif //DEBUG_IMG

        // reset match variables
        match = false;
        i = smt->getNTiles();

        // Optimisation
        if( cnum == 0){
            // only exact matches will be referenced.
            hash = ImageBufAlgo::computePixelHashSHA1( tileBuf );
            for( i = 0; i < hashTable.size(); ++i ){
                if(! hashTable[ i ].compare( hash ) ){
                    match = true;
                    break;
                } 
            }
            if(! match ) hashTable.push_back( hash );
        }
        else {
            //Comparison based on numerical differences of pixels
            listEntry = new TileBufListEntry;
            listEntry->image.copy( tileBuf );
            listEntry->tileNum = smt->getNTiles();

            ImageBufAlgo::CompareResults result;

            for( auto it = tileList.begin(); it != tileList.end(); it++ ){
                TileBufListEntry *listEntry2 = *it;
                ImageBufAlgo::compare( tileBuf, listEntry2->image,
                        cpet, 1.0f, result);
                // TODO give control on tweaking matching
                if( (int)result.nfail < cnet ){
                    match = true;
                    i = listEntry2->tileNum;
                    delete listEntry;
                    break;
                }
            }
            if(! match ){
                tileList.push_back( listEntry );
                if( (int)tileList.size() > cnum ){
                    delete tileList[ 0 ];
                    tileList.pop_front();
                }
            }
        }

        // write tile to file.
        if(! match ) {
            smt->append( &tileBuf );
        }

        tileBuf.clear();

        // Write index to tilemap
        it[0] = currentTile;

        // progress report
        cout << "\033[1A\033[2K\033[0G\t" << currentTile+1 << " of " << mapSpec.image_pixels() << ", %" << ((float)currentTile + 1) / mapSpec.image_pixels() * 100 << " complete." << endl;
    }
    hashTable.clear();
    if( verbose ) cout << endl;

    // Save tileindex
    mapBuf.save( "tilemap.exr", "exr" );
}
开发者ID:abma,项目名称:MapConv,代码行数:101,代码来源:smtool.cpp

示例3: smt

bool
SMT::save()
{
	// Make sure we have some source images before continuing
	if( sourceFiles.size() == 0) {
		if( !quiet )cout << "ERROR: No source images to convert" << endl;
		return true;
	}

	// Build SMT Header //
	//////////////////////
	char filename[256];
	sprintf(filename, "%s.smt", outPrefix.c_str());

	if( verbose ) printf("\nINFO: Creating %s\n", filename );
	fstream smt( filename, ios::binary | ios::out );
	if( !smt.good() ) {
		cout << "ERROR: fstream error." << endl;
		return true;
	}

	SMTHeader header;
	header.tileRes = tileRes;
	header.tileType = tileType;
	if( verbose ) {
		cout << "    Version: " << header.version << endl;
		cout << "    nTiles: n/a\n";
		printf( "    tileRes: (%i,%i)%i.\n", tileRes, tileRes, 4);
		cout << "    tileType: ";
		if( tileType == DXT1 ) cout << "DXT1" << endl;
		cout << "    tileSize: " << tileSize << " bytes" << endl;
	}

	smt.write( (char *)&header, sizeof(SMTHeader) );
	smt.close();

	// setup size for index dimensions
	int tcx = width * 16; // tile count x
	int tcz = length * 16; // tile count z
	unsigned int *indexPixels = new unsigned int[tcx * tcz];

	// Load source image
	if( verbose )cout << "INFO: Loading Source Image(s)\n";
	ImageBuf *bigBuf = buildBig();
	ImageSpec bigSpec = bigBuf->spec();

	// Process decals
	if( !decalFile.empty() ) {
		if( verbose )cout << "INFO: Processing decals\n";
		pasteDecals( bigBuf );
	}

	// Swizzle channels
	if( verbose )cout << "INFO: Swizzling channels\n";
	ImageBuf fixBuf;
	int map[] = { 2, 1, 0, 3 };
	ImageBufAlgo::channels( fixBuf, *bigBuf, 4, map );
	bigBuf->copy( fixBuf );
	fixBuf.clear();

	// Process Tiles
	if( verbose )cout << "INFO: Processing tiles\n";

	// Time reporting vars
	timeval t1, t2;
    double elapsedTime;
	deque<double> readings;
	double averageTime = 0;
	double intervalTime = 0;

	// Loop vars
	int totalTiles = tcx * tcz;
	int currentTile;

	// Tile Vars
	ROI roi;
	ImageSpec tileSpec(tileRes, tileRes, 4, TypeDesc::UINT8 );

	// Comparison vars
	bool match;
	bool yee = false;
	unsigned int i;
	string hash;
	vector<string> hashTable;
	TileBufListEntry *listEntry;
	deque<TileBufListEntry *> tileList;

	// Open smt file for writing tiles
	smt.open(filename, ios::binary | ios::out | ios::app );

	// loop through tile columns
	for ( int z = 0; z < tcz; z++) {
		// loop through tile rows
		for ( int x = 0; x < tcx; x++) {
			currentTile = z * tcx + x + 1;
    		gettimeofday(&t1, NULL);

			// pull a region of the big image to use as a tile.
			roi.xbegin = x * tileRes;
			roi.xend = x * tileRes + tileRes;
//.........这里部分代码省略.........
开发者ID:pajohns,项目名称:MapConv,代码行数:101,代码来源:smt.cpp

示例4: roi

bool
SMF::saveGrass()
{
	if( verbose )cout << "INFO: saveGrass\n";

	SMFEHGrass *grassHeader = NULL;
	for( unsigned int i = 0; i < extraHeaders.size(); ++i ) {
		if( extraHeaders[ i ]->type == 1 )
			grassHeader = reinterpret_cast<SMFEHGrass *>( extraHeaders[ i ] );
	}
	if( !grassHeader )return true;

	ImageBuf *imageBuf = NULL;
	ROI roi(	0, width * 16,
				0, length * 16,
				0, 1,
				0, 1);
	ImageSpec imageSpec(roi.xend, roi.yend, roi.chend, TypeDesc::UINT8 );

	if( is_smf(grassFile) ) {
		// Load from SMF
		SMF sourcesmf(grassFile);
		imageBuf = sourcesmf.getGrass();
	}
	if( !imageBuf ) {
		// Load image file
		imageBuf = new ImageBuf( grassFile );
		imageBuf->read( 0, 0, false, TypeDesc::UINT8 );
		if( imageBuf->initialized() ) {
			delete imageBuf;
			imageBuf = NULL;
		}
	}
	if( !imageBuf ) {
		// Generate blank
		imageBuf = new ImageBuf( "grass", imageSpec );
	}

	imageSpec = imageBuf->specmod();
	ImageBuf fixBuf;

	// Fix the number of channels
	if( imageSpec.nchannels != roi.chend ) {
		int map[] = {0};
		ImageBufAlgo::channels(fixBuf, *imageBuf, roi.chend, map );
		imageBuf->copy( fixBuf );
		fixBuf.clear();
	}

	// Fix the Dimensions
	if ( imageSpec.width != roi.xend || imageSpec.height != roi.yend ) {
		if( verbose )
			printf( "\tWARNING: %s is (%i,%i), wanted (%i, %i) Resampling.\n",
			typeFile.c_str(), imageSpec.width, imageSpec.height, roi.xend, roi.yend);
		ImageBufAlgo::resample(fixBuf, *imageBuf, false, roi);
		imageBuf->copy( fixBuf );
		fixBuf.clear();		
	}

	unsigned char *pixels = (unsigned char *)imageBuf->localpixels();

	char filename[256];
	sprintf( filename, "%s.smf", outPrefix.c_str() );

	if( verbose )printf( "    Source: %s.\n", grassFile.c_str() );

	fstream smf(filename, ios::binary | ios::in | ios::out);
	smf.seekp(grassHeader->grassPtr);

	smf.write( (char *)pixels, imageBuf->spec().image_bytes() );
	smf.close();
	
	delete imageBuf;
	if( is_smf( grassFile ) ) delete [] pixels;

	return false;
}
开发者ID:pajohns,项目名称:MapConv,代码行数:77,代码来源:smf.cpp

示例5: smf

bool
SMF::saveTilemap()
{
	if( verbose )cout << "INFO: saveTilemap\n";

	char filename[256];
	sprintf( filename, "%s.smf", outPrefix.c_str() );

	fstream smf(filename, ios::binary | ios::in | ios::out);
	smf.seekp(tilesPtr);

	// Tiles Header
	int nTileFiles = smtList.size();
	smf.write( (char *)&nTileFiles, 4);
	smf.write( (char *)&nTiles, 4);
	if(verbose)printf( "    %i tiles referenced in %i files\n", nTiles, nTileFiles );

	// SMT Names
	for(unsigned int i = 0; i < smtList.size(); ++i) {
		if( verbose )printf( "\t%i %s\n", smtTiles[i], smtList[i].c_str() );
		smf.write( (char *)&smtTiles[i], 4);
		smf.write( smtList[i].c_str(), smtList[i].size() +1 );
	}

	// Dimensions of displacement map.
	ImageBuf *imageBuf = NULL;
	ROI roi(	0, width * 16,  // xbegin, xend
				0, length * 16, // ybegin, yend
				0, 1,               // zbegin, zend
				0, 1);              // chbegin, chend
	ImageSpec imageSpec( roi.xend, roi.yend, roi.chend, TypeDesc::UINT );

	if( is_smf(tilemapFile) ) {
		// Load from SMF
		SMF sourcesmf(tilemapFile);
		imageBuf = sourcesmf.getTilemap();
	}
   	if( !imageBuf ) {
		// load image file
		imageBuf = new ImageBuf( tilemapFile );
		imageBuf->read( 0, 0, false, TypeDesc::UINT );
		if( !imageBuf->initialized() ) {
			delete imageBuf;
			imageBuf = NULL;
		}
	}
	if( !imageBuf ) {
		// Generate blank
		imageBuf = new ImageBuf( "tilemap", imageSpec );
		for ( unsigned int i = 0; i < imageSpec.image_pixels(); ++i )
			((unsigned int *)imageBuf->localpixels())[ i ] = i;
	}

	imageSpec = imageBuf->specmod();
	ImageBuf fixBuf;
	// Fix the number of channels
	if( imageSpec.nchannels != roi.chend ) {
		int map[] = {0};
		ImageBufAlgo::channels(fixBuf, *imageBuf, roi.chend, map);
		imageBuf->copy(fixBuf);
		fixBuf.clear();
	}

	// Fix the size
	// FIXME image should never be resized, instead tiling either from an edge or centred.
	if ( imageSpec.width != roi.xend || imageSpec.height != roi.yend ) {
		if( verbose )
			printf( "\tWARNING: %s is (%i,%i), wanted (%i, %i), Resampling.\n",
			tilemapFile.c_str(), imageSpec.width, imageSpec.height, roi.xend, roi.yend );
		ImageBufAlgo::resample(fixBuf, *imageBuf, false, roi);
		imageBuf->copy(fixBuf);
		fixBuf.clear();
	}

	unsigned int *pixels = (unsigned int *)imageBuf->localpixels();

	// write the data to the smf
	smf.write( (char *)pixels, imageBuf->spec().image_bytes() );
	smf.close();

	delete imageBuf;
	if( is_smf( tilemapFile ) ) delete [] pixels;

	return false;
}
开发者ID:pajohns,项目名称:MapConv,代码行数:85,代码来源:smf.cpp


注:本文中的ImageBuf::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。