void decode_image_impl(image_type& image) { if (image.m_format == Format::RAW_ARRAY) { return; } char* buf = NULL; size_t length = 0; if (image.m_format == Format::JPG) { decode_jpeg((const char*)image.get_image_data(), image.m_image_data_size, &buf, length); } else if (image.m_format == Format::PNG) { decode_png((const char*)image.get_image_data(), image.m_image_data_size, &buf, length); } else { log_and_throw(std::string("Cannot decode image. Unknown format.")); }; image.m_image_data.reset(buf); image.m_image_data_size = length; image.m_format = Format::RAW_ARRAY; }
void encode_image_impl(image_type& image) { if (image.m_format != Format::RAW_ARRAY){ return; } char* buf = NULL; size_t length = 0; encode_png((const char*)image.get_image_data(), image.m_width, image.m_height, image.m_channels, &buf, length); image.m_image_data.reset(buf); image.m_image_data_size = length; image.m_format = Format::PNG; }