This simplifies the pixel format handling in the texture classes.
}
}
-PixelFormat pixelformat_from_image(const Graphics::Image &image)
+PixelFormat pixelformat_from_image(const Graphics::Image &image, bool srgb)
{
PixelComponents comp = components_from_graphics(image.get_format());
- return make_pixelformat(comp, UNSIGNED_BYTE);
+ return make_pixelformat(comp, UNSIGNED_BYTE, srgb);
}
PixelFormat make_pixelformat(PixelComponents comp, DataType type, bool srgb)
void operator>>(const LexicalConverter &, PixelFormat &);
PixelComponents components_from_graphics(Graphics::PixelFormat);
-PixelFormat pixelformat_from_image(const Graphics::Image &);
+PixelFormat pixelformat_from_image(const Graphics::Image &, bool = false);
PixelFormat make_pixelformat(PixelComponents, DataType, bool = false);
inline PixelComponents get_components(PixelFormat f) { return static_cast<PixelComponents>(f&0xFF); }
if(img.get_height()!=1)
throw incompatible_data("Texture1D::image");
- unsigned w = img.get_width();
- PixelFormat fmt = pixelformat_from_image(img);
- storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv);
-
+ storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), lv);
image(0, img.get_pixels());
}
void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer)
{
- unsigned w = img.get_width();
- unsigned h = img.get_height();
- PixelFormat fmt = pixelformat_from_image(img);
- storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, lv);
-
+ storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), img.get_height(), lv);
image(0, from_buffer ? 0 : img.get_pixels());
}
unsigned d = h/w;
h = w;
- PixelFormat fmt = pixelformat_from_image(img);
- storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, d, lv);
-
+ storage(pixelformat_from_image(img, use_srgb_format), w, h, d, lv);
image(0, img.get_pixels());
}
if(w!=h)
throw incompatible_data("TextureCube::image");
- PixelFormat fmt = pixelformat_from_image(img);
- storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w);
-
+ storage(pixelformat_from_image(img, use_srgb_format), w);
image(face, 0, img.get_pixels());
}
throw incompatible_data("TextureCube::image");
h /= 6;
- PixelFormat fmt = pixelformat_from_image(img);
if(size==0)
- storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv);
+ storage(pixelformat_from_image(img, use_srgb_format), w, lv);
else if(w!=size || h!=size)
throw incompatible_data("TextureCube::image");