mirror of
https://github.com/minetest/minetestmapper.git
synced 2025-07-01 08:00:22 +02:00
Add a load function to Image, also add some consts.
This commit is contained in:
21
Image.cpp
21
Image.cpp
@ -74,7 +74,7 @@ void Image::setPixel(int x, int y, const Color &c)
|
|||||||
m_image->tpixels[y][x] = color2int(c);
|
m_image->tpixels[y][x] = color2int(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color Image::getPixel(int x, int y)
|
Color Image::getPixel(int x, int y) const
|
||||||
{
|
{
|
||||||
SIZECHECK_FUZZY(x, y);
|
SIZECHECK_FUZZY(x, y);
|
||||||
return int2color(m_image->tpixels[y][x]);
|
return int2color(m_image->tpixels[y][x]);
|
||||||
@ -106,7 +106,7 @@ void Image::drawCircle(int x, int y, int diameter, const Color &c)
|
|||||||
gdImageArc(m_image, x, y, diameter, diameter, 0, 360, color2int(c));
|
gdImageArc(m_image, x, y, diameter, diameter, 0, 360, color2int(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::save(const std::string &filename)
|
void Image::save(const std::string &filename) const
|
||||||
{
|
{
|
||||||
#if (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION == 1 && GD_RELEASE_VERSION >= 1) || (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION > 1) || GD_MAJOR_VERSION > 2
|
#if (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION == 1 && GD_RELEASE_VERSION >= 1) || (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION > 1) || GD_MAJOR_VERSION > 2
|
||||||
const char *f = filename.c_str();
|
const char *f = filename.c_str();
|
||||||
@ -128,6 +128,23 @@ void Image::save(const std::string &filename)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Image::Image(std::string const &fileName)
|
||||||
|
{
|
||||||
|
m_image = gdImageCreateFromFile(fileName.c_str());
|
||||||
|
|
||||||
|
if (!m_image)
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "Error loading image file: " << fileName;
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Image::scaleBlit(Image *to, int x, int y, int w, int h) const
|
||||||
|
{
|
||||||
|
gdImageCopyResampled(to->m_image, m_image, x,y, 0,0, w, h, gdImageSX(m_image),gdImageSY(m_image));
|
||||||
|
}
|
||||||
|
|
||||||
void Image::fill(Color &c)
|
void Image::fill(Color &c)
|
||||||
{
|
{
|
||||||
|
@ -16,16 +16,18 @@ struct Color {
|
|||||||
|
|
||||||
class Image {
|
class Image {
|
||||||
public:
|
public:
|
||||||
|
Image(const std::string &fileName);
|
||||||
Image(int width, int height);
|
Image(int width, int height);
|
||||||
~Image();
|
~Image();
|
||||||
|
|
||||||
|
void scaleBlit(Image *to, int x, int y, int w, int h) const;
|
||||||
void setPixel(int x, int y, const Color &c);
|
void setPixel(int x, int y, const Color &c);
|
||||||
Color getPixel(int x, int y);
|
Color getPixel(int x, int y) const;
|
||||||
void drawLine(int x1, int y1, int x2, int y2, const Color &c);
|
void drawLine(int x1, int y1, int x2, int y2, const Color &c);
|
||||||
void drawText(int x, int y, const std::string &s, const Color &c);
|
void drawText(int x, int y, const std::string &s, const Color &c);
|
||||||
void drawFilledRect(int x, int y, int w, int h, const Color &c);
|
void drawFilledRect(int x, int y, int w, int h, const Color &c);
|
||||||
void drawCircle(int x, int y, int diameter, const Color &c);
|
void drawCircle(int x, int y, int diameter, const Color &c);
|
||||||
void save(const std::string &filename);
|
void save(const std::string &filename) const;
|
||||||
void fill(Color &c);
|
void fill(Color &c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user