X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_bmp%2Fmptr_bmp.cpp;h=9151cfe8ce2b18d6284fa2cba5306212647dfea2;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=b69ae955f18bd65d1aae3eaa0667fa4c15269922;hpb=f0bb3efdc247acff17a7feb7c3d22911f47959f7;p=synfig.git diff --git a/synfig-core/trunk/src/modules/mod_bmp/mptr_bmp.cpp b/synfig-core/trunk/src/modules/mod_bmp/mptr_bmp.cpp index b69ae95..9151cfe 100644 --- a/synfig-core/trunk/src/modules/mod_bmp/mptr_bmp.cpp +++ b/synfig-core/trunk/src/modules/mod_bmp/mptr_bmp.cpp @@ -1,8 +1,10 @@ -/*! ======================================================================== -** Synfig -** bmp Target Module -** $Id: mptr_bmp.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $ +/* === S Y N F I G ========================================================= */ +/*! \file mptr_bmp.cpp +** \brief bmp Target Module ** +** $Id$ +** +** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** ** This package is free software; you can redistribute it and/or @@ -14,6 +16,7 @@ ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** General Public License for more details. +** \endlegal ** ** === N O T E S =========================================================== ** @@ -50,9 +53,10 @@ SYNFIG_IMPORTER_INIT(bmp_mptr); SYNFIG_IMPORTER_SET_NAME(bmp_mptr,"bmp"); SYNFIG_IMPORTER_SET_EXT(bmp_mptr,"bmp"); SYNFIG_IMPORTER_SET_VERSION(bmp_mptr,"0.1"); -SYNFIG_IMPORTER_SET_CVS_ID(bmp_mptr,"$Id: mptr_bmp.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $"); +SYNFIG_IMPORTER_SET_CVS_ID(bmp_mptr,"$Id$"); /* === M E T H O D S ======================================================= */ +namespace synfig { struct BITMAPFILEHEADER { @@ -78,6 +82,8 @@ struct BITMAPINFOHEADER unsigned long biClrImportant; }; +} + #ifdef WORDS_BIGENDIAN inline long little_endian(const long &x) { @@ -119,86 +125,86 @@ bmp_mptr::~bmp_mptr() } bool -bmp_mptr::get_frame(synfig::Surface &surface,Time, synfig::ProgressCallback *cb) +bmp_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::ProgressCallback *cb) { FILE *file=fopen(filename.c_str(),"rb"); if(!file) { - if(cb)cb->error("bmp_mptr::GetFrame(): "+strprintf(_("Unable to open %s"),filename.c_str())); + if(cb)cb->error("bmp_mptr::GetFrame(): "+strprintf(_("Unable to open %s"),filename.c_str())); else synfig::error("bmp_mptr::GetFrame(): "+strprintf(_("Unable to open %s"),filename.c_str())); return false; } - BITMAPFILEHEADER fileheader; - BITMAPINFOHEADER infoheader; + synfig::BITMAPFILEHEADER fileheader; + synfig::BITMAPINFOHEADER infoheader; char b_char=fgetc(file); char m_char=fgetc(file); - + if(b_char!='B' || m_char!='M') { - if(cb)cb->error("bmp_mptr::GetFrame(): "+strprintf(_("%s is not in BMP format"),filename.c_str())); + if(cb)cb->error("bmp_mptr::GetFrame(): "+strprintf(_("%s is not in BMP format"),filename.c_str())); else synfig::error("bmp_mptr::GetFrame(): "+strprintf(_("%s is not in BMP format"),filename.c_str())); return false; } - - if(fread(&fileheader.bfSize, 1, sizeof(BITMAPFILEHEADER)-4, file)!=sizeof(BITMAPFILEHEADER)-4) + + if(fread(&fileheader.bfSize, 1, sizeof(synfig::BITMAPFILEHEADER)-4, file)!=sizeof(synfig::BITMAPFILEHEADER)-4) { - String str("bmp_mptr::get_frame(): "+strprintf(_("Failure while reading BITMAPFILEHEADER from %s"),filename.c_str())); - if(cb)cb->error(str); + String str("bmp_mptr::get_frame(): "+strprintf(_("Failure while reading BITMAPFILEHEADER from %s"),filename.c_str())); + if(cb)cb->error(str); else synfig::error(str); return false; } - - if(fread(&infoheader, 1, sizeof(BITMAPINFOHEADER), file)!=sizeof(BITMAPINFOHEADER)) + + if(fread(&infoheader, 1, sizeof(synfig::BITMAPINFOHEADER), file)!=sizeof(synfig::BITMAPINFOHEADER)) { - String str("bmp_mptr::get_frame(): "+strprintf(_("Failure while reading BITMAPINFOHEADER from %s"),filename.c_str())); - if(cb)cb->error(str); + String str("bmp_mptr::get_frame(): "+strprintf(_("Failure while reading BITMAPINFOHEADER from %s"),filename.c_str())); + if(cb)cb->error(str); else synfig::error(str); return false; } - + int offset=little_endian(fileheader.bfOffsetBits); - - if(offset!=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)-2) + + if(offset!=sizeof(synfig::BITMAPFILEHEADER)+sizeof(synfig::BITMAPINFOHEADER)-2) { - String str("bmp_mptr::get_frame(): "+strprintf(_("Bad BITMAPFILEHEADER in %s. (bfOffsetBits=%d, should be %d)"),filename.c_str(),offset,sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)-2)); - if(cb)cb->error(str); + String str("bmp_mptr::get_frame(): "+strprintf(_("Bad BITMAPFILEHEADER in %s. (bfOffsetBits=%d, should be %d)"),filename.c_str(),offset,sizeof(synfig::BITMAPFILEHEADER)+sizeof(synfig::BITMAPINFOHEADER)-2)); + if(cb)cb->error(str); else synfig::error(str); return false; } if(little_endian(infoheader.biSize)!=little_endian(40)) { - String str("bmp_mptr::get_frame(): "+strprintf(_("Bad BITMAPINFOHEADER in %s. (biSize=%d, should be 40)"),filename.c_str(),little_endian(infoheader.biSize))); - if(cb)cb->error(str); + String str("bmp_mptr::get_frame(): "+strprintf(_("Bad BITMAPINFOHEADER in %s. (biSize=%d, should be 40)"),filename.c_str(),little_endian(infoheader.biSize))); + if(cb)cb->error(str); else synfig::error(str); return false; } - + int w,h,bit_count; w=little_endian(infoheader.biWidth); h=little_endian(infoheader.biHeight); bit_count=little_endian_short(infoheader.biBitCount); - + synfig::warning("w:%d\n",w); synfig::warning("h:%d\n",h); synfig::warning("bit_count:%d\n",bit_count); - + if(little_endian(infoheader.biCompression)) { - if(cb)cb->error("bmp_mptr::GetFrame(): "+string(_("Reading compressed bitmaps is not supported"))); + if(cb)cb->error("bmp_mptr::GetFrame(): "+string(_("Reading compressed bitmaps is not supported"))); else synfig::error("bmp_mptr::GetFrame(): "+string(_("Reading compressed bitmaps is not supported"))); return false; } if(bit_count!=24 && bit_count!=32) { - if(cb)cb->error("bmp_mptr::GetFrame(): "+strprintf(_("Unsupported bit depth (bit_count=%d, should be 24 or 32)"),bit_count)); + if(cb)cb->error("bmp_mptr::GetFrame(): "+strprintf(_("Unsupported bit depth (bit_count=%d, should be 24 or 32)"),bit_count)); else synfig::error("bmp_mptr::GetFrame(): "+strprintf(_("Unsupported bit depth (bit_count=%d, should be 24 or 32)"),bit_count)); return false; } - + int x; int y; surface.set_wh(w,h); @@ -211,7 +217,7 @@ bmp_mptr::get_frame(synfig::Surface &surface,Time, synfig::ProgressCallback *cb) float b=gamma().b_U8_to_F32((unsigned char)fgetc(file)); float g=gamma().g_U8_to_F32((unsigned char)fgetc(file)); float r=gamma().r_U8_to_F32((unsigned char)fgetc(file)); - + surface[h-y-1][x]=Color( r, g, @@ -221,8 +227,9 @@ bmp_mptr::get_frame(synfig::Surface &surface,Time, synfig::ProgressCallback *cb) if(bit_count==32) fgetc(file); } - - fclose(file); + + fclose(file); return true; } +