Hosting courtesy of Sourceforge

SourceForge Logo
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ImageSmooth.cpp

Go to the documentation of this file.
00001 //
00002 //                                 ImageSmooth.cpp
00003 //                             -------------------
00004 //    begin                : Sun Mar 3 2002
00005 //    copyright            : (C) 2002 by Rob Renaud
00006 //    email                : rrenaud@eden.rutgers.edu
00007 //
00008 //   This program is free software; you can redistribute it and/or modify
00009 //   it under the terms of the GNU General Public License as published by
00010 //   the Free Software Foundation; either version 2 of the License, or
00011 //   (at your option) any later version.
00012 //
00013 
00014 #include "../Config.h"
00015 #include "draw.h"
00016 #include <iostream>
00017 #include <cmath>
00018 
00019 using namespace Graphics;
00020 using std::cout;
00021 using std::endl;
00022 
00023 const int RED_DELTA=15;
00024 const int GREEN_DELTA=15;
00025 const int BLUE_DELTA=15;
00026 
00027 int main(int argc, char* argv[]) {
00028         if (argc < 2) {
00029                 return 0;
00030         }
00031         SDL_Init(SDL_INIT_VIDEO);
00032         SDL_Surface* screen=SDL_SetVideoMode(300, 300, 16, SDL_DOUBLEBUF);
00033         
00034         for (int i = 1; i < argc; i++) {
00035                 SDL_Surface* modImage = SDL_LoadBMP(argv[i]);
00036                 SDL_Surface* unmodImage = SDL_LoadBMP(argv[i]);
00037                 SDL_Surface* transUnmodifiedImage = SDL_LoadBMP(argv[i]);
00038                 
00039                 SDL_PixelFormat* f = modImage->format;
00040                 makeTopLeftPixelTrans(transUnmodifiedImage);
00041                 
00042                 Uint32 topLeftPixel = getpixel(modImage,0 , 0);
00043 
00044                 int red= (int) calcRedComp(f, topLeftPixel);
00045                 int green= (int) calcGreenComp(f ,topLeftPixel);
00046                 int blue= (int) calcBlueComp(f, topLeftPixel);
00047                 
00048                 for (int x = 0; x < modImage->w; x++) {
00049                         for (int y = 0; y < modImage->h; y++) {
00050                                 Uint32 curPixel = getpixel(modImage, x, y);
00051                                 
00052                                 int curRedDelta         =       abs(((int) calcRedComp  (f ,curPixel)) - red);
00053                                 int curGreenDelta       =       abs(((int) calcGreenComp(f ,curPixel)) - green);
00054                                 int curBlueDelta        =   abs(((int) calcBlueComp     (f ,curPixel)) - blue);
00055                                 
00056                                 if ( curRedDelta < RED_DELTA  && curGreenDelta < GREEN_DELTA
00057                                  && curBlueDelta < BLUE_DELTA && curPixel != topLeftPixel) {
00058                                         putpixel(modImage, x, y, topLeftPixel);
00059                                         cout << "Changed a pixel\t";
00060                                 }
00061                                 else {
00062                                         cout << "Not Change\t";
00063                                 }
00064                                 cout << curRedDelta << "\t" << curGreenDelta << "\t" << curBlueDelta << endl;                           
00065                         }
00066                 }
00067                 
00068                 while (1) {
00069                         bool innerLoopDone=false;
00070                         bool quit=false;
00071                         SDL_Rect loc;
00072                         loc.x=loc.y=0;
00073                         
00074                         SDL_FillRect(screen, NULL, 0);
00075                         SDL_BlitSurface(modImage, NULL, screen, &loc);
00076                         loc.x+=100;
00077                         SDL_BlitSurface(unmodImage, NULL, screen, &loc);
00078                         loc.x+=100;
00079                         SDL_BlitSurface(transUnmodifiedImage, NULL, screen, &loc);
00080                         
00081                         SDL_PumpEvents();
00082                         if (SDL_GetKeyState(NULL)[SDLK_y]) {
00083                                 SDL_SaveBMP(modImage, argv[i]);
00084                                 innerLoopDone=true;
00085                         }
00086                         if (SDL_GetKeyState(NULL)[SDLK_n]) {
00087                                 innerLoopDone=true;
00088                         }
00089                         if (SDL_GetKeyState(NULL)[SDLK_ESCAPE]) {
00090                                 innerLoopDone=quit=true;
00091                         }
00092                         SDL_Flip(screen);
00093                         if (innerLoopDone) {
00094                                 SDL_FreeSurface(modImage);
00095                                 SDL_FreeSurface(unmodImage);
00096                                 SDL_FreeSurface(transUnmodifiedImage);
00097                                 if (quit) return 0;
00098                                 break;
00099                         }
00100                 }
00101         }
00102         return 0;
00103 }

Generated on Tue May 21 07:26:51 2002 for BomberLAN by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001