PTdecode/CImg-1.3.0/examples/use_draw_gradient.cpp

changeset 5
1204ebf9340d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/PTdecode/CImg-1.3.0/examples/use_draw_gradient.cpp	Mon Aug 03 14:09:20 2009 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +/*
     1.5 + #
     1.6 + #  File        : use_draw_gradient.cpp
     1.7 + #                ( C++ source file )
     1.8 + #
     1.9 + #  Description : Example of use for the CImg plugin 'plugins/draw_gradient.h'.
    1.10 + #                This file is a part of the CImg Library project.
    1.11 + #                ( http://cimg.sourceforge.net )
    1.12 + #
    1.13 + #  Copyright  : Jerome Boulanger
    1.14 + #                ( http://www.ricam.oeaw.ac.at/people/page.cgi?firstn=Jerome;lastn=Boulanger )
    1.15 + #
    1.16 + #  License     : CeCILL v2.0
    1.17 + #                ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
    1.18 + #
    1.19 + #  This software is governed by the CeCILL  license under French law and
    1.20 + #  abiding by the rules of distribution of free software.  You can  use,
    1.21 + #  modify and/ or redistribute the software under the terms of the CeCILL
    1.22 + #  license as circulated by CEA, CNRS and INRIA at the following URL
    1.23 + #  "http://www.cecill.info".
    1.24 + #
    1.25 + #  As a counterpart to the access to the source code and  rights to copy,
    1.26 + #  modify and redistribute granted by the license, users are provided only
    1.27 + #  with a limited warranty  and the software's author,  the holder of the
    1.28 + #  economic rights,  and the successive licensors  have only  limited
    1.29 + #  liability.
    1.30 + #
    1.31 + #  In this respect, the user's attention is drawn to the risks associated
    1.32 + #  with loading,  using,  modifying and/or developing or reproducing the
    1.33 + #  software by the user in light of its specific status of free software,
    1.34 + #  that may mean  that it is complicated to manipulate,  and  that  also
    1.35 + #  therefore means  that it is reserved for developers  and  experienced
    1.36 + #  professionals having in-depth computer knowledge. Users are therefore
    1.37 + #  encouraged to load and test the software's suitability as regards their
    1.38 + #  requirements in conditions enabling the security of their systems and/or
    1.39 + #  data to be ensured and,  more generally, to use and operate it in the
    1.40 + #  same conditions as regards security.
    1.41 + #
    1.42 + #  The fact that you are presently reading this means that you have had
    1.43 + #  knowledge of the CeCILL license and that you accept its terms.
    1.44 + #
    1.45 +*/
    1.46 +
    1.47 +#define cimg_plugin "plugins/draw_gradient.h"
    1.48 +#include "CImg.h"
    1.49 +using namespace cimg_library;
    1.50 +
    1.51 +// The lines below are necessary when using a non-standard compiler as visualcpp6.
    1.52 +#ifdef cimg_use_visualcpp6
    1.53 +#define std
    1.54 +#endif
    1.55 +#ifdef min
    1.56 +#undef min
    1.57 +#undef max
    1.58 +#endif
    1.59 +
    1.60 +// Main procedure
    1.61 +//---------------
    1.62 +int main(int argc,char **argv) {
    1.63 +
    1.64 +  // Read command line arguments
    1.65 +  //----------------------------
    1.66 +  cimg_usage("Example of the use of draw_gradient CImg plugin");
    1.67 +  const char *const file_i  = cimg_option("-i",(char*)0,"Input image");
    1.68 +  const int shape  = cimg_option("-s",1,"shape [0,6]");
    1.69 +  const int profile  = cimg_option("-p",0,"profile [0,7]");
    1.70 +
    1.71 +  // Define an image
    1.72 +  CImg<unsigned char> img;
    1.73 +  if (file_i) img.load(file_i).resize(-100,-100,-100,3);
    1.74 +  else img.assign(300,200,1,3,0);
    1.75 +
    1.76 +  // Define the color of the gradient
    1.77 +  CImg<unsigned char> col(3);
    1.78 +  const unsigned char col1[3] = { 0,0,255 }, col2[3] = { 255,255,255 };
    1.79 +  CImgDisplay disp(img,"Click and drag to create color gradient",0);
    1.80 +  while (!disp.is_closed && !disp.key) {
    1.81 +
    1.82 +    // Get a vector direction from the user.
    1.83 +    const CImg<int> selection = img.get_select(disp,1);
    1.84 +
    1.85 +    // Draw a gradient using the selected coordinated.
    1.86 +    col.rand(100,255);
    1.87 +    printf("Gradient with %s from color (%d,%d,%d) to (%d,%d,%d)\n",
    1.88 +           CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2),col1[0],col1[1],col2[2]);
    1.89 +    img.draw_gradient(selection(0),selection(1),selection(3),selection(4),
    1.90 +                      col.ptr(),col1,shape,profile,.7f).display(disp);
    1.91 +  }
    1.92 +
    1.93 +  // color 0 to transparency
    1.94 +  if (file_i) img.load(file_i).resize(-100,-100,-100,3);
    1.95 +  else img.assign(300,200,1,3,0);
    1.96 +  img.display(disp);
    1.97 +  disp.show().flush();
    1.98 +  while (!disp.is_closed && !disp.key) {
    1.99 +
   1.100 +    // Get a vector direction from the user.
   1.101 +    const CImg<int> selection = img.get_select(disp,1);
   1.102 +
   1.103 +    // Draw a gradient using the selected coordinated.
   1.104 +    col.rand(100,255);
   1.105 +    printf("Gradient with %s from color (%d,%d,%d) to transparency\n",
   1.106 +           CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2));
   1.107 +    img.draw_gradient(selection(0),selection(1),selection(3),selection(4),
   1.108 +                      col.ptr(),0,shape,profile,.7f).display(disp);
   1.109 +  }
   1.110 +
   1.111 +
   1.112 +  // transparency to color 1
   1.113 +  if (file_i) img.load(file_i).resize(-100,-100,-100,3);
   1.114 +  else img.assign(300,200,1,3,0);
   1.115 +  img.display(disp);
   1.116 +  disp.show().flush();
   1.117 +  while (!disp.is_closed && !disp.key) {
   1.118 +
   1.119 +    // Get a vector direction from the user.
   1.120 +    const CImg<int> selection = img.get_select(disp,1);
   1.121 +
   1.122 +    // Draw a gradient using the selected coordinated.
   1.123 +    col.rand(100,255);
   1.124 +    printf("Gradient with %s from transparency to color (%d,%d,%d)\n",
   1.125 +           CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2));
   1.126 +    img.draw_gradient(selection(0),selection(1),selection(3),selection(4),
   1.127 +                      0,col.ptr(),shape,profile,.7f).display(disp);
   1.128 +  }
   1.129 +
   1.130 +  // random
   1.131 +  if (file_i) img.load(file_i).resize(-100,-100,-100,3);
   1.132 +  else img.assign(300,200,1,3,0);
   1.133 +  disp.set_title("Random color gradient").show().flush();
   1.134 +  CImg<unsigned char> visu(img);
   1.135 +  visu.display(disp);
   1.136 +  while (!disp.is_closed && !disp.key) {
   1.137 +    const int
   1.138 +      x = (int)(cimg::rand()*visu.dimx()),
   1.139 +      y = (int)(cimg::rand()*visu.dimy()),
   1.140 +      rx = (int)((cimg::rand()*25+5)*(cimg::rand()>.5?-1:1)),
   1.141 +      ry = (int)((cimg::rand()*25+5)*(cimg::rand()>.5?-1:1));
   1.142 +    col.rand(64,255);
   1.143 +    img.draw_gradient(x,y,x+rx,y+ry,col.ptr(),0,shape,profile,.4f);
   1.144 +    visu = img;
   1.145 +    visu.draw_text(10,10,"%.1ffps",col2,0,1,11,disp.frames_per_second()).display(disp);
   1.146 +    if (disp.is_resized) disp.resize();
   1.147 +  }
   1.148 +
   1.149 +  return 0;
   1.150 +}