replace const char * with std::string and save filename in the object when created by filename. Long term, we may represent an image by filename and load the image on demand. For potential use with sendfile.
parent
88be2e1865
commit
9a999d1465
|
@ -142,9 +142,10 @@ Image::Image() :
|
|||
blend = fptr_blend;
|
||||
}
|
||||
|
||||
Image::Image(const char *filename) {
|
||||
Image::Image(const std::string &filename) {
|
||||
if ( !initialised )
|
||||
Initialise();
|
||||
filename_ = filename;
|
||||
width = 0;
|
||||
linesize = 0;
|
||||
height = 0;
|
||||
|
@ -925,10 +926,10 @@ Image *Image::HighlightEdges(
|
|||
return high_image;
|
||||
}
|
||||
|
||||
bool Image::ReadRaw(const char *filename) {
|
||||
bool Image::ReadRaw(const std::string &filename) {
|
||||
FILE *infile;
|
||||
if ( (infile = fopen(filename, "rb")) == nullptr ) {
|
||||
Error("Can't open %s: %s", filename, strerror(errno));
|
||||
if ( (infile = fopen(filename.c_str(), "rb")) == nullptr ) {
|
||||
Error("Can't open %s: %s", filename.c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -947,7 +948,7 @@ bool Image::ReadRaw(const char *filename) {
|
|||
|
||||
if ( fread(buffer, size, 1, infile) < 1 ) {
|
||||
fclose(infile);
|
||||
Error("Unable to read from '%s': %s", filename, strerror(errno));
|
||||
Error("Unable to read from '%s': %s", filename.c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -956,15 +957,15 @@ bool Image::ReadRaw(const char *filename) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Image::WriteRaw(const char *filename) const {
|
||||
bool Image::WriteRaw(const std::string &filename) const {
|
||||
FILE *outfile;
|
||||
if ( (outfile = fopen(filename, "wb")) == nullptr ) {
|
||||
Error("Can't open %s: %s", filename, strerror(errno));
|
||||
if ( (outfile = fopen(filename.c_str(), "wb")) == nullptr ) {
|
||||
Error("Can't open %s: %s", filename.c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( fwrite( buffer, size, 1, outfile ) != 1 ) {
|
||||
Error("Unable to write to '%s': %s", filename, strerror(errno));
|
||||
Error("Unable to write to '%s': %s", filename.c_str(), strerror(errno));
|
||||
fclose(outfile);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -135,10 +135,11 @@ class Image {
|
|||
int buffertype; /* 0=not ours, no need to call free(), 1=malloc() buffer, 2=new buffer */
|
||||
int holdbuffer; /* Hold the buffer instead of replacing it with new one */
|
||||
std::string annotation_;
|
||||
std::string filename_;
|
||||
|
||||
public:
|
||||
Image();
|
||||
explicit Image(const char *filename);
|
||||
explicit Image(const std::string &filename);
|
||||
Image(int p_width, int p_height, int p_colours, int p_subpixelorder, uint8_t *p_buffer=0, unsigned int padding=0);
|
||||
Image(int p_width, int p_linesize, int p_height, int p_colours, int p_subpixelorder, uint8_t *p_buffer=0, unsigned int padding=0);
|
||||
explicit Image(const Image &p_image);
|
||||
|
@ -163,6 +164,7 @@ class Image {
|
|||
inline unsigned int Colours() const { return colours; }
|
||||
inline unsigned int SubpixelOrder() const { return subpixelorder; }
|
||||
inline unsigned int Size() const { return size; }
|
||||
std::string Filename() const { return filename_; }
|
||||
|
||||
AVPixelFormat AVPixFormat() const;
|
||||
|
||||
|
@ -219,8 +221,8 @@ class Image {
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool ReadRaw(const char *filename);
|
||||
bool WriteRaw(const char *filename) const;
|
||||
bool ReadRaw(const std::string &filename);
|
||||
bool WriteRaw(const std::string &filename) const;
|
||||
|
||||
bool ReadJpeg(const std::string &filename, unsigned int p_colours, unsigned int p_subpixelorder);
|
||||
|
||||
|
|
Loading…
Reference in New Issue