예제 #1
0
void 
TGA::write(const std::string& filename, const TGAHeader& header, const i8* dataptr, u32 byte)
{
    if (dataptr == nullptr)
        throw TGAException("Invalid data source pointer");
    
    std::ofstream imagefile(filename.c_str(), std::ios::out | std::ios::binary);

    imagefile.write(reinterpret_cast<const i8*>(&header), sizeof(TGAHeader));
    imagefile.write(dataptr, byte);
    imagefile.close();
}
예제 #2
0
int main(int argc, char** argv){
	if(argc != 3){
		cout << "USAGE :: ./Parse <image_path> <datafile_path>";
		exit(-1);
	}
	string imagefile(argv[1]);
	string datafile(argv[2]);
	bool DEBUG = false;
	Mat Image = imread(imagefile, 1);

	if(DEBUG){
		// show image
		namedWindow("image", CV_WINDOW_AUTOSIZE);
		imshow("image", Image);
	}

	// get image info in a struct
	AnnotatedDatasetInfo info = getImageData(Image, datafile);

	if(DEBUG){
		// printing data
		int rows = 240;
		int cols = 320;
		cout << "Mat\n";
		for(int i = 0; i < rows; i++)
		{
			for(int j = 0; j < cols; j++)
				cout << info.Labels.at<int>(i, j) << " ";
			cout << endl;
		}
		cout << "\nDepth\n";
		for(int i = 0; i < rows; i++)
		{
			for(int j = 0; j < cols; j++)
				cout << info.Depths.at<Vec3f>(i, j)[0] << ", " << info.Depths.at<Vec3f>(i, j)[1] << ", " << info.Depths.at<Vec3f>(i, j)[2] << " :: ";
			cout << endl;
		}	
		cout << "\nPoints\n";
		for(int i = 0; i <= 1; i++)
		{
			for(int j = 0; j < info.Points[i].size(); j++)
				cout << "(" << info.Points[i][j].x << ", " << info.Points[i][j].y << "), ";
			cout << endl;
		}	

		waitKey(0);
	}
}
예제 #3
0
파일: Entry.cpp 프로젝트: Marneus68/DOSMAN
void dosman::Entry::construct(void)
{
    DIR *dir;
    struct dirent *ent;
    int score;

    hasImage = false;
    hasConf = false;

    if ((dir = opendir (path.c_str())) != NULL) { 
        while ((ent = readdir (dir)) != NULL) {
            if (ent->d_name[0] == '.') continue;

            std::string filename(ent->d_name);
            std::string imagefile(DOSMAN_ENTRY_COVER);
            std::string dosboxconf(DOSMAN_ENTRY_CONF);

            if (filename.compare(0, imagefile.length(), imagefile) == 0) {
                hasImage = true;
                imagePath = path + "/" + filename;
                continue;
            }

            if (filename.compare(0, dosboxconf.length(), dosboxconf) == 0) {
                hasConf = true;
                continue;
            }
        }
        closedir (dir);

        if (!hasConf) throw InvalidEntryException(path);

        try {
            config = new KeyValueParser(path + "/" + DOSMAN_ENTRY_CONF);
        } catch (...) {
            throw InvalidConfigFileException(path);
        }
    }
}
예제 #4
0
void GatherFolderImg::computeDimensions() {
	int n_slices = -1 ;
	fs::path filePath;
	do {
		n_slices++ ;
		filePath = _folderpath ;
		filePath /= QString( ANTHILL_SLICE_NAME ).arg( n_slices, 0, 10 ).toStdString() ;
	} while ( boost::filesystem::exists( filePath ) ) ;
	n_slices-- ;
	filePath = _folderpath ;
	filePath /= QString( ANTHILL_SLICE_NAME ).arg( n_slices, 0, 10 ).toStdString() ;
	std::map<int, QString > desc ;
	QFile imagefile( filePath.string().c_str() ) ;
	if ( /*io::*/pgmheader( imagefile, desc ) ) {
		int n_cols = desc[ PGM_HEADER_IMAGE_WIDTH ].toInt() ;
		int n_rows = desc[ PGM_HEADER_IMAGE_HEIGHT ].toInt() ;
		_scene = new BillonTpl< arma::u8 >( n_rows, n_cols, n_slices+1 ) ;
		_scene->fill(0);
	} else {
		std::cerr<<desc[ PGM_HEADER_ERROR ].toStdString()<<std::endl;
	}
	imagefile.close() ;
}
예제 #5
0
	bool D3D9texture::loadFile2D()
	{
		D3D9_SCOPELOCK;

		HRESULT hr;
		const byte_t* data;
		int flags = 0;

		if (!(m_initFlags.isSet(IF_NoMipmap)))
			flags |= Image::Mipmap;

		flags |= Image::ExpandAlpha;

		std::auto_ptr<Image> imagefile(new Image);
		if (!imagefile->loadFile(m_name, flags)) {
//			Debugf("D3D9texture::loadFile2D: can't find image file for %s\n", m_name.c_str());
			return false;
		}

		m_width = imagefile->getWidth();
		m_height = imagefile->getHeight();
		//		mDesc.format = imagefile->getFormat();
		if (!Math::isPowerOfTwo(m_width) || !Math::isPowerOfTwo(m_height)) {
			//			if (!(mDesc.flags & TexFlag_allowNPOT))
			Errorf("GLtexture::loadFile2D: texture %s size isn't power of two", m_name.c_str());
			//			else
			//				Debugf("GLtexture::loadFile2D: texture %s size isn't power of two\n", mDesc.name.c_str());
		}

		m_format = imagefile->getFormat();

		D3DFORMAT d3dformat;

		trTexFormat(imagefile->getFormat(), d3dformat);

		DWORD d3dusage = 0;

		int mipdown = image_mip->getInteger();
		if (m_initFlags.isSet(IF_NoMipmap) || imagefile->getNumMipmapLevels() <= 1) {
			m_isMipmaped = false;
			mipdown = 0;
		} else {
			m_isMipmaped = true;
			mipdown = Math::clamp(mipdown, 0, imagefile->getNumMipmapLevels()-1);

			m_width >>= mipdown;
			m_height >>= mipdown;
			if (m_width < 1) m_width = 1;
			if (m_height < 1) m_height = 1;
		}


//		m_initFlags = 0;

		if (m_initFlags.isSet(Texture::IF_RenderTarget)) {
			Errorf("Can't load render target from a file");
		}

		if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) {
			d3dusage |= D3DUSAGE_AUTOGENMIPMAP;
			m_isMipmaped = true;
			m_hardwareGenMipmap = checkIfSupportHardwareMipmapGeneration(d3dformat, d3dusage);

			if (!m_hardwareGenMipmap) {
				d3dusage &= ~D3DUSAGE_AUTOGENMIPMAP;
			}
		}

		if (m_object == 0) {
			V(d3d9Device->CreateTexture(m_width, m_height, !m_isMipmaped, d3dusage, d3dformat, D3DPOOL_MANAGED, &m_object, 0));
		}

		int width, height;
		width = m_width;
		height = m_height;
		for (DWORD i = 0; i < m_object->GetLevelCount(); i++) {
			if (i + mipdown >= (DWORD)imagefile->getNumMipmapLevels()) {
				// if no image for this level, break
				break;
			}

			uint_t datasize = imagefile->getFormat().calculateDataSize(width, height);
			m_videoMemoryUsed += datasize;

			data = imagefile->getData(i + mipdown);
#if 0
			LPDIRECT3DSURFACE9 surface;

			V(m_object->GetSurfaceLevel(i, &surface));

			D3DXLoadSurfaceFromMemory(surface, 0, 0, data, d3dformat, pitch, 0, rect, D3DX_FILTER_NONE, 0);
#else
			D3DLOCKED_RECT lockedRect;
			V(m_object->LockRect(i, &lockedRect, 0, 0));
			int mypitch = m_format.calculateDataSize(width, 1);
			if (mypitch != lockedRect.Pitch) {
				Errorf("mypitch != lockedRect.Pitch");
			}
			memcpy(lockedRect.pBits, data, datasize);
			V(m_object->UnlockRect(i));
#endif
			width >>= 1;
			height >>= 1;
			if (width < 1) width = 1;
			if (height < 1) height = 1;

			if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) {
//				break;
			}
		}

		if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) {
			generateMipmap();
		}

		if (m_isMipmaped) {
			setFilterMode(FM_Trilinear);
		} else {
			setFilterMode(FM_Linear);
		}

		setClampMode(CM_Repeat);

		setPrivateData();

		g_statistic->addValue(stat_textureMemory, m_videoMemoryUsed);

		return true;
	}