41 #include "vpImageIoBackend.h" 43 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) 44 # define VISP_HAVE_SSE2 1 47 #ifndef VISP_HAVE_SSE2 51 #define STB_IMAGE_IMPLEMENTATION 52 #include <stb_image.h> 54 #define STB_IMAGE_WRITE_IMPLEMENTATION 55 #include <stb_image_write.h> 60 int width = 0, height = 0, channels = 0;
61 unsigned char *image = stbi_load(filename.c_str(), &width, &height, &channels, STBI_grey);
65 I.
init(image, static_cast<unsigned int>(height), static_cast<unsigned int>(width),
true);
66 stbi_image_free(image);
71 int width = 0, height = 0, channels = 0;
72 unsigned char *image = stbi_load(filename.c_str(), &width, &height, &channels, STBI_rgb_alpha);
76 I.
init(reinterpret_cast<vpRGBa*>(image), static_cast<unsigned int>(height), static_cast<unsigned int>(width),
true);
77 stbi_image_free(image);
82 int res = stbi_write_jpg(filename.c_str(),
static_cast<int>(I.
getWidth()), static_cast<int>(I.
getHeight()), STBI_grey,
83 reinterpret_cast<void*>(I.
bitmap), quality);
89 void writeJPEGStb(
const vpImage<vpRGBa> &I,
const std::string &filename,
int quality)
91 int res = stbi_write_jpg(filename.c_str(),
static_cast<int>(I.
getWidth()), static_cast<int>(I.
getHeight()), STBI_rgb_alpha,
92 reinterpret_cast<void*>(I.
bitmap), quality);
100 const int stride_in_bytes =
static_cast<int>(I.
getWidth());
101 int res = stbi_write_png(filename.c_str(),
static_cast<int>(I.
getWidth()), static_cast<int>(I.
getHeight()), STBI_grey,
102 reinterpret_cast<void*>(I.
bitmap), stride_in_bytes);
108 void writePNGStb(
const vpImage<vpRGBa> &I,
const std::string &filename)
110 const int stride_in_bytes =
static_cast<int>(4 * I.
getWidth());
111 int res = stbi_write_png(filename.c_str(),
static_cast<int>(I.
getWidth()), static_cast<int>(I.
getHeight()), STBI_rgb_alpha,
112 reinterpret_cast<void*>(I.
bitmap), stride_in_bytes);
Type * bitmap
points toward the bitmap
Error that can be emited by the vpImage class and its derivates.
void init(unsigned int height, unsigned int width)
Set the size of the image.
unsigned int getHeight() const
unsigned int getWidth() const