432,257 Members | 928 Online
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

# save(char* filename)

 P: n/a This program need to draw the some triangles into a 512 × 512 buffer (in memory). Or save it to a file. #include "project3.h" Image::Image(int xres, int yres): xres(xres), yres(yres) { image =new Color*[yres]; for (int i=0;i r? g : r); return (b > temp? b : temp); } }; /* An image is a collection of xres*yres Colors. ** ** You can write to a pixel by saying "myImage(x,y) = Color(1, 0.5, 0);" ** ** You can save the entire image to a PPM file by calling myImage.save("output.ppm"); */ class Image { float* buf; Color** image; int xres, yres; public: Image(int xres, int yres); ~Image(); inline int getXRes() const { return xres; } inline int getYRes() const { return yres; } inline Color& operator()(int x, int y) { return image[y][x]; } void save(char* file); }; #endif Sep 7 '05 #1
5 Replies

 P: n/a George wrote: This program need to draw the some triangles into a 512 × 512 buffer (in memory). Or save it to a file. If you're seeking comments, see below. If you're not, explain what it is you want next time. #include "project3.h" Image::Image(int xres, int yres): xres(xres), yres(yres) { image =new Color*[yres]; for (int i=0;ir is 0.8 and c.r is 0.7, the resulting Color will have r == 1.5, which is definitely not in the range [0..1]. } inline Color operator-(const Color& c) const { return Color(r-c.r, g-c.g, b-c.b); Same notion here. If 'c.r' is smaller than 'this->r', you can slip into the negative values... } inline Color operator*(float s) const { return Color(r*s, g*s, b*s); Same here. No checking apparently is done. You desperately need to make sure the results are in the range. } inline Color& operator+=(const Color& c) { r+=c.r; g+=c.g; b+=c.b; Same here. return *this; } inline float red() const { return r; } inline float green() const { return g; } inline float blue() const { return b; } inline float luminance() const { return (float)(0.3*g + 0.6*r + 0.1*b); } inline float max_component() const { float temp = (g > r? g : r); return (b > temp? b : temp); } }; /* An image is a collection of xres*yres Colors. ** ** You can write to a pixel by saying "myImage(x,y) = Color(1, 0.5, 0);" ** ** You can save the entire image to a PPM file by calling myImage.save("output.ppm"); */ class Image { float* buf; ^^^^^^^^^^^ This member variable doesn't seem to be used... Color** image; int xres, yres; public: Image(int xres, int yres); ~Image(); inline int getXRes() const { return xres; } inline int getYRes() const { return yres; } inline Color& operator()(int x, int y) { return image[y][x]; } void save(char* file); }; #endif V Sep 7 '05 #2

 P: n/a Sorry to be confusing but I was just wondering how I should go about creating the void save(char* file). Sep 7 '05 #3

 P: n/a George wrote: Sorry to be confusing but I was just wondering how I should go about creating the void save(char* file). When I dream, I have a pony. Socks Sep 7 '05 #4

 P: n/a "George" writes: Sorry to be confusing but I was just wondering how I should go about creating the void save(char* file). Have a look at the "Thinking in C++" books, especially Vol. 2, Ch. 4, which discusses C++'s standard iostream classes. Also of interest is the group FAQ, esp. section 15: sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org Sep 7 '05 #5

 P: n/a George wrote: Sorry to be confusing but I was just wondering how I should go about creating the void save(char* file). You should open a file stream for output, then output the data the way you need it to be in the file, then close the stream. Then return from the function. Or just return without closing, it will close itself. V Sep 7 '05 #6

### This discussion thread is closed

Replies have been disabled for this discussion.