Image::Private::Private()
{
#ifdef WITH_DEVIL
- id=0;
+ id = 0;
#endif
#ifdef WITH_LIBPNG
- fmt=RGB;
- width=0;
- height=0;
- data=0;
+ fmt = RGB;
+ width = 0;
+ height = 0;
+ data = 0;
#endif
}
#ifdef WITH_LIBPNG
void read(png_struct *png, png_byte *data, png_size_t size)
{
- IO::Base *in=reinterpret_cast<IO::Base *>(png_get_io_ptr(png));
+ IO::Base *in = reinterpret_cast<IO::Base *>(png_get_io_ptr(png));
in->read(reinterpret_cast<char *>(data), size);
}
void load_png(IO::Base &in, Image::Private &priv)
{
- png_struct *png=0;
- png_info *info=0;
- priv.data=0;
+ png_struct *png = 0;
+ png_info *info = 0;
+ priv.data = 0;
try
{
- png=png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
- info=png_create_info_struct(png);
+ png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
+ info = png_create_info_struct(png);
if(setjmp(png_jmpbuf(png)))
throw Exception("Error loading PNG image");
int depth;
int color;
png_get_IHDR(png, info, &width, &height, &depth, &color, 0, 0, 0);
- priv.width=width;
- priv.height=height;
+ priv.width = width;
+ priv.height = height;
if(depth!=8)
throw Exception("Only 8-bit PNG images are supported");
switch(color)
{
- case PNG_COLOR_TYPE_PALETTE: priv.fmt=COLOR_INDEX; break;
- case PNG_COLOR_TYPE_GRAY: priv.fmt=LUMINANCE; break;
- case PNG_COLOR_TYPE_GRAY_ALPHA: priv.fmt=LUMINANCE_ALPHA; break;
- case PNG_COLOR_TYPE_RGB: priv.fmt=RGB; break;
- case PNG_COLOR_TYPE_RGB_ALPHA: priv.fmt=RGBA; break;
+ case PNG_COLOR_TYPE_PALETTE: priv.fmt = COLOR_INDEX; break;
+ case PNG_COLOR_TYPE_GRAY: priv.fmt = LUMINANCE; break;
+ case PNG_COLOR_TYPE_GRAY_ALPHA: priv.fmt = LUMINANCE_ALPHA; break;
+ case PNG_COLOR_TYPE_RGB: priv.fmt = RGB; break;
+ case PNG_COLOR_TYPE_RGB_ALPHA: priv.fmt = RGBA; break;
default: throw Exception("Unknown color type");
}
- unsigned nchans=png_get_channels(png, info);
+ unsigned nchans = png_get_channels(png, info);
if(nchans==4 && priv.fmt==RGB)
png_set_strip_alpha(png);
- unsigned rowstride=priv.width*nchans;
- priv.data=new char[rowstride*priv.height];
+ unsigned rowstride = priv.width*nchans;
+ priv.data = new char[rowstride*priv.height];
for(unsigned y=0; y<priv.height; ++y)
png_read_row(png, reinterpret_cast<png_byte *>(priv.data+rowstride*(priv.height-1-y)), 0);
#ifdef WITH_DEVIL
void ensure_devil_image(unsigned &id)
{
- static bool init_done=false;
+ static bool init_done = false;
if(!init_done)
{
ilInit();
ilEnable(IL_ORIGIN_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
- init_done=true;
+ init_done = true;
}
if(!id)