Wed, 05 Aug 2009 15:02:31 +0100
PTdecode: add support for uncompressed data (NOTE: *NOT* supported by the PT-2450DX)
philpem@5 | 1 | /* |
philpem@5 | 2 | # |
philpem@5 | 3 | # File : use_draw_gradient.cpp |
philpem@5 | 4 | # ( C++ source file ) |
philpem@5 | 5 | # |
philpem@5 | 6 | # Description : Example of use for the CImg plugin 'plugins/draw_gradient.h'. |
philpem@5 | 7 | # This file is a part of the CImg Library project. |
philpem@5 | 8 | # ( http://cimg.sourceforge.net ) |
philpem@5 | 9 | # |
philpem@5 | 10 | # Copyright : Jerome Boulanger |
philpem@5 | 11 | # ( http://www.ricam.oeaw.ac.at/people/page.cgi?firstn=Jerome;lastn=Boulanger ) |
philpem@5 | 12 | # |
philpem@5 | 13 | # License : CeCILL v2.0 |
philpem@5 | 14 | # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) |
philpem@5 | 15 | # |
philpem@5 | 16 | # This software is governed by the CeCILL license under French law and |
philpem@5 | 17 | # abiding by the rules of distribution of free software. You can use, |
philpem@5 | 18 | # modify and/ or redistribute the software under the terms of the CeCILL |
philpem@5 | 19 | # license as circulated by CEA, CNRS and INRIA at the following URL |
philpem@5 | 20 | # "http://www.cecill.info". |
philpem@5 | 21 | # |
philpem@5 | 22 | # As a counterpart to the access to the source code and rights to copy, |
philpem@5 | 23 | # modify and redistribute granted by the license, users are provided only |
philpem@5 | 24 | # with a limited warranty and the software's author, the holder of the |
philpem@5 | 25 | # economic rights, and the successive licensors have only limited |
philpem@5 | 26 | # liability. |
philpem@5 | 27 | # |
philpem@5 | 28 | # In this respect, the user's attention is drawn to the risks associated |
philpem@5 | 29 | # with loading, using, modifying and/or developing or reproducing the |
philpem@5 | 30 | # software by the user in light of its specific status of free software, |
philpem@5 | 31 | # that may mean that it is complicated to manipulate, and that also |
philpem@5 | 32 | # therefore means that it is reserved for developers and experienced |
philpem@5 | 33 | # professionals having in-depth computer knowledge. Users are therefore |
philpem@5 | 34 | # encouraged to load and test the software's suitability as regards their |
philpem@5 | 35 | # requirements in conditions enabling the security of their systems and/or |
philpem@5 | 36 | # data to be ensured and, more generally, to use and operate it in the |
philpem@5 | 37 | # same conditions as regards security. |
philpem@5 | 38 | # |
philpem@5 | 39 | # The fact that you are presently reading this means that you have had |
philpem@5 | 40 | # knowledge of the CeCILL license and that you accept its terms. |
philpem@5 | 41 | # |
philpem@5 | 42 | */ |
philpem@5 | 43 | |
philpem@5 | 44 | #define cimg_plugin "plugins/draw_gradient.h" |
philpem@5 | 45 | #include "CImg.h" |
philpem@5 | 46 | using namespace cimg_library; |
philpem@5 | 47 | |
philpem@5 | 48 | // The lines below are necessary when using a non-standard compiler as visualcpp6. |
philpem@5 | 49 | #ifdef cimg_use_visualcpp6 |
philpem@5 | 50 | #define std |
philpem@5 | 51 | #endif |
philpem@5 | 52 | #ifdef min |
philpem@5 | 53 | #undef min |
philpem@5 | 54 | #undef max |
philpem@5 | 55 | #endif |
philpem@5 | 56 | |
philpem@5 | 57 | // Main procedure |
philpem@5 | 58 | //--------------- |
philpem@5 | 59 | int main(int argc,char **argv) { |
philpem@5 | 60 | |
philpem@5 | 61 | // Read command line arguments |
philpem@5 | 62 | //---------------------------- |
philpem@5 | 63 | cimg_usage("Example of the use of draw_gradient CImg plugin"); |
philpem@5 | 64 | const char *const file_i = cimg_option("-i",(char*)0,"Input image"); |
philpem@5 | 65 | const int shape = cimg_option("-s",1,"shape [0,6]"); |
philpem@5 | 66 | const int profile = cimg_option("-p",0,"profile [0,7]"); |
philpem@5 | 67 | |
philpem@5 | 68 | // Define an image |
philpem@5 | 69 | CImg<unsigned char> img; |
philpem@5 | 70 | if (file_i) img.load(file_i).resize(-100,-100,-100,3); |
philpem@5 | 71 | else img.assign(300,200,1,3,0); |
philpem@5 | 72 | |
philpem@5 | 73 | // Define the color of the gradient |
philpem@5 | 74 | CImg<unsigned char> col(3); |
philpem@5 | 75 | const unsigned char col1[3] = { 0,0,255 }, col2[3] = { 255,255,255 }; |
philpem@5 | 76 | CImgDisplay disp(img,"Click and drag to create color gradient",0); |
philpem@5 | 77 | while (!disp.is_closed && !disp.key) { |
philpem@5 | 78 | |
philpem@5 | 79 | // Get a vector direction from the user. |
philpem@5 | 80 | const CImg<int> selection = img.get_select(disp,1); |
philpem@5 | 81 | |
philpem@5 | 82 | // Draw a gradient using the selected coordinated. |
philpem@5 | 83 | col.rand(100,255); |
philpem@5 | 84 | printf("Gradient with %s from color (%d,%d,%d) to (%d,%d,%d)\n", |
philpem@5 | 85 | CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2),col1[0],col1[1],col2[2]); |
philpem@5 | 86 | img.draw_gradient(selection(0),selection(1),selection(3),selection(4), |
philpem@5 | 87 | col.ptr(),col1,shape,profile,.7f).display(disp); |
philpem@5 | 88 | } |
philpem@5 | 89 | |
philpem@5 | 90 | // color 0 to transparency |
philpem@5 | 91 | if (file_i) img.load(file_i).resize(-100,-100,-100,3); |
philpem@5 | 92 | else img.assign(300,200,1,3,0); |
philpem@5 | 93 | img.display(disp); |
philpem@5 | 94 | disp.show().flush(); |
philpem@5 | 95 | while (!disp.is_closed && !disp.key) { |
philpem@5 | 96 | |
philpem@5 | 97 | // Get a vector direction from the user. |
philpem@5 | 98 | const CImg<int> selection = img.get_select(disp,1); |
philpem@5 | 99 | |
philpem@5 | 100 | // Draw a gradient using the selected coordinated. |
philpem@5 | 101 | col.rand(100,255); |
philpem@5 | 102 | printf("Gradient with %s from color (%d,%d,%d) to transparency\n", |
philpem@5 | 103 | CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2)); |
philpem@5 | 104 | img.draw_gradient(selection(0),selection(1),selection(3),selection(4), |
philpem@5 | 105 | col.ptr(),0,shape,profile,.7f).display(disp); |
philpem@5 | 106 | } |
philpem@5 | 107 | |
philpem@5 | 108 | |
philpem@5 | 109 | // transparency to color 1 |
philpem@5 | 110 | if (file_i) img.load(file_i).resize(-100,-100,-100,3); |
philpem@5 | 111 | else img.assign(300,200,1,3,0); |
philpem@5 | 112 | img.display(disp); |
philpem@5 | 113 | disp.show().flush(); |
philpem@5 | 114 | while (!disp.is_closed && !disp.key) { |
philpem@5 | 115 | |
philpem@5 | 116 | // Get a vector direction from the user. |
philpem@5 | 117 | const CImg<int> selection = img.get_select(disp,1); |
philpem@5 | 118 | |
philpem@5 | 119 | // Draw a gradient using the selected coordinated. |
philpem@5 | 120 | col.rand(100,255); |
philpem@5 | 121 | printf("Gradient with %s from transparency to color (%d,%d,%d)\n", |
philpem@5 | 122 | CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2)); |
philpem@5 | 123 | img.draw_gradient(selection(0),selection(1),selection(3),selection(4), |
philpem@5 | 124 | 0,col.ptr(),shape,profile,.7f).display(disp); |
philpem@5 | 125 | } |
philpem@5 | 126 | |
philpem@5 | 127 | // random |
philpem@5 | 128 | if (file_i) img.load(file_i).resize(-100,-100,-100,3); |
philpem@5 | 129 | else img.assign(300,200,1,3,0); |
philpem@5 | 130 | disp.set_title("Random color gradient").show().flush(); |
philpem@5 | 131 | CImg<unsigned char> visu(img); |
philpem@5 | 132 | visu.display(disp); |
philpem@5 | 133 | while (!disp.is_closed && !disp.key) { |
philpem@5 | 134 | const int |
philpem@5 | 135 | x = (int)(cimg::rand()*visu.dimx()), |
philpem@5 | 136 | y = (int)(cimg::rand()*visu.dimy()), |
philpem@5 | 137 | rx = (int)((cimg::rand()*25+5)*(cimg::rand()>.5?-1:1)), |
philpem@5 | 138 | ry = (int)((cimg::rand()*25+5)*(cimg::rand()>.5?-1:1)); |
philpem@5 | 139 | col.rand(64,255); |
philpem@5 | 140 | img.draw_gradient(x,y,x+rx,y+ry,col.ptr(),0,shape,profile,.4f); |
philpem@5 | 141 | visu = img; |
philpem@5 | 142 | visu.draw_text(10,10,"%.1ffps",col2,0,1,11,disp.frames_per_second()).display(disp); |
philpem@5 | 143 | if (disp.is_resized) disp.resize(); |
philpem@5 | 144 | } |
philpem@5 | 145 | |
philpem@5 | 146 | return 0; |
philpem@5 | 147 | } |