our_dick/include/engine/image.hpp

81 lines
2.0 KiB
C++

/**
This file is a part of our_dick
Copyright (C) 2020-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_ENGINE_IMAGE_HPP
#define OUR_DICK_ENGINE_IMAGE_HPP
#include <string>
namespace egn{
//class handling image loading from files
class image
{
private:
int m_width;
int m_height;
int m_channels; //color channels
unsigned char* m_data;
public:
//read in image data from 'file', trying to load with 'req_chan' number of channels.
image(const char* file, bool flip = false, int req_chan = 0);
image(const image&);
image(image&&);
~image();
image& operator=(const image&);
image& operator=(image&&);
//check if m_data is a null pointer
operator bool()const;
bool valid()const;
int get_width()const;
int get_height()const;
int get_channels()const;
const unsigned char* data()const;
unsigned char* data();
};
class deferred_image
{
private:
std::string m_filename;
bool m_flip = false;
int m_req_chan = 0;
public:
deferred_image(const char* file, bool flip = false, int req_chan = 0);
deferred_image(const std::string& file, bool flip = false, int req_chan = 0);
deferred_image(const deferred_image&) = default;
deferred_image(deferred_image&&) = default;
~deferred_image(void) = default;
deferred_image& operator=(const deferred_image&) = default;
deferred_image& operator=(deferred_image&&) = default;
operator image(void)const;
image get_image(void)const;
};
}
#endif