extern crate freeimage;
use ::Image;
use gl::types::*;
use gl;
impl Image for freeimage::Bitmap{
type DataType = u8;
#[cfg(all(not(feature = "gles"), not(feature="webgl")))]
fn gl_internal_format_type(&self) -> Option<(GLenum, GLenum, GLenum)>{
let bytes_pp = self.bpp()/8;
match self.ty(){
freeimage::Type::BITMAP => {
let (internal, format) = match bytes_pp{
0 | 1 => (gl::R8, gl::RED),
2 => (gl::RG8, gl::RG),
3 => (gl::RGB8, gl::BGR),
4 => (gl::RGBA8, gl::BGRA),
_ => panic!("non recognized image depth {}", bytes_pp),
};
Some((internal, format, gl::UNSIGNED_BYTE))
},
freeimage::Type::UINT16 => Some((gl::R16, gl::RED, gl::UNSIGNED_SHORT)),
freeimage::Type::INT16 => Some((gl::R16, gl::RED, gl::SHORT)),
freeimage::Type::RGB16 => Some((gl::RGB16, gl::RGB, gl::UNSIGNED_SHORT)),
freeimage::Type::UINT32 => Some((gl::R32UI, gl::RED, gl::UNSIGNED_INT)),
freeimage::Type::INT32 => Some((gl::R32I, gl::RED, gl::INT)),
freeimage::Type::FLOAT => Some((gl::R32F, gl::RED, gl::FLOAT)),
freeimage::Type::RGBA16 => Some((gl::RGBA16, gl::RGBA, gl::UNSIGNED_SHORT)),
freeimage::Type::RGBF => Some((gl::RGB32F, gl::RGB, gl::FLOAT)),
freeimage::Type::RGBAF => Some((gl::RGB32F, gl::RGBA, gl::FLOAT)),
_ => None
}
}
#[cfg(any(feature = "gles", feature="webgl"))]
fn gl_internal_format_type(&self) -> Option<(GLenum, GLenum, GLenum)> {
let bytes_pp = self.bpp()/8;
match self.ty(){
freeimage::Type::BITMAP => {
let (internal, format) = match bytes_pp{
0 | 1 => (gl::R8, gl::RED),
2 => (gl::RG8, gl::RG),
3 => (gl::RGB8, gl::RGB),
4 => (gl::RGBA8, gl::BGRA_EXT),
_ => panic!("non recognized image depth"),
};
Some((internal, format, gl::UNSIGNED_BYTE))
},
freeimage::Type::UINT16 => Some((gl::R16UI, gl::RED, gl::UNSIGNED_SHORT)),
freeimage::Type::INT16 => Some((gl::R16I, gl::RED, gl::SHORT)),
freeimage::Type::RGB16 => Some((gl::RGB16UI, gl::RGB, gl::UNSIGNED_SHORT)),
freeimage::Type::UINT32 => Some((gl::R32UI, gl::RED, gl::UNSIGNED_INT)),
freeimage::Type::INT32 => Some((gl::R32I, gl::RED, gl::INT)),
freeimage::Type::FLOAT => Some((gl::R32F, gl::RED, gl::FLOAT)),
freeimage::Type::RGBA16 => Some((gl::RGBA16UI, gl::RGBA, gl::UNSIGNED_SHORT)),
freeimage::Type::RGBF => Some((gl::RGB32F, gl::RGB, gl::FLOAT)),
freeimage::Type::RGBAF => Some((gl::RGB32F, gl::RGBA, gl::FLOAT)),
_ => None
}
}
fn width(&self, _level: usize) -> usize{
self.width()
}
fn height(&self, _level: usize) -> usize{
self.height()
}
fn pitch_bytes(&self, _level: usize) -> usize{
self.pitch()
}
fn bytes_per_pixel(&self) -> usize{
self.bpp()/8
}
fn pitch_components(&self, _level: usize) -> usize{
let bytes_pp = self.bpp() / 8;
self.pitch() / bytes_pp.max(1)
}
fn num_components(&self) -> usize{
let bytes_pp = self.bpp()/8;
match self.ty(){
freeimage::Type::BITMAP => bytes_pp,
freeimage::Type::UINT16 => 1,
freeimage::Type::INT16 => 1,
freeimage::Type::RGB16 => 3,
freeimage::Type::UINT32 => 1,
freeimage::Type::INT32 => 1,
freeimage::Type::FLOAT => 1,
freeimage::Type::DOUBLE => 1,
freeimage::Type::RGBA16 => 4,
freeimage::Type::RGBF => 3,
freeimage::Type::RGBAF => 4,
freeimage::Type::UNKNOWN | freeimage::Type::COMPLEX => panic!()
}
}
fn data(&self) -> &[u8]{
self.bits()
}
fn levels(&self) -> usize{
1
}
fn mipmap(&self, level: usize) -> Option<&[u8]>{
if level == 0 {
Some(self.data())
}else{
None
}
}
fn is_gpu_compressed(&self) -> bool{
false
}
}