Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleChessboard.cpp

Example for drawing a chessboard in an image

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleChessboard.cpp
@brief Example for drawing a chessboard in an image
@ingroup g_examples
@author MIP
*/
// must be first:
//#include <Base/Common/LeakChecking.h>
#include <iostream>
#include <Base/Image/ImageBase.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/ImageIO.hh>
using namespace BIAS;
using namespace std;
int main()
{
unsigned int size=2048;
Image<unsigned char> im(size, size, 1);
unsigned int chess_field_size=128;
unsigned int x=0, y=0, c=0, r=0;
unsigned char color=0;
unsigned char **ida=im.GetImageDataArray();
for (y=chess_field_size; y<=im.GetHeight(); y+=chess_field_size){
for (x=chess_field_size; x<=im.GetHeight(); x+=chess_field_size){
if (y==chess_field_size)
color = (color==0) ? (unsigned char)255 : (unsigned char)0;
else
color = (ida[y-chess_field_size-1][x-1]==0) ?
(unsigned char)255 : (unsigned char)0;
for (r=1; r<=chess_field_size; r++){
for (c=1; c<=chess_field_size; c++){
ida[y-r][x-c]=color;
}
}
}
}
//if (ImageIO::Save("chessboard", im)!=0){
if (ImageIO::Save("chessboard", im)!=0){
BIASERR("error writing image ");
return -2;
}
if (ImageIO::Save("chessboard", im, ImageIO::FF_ppm)!=0){
BIASERR("error exporting image ");
return -2;
}
return 0;
}