本文整理汇总了C++中Img类的典型用法代码示例。如果您正苦于以下问题:C++ Img类的具体用法?C++ Img怎么用?C++ Img使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Img类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BlitTransparent
//XYZZY - temporary?
void BlitTransparent(
Img const& srcimg, Box const& srcbox,
Palette const& srcpalette,
Img& destimg, Box& destbox,
PenColour const& transparentcolour )
{
switch(srcimg.Fmt())
{
case FMT_I8:
assert(transparentcolour.IdxValid());
//assert(srcpalette!=0);
BlitI8Keyed(srcimg,srcbox,srcpalette, destimg, destbox, transparentcolour.idx());
return;
case FMT_RGBX8:
if (destimg.Fmt() != FMT_I8)
BlitRGBX8Keyed(srcimg,srcbox, destimg, destbox, transparentcolour.rgb());
return;
case FMT_RGBA8:
if (destimg.Fmt() != FMT_I8)
BlitRGBA8Keyed(srcimg, srcbox, destimg, destbox);
return;
default:
assert(false);
}
}
示例2: SporeGen
void Sporulation::SporeGen(Img& I, double *weather, double rate){
//unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
//std::default_random_engine generator(seed);
int height = I.getHeight();
int width = I.getWidth();
if(!sp){
sp = (int **)CPLMalloc(sizeof(int *) * height);
int *stream = (int *)CPLMalloc(sizeof(int)*width*height);
for(int i=0;i<height;i++){
sp[i] = &stream[i*width];
}
}
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
if(I.data[i][j]>0){
double lambda = rate * weather[i*width+j];
int sum=0;
poisson_distribution<int> distribution(lambda);
for(int k=0;k<I.data[i][j];k++){
sum += distribution(generator);
}
sp[i][j] = sum;
}
}
}
}
示例3: main
int main( int argc, char *argv[] ) {
if (argc != 3)
cout << "usage:\n\tunfold INPUT_FILE OUTPUT_FILE\n";
Img input(argv[1]);
Unfolder unfolder;
Img *output = NULL;
Img *debug = unfolder.unfold(input, output, true);
// // Now rotate the image by 90 degrees.
// int width = output->getWidth();
// Img* rotated = ImgOps::rotate(output, width/4, NULL);
// Write output image to file.
output->save(string(argv[2]));
// Write debug image to file.
debug->save("debug.jpg");
// Display the debug image.
// ImgWindow window("Unfolder debug image");
// window.setImg(*debug);
// window.refresh();
ImgWindow::waitAll();
return 0;
}
示例4: draw_points
template<class T> static void draw_points(Img<T> &img, const icl64f &value,
std::vector<Point32f> &approx){
T *d = img.getData(0);
int lineStep = img.getLineStep();
for(std::vector<Point32f>::iterator it = approx.begin(); it != approx.end(); ++it){
*(d + (int)(it->y) * lineStep + (int)(it->x)) = value;
}
}
示例5: BlitRGBA8
// blit an RGBA img, blending with src alpha onto the dest (must be RGBX8 or RGBA8)
void BlitRGBA8( Img const& srcimg, Box const& srcbox, Img& destimg, Box& destbox )
{
assert(srcimg.Fmt()==FMT_RGBA8);
assert(destimg.Fmt()!=FMT_I8);
Box destclipped( destbox );
Box srcclipped( srcbox );
clip_blit( srcimg.Bounds(), srcclipped, destimg.Bounds(), destclipped );
const int w = destclipped.w;
int y;
for( y=0; y<destclipped.h; ++y )
{
RGBA8 const* src = srcimg.PtrConst_RGBA8( srcclipped.x+0, srcclipped.y+y );
switch(destimg.Fmt())
{
case FMT_I8:
assert(false); // not implemented
break;
case FMT_RGBX8:
scan_RGBA8_RGBX8(src, destimg.Ptr_RGBX8(destclipped.x+0,destclipped.y+y), w);
break;
case FMT_RGBA8:
scan_RGBA8_RGBA8(src, destimg.Ptr_RGBA8(destclipped.x+0,destclipped.y+y), w);
break;
default:
assert(false);
break;
}
}
destbox = destclipped;
}
示例6: BlitMatteRGBA8
// blit an RGBA img, blending matte colour with src alpha onto the dest
void BlitMatteRGBA8(
Img const& srcimg, Box const& srcbox,
Img& destimg, Box& destbox,
PenColour const& matte )
{
assert(srcimg.Fmt()==FMT_RGBA8);
Box destclipped( destbox );
Box srcclipped( srcbox );
clip_blit( srcimg.Bounds(), srcclipped, destimg.Bounds(), destclipped );
const int w = destclipped.w;
int y;
for( y=0; y<destclipped.h; ++y )
{
RGBA8 const* src = srcimg.PtrConst_RGBA8( srcclipped.x+0, srcclipped.y+y );
switch(destimg.Fmt())
{
case FMT_I8:
scan_matte_RGBA8_I8(src, destimg.Ptr_I8(destclipped.x+0,destclipped.y+y), w, matte.idx());
break;
case FMT_RGBX8:
scan_matte_RGBA8_RGBX8(src, destimg.Ptr_RGBX8(destclipped.x+0,destclipped.y+y), w, matte.rgb());
break;
case FMT_RGBA8:
scan_matte_RGBA8_RGBA8(src, destimg.Ptr_RGBA8(destclipped.x+0,destclipped.y+y), w, matte.rgb());
break;
default:
assert(false);
break;
}
}
destbox = destclipped;
}
示例7: aImg
VectorImgFilter::AutoImg VectorImgFilter::removeVerticals(const Img &vi,
double prec)
{
AutoImg aImg( new VectorImg( vi.linesCnt() ) );
Img &img=*aImg.get(); // helper reference
for(unsigned int i=0; i<vi.linesCnt(); ++i)
{
const Line2DCont &l =vi[i]; // get i-th line
const Point2DCont &p1=l.getFrom(); // get first of 2 points
const Point2DCont &p2=l.getTo(); // get second of 2 points
if( fabs(p1[0]-p2[0])>prec ) // line is NOT vertical?
img.add(l); // add line to output
};
return aImg;
};
示例8: nn_search
// nearest neighbor search, using a given coherence set
void nn_search(Img *destim, int di, int dj, const Kcoherence<K> &kset,
int offx, int offy,
unsigned &bestdiff,unsigned &bestidx)
{
for(int k=0;k<kset.n;k++) {
int i,j;
srcim->idx_to_ij(kset[k],i,j);
i = srcim->wrapw(i+offx);
j = srcim->wraph(j+offy);
if(!srcwrap && (i<Nsize || i>=srcim->w-Nsize))
continue;
if(!srcwrap && (j<Nsize || j>=srcim->h-Nsize))
continue;
unsigned diff = neighbor_diff(destim, srcim, di,dj, i,j, Nsize);
if(diff < bestdiff) {
bestdiff = diff;
bestidx = srcim->ij_to_idx(i,j);
}
}
}
示例9: main
int main() {
float scale = 400.f;
float offset_x = 5.9f;
float offset_y = 5.1f;
float offset_z = 0.05f;
float lacunarity = 1.99f;
float persistance = 0.5f;
Img img;
while (!img.is_closed()) {
Measure measure;
measure.start();
const SimplexNoise simplex(0.1f/scale, 0.5f, lacunarity, persistance); // Amplitude of 0.5 for the 1st octave : sum ~1.0f
const int octaves = static_cast<int>(5 + std::log(scale)); // Estimate number of octaves needed for the current scale
std::ostringstream title;
title << "2D Simplex Perlin noise (" << octaves << " octaves)";
img.set_title(title.str().c_str());
for (int row = 0; row < img.height(); ++row) {
const float y = static_cast<float>(row - img.height()/2 + offset_y*scale);
for (int col = 0; col < img.width(); ++col) {
const float x = static_cast<float>(col - img.width()/2 + offset_x*scale);
// TODO(SRombauts): Add 'erosion' with simple smoothing like exponential, and other 'modifiers' like in libnoise
// Generate "biomes", ie smooth geographic variation in frequency & amplitude,
// and add smaller details, summing the noise values for the coordinate
const float noise = simplex.fractal(octaves, x, y) + offset_z;
const color3f color = ramp(noise); // convert to color
img.draw_point(col, row, (float*)&color);
}
}
img.display();
const double diff_ms = measure.get();
std::cout << std::fixed << diff_ms << "ms\n";
img.user(scale, offset_x, offset_y, offset_z, lacunarity, persistance);
}
return 0;
}
示例10: FiltMedImg
void FiltMedImg(const Img& in, const int k_width, const int k_height, const int channel, Img& out) {
const int width = in.width();
const int height = in.height();
const int num_channel = in.channel();
assert(num_channel > channel);
out.Reshape(width, height, 1);
const double* in_data = in.data();
double* out_data = out.mutable_data();
for(int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
int w_start = w - ((k_width) / 2);
int h_start = h - ((k_height) / 2);
int kw_start = 0;
int kh_start = 0;
int kw_end = k_width;
int kh_end = k_height;
std::vector<double> temp_list;
for (int i = kh_start; i < kh_end; i++ ) {
for (int j = kw_start; j < kw_end; j++) {
int w_temp = w_start + j;
int h_temp = h_start + i;
if (w_temp >=0 && w_temp < width && h_temp >= 0 && h_temp < height) {
temp_list.push_back(in_data[h_temp * width + w_temp]);
}
}
}
std::sort(temp_list.begin(), temp_list.end());
out_data[h * width + w] = temp_list[temp_list.size()/2];
}
}
}
示例11: FiltMaxImg
void FiltMaxImg(const Img& in, const int k_width, const int k_height, const int channel, Img& out) {
const int width = in.width();
const int height = in.height();
const int num_channel = in.channel();
assert(num_channel > channel);
out.Reshape(width, height, 1);
const double* in_data = in.data();
double* out_data = out.mutable_data();
for(int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
int w_start = w - ((k_width) / 2);
int h_start = h - ((k_height) / 2);
int kw_start = 0;
int kh_start = 0;
int kw_end = k_width;
int kh_end = k_height;
double max_value = -MAX_DOUBLE;
for (int i = kh_start; i < kh_end; i++ ) {
for (int j = kw_start; j < kw_end; j++) {
int w_temp = w_start + j;
int h_temp = h_start + i;
if (w_temp >=0 && w_temp < width && h_temp >= 0 && h_temp < height) {
max_value = std::max(max_value, in_data[h_temp * width + w_temp]);
}
}
}
out_data[h * width + w] = max_value;
}
}
}
示例12: FiltImg
void FiltImg(const Img& in, const Img& filter, const int channel, Img& out) {
const int width = in.width();
const int height = in.height();
const int num_channel = in.channel();
assert(num_channel > channel);
out.Reshape(width, height, 1);
const double* in_data = in.data() + channel * out.dim();
const double* filter_data = filter.data();
double* out_data = out.mutable_data();
const int k_width = filter.width();
const int k_height = filter.height();
for(int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
int w_start = w - ((k_width) / 2);
int h_start = h - ((k_height) / 2);
int kw_start = 0;
int kh_start = 0;
int kw_end = k_width;
int kh_end = k_height;
double sum = 0;
for (int i = kh_start; i < kh_end; i++ ) {
for (int j = kw_start; j < kw_end; j++) {
int w_temp = w_start + j;
int h_temp = h_start + i;
if (w_temp >=0 && w_temp < width && h_temp >= 0 && h_temp < height) {
sum += in_data[h_temp * width + w_temp] * filter_data[i * k_width + j];
//printf("%f x %f, ", in_data[h_temp * width + w_temp], filter_data[i * k_width + j]);
//printf("%d %d, \n", h_temp, w_temp);
}
}
}
out_data[h * width + w] = sum;
}
}
}
示例13: main
int main(int argc, char *argv[])
{
if (argc!=2 && argc!=3) {
std::cerr<<"To extract a file: "<<std::endl;
std::cerr<<argv[0]<<" <img> <file>"<<std::endl;
std::cerr<<"To extract all files: "<<std::endl;
std::cerr<<argv[0]<<" <img>"<<std::endl;
return EXIT_FAILURE;
}
bool all_files = argc==2;
std::string extract;
if (!all_files) extract = argv[2];
try {
std::ifstream in;
in.open(argv[1], std::ios::binary);
APP_ASSERT_IO_SUCCESSFUL(in,"opening IMG");
Img img;
img.init(in, argv[1]);
if (!all_files) {
unsigned long off = img.fileOffset(extract);
unsigned long sz = img.fileSize(extract);
extract_file(in, extract, off, sz);
return EXIT_SUCCESS;
}
for (size_t i=0 ; i<img.size() ; i++) {
unsigned long off = img.fileOffset(i);
unsigned long sz = img.fileSize(i);
extract_file(in, img.fileName(i), off, sz);
}
return EXIT_SUCCESS;
} catch (const Exception &e) {
CERR << e << std::endl;
return EXIT_FAILURE;
}
}
示例14: writeImage
bool writeImage(const std::string& path, Img& img)
{
if (endsWith(path, ".ptx")) {
// make sure it's a power of two
if (!checkPowerOfTwo(img)) return 0;
// write ptx face-zero image
std::string error;
PtexWriter* ptx = PtexWriter::open(path.c_str(), Ptex::mt_quad, img.dt,
img.nchan, img.achan, 1, error);
if (!ptx) {
std::cerr << error << std::endl;
return 0;
}
ptx->setBorderModes(opt.uMode, opt.vMode);
// write image top-down (flipped)
int rowlen = img.w * img.nchan * Ptex::DataSize(img.dt);
char* toprow = (char*) img.data + (img.h-1) * rowlen;
Ptex::Res res(PtexUtils::floor_log2(img.w), PtexUtils::floor_log2(img.h));
int adjfaces[4], adjedges[4];
if (opt.uMode == Ptex::m_periodic) { adjfaces[0] = 0; adjfaces[2] = 0; adjedges[0] = 2; adjedges[2] = 0; }
else { adjfaces[0] = -1; adjfaces[2] = -1; adjedges[0] = 0; adjedges[2] = 0; }
if (opt.vMode == Ptex::m_periodic) { adjfaces[1] = 0; adjfaces[3] = 0; adjedges[1] = 3; adjedges[3] = 1; }
else { adjfaces[1] = -1; adjfaces[3] = -1; adjedges[1] = 0; adjedges[3] = 0; }
Ptex::FaceInfo finfo(res, adjfaces, adjedges);
ptx->writeFace(0, finfo, toprow, -rowlen);
// write meta data
for (std::map<std::string,std::string>::iterator iter = opt.meta.begin(), end = opt.meta.end();
iter != end; iter++)
{
ptx->writeMeta(iter->first.c_str(), iter->second.c_str());
}
bool ok = ptx->close(error);
if (!ok) {
std::cerr << error << std::endl;
}
ptx->release();
return ok;
}
else {
return img.save(path);
}
}
示例15: BlitMatte
// blit the src as a matte
void BlitMatte(
Img const& srcimg, Box const& srcbox,
Img& destimg, Box& destbox,
PenColour const& transparentcolour,
PenColour const& mattecolour )
{
switch(srcimg.Fmt())
{
case FMT_I8:
BlitMatteI8Keyed(srcimg,srcbox,destimg,destbox,transparentcolour.idx(), mattecolour);
return;
case FMT_RGBX8:
BlitMatteRGBX8Keyed(srcimg,srcbox,destimg,destbox,transparentcolour.rgb(), mattecolour);
return;
case FMT_RGBA8:
BlitMatteRGBA8Keyed(srcimg,srcbox,destimg,destbox, mattecolour);
return;
default:
assert(false);
}
}