473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

save(char* filename)

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<yres;i++)
image[i] = new Color[xres];
}
Image::~Image()
{
if(image)
{
for (int i=0;i<yres;i++)
delete[] image[i];

delete[] image;
}
}
void Image::save(char* filename)
{

}

#ifndef IMAGE_H
#define IMAGE_H 1

/* A Color is a RGB float.
**
** R, G, and B are all in the range [0..1]
**
** This class allows you to add, subtract, and multiply colors,
** It also allows you to get the separate components (e.g.,
myColor.red() ),
** use constructions like "myColor += yourColor;"
*/
class Color
{
float r,g,b;
public:
inline Color(): r(0), g(0), b(0) {}
inline Color(float r, float g, float b) : r(r), g(g), b(b){}
inline ~Color() {}
inline Color operator*(const Color& c) const
{
return Color(r*c.r, g*c.g, b*c.b);
}
inline Color operator+(const Color& c) const
{
return Color(r+c.r, g+c.g, b+c.b);
}
inline Color operator-(const Color& c) const
{
return Color(r-c.r, g-c.g, b-c.b);
}
inline Color operator*(float s) const
{
return Color(r*s, g*s, b*s);
}
inline Color& operator+=(const Color& c)
{
r+=c.r;
g+=c.g;
b+=c.b;
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;
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 3988
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;i<yres;i++)
image[i] = new Color[xres];
}
Image::~Image()
{
if(image)
{
for (int i=0;i<yres;i++)
delete[] image[i];

delete[] image;
}
}
Read about "The Rule of Three".
void Image::save(char* filename)
If you intend to provide the file name as a string literal (in double
quotes), then I strongly recommend you use 'const char*' as your argument
instead of a pointer to non-const char:

void Image::save(const char* filename)

Also it would be nice if it has either 'bool' or 'int' return value to
indicate the success or failure or threw an exception...
{

}

#ifndef IMAGE_H
#define IMAGE_H 1

/* A Color is a RGB float.
**
** R, G, and B are all in the range [0..1]
**
** This class allows you to add, subtract, and multiply colors,
** It also allows you to get the separate components (e.g.,
myColor.red() ),
** use constructions like "myColor += yourColor;"
*/
class Color
{
float r,g,b;
public:
inline Color(): r(0), g(0), b(0) {}
inline Color(float r, float g, float b) : r(r), g(g), b(b){}
inline ~Color() {}
inline Color operator*(const Color& c) const
{
return Color(r*c.r, g*c.g, b*c.b);
}
inline Color operator+(const Color& c) const
{
return Color(r+c.r, g+c.g, b+c.b);
Watch out for overflow. If this->r 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
Sorry to be confusing but I was just wondering how I should go about
creating the void save(char* file).

Sep 7 '05 #3
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
"George" <bu*******@hotmail.com> 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.

<http://www.mindview.net/Books>

Also of interest is the group FAQ, esp. section 15:

<http://www.parashift.com/c++-faq-lite/>

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Sep 7 '05 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Olav Tollefsen | last post by:
I have an .aspx file with the following code in Form_Load: image = System.Drawing.Image.FromFile(imageFilename); Response.ContentType = "image/jpeg"; image.Save(Response.OutputStream,...
2
by: Peter Proost | last post by:
Hi group when save a bitmap called saveBmp like this: <<<< saveBmp.Save(filename, ImageFormat.Jpeg) <<<< the bitmap gets saved with it's size propertys, so if I right click the file and...
1
by: DSchlichte | last post by:
Hello ' I need some help. I've created a little application to paint, save and load pictures (Bitmap-graphics) into ' a picturebox-object on the desktop. There's no problem to paint or to load...
1
by: liuhengyi | last post by:
Hi, I have a test program that creates 5 threads and each thread uses XmlDocument.Save(filename) to save a Xml dom to a file. I have put the lock statement around the Save to prevent from...
4
by: Frank | last post by:
Private Sub SaveBitmap(ByVal fileName As String, ByVal p As System.Drawing.Bitmap) ...snip p.Save(fileName, Imaging.ImageFormat.Icon) Does not produce an icon formatted file. At least if I...
0
by: AnfieldRoar | last post by:
Hi, if I load an XML file, then modify a value, then try to save it I get an exception, access denied error. I've tried everything - help please???? For example: XmlReaderSettings settings =...
0
by: Darqer | last post by:
Hello There is a possibility to show DownloadFile form in web browser using following peace of code HttpContext context = HttpContext.Current; context.Response.ContentType =...
2
by: Navpreet Singh | last post by:
Hello Sir The code given below is the vxml code in which i can record my voice but when i want to try to save the recorded file using php script the error occours. The php code is also given below....
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.