Example #1
0
bool egami::loadEDF(const std::string& _inputFile, egami::Image& _ouputImage) {
	
	etk::FSNode file(_inputFile);
	if (false == file.exist()) {
		EGAMI_ERROR("File does not existed='" << file << "'");
		return false;
	}
	if(false == file.fileOpenRead() ) {
		EGAMI_ERROR("Can not find the file name='" << file << "'");
		return false;
	}
	std::string line;
	file.fileGets(line);
	if (etk::start_with(line, "#edf", false) == false) {
		EGAMI_ERROR("This file seams not to be a EDF file ...");
		file.fileClose();
		return false;
	}
	// count number of colomn max an number of line max:
	ivec2 size(0,0);
	while (file.fileGets(line) == true) {
		if (line.size()/2 > (size_t)size.x()) {
			size.setValue(line.size()/2, size.y()+1);
		} else {
			size += ivec2(0,1);
		}
	}
	if (line.size()/2 > (size_t)size.x()) {
		size.setValue(line.size()/2, size.y()+1);
	} else {
		size += ivec2(0,1);
	}
	EGAMI_DEBUG("'" << file << "' ==> size=" << size);
	// jup to the start of the file
	file.fileSeek(0, etk::FSN_SEEK_START);
	// drop the first line
	file.fileGets(line);
	
	
	// resize output:
	_ouputImage.resize(size);
	int32_t currentLineId = 0;
	char tmp[3];
	tmp[2] = '\0';
	while (file.fileGets(line) == true) {
		if (line.size() <= 0) {
			continue;
		}
		for (size_t xxx = 0; xxx < line.size()-1; xxx+=2) {
			tmp[0] = line[xxx];
			tmp[1] = line[xxx+1];
			int32_t val = 0;
			sscanf(tmp, "%x", &val);
			_ouputImage.set(ivec2(xxx/2, currentLineId), etk::Color<>((uint8_t)val, (uint8_t)val, (uint8_t)val, (uint8_t)val));
		}
		++currentLineId;
	}
	if (line.size() > 0) {
		for (size_t xxx = 0; xxx < line.size()-1; xxx+=2) {
			tmp[0] = line[xxx];
			tmp[1] = line[xxx+1];
			int32_t val = 0;
			sscanf(tmp, "%x", &val);
			_ouputImage.set(ivec2(xxx/2, currentLineId), etk::Color<>((uint8_t)val, (uint8_t)val, (uint8_t)val, (uint8_t)val));
		}
	}
	file.fileClose();
	return true;
}
Example #2
0
void ewol::resource::DistanceFieldFont::generateDistanceField(const egami::ImageMono& _input, egami::Image& _output) {
	std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
	int32_t size = _input.getSize().x() * _input.getSize().y();
	std::vector<short> xdist(size);
	std::vector<short> ydist(size);
	std::vector<double> gx(size);
	std::vector<double> gy(size);
	std::vector<double> data(size);
	std::vector<double> outside(size);
	std::vector<double> inside(size);
	// Convert img into double (data)
	double img_min = 255, img_max = -255;
	for (int32_t yyy = 0; yyy < _input.getSize().y(); ++yyy) {
		for (int32_t xxx = 0; xxx < _input.getSize().x(); ++xxx) {
			int32_t iii = yyy * _input.getSize().x() + xxx;
			double v = _input.get(ivec2(xxx, yyy));
			data[iii] = v;
			if (v > img_max) {
				img_max = v;
			}
			if (v < img_min) {
				img_min = v;
			}
		}
	}
	// Rescale image levels between 0 and 1
	for (int32_t yyy = 0; yyy < _input.getSize().y(); ++yyy) {
		for (int32_t xxx = 0; xxx < _input.getSize().x(); ++xxx) {
			int32_t iii = yyy * _input.getSize().x() + xxx;
			data[iii] = (_input.get(ivec2(xxx, yyy))-img_min)/img_max;
		}
	}
	
	// Compute outside = edtaa3(bitmap); % Transform background (0's)
	computegradient(&data[0], _input.getSize().x(), _input.getSize().y(), &gx[0], &gy[0]);
	edtaa3(&data[0], &gx[0], &gy[0], _input.getSize().x(), _input.getSize().y(), &xdist[0], &ydist[0], &outside[0]);
	for(size_t iii = 0; iii < outside.size(); ++iii) {
		if( outside[iii] < 0 ) {
			outside[iii] = 0.0;
		}
	}
	
	// Compute inside = edtaa3(1-bitmap); % Transform foreground (1's)
	for(size_t iii = 0; iii < gx.size(); ++iii) {
		gx[iii] = 0;
	}
	for(size_t iii = 0; iii < gy.size(); ++iii) {
		gy[iii] = 0;
	}
	for(size_t iii = 0; iii < data.size(); ++iii) {
		data[iii] = 1 - data[iii];
	}
	computegradient( &data[0], _input.getSize().x(), _input.getSize().y(), &gx[0], &gy[0]);
	edtaa3(&data[0], &gx[0], &gy[0], _input.getSize().x(), _input.getSize().y(), &xdist[0], &ydist[0], &inside[0]);
	for(size_t iii = 0; iii < inside.size(); ++iii) {
		if( inside[iii] < 0 ) {
			inside[iii] = 0.0;
		}
	}
	
	_output.resize(_input.getSize(), etk::Color<>(0));
	_output.clear(etk::Color<>(0));
	for (int32_t xxx = 0; xxx < _output.getSize().x(); ++xxx) {
		for (int32_t yyy = 0; yyy < _output.getSize().y(); ++yyy) {
			int32_t iii = yyy * _output.getSize().x() + xxx;
			outside[iii] -= inside[iii];
			outside[iii] = 128+outside[iii]*16;
			if( outside[iii] < 0 ) {
				outside[iii] = 0;
			}
			if( outside[iii] > 255 ) {
				outside[iii] = 255;
			}
			uint8_t val = 255 - (unsigned char) outside[iii];
			// TODO : Remove multiple size of the map ...
			_output.set(ivec2(xxx, yyy), etk::Color<>((int32_t)val,(int32_t)val,(int32_t)val,255));
		}
	}
}