/************************************************************************/ // compile as: // fltk-config --use-images --compile twin_image.cxx // // invoke as: // twin_image somefile.jpg (should work with many image types, jpg, png, etc...) #include #include #include #include #include #include #include #include #include #include Fl_Double_Window *main_win = NULL; Fl_Shared_Image *img = NULL; Fl_RGB_Image *img_3 = NULL; int depth = 0; int count = 0; int width = 0; int height = 0; const char *datap = NULL; int xoff = 0; int yoff = 0; const double frame_delay = (1.0 / 10.0); /************************************************************************/ Fl_Box *box_1; Fl_Box *box_3; /************************************************************************/ void load_file(const char *n) { if (img) img->release(); img = Fl_Shared_Image::get(n); if (!img) { puts("Image file format not recognized!"); fflush(stdout); return; } if (img->w() > box_1->w() || img->h() > box_1->h()) { Fl_Image *temp; if (img->w() > img->h()) temp = img->copy(box_1->w(), box_1->h() * img->h() / img->w()); else temp = img->copy(box_1->w() * img->w() / img->h(), box_1->h()); img->release(); img = (Fl_Shared_Image *)temp; } box_1->image(img); box_1->redraw(); } // load_file /************************************************************************/ void quit_cb(Fl_Button *, void *) { main_win->hide(); } // quit_cb /************************************************************************/ void process_cb(void *) { unsigned total = width * height * depth; static char *processed_data = NULL; if (processed_data == NULL) { // setup processed data processed_data = new char [total]; for (unsigned idx = 0; idx < total; idx ++) { processed_data[idx] = datap[idx]; } } else { // process data for (unsigned idx = 0; idx < total; idx ++) { processed_data[idx] = (processed_data[idx] + 3) & 0xFF; } } if (img_3 != NULL) { delete img_3; } img_3 = new Fl_RGB_Image((const uchar *)processed_data, width, height, depth); box_3->image(img_3); box_3->redraw(); Fl::repeat_timeout(frame_delay, process_cb); } // process_cb /************************************************************************/ int main(int argc, char **argv) { fl_register_images(); Fl::get_system_colors(); main_win = new Fl_Double_Window(615, 300); main_win->begin(); box_1 = new Fl_Box(0, 0, 200, 200); box_3 = new Fl_Box(410, 0, 200, 200); Fl_Button *quit = new Fl_Button(540, 260, 60, 30); quit->label("Quit"); quit->callback((Fl_Callback *)quit_cb); main_win->end(); if (argv[1]) { load_file(argv[1]); } else { printf("Need a file ot process\n"); return -1; } depth = img->d(); count = img->count(); datap = img->data()[0]; width = img->w(); height = img->h(); if (height < box_1->h()) { yoff = (box_1->h() - height) / 2; } if (width < box_1->w()) { xoff = (box_1->w() - width) / 2; } printf("Depth: %d Count: %d W: %d H: %d\n", depth, count, width, height); printf("X offs %d Y offs %d\n", xoff, yoff); fflush(stdout); main_win->show(); // animate the refresh Fl::add_timeout(frame_delay, process_cb); return Fl::run(); } // main /* End of File */