int handle_decode(char **argv, Images &images, int quality, int scale) { char *ext = strrchr(argv[1],'.'); if (!check_compatible_extension(ext)) { e_printf("Error: expected \".png\", \".pnm\" or \".pam\" file name extension for output file\n"); return 1; } const auto tim0 = high_resolution_clock::now(); if (!decode_flif(argv, images, quality, scale)) {e_printf("Error: could not decode FLIF file\n"); return 3; } const auto tim1 = high_resolution_clock::now(); printf("decoded in %lld msec\n", duration_cast<milliseconds>(tim1 - tim0).count()); if (scale>1) v_printf(3,"Downscaling output: %ux%u -> %ux%u\n",images[0].cols(),images[0].rows(),images[0].cols()/scale,images[0].rows()/scale); if (images.size() == 1) { if (!images[0].save(argv[1],scale)) return 2; } else { int counter=0; std::vector<char> vfilename(strlen(argv[1])+6); char *filename = &vfilename[0]; strcpy(filename,argv[1]); char *a_ext = strrchr(filename,'.'); for (Image& image : images) { sprintf(a_ext,"-%03d%s",counter++,ext); if (!image.save(filename,scale)) return 2; v_printf(2," (%i/%i) \r",counter,(int)images.size()); v_printf(4,"\n"); } } v_printf(2,"\n"); return 0; }
static void makeThumbWrapper ( void *state , ThreadEntry *t ) { Images *THIS = (Images *)state; // control loop if ( ! THIS->downloadImages() ) return; // all done THIS->m_callback ( THIS->m_state ); }
QPixmap Addressbook::icon(const QString &uid) { Images* icons = KonversationApplication::instance()->images(); QIconSet currentIcon; if(!isPresent(uid)) return QPixmap(); switch(presenceStatus(uid)) { case 0: //Unknown case 1: //Offline case 2: //connecting - invalid for us? currentIcon = icons->getKimproxyOffline(); break; case 3: //Away currentIcon = icons->getKimproxyAway(); break; case 4: //Online currentIcon = icons->getKimproxyOnline(); break; default: //error kdDebug() << "Unknown status " << uid << endl; return QPixmap(); } QPixmap joinedIcon = currentIcon.pixmap(QIconSet::Automatic, QIconSet::Active, QIconSet::On); return joinedIcon; }
Images LoadImagesFromDisk(const std::string & path) { Images result; int exceptionCounter = 0; for (int i = 0; i != 100; ++i) { try { result.push_back(Image::fromFile(path + std::to_string(i))); } catch (boost::exception & exc) { exc << ProgressTag(i); if (const std::string * fileName = boost::get_error_info<FileNameTag>(exc)) { std::cerr << "Failed to load image " << i << "/100: " << *fileName << ". Origin: "; const char * file = *boost::get_error_info<boost::throw_file>(exc); int line = *boost::get_error_info<boost::throw_line>(exc); const char * func = *boost::get_error_info<boost::throw_function>(exc); std::cerr << file << ":" << line << ": " << func << std::endl; if (++exceptionCounter >= 10) { BOOST_THROW_EXCEPTION(TooManyErrors() << InformationTag("Too many exceptions. Bailing out.")); } } } } return result; }
int handle_decode(char **argv, Images &images, int quality, int scale) { char *ext = strrchr(argv[1],'.'); if (!check_compatible_extension(ext)) { e_printf("Error: expected \".png\", \".pnm\" or \".pam\" file name extension for output file\n"); return 1; } if (!decode_flif(argv, images, quality, scale)) return 3; if (scale>1) v_printf(3,"Downscaling output: %ux%u -> %ux%u\n",images[0].cols(),images[0].rows(),images[0].cols()/scale,images[0].rows()/scale); if (images.size() == 1) { if (!images[0].save(argv[1],scale)) return 2; } else { int counter=0; std::vector<char> vfilename(strlen(argv[1])+6); char *filename = &vfilename[0]; strcpy(filename,argv[1]); char *a_ext = strrchr(filename,'.'); for (Image& image : images) { sprintf(a_ext,"-%03d%s",counter++,ext); if (!image.save(filename,scale)) return 2; v_printf(2," (%i/%i) \r",counter,(int)images.size()); v_printf(4,"\n"); } } v_printf(2,"\n"); return -1; }
bool process(const ColorRanges *srcRanges, const Images &images) { int np=srcRanges->numPlanes(); nb = images.size(); seen_before.clear(); seen_before.resize(nb,-1); bool dupes_found=false; for (unsigned int fr=1; fr<images.size(); fr++) { const Image& image = images[fr]; for (unsigned int ofr=0; ofr<fr; ofr++) { const Image& oimage = images[ofr]; bool identical=true; for (uint32_t r=0; r<image.rows(); r++) { for (uint32_t c=0; c<image.cols(); c++) { for (int p=0; p<np; p++) { if(image(p,r,c) != oimage(p,r,c)) { identical=false; break;} } if (!identical) {break;} } if (!identical) {break;} } if (identical) {seen_before[fr] = ofr; dupes_found=true; break;} } } return dupes_found; }
static void downloadImageWrapper ( void *state ) { Images *THIS = (Images *)state; // control loop if ( ! THIS->downloadImages() ) return; // all done THIS->m_callback ( THIS->m_state ); }
// Use of ThreadEntry parameter is NOT thread safe static void makeThumbWrapper ( void *state, job_exit_t exit_type ) { Images *THIS = (Images *)state; // control loop if ( ! THIS->downloadImages() ) return; // all done THIS->m_callback ( THIS->m_state ); }
static void gotImgIpWrapper ( void *state , long ip ) { Images *THIS = (Images *)state; // control loop if ( ! THIS->downloadImages() ) return; // call callback at this point, we are done with the download loop THIS->m_callback ( THIS->m_state ); }
bool encode_load_input_images(int argc, char **argv, Images &images) { int nb_input_images = argc-1; while(argc>1) { Image image; v_printf(2,"\r"); if (!image.load(argv[0])) { e_printf("Could not read input file: %s\n", argv[0]); return false; }; images.push_back(std::move(image)); Image& last_image = images.back(); if (last_image.rows() != images[0].rows() || last_image.cols() != images[0].cols()) { e_printf("Dimensions of all input images should be the same!\n"); e_printf(" First image is %ux%u\n",images[0].cols(),images[0].rows()); e_printf(" This image is %ux%u: %s\n",last_image.cols(),last_image.rows(),argv[0]); return false; } if (last_image.numPlanes() < images[0].numPlanes()) { if (images[0].numPlanes() == 3) last_image.ensure_chroma(); else if (images[0].numPlanes() == 4) last_image.ensure_alpha(); else { e_printf("Problem while loading input images, please report this.\n"); return false; } } else if (last_image.numPlanes() > images[0].numPlanes()) { if (last_image.numPlanes() == 3) { for (Image& i : images) i.ensure_chroma(); } else if (last_image.numPlanes() == 4) { for (Image& i : images) i.ensure_alpha(); } else { e_printf("Problem while loading input images, please report this.\n"); return false; } } argc--; argv++; if (nb_input_images>1) {v_printf(2," (%i/%i) ",(int)images.size(),nb_input_images); v_printf(4,"\n");} } v_printf(2,"\n"); return true; }
// we got a reply void gotTermListWrapper ( void *state ) { Images *THIS = (Images *)state; // process/store the reply THIS->gotTermList(); // try to launch more, returns false if it blocks if ( ! THIS->launchRequests() ) return; // all done THIS->m_callback ( THIS->m_state ); }
int main(int argc, char * argv[]) { //Load the config and apply //Load the configs of screen win_w = cfg.Load(KEY_WINWIDTH); win_h = cfg.Load(KEY_WINHEIGHT); //Load the volumn and apply snd.ApplyCfg(BGMCN, cfg.Load(BGMCN)); snd.ApplyCfg(SECN, cfg.Load(SECN)); snd.ApplyCfg(VCECN, cfg.Load(VCECN)); //Init SDL_Init(SDL_INIT_EVENTS); win = SDL_CreateWindow("MaikazeSekai", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, win_w, win_h, SDL_WINDOW_OPENGL); ren = SDL_CreateRenderer(win, -1, 0); SDL_RenderSetLogicalSize(ren, 1280, 720); blk = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, win_w, win_h); //sent the renderer to Class Image as a stage and init them with the FileMgr img.Init(ren, &file); snd.Init(&file); auto *rw = SDL_RWFromFile("z:/star.png", "r"); auto sur = IMG_Load_RW(rw, AUTOFREE); auto tex = SDL_CreateTextureFromSurface(ren, sur); SDL_FreeSurface(sur); SDL_Rect rt = { 0, 0, 2362, 7087 }; SDL_RenderCopy(ren, tex, NULL, &rt); SDL_RenderPresent(ren); SDL_DestroyTexture(tex); auto *rw2 = SDL_RWFromFile("z:/1.png", "r"); auto sur2 = IMG_Load_RW(rw2, AUTOFREE); auto tex2 = SDL_CreateTextureFromSurface(ren, sur2); SDL_FreeSurface(sur2); SDL_Rect rt2 = { 0, 0, 800, 900 }; SDL_RenderCopy(ren, tex2, NULL, &rt2); SDL_RenderPresent(ren); //SDL_DestroyTexture(tex); // BGM("yui.wav", 1, 0); BG("sample.png"); img.OnDraw(); //Refresh the textures on renderer SDL_RenderPresent(ren); UnLoadBG(); //SDL_DestroyTexture() //Logo(); //Title(); SDL_Quit(); return 0; }
/** * \brief retrieve the most recent image from the guider */ void guidercommand::image(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 3) { throw std::runtime_error("missing imageid argument"); } std::string imageid = arguments[2]; Astro::Image_ptr image = guider->mostRecentImage(); Images images; images.assign(imageid, image); }
~BlendBaton() { for (Images::iterator cur = images.begin(); cur != images.end(); cur++) { (*cur)->buffer.Dispose(); } #if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 4 ev_unref(EV_DEFAULT_UC); #endif // Note: The result buffer is freed by the node Buffer's free callback callback.Dispose(); }
void Enhancer::analyze(void) { for (int i=0; i<p_files->size(); i++) { Images *images = p_files->at(i)->load_images(); for (int idx=0; idx<images->size(); idx++) { Image *img = images->at(idx); //img->gen_preview(); //img->gen_thumbnail(); img->analyse(&m_filterQueue); //img->free_pix(); p_images->push_back(img); } delete images; std::cout << i << std::endl; } }
template<typename Coder> void flif_decode_scanlines_inner(std::vector<Coder> &coders, Images &images, const ColorRanges *ranges) { ColorVal min,max; int nump = images[0].numPlanes(); for (int k=0,i=0; k < 5; k++) { int p=PLANE_ORDERING[k]; if (p>=nump) continue; i++; Properties properties((nump>3?NB_PROPERTIES_scanlinesA[p]:NB_PROPERTIES_scanlines[p])); v_printf(2,"\r%i%% done [%i/%i] DEC[%ux%u] ",(int)(100*pixels_done/pixels_todo),i,nump,images[0].cols(),images[0].rows()); v_printf(4,"\n"); pixels_done += images[0].cols()*images[0].rows(); if (ranges->min(p) >= ranges->max(p)) continue; for (uint32_t r = 0; r < images[0].rows(); r++) { for (int fr=0; fr< (int)images.size(); fr++) { Image& image = images[fr]; uint32_t begin=image.col_begin[r], end=image.col_end[r]; if (image.seen_before >= 0) { for(uint32_t c=0; c<image.cols(); c++) image.set(p,r,c,images[image.seen_before](p,r,c)); continue; } if (fr>0) { for (uint32_t c = 0; c < begin; c++) if (nump>3 && p<3 && image(3,r,c) == 0) image.set(p,r,c,predict_and_calcProps_scanlines(properties,ranges,image,p,r,c,min,max)); else if (p !=4 ) image.set(p,r,c,images[fr-1](p,r,c)); /* else if (nump>4 && p<4 && image(4,r,c) > 0) image.set(p,r,c,images[fr-image(4,r,c)](p,r,c)); else { int oldframe=fr-1; image.set(p,r,c,images[oldframe](p,r,c)); while(p == 4 && image(p,r,c) > 0) {oldframe -= image(p,r,c); assert(oldframe>=0); image.set(p,r,c,images[oldframe](p,r,c));} } */ } else { if (nump>3 && p<3) { begin=0; end=image.cols(); } } for (uint32_t c = begin; c < end; c++) { ColorVal guess = predict_and_calcProps_scanlines(properties,ranges,image,p,r,c,min,max); if (p==4 && max > fr) max = fr; if (nump>3 && p<3 && image(3,r,c) == 0) {image.set(p,r,c,guess); continue;} if (nump>4 && p<4 && image(4,r,c) > 0) {image.set(p,r,c,images[fr-image(4,r,c)](p,r,c)); continue;} ColorVal curr = coders[p].read_int(properties, min - guess, max - guess) + guess; image.set(p,r,c, curr); } if (fr>0) { for (uint32_t c = end; c < image.cols(); c++) if (nump>3 && p<3 && image(3,r,c) == 0) image.set(p,r,c,predict_and_calcProps_scanlines(properties,ranges,image,p,r,c,min,max)); else if (p !=4 ) image.set(p,r,c,images[fr-1](p,r,c)); /* else if (nump>4 && p<4 && image(4,r,c) > 0) image.set(p,r,c,images[fr-image(4,r,c)](p,r,c)); else { int oldframe=fr-1; image.set(p,r,c,images[oldframe](p,r,c)); while(p == 4 && image(p,r,c) > 0) {oldframe -= image(p,r,c); assert(oldframe>=0); image.set(p,r,c,images[oldframe](p,r,c));} }*/ } } } } }
void Element::draw(QPainter &painter, Images &images) const { switch (_type) { case Element::MINE_S: case Element::MINE_L: case Element::MINE_M: case Element::MINE_S_ON: case Element::MINE_L_ON: case Element::MINE_M_ON: case Element::MINE_EXPLO: painter.drawImage(_center, images.getImage(_type)); break; case Element::SHIP_1: case Element::SHIP_2: case Element::SHIP_3: case Element::SHIP_4: /* Draw shield */ if (shielded()) { DEBUG("Element::draw() Shield", false); painter.drawImage(QRect(QPoint(_center.x() - 20, _center.y() - 20),QSize(40,40)), images.getImage(Element::SHIELD, _angle)); } painter.drawImage(QRect(QPoint(_imageCenter .x(), _imageCenter.y()), QSize(32,32)) , images.getImage(_type, _angle)); break; case Element::SHOT: if(playSound()) QSound::play("sound/shot.wav"); DEBUG("Type : " << _type, false); painter.drawImage(QRect(QPoint(_center.x() - 10, _center.y() - 10), QSize(20, 20)), images.getImage(_type)); break; default: break; } }
void PlayerInfos::draw(QPainter &painter, Images &images) const { painter.setPen(_color); painter.setBrush(_brush); painter.drawText(_position, _pseudo); painter.drawText(_position.x(), _position.y() + 15, _scoreText); /* Draw lives */ for (quint32 i = 0; i < _lives; ++i) { painter.drawImage (_position.x() + i * 24, _position.y() + 25, images.getImage(Element::LIVE)); } }
bool encode_load_input_images(int argc, char **argv, Images &images) { int nb_input_images = argc-1; while(argc>1) { Image image; v_printf(2,"\r"); if (!image.load(argv[0])) { e_printf("Could not read input file: %s\n", argv[0]); return false; }; images.push_back(std::move(image)); const Image& last_image = images.back(); if (last_image.rows() != images[0].rows() || last_image.cols() != images[0].cols() || last_image.numPlanes() != images[0].numPlanes()) { e_printf("Dimensions of all input images should be the same!\n"); e_printf(" First image is %ux%u, %i channels.\n",images[0].cols(),images[0].rows(),images[0].numPlanes()); e_printf(" This image is %ux%u, %i channels: %s\n",last_image.cols(),last_image.rows(),last_image.numPlanes(),argv[0]); return false; } argc--; argv++; if (nb_input_images>1) {v_printf(2," (%i/%i) ",(int)images.size(),nb_input_images); v_printf(4,"\n");} } v_printf(2,"\n"); return true; }
bool encode_flif(int argc, char **argv, Images &images, int palette_size, int acb, flifEncodingOptional method, int lookback, int learn_repeats, int frame_delay, int divisor=CONTEXT_TREE_COUNT_DIV, int min_size=CONTEXT_TREE_MIN_SUBTREE_SIZE, int split_threshold=CONTEXT_TREE_SPLIT_THRESHOLD, int yiq=1, int plc=1) { bool flat=true; for (Image &image : images) if (image.uses_alpha()) flat=false; if (flat && images[0].numPlanes() == 4) { v_printf(2,"Alpha channel not actually used, dropping it.\n"); for (Image &image : images) image.drop_alpha(); } bool grayscale=true; for (Image &image : images) if (image.uses_color()) grayscale=false; if (grayscale && images[0].numPlanes() == 3) { v_printf(2,"Chroma not actually used, dropping it.\n"); for (Image &image : images) image.drop_color(); } uint64_t nb_pixels = (uint64_t)images[0].rows() * images[0].cols(); std::vector<std::string> desc; if (nb_pixels > 2) { // no point in doing anything for 1- or 2-pixel images if (plc) desc.push_back("PLC"); // compactify channels if (yiq) desc.push_back("YIQ"); // convert RGB(A) to YIQ(A) desc.push_back("BND"); // get the bounds of the color spaces } if (palette_size < 0) { palette_size = 1024; if (nb_pixels * images.size() / 2 < 1024) palette_size = nb_pixels * images.size() / 2; } if (palette_size > 0) desc.push_back("PLA"); // try palette (including alpha) if (palette_size > 0) desc.push_back("PLT"); // try palette (without alpha) if (acb == -1) { // not specified if ACB should be used if (nb_pixels * images.size() > 10000) desc.push_back("ACB"); // try auto color buckets on large images } else if (acb) desc.push_back("ACB"); // try auto color buckets if forced if (method.o == Optional::undefined) { // no method specified, pick one heuristically if (nb_pixels * images.size() < 10000) method.encoding=flifEncoding::nonInterlaced; // if the image is small, not much point in doing interlacing else method.encoding=flifEncoding::interlaced; // default method: interlacing } if (images.size() > 1) { desc.push_back("DUP"); // find duplicate frames desc.push_back("FRS"); // get the shapes of the frames if (lookback != 0) desc.push_back("FRA"); // make a "deep" alpha channel (negative values are transparent to some previous frame) } if (learn_repeats < 0) { // no number of repeats specified, pick a number heuristically learn_repeats = TREE_LEARN_REPEATS; if (nb_pixels * images.size() < 5000) learn_repeats--; // avoid large trees for small images if (learn_repeats < 0) learn_repeats=0; } FILE *file = fopen(argv[0],"wb"); if (!file) return false; FileIO fio(file, argv[0]); return flif_encode(fio, images, desc, method.encoding, learn_repeats, acb, frame_delay, palette_size, lookback, divisor, min_size, split_threshold); }
int handle_decode(int argc, char **argv, Images &images, int quality, int scale, int resize_width, int resize_height) { if (scale < 0) { // just identify the file(s), don't actually decode while (argc>0) { decode_flif(argv, images, quality, scale, resize_width, resize_height); argv++; argc--; } return 0; } char *ext = strrchr(argv[1],'.'); if (!check_compatible_extension(ext) && strcmp(argv[1],"null:")) { e_printf("Error: expected \".png\", \".pnm\" or \".pam\" file name extension for output file\n"); return 1; } if (!decode_flif(argv, images, quality, scale, resize_width, resize_height)) { e_printf("Error: could not decode FLIF file\n"); return 3; } if (!strcmp(argv[1],"null:")) return 0; // if (scale>1) // v_printf(3,"Downscaling output: %ux%u -> %ux%u\n",images[0].cols(),images[0].rows(),images[0].cols()/scale,images[0].rows()/scale); if (images.size() == 1) { if (!images[0].save(argv[1])) return 2; } else { int counter=0; std::vector<char> vfilename(strlen(argv[1])+6); char *filename = &vfilename[0]; strcpy(filename,argv[1]); char *a_ext = strrchr(filename,'.'); for (Image& image : images) { sprintf(a_ext,"-%03d%s",counter++,ext); if (!image.save(filename)) return 2; v_printf(2," (%i/%i) \r",counter,(int)images.size()); v_printf(4,"\n"); } } v_printf(2,"\n"); return 0; }
bool process(const ColorRanges *srcRanges, const Images &images) { if (images.size()<2) return false; int np=srcRanges->numPlanes(); nb = 0; cols = images[0].cols(); for (unsigned int fr=1; fr<images.size(); fr++) { const Image& image = images[fr]; if (image.seen_before >= 0) continue; nb += image.rows(); for (uint32_t r=0; r<image.rows(); r++) { bool beginfound=false; for (uint32_t c=0; c<image.cols(); c++) { if (image.alpha_zero_special && np>3 && image(3,r,c) == 0 && images[fr-1](3,r,c)==0) continue; for (int p=0; p<np; p++) { if(image(p,r,c) != images[fr-1](p,r,c)) { beginfound=true; break;} } if (beginfound) {b.push_back(c); break;} } if (!beginfound) {b.push_back(image.cols()); e.push_back(image.cols()); continue;} bool endfound=false; for (uint32_t c=image.cols()-1; c >= b.back(); c--) { if (image.alpha_zero_special && np>3 && image(3,r,c) == 0 && images[fr-1](3,r,c)==0) continue; for (int p=0; p<np; p++) { if(image(p,r,c) != images[fr-1](p,r,c)) { endfound=true; break;} } if (endfound) {e.push_back(c+1); break;} } if (!endfound) {e.push_back(0); continue;} //shouldn't happen, right? } } /* does not seem to do much good at all if (nb&1) {b.push_back(b[nb-1]); e.push_back(e[nb-1]);} for (unsigned int i=0; i<nb; i+=2) { b[i]=b[i+1]=std::min(b[i],b[i+1]); } for (unsigned int i=0; i<nb; i+=2) { e[i]=e[i+1]=std::max(e[i],e[i+1]); } */ return true; }
bool process(const ColorRanges *srcRanges, const Images &images) { std::vector<ColorVal> pixel(images[0].numPlanes()); // fill buckets for (const Image& image : images) for (uint32_t r=0; r<image.rows(); r++) { for (uint32_t c=0; c<image.cols(); c++) { int p; for (p=0; p<image.numPlanes(); p++) { ColorVal v = image(p,r,c); pixel[p] = v; } if (image.alpha_zero_special && p>3 && pixel[3]==0) { cb->findBucket(3, pixel).addColor(0,max_per_colorbucket[3]); continue;} cb->addColor(pixel); } } cb->bucket0.simplify_lossless(); cb->bucket3.simplify_lossless(); for (auto& b : cb->bucket1) b.simplify_lossless(); for (auto& bv : cb->bucket2) for (auto& b : bv) b.simplify_lossless(); // TODO: IMPROVE THESE HEURISTICS! // TAKE IMAGE SIZE INTO ACCOUNT! // CONSIDER RELATIVE AREA OF BUCKETS / BOUNDS! // printf("Filled color buckets with %i discrete colors + %i continous buckets\n",totaldiscretecolors,totalcontinuousbuckets); int64_t total_pixels = (int64_t) images.size() * images[0].rows() * images[0].cols(); v_printf(7,", [D=%i,C=%i,P=%i]",totaldiscretecolors,totalcontinuousbuckets,(int) (total_pixels/100)); if (totaldiscretecolors < total_pixels/200 && totalcontinuousbuckets < total_pixels/50) return true; if (totaldiscretecolors < total_pixels/100 && totalcontinuousbuckets < total_pixels/200) return true; if (totaldiscretecolors < total_pixels/40 && totalcontinuousbuckets < total_pixels/500) return true; // simplify buckets for (int factor = 95; factor >= 35; factor -= 10) { for (auto& b : cb->bucket1) b.simplify(factor); for (auto& bv : cb->bucket2) for (auto& b : bv) b.simplify(factor-20); v_printf(8,"->[D=%i,C=%i]",totaldiscretecolors,totalcontinuousbuckets); if (totaldiscretecolors < total_pixels/200 && totalcontinuousbuckets < total_pixels/100) return true; } return false; }
// a heuristic to figure out if this is going to help (it won't help if we introduce more entropy than what is eliminated) bool process(const ColorRanges *srcRanges, const Images &images) { if (images.size() < 2) return false; int nump=images[0].numPlanes(); nb_frames = images.size(); int64_t pixel_cost = 1; for (int p=0; p<nump; p++) pixel_cost *= (1 + srcRanges->max(p) - srcRanges->min(p)); // pixel_cost is roughly the cost per pixel (number of different values a pixel can take) if (pixel_cost < 16) {v_printf(7,", no_FRA[pixels_too_cheap:%i]", pixel_cost); return false;} // pixels are too cheap, no point in trying to save stuff std::vector<uint64_t> found_pixels(images.size(), 0); uint64_t new_pixels=0; max_lookback=1; if (user_max_lookback == -1) user_max_lookback = images.size()-1; for (int fr=1; fr < (int)images.size(); fr++) { const Image& image = images[fr]; for (uint32_t r=0; r<image.rows(); r++) { for (uint32_t c=image.col_begin[r]; c<image.col_end[r]; c++) { new_pixels++; for (int prev=1; prev <= fr; prev++) { if (prev>user_max_lookback) break; bool identical=true; if (image.alpha_zero_special && nump>3 && image(3,r,c) == 0 && images[fr-prev](3,r,c) == 0) identical=true; else for (int p=0; p<nump; p++) { if(image(p,r,c) != images[fr-prev](p,r,c)) { identical=false; break;} } if (identical) { found_pixels[prev]++; new_pixels--; if (prev>max_lookback) max_lookback=prev; break;} } } } } if (images.size() > 2) v_printf(7,", trying_FRA(at -1: %llu, at -2: %llu, new: %llu)",(long long unsigned) found_pixels[1],(long long unsigned) found_pixels[2], (long long unsigned) new_pixels); if (max_lookback>256) max_lookback=256; for(int i=1; i <= max_lookback; i++) { v_printf(8,"at lookback %i: %llu pixels\n",-i, found_pixels[i]); if (found_pixels[i] <= new_pixels/200 || i>pixel_cost) {max_lookback=i-1; break;} found_pixels[0] += found_pixels[i]; } for(int i=max_lookback+1; i<(int)images.size(); i++) { if (found_pixels[i] > new_pixels/200 && i<pixel_cost) {max_lookback=i; found_pixels[0] += found_pixels[i];} else new_pixels += found_pixels[i]; } return (found_pixels[0] * pixel_cost > new_pixels * (2 + max_lookback)); };
void data(Images &images) const { for (int fr=1; fr < (int)images.size(); fr++) { uint32_t ipixels=0; Image& image = images[fr]; for (uint32_t r=0; r<image.rows(); r++) { for (uint32_t c=image.col_begin[r]; c<image.col_end[r]; c++) { for (int prev=1; prev <= fr; prev++) { if (prev>max_lookback) break; bool identical=true; if (image.alpha_zero_special && image(3,r,c) == 0 && images[fr-prev](3,r,c) == 0) identical=true; else for (int p=0; p<4; p++) { if(image(p,r,c) != images[fr-prev](p,r,c)) { identical=false; break;} } if (identical) {image.set(4,r,c, prev); ipixels++; break;} } } } // printf("frame %i: found %u pixels from previous frames\n", fr, ipixels); } }
Images FrameData::startReadback( const Frame& frame, util::ObjectManager& glObjects, const DrawableConfig& config, const PixelViewports& regions ) { if( _impl->data.buffers == Frame::BUFFER_NONE ) return Images(); const Zoom& zoom = frame.getZoom(); if( !zoom.isValid( )) { LBWARN << "Invalid zoom factor, skipping frame" << std::endl; return Images(); } const eq::PixelViewport& framePVP = getPixelViewport(); const PixelViewport absPVP = framePVP + frame.getOffset(); if( !absPVP.isValid( )) return Images(); Images images; // readback the whole screen when using textures if( getType() == eq::Frame::TYPE_TEXTURE ) { Image* image = newImage( getType(), config ); if( image->startReadback( getBuffers(), absPVP, zoom, glObjects )) images.push_back( image ); image->setOffset( 0, 0 ); return images; } //else read only required regions #if 0 // TODO: issue #85: move automatic ROI detection to eq::Channel PixelViewports regions; if( _impl->data.buffers & Frame::BUFFER_DEPTH && zoom == Zoom::NONE ) regions = _impl->roiFinder->findRegions( _impl->data.buffers, absPVP, zoom, frame.getAssemblyStage(), frame.getFrameID(), glObjects); else regions.push_back( absPVP ); #endif LBASSERT( getType() == eq::Frame::TYPE_MEMORY ); const eq::Pixel& pixel = getPixel(); for( uint32_t i = 0; i < regions.size(); ++i ) { PixelViewport pvp = regions[ i ] + frame.getOffset(); pvp.intersect( absPVP ); if( !pvp.hasArea( )) continue; Image* image = newImage( getType(), config ); if( image->startReadback( getBuffers(), pvp, zoom, glObjects )) images.push_back( image ); pvp -= frame.getOffset(); pvp.apply( zoom ); image->setOffset( (pvp.x - framePVP.x) * pixel.w, (pvp.y - framePVP.y) * pixel.h ); } return images; }
int main(int argc, char **argv) { Images images; int mode = 0; // 0 = encode, 1 = decode int method = 0; // 1=non-interlacing, 2=interlacing int quality = 100; // 100 = everything, positive value: partial decode, negative value: only rough data int learn_repeats = -1; int acb = -1; // try auto color buckets int scale = 1; int frame_delay = 100; int palette_size = 512; int lookback = 1; if (strcmp(argv[0],"flif") == 0) mode = 0; if (strcmp(argv[0],"dflif") == 0) mode = 1; if (strcmp(argv[0],"deflif") == 0) mode = 1; if (strcmp(argv[0],"decflif") == 0) mode = 1; static struct option optlist[] = { {"help", 0, NULL, 'h'}, {"encode", 0, NULL, 'e'}, {"decode", 0, NULL, 'd'}, {"first", 1, NULL, 'f'}, {"verbose", 0, NULL, 'v'}, {"interlace", 0, NULL, 'i'}, {"no-interlace", 0, NULL, 'n'}, {"acb", 0, NULL, 'a'}, {"no-acb", 0, NULL, 'b'}, {"quality", 1, NULL, 'q'}, {"scale", 1, NULL, 's'}, {"palette", 1, NULL, 'p'}, {"repeats", 1, NULL, 'r'}, {"frame-delay", 1, NULL, 'f'}, {"lookback", 1, NULL, 'l'}, {0, 0, 0, 0} }; int i,c; while ((c = getopt_long (argc, argv, "hedvinabq:s:p:r:f:l:", optlist, &i)) != -1) { switch (c) { case 'e': mode=0; break; case 'd': mode=1; break; case 'v': verbosity++; break; case 'i': if (method==0) method=2; break; case 'n': method=1; break; case 'a': acb=1; break; case 'b': acb=0; break; case 'p': palette_size=atoi(optarg); if (palette_size < -1 || palette_size > 30000) {fprintf(stderr,"Not a sensible number for option -p\n"); return 1; } if (palette_size == 0) {v_printf(2,"Palette disabled\n"); } break; case 'q': quality=atoi(optarg); if (quality < -1 || quality > 100) {fprintf(stderr,"Not a sensible number for option -q\n"); return 1; } break; case 's': scale=atoi(optarg); if (scale < 1 || scale > 128) {fprintf(stderr,"Not a sensible number for option -s\n"); return 1; } break; case 'r': learn_repeats=atoi(optarg); if (learn_repeats < 0 || learn_repeats > 1000) {fprintf(stderr,"Not a sensible number for option -r\n"); return 1; } break; case 'f': frame_delay=atoi(optarg); if (frame_delay < 0 || frame_delay > 60000) {fprintf(stderr,"Not a sensible number for option -f\n"); return 1; } break; case 'l': lookback=atoi(optarg); if (lookback < -1 || lookback > 256) {fprintf(stderr,"Not a sensible number for option -l\n"); return 1; } break; case 'h': default: show_help(); return 0; } } argc -= optind; argv += optind; v_printf(3," _____ __ (__) _____"); v_printf(3,"\n (___ || | | || ___) ");v_printf(2,"FLIF 0.1 [2 October 2015]"); v_printf(3,"\n (__ || |_|__|| __) Free Lossless Image Format"); v_printf(3,"\n (__||______) |__) (c) 2010-2015 J.Sneyers & P.Wuille, GNU GPL v3+\n"); v_printf(3,"\n"); if (argc == 0) { //fprintf(stderr,"Input file missing.\n"); if (verbosity == 1) show_help(); return 1; } if (argc == 1) { fprintf(stderr,"Output file missing.\n"); show_help(); return 1; } if (file_exists(argv[0])) { if (mode == 0 && file_is_flif(argv[0])) { v_printf(2,"Input file is a FLIF file, adding implicit -d\n"); mode = 1; } char *f = strrchr(argv[0],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[0],'.'); if (mode == 0) { if (ext && ( !strcasecmp(ext,".png") || !strcasecmp(ext,".pnm") || !strcasecmp(ext,".ppm") || !strcasecmp(ext,".pgm") || !strcasecmp(ext,".pbm") || !strcasecmp(ext,".pam"))) { // ok } else { fprintf(stderr,"Warning: expected \".png\" or \".pnm\" file name extension for input file, trying anyway...\n"); } } else { if (ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") ))) { // ok } else { fprintf(stderr,"Warning: expected file name extension \".flif\" for input file, trying anyway...\n"); } } } else if (argc>0) { fprintf(stderr,"Input file does not exist: %s\n",argv[0]); return 1; } if (mode == 0) { int nb_input_images = argc-1; while(argc>1) { Image image; v_printf(2,"\r"); if (!image.load(argv[0])) { fprintf(stderr,"Could not read input file: %s\n", argv[0]); return 2; }; images.push_back(image); if (image.rows() != images[0].rows() || image.cols() != images[0].cols() || image.numPlanes() != images[0].numPlanes()) { fprintf(stderr,"Dimensions of all input images should be the same!\n"); fprintf(stderr," First image is %ux%u, %i channels.\n",images[0].cols(),images[0].rows(),images[0].numPlanes()); fprintf(stderr," This image is %ux%u, %i channels: %s\n",image.cols(),image.rows(),image.numPlanes(),argv[0]); return 2; } argc--; argv++; if (nb_input_images>1) {v_printf(2," (%i/%i) ",(int)images.size(),nb_input_images); v_printf(4,"\n");} } v_printf(2,"\n"); bool flat=true; for (Image &image : images) if (image.uses_alpha()) flat=false; if (flat && images[0].numPlanes() == 4) { v_printf(2,"Alpha channel not actually used, dropping it.\n"); for (Image &image : images) image.drop_alpha(); } uint64_t nb_pixels = (uint64_t)images[0].rows() * images[0].cols(); std::vector<std::string> desc; desc.push_back("YIQ"); // convert RGB(A) to YIQ(A) desc.push_back("BND"); // get the bounds of the color spaces if (palette_size > 0) desc.push_back("PLA"); // try palette (including alpha) if (palette_size > 0) desc.push_back("PLT"); // try palette (without alpha) if (acb == -1) { // not specified if ACB should be used if (nb_pixels > 10000) desc.push_back("ACB"); // try auto color buckets on large images } else if (acb) desc.push_back("ACB"); // try auto color buckets if forced if (method == 0) { // no method specified, pick one heuristically if (nb_pixels < 10000) method=1; // if the image is small, not much point in doing interlacing else method=2; // default method: interlacing } if (images.size() > 1) { desc.push_back("DUP"); // find duplicate frames desc.push_back("FRS"); // get the shapes of the frames if (lookback != 0) desc.push_back("FRA"); // make a "deep" alpha channel (negative values are transparent to some previous frame) } if (learn_repeats < 0) { // no number of repeats specified, pick a number heuristically learn_repeats = TREE_LEARN_REPEATS; if (nb_pixels < 5000) learn_repeats--; // avoid large trees for small images if (learn_repeats < 0) learn_repeats=0; } encode(argv[0], images, desc, method, learn_repeats, acb, frame_delay, palette_size, lookback); } else { char *ext = strrchr(argv[1],'.'); if (ext && ( !strcasecmp(ext,".png") || !strcasecmp(ext,".pnm") || !strcasecmp(ext,".ppm") || !strcasecmp(ext,".pgm") || !strcasecmp(ext,".pbm") || !strcasecmp(ext,".pam"))) { // ok } else { fprintf(stderr,"Error: expected \".png\", \".pnm\" or \".pam\" file name extension for output file\n"); return 1; } if (!decode(argv[0], images, quality, scale)) return 3; if (scale>1) v_printf(3,"Downscaling output: %ux%u -> %ux%u\n",images[0].cols(),images[0].rows(),images[0].cols()/scale,images[0].rows()/scale); if (images.size() == 1) { if (!images[0].save(argv[1],scale)) return 2; } else { int counter=0; std::vector<char> vfilename(strlen(argv[1])+6); char *filename = &vfilename[0]; strcpy(filename,argv[1]); char *a_ext = strrchr(filename,'.'); for (Image& image : images) { sprintf(a_ext,"-%03d%s",counter++,ext); if (!image.save(filename,scale)) return 2; v_printf(2," (%i/%i) \r",counter,(int)images.size()); v_printf(4,"\n"); } } v_printf(2,"\n"); } for (Image &image : images) image.clear(); return 0; }
void *thumbStartWrapper_r ( void *state , ThreadEntry *t ) { Images *THIS = (Images *)state; THIS->thumbStart_r ( true /* am thread?*/ ); return NULL; }
// Use of ThreadEntry parameter is NOT thread safe void thumbStartWrapper_r ( void *state ) { Images *THIS = (Images *)state; THIS->thumbStart_r ( true /* am thread?*/ ); }
int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of 3D textures."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("--images [filenames]","Specify a stack of 2d images to build the 3d volume from."); arguments.getApplicationUsage()->addCommandLineOption("--shader","Use OpenGL Shading Language. (default)"); arguments.getApplicationUsage()->addCommandLineOption("--no-shader","Disable use of OpenGL Shading Language."); arguments.getApplicationUsage()->addCommandLineOption("--gpu-tf","Aply the transfer function on the GPU. (default)"); arguments.getApplicationUsage()->addCommandLineOption("--cpu-tf","Apply the transfer function on the CPU."); arguments.getApplicationUsage()->addCommandLineOption("--mip","Use Maximum Intensity Projection (MIP) filtering."); arguments.getApplicationUsage()->addCommandLineOption("--isosurface","Use Iso surface render."); arguments.getApplicationUsage()->addCommandLineOption("--light","Use normals computed on the GPU to render a lit volume."); arguments.getApplicationUsage()->addCommandLineOption("-n","Use normals computed on the GPU to render a lit volume."); arguments.getApplicationUsage()->addCommandLineOption("--xSize <size>","Relative width of rendered brick."); arguments.getApplicationUsage()->addCommandLineOption("--ySize <size>","Relative length of rendered brick."); arguments.getApplicationUsage()->addCommandLineOption("--zSize <size>","Relative height of rendered brick."); arguments.getApplicationUsage()->addCommandLineOption("--maxTextureSize <size>","Set the texture maximum resolution in the s,t,r (x,y,z) dimensions."); arguments.getApplicationUsage()->addCommandLineOption("--s_maxTextureSize <size>","Set the texture maximum resolution in the s (x) dimension."); arguments.getApplicationUsage()->addCommandLineOption("--t_maxTextureSize <size>","Set the texture maximum resolution in the t (y) dimension."); arguments.getApplicationUsage()->addCommandLineOption("--r_maxTextureSize <size>","Set the texture maximum resolution in the r (z) dimension."); arguments.getApplicationUsage()->addCommandLineOption("--modulate-alpha-by-luminance","For each pixel multiply the alpha value by the luminance."); arguments.getApplicationUsage()->addCommandLineOption("--replace-alpha-with-luminance","For each pixel set the alpha value to the luminance."); arguments.getApplicationUsage()->addCommandLineOption("--replace-rgb-with-luminance","For each rgb pixel convert to the luminance."); arguments.getApplicationUsage()->addCommandLineOption("--num-components <num>","Set the number of components to in he target image."); arguments.getApplicationUsage()->addCommandLineOption("--no-rescale","Disable the rescaling of the pixel data to 0.0 to 1.0 range"); arguments.getApplicationUsage()->addCommandLineOption("--rescale","Enable the rescale of the pixel data to 0.0 to 1.0 range (default)."); arguments.getApplicationUsage()->addCommandLineOption("--shift-min-to-zero","Shift the pixel data so min value is 0.0."); arguments.getApplicationUsage()->addCommandLineOption("--sequence-length <num>","Set the length of time that a sequence of images with run for."); arguments.getApplicationUsage()->addCommandLineOption("--sd <num>","Short hand for --sequence-length"); arguments.getApplicationUsage()->addCommandLineOption("--sdwm <num>","Set the SampleDensityWhenMovingProperty to specified value"); arguments.getApplicationUsage()->addCommandLineOption("--lod","Enable techniques to reduce the level of detail when moving."); // arguments.getApplicationUsage()->addCommandLineOption("--raw <sizeX> <sizeY> <sizeZ> <numberBytesPerComponent> <numberOfComponents> <endian> <filename>","read a raw image data"); // construct the viewer. osgViewer::Viewer viewer(arguments); // add the window size toggle handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); { osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); osgGA::FlightManipulator* flightManipulator = new osgGA::FlightManipulator(); flightManipulator->setYawControlMode(osgGA::FlightManipulator::NO_AUTOMATIC_YAW); keyswitchManipulator->addMatrixManipulator( '2', "Flight", flightManipulator ); viewer.setCameraManipulator( keyswitchManipulator.get() ); } // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); viewer.getCamera()->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout); return 1; } std::string outputFile; while (arguments.read("-o",outputFile)) {} osg::ref_ptr<osg::TransferFunction1D> transferFunction; std::string tranferFunctionFile; while (arguments.read("--tf",tranferFunctionFile)) { transferFunction = readTransferFunctionFile(tranferFunctionFile); } while (arguments.read("--tf-255",tranferFunctionFile)) { transferFunction = readTransferFunctionFile(tranferFunctionFile,1.0f/255.0f); } while(arguments.read("--test")) { transferFunction = new osg::TransferFunction1D; transferFunction->setColor(0.0, osg::Vec4(1.0,0.0,0.0,0.0)); transferFunction->setColor(0.5, osg::Vec4(1.0,1.0,0.0,0.5)); transferFunction->setColor(1.0, osg::Vec4(0.0,0.0,1.0,1.0)); } while(arguments.read("--test2")) { transferFunction = new osg::TransferFunction1D; transferFunction->setColor(0.0, osg::Vec4(1.0,0.0,0.0,0.0)); transferFunction->setColor(0.5, osg::Vec4(1.0,1.0,0.0,0.5)); transferFunction->setColor(1.0, osg::Vec4(0.0,0.0,1.0,1.0)); transferFunction->assign(transferFunction->getColorMap()); } { // deprecated options bool invalidOption = false; unsigned int numSlices=500; while (arguments.read("-s",numSlices)) { OSG_NOTICE<<"Warning: -s option no longer supported."<<std::endl; invalidOption = true; } float sliceEnd=1.0f; while (arguments.read("--clip",sliceEnd)) { OSG_NOTICE<<"Warning: --clip option no longer supported."<<std::endl; invalidOption = true; } if (invalidOption) return 1; } float xMultiplier=1.0f; while (arguments.read("--xMultiplier",xMultiplier)) {} float yMultiplier=1.0f; while (arguments.read("--yMultiplier",yMultiplier)) {} float zMultiplier=1.0f; while (arguments.read("--zMultiplier",zMultiplier)) {} float alphaFunc=0.02f; while (arguments.read("--alphaFunc",alphaFunc)) {} ShadingModel shadingModel = Standard; while(arguments.read("--mip")) shadingModel = MaximumIntensityProjection; while (arguments.read("--isosurface") || arguments.read("--iso-surface")) shadingModel = Isosurface; while (arguments.read("--light") || arguments.read("-n")) shadingModel = Light; float xSize=0.0f, ySize=0.0f, zSize=0.0f; while (arguments.read("--xSize",xSize)) {} while (arguments.read("--ySize",ySize)) {} while (arguments.read("--zSize",zSize)) {} osg::ref_ptr<TestSupportOperation> testSupportOperation = new TestSupportOperation; viewer.setRealizeOperation(testSupportOperation.get()); viewer.realize(); int maximumTextureSize = testSupportOperation->maximumTextureSize; int s_maximumTextureSize = maximumTextureSize; int t_maximumTextureSize = maximumTextureSize; int r_maximumTextureSize = maximumTextureSize; while(arguments.read("--maxTextureSize",maximumTextureSize)) { s_maximumTextureSize = maximumTextureSize; t_maximumTextureSize = maximumTextureSize; r_maximumTextureSize = maximumTextureSize; } while(arguments.read("--s_maxTextureSize",s_maximumTextureSize)) {} while(arguments.read("--t_maxTextureSize",t_maximumTextureSize)) {} while(arguments.read("--r_maxTextureSize",r_maximumTextureSize)) {} // set up colour space operation. osg::ColorSpaceOperation colourSpaceOperation = osg::NO_COLOR_SPACE_OPERATION; osg::Vec4 colourModulate(0.25f,0.25f,0.25f,0.25f); while(arguments.read("--modulate-alpha-by-luminance")) { colourSpaceOperation = osg::MODULATE_ALPHA_BY_LUMINANCE; } while(arguments.read("--modulate-alpha-by-colour", colourModulate.x(),colourModulate.y(),colourModulate.z(),colourModulate.w() )) { colourSpaceOperation = osg::MODULATE_ALPHA_BY_COLOR; } while(arguments.read("--replace-alpha-with-luminance")) { colourSpaceOperation = osg::REPLACE_ALPHA_WITH_LUMINANCE; } while(arguments.read("--replace-rgb-with-luminance")) { colourSpaceOperation = osg::REPLACE_RGB_WITH_LUMINANCE; } enum RescaleOperation { NO_RESCALE, RESCALE_TO_ZERO_TO_ONE_RANGE, SHIFT_MIN_TO_ZERO }; RescaleOperation rescaleOperation = RESCALE_TO_ZERO_TO_ONE_RANGE; while(arguments.read("--no-rescale")) rescaleOperation = NO_RESCALE; while(arguments.read("--rescale")) rescaleOperation = RESCALE_TO_ZERO_TO_ONE_RANGE; while(arguments.read("--shift-min-to-zero")) rescaleOperation = SHIFT_MIN_TO_ZERO; bool resizeToPowerOfTwo = false; unsigned int numComponentsDesired = 0; while(arguments.read("--num-components", numComponentsDesired)) {} bool useManipulator = false; while(arguments.read("--manipulator") || arguments.read("-m")) { useManipulator = true; } bool useShader = true; while(arguments.read("--shader")) { useShader = true; } while(arguments.read("--no-shader")) { useShader = false; } bool gpuTransferFunction = true; while(arguments.read("--gpu-tf")) { gpuTransferFunction = true; } while(arguments.read("--cpu-tf")) { gpuTransferFunction = false; } double sampleDensityWhenMoving = 0.0; while(arguments.read("--sdwm", sampleDensityWhenMoving)) {} while(arguments.read("--lod")) { sampleDensityWhenMoving = 0.02; } double sequenceLength = 10.0; while(arguments.read("--sequence-duration", sequenceLength) || arguments.read("--sd", sequenceLength)) {} typedef std::list< osg::ref_ptr<osg::Image> > Images; Images images; std::string vh_filename; while (arguments.read("--vh", vh_filename)) { std::string raw_filename, transfer_filename; int xdim(0), ydim(0), zdim(0); osgDB::ifstream header(vh_filename.c_str()); if (header) { header >> raw_filename >> transfer_filename >> xdim >> ydim >> zdim >> xSize >> ySize >> zSize; } if (xdim*ydim*zdim==0) { std::cout<<"Error in reading volume header "<<vh_filename<<std::endl; return 1; } if (!raw_filename.empty()) { images.push_back(readRaw(xdim, ydim, zdim, 1, 1, "little", raw_filename)); } if (!transfer_filename.empty()) { osgDB::ifstream fin(transfer_filename.c_str()); if (fin) { osg::TransferFunction1D::ColorMap colorMap; float value = 0.0; while(fin && value<=1.0) { float red, green, blue, alpha; fin >> red >> green >> blue >> alpha; if (fin) { colorMap[value] = osg::Vec4(red/255.0f,green/255.0f,blue/255.0f,alpha/255.0f); std::cout<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<")"; std::cout<<" ("<<colorMap[value]<<")"<<std::endl; } value += 1/255.0; } if (colorMap.empty()) { std::cout<<"Error: No values read from transfer function file: "<<transfer_filename<<std::endl; return 0; } transferFunction = new osg::TransferFunction1D; transferFunction->assign(colorMap); } } }