blur - return 1 } // need a cast since atof returns a...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 // CS559-2008 Project 1 - Picture Processor // // 10/02/2008 // file: Blur.cpp // implements the Blur commands #include "PictureProcessor.H" #include "TargaImage.H" #define KERNEL_SIZE 9 // syntax blur V k class BlurCmd() : public Command { public: BlurCmd() : Command("blur", 3) {} TargaImage* img = context.getImage(cmd[1]) if (!img) { printf("Error! No image to Blur\n") return 1 } int k = atoi(cmd[2]) if (k < 0){ printf("Error! Blur parameter should not be negative\n") return 1 } // syntax desaturate V a class DesaturateCmd() : public Command { public: DesaturateCmd() : Command("desaturate", 3) {} TargaImage* img = context.getImage(cmd[1]) if (!img){ printf("Error! No image to desaturate\n")
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return 1 } // need a cast since atof returns a double float a = static_cast&lt;float&gt;(atof(cmd[2])) if (a&lt;0 || a&gt;1){ Sheet1 Page 2 printf(&quot;Error, the desaturate value should between 0 to 1\n&quot;) return 1 } if (a==0) return 1 else{ unsigned char* p = img-&gt;pixels() int i, k for (int y = 0 y &lt; (int)(img-&gt;heigth()) for (int x = 0 x &lt; (int)(img-&gt;width()) i = ( y * img-&gt;width() + x) * 4 // using this brightness formula k = (int)(0.3 * p[i] + 0.59 * p[i+1] + 0.11 * p[i+2]) p[i] = (int)((1.0 - a) * p[i] + a * k) p[i+1] = (int)((1.0 - a) * p[i+1] + a * k) p[i+2] = (int)((1.0 - a) * p[i+2] + a * k) } } } return 0 } } // be sure to create an instance of one of these DesaturateCmd desaturateCmd Sheet1 Page 3 Sheet1 Page 4 y++){ x++){...
View Full Document

Page1 / 4

blur - return 1 } // need a cast since atof returns a...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online