diff options
author | Karl Berry <karl@freefriends.org> | 2006-07-09 22:44:40 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-07-09 22:44:40 +0000 |
commit | 6684474324a04b457fe7019684c42eb68c4fea4b (patch) | |
tree | 63f0520f448252eb06342d5e0ea8e700c4976136 /Build/source/utils/sam2p/in_bmp.cpp | |
parent | bb92d19047f4437f2d13091072ec63a5641dc43c (diff) |
new graphics utility sam2p
git-svn-id: svn://tug.org/texlive/trunk@1792 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/sam2p/in_bmp.cpp')
-rw-r--r-- | Build/source/utils/sam2p/in_bmp.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Build/source/utils/sam2p/in_bmp.cpp b/Build/source/utils/sam2p/in_bmp.cpp new file mode 100644 index 00000000000..8784916d13d --- /dev/null +++ b/Build/source/utils/sam2p/in_bmp.cpp @@ -0,0 +1,47 @@ +/* + * in_bmp.cpp -- read a Windows(?) BMP bitmap file + * by pts@fazekas.hu at Sat Mar 2 00:46:54 CET 2002 + * + */ + +#ifdef __GNUC__ +#pragma implementation +#endif + +#include "image.hpp" +#include "error.hpp" + +#if USE_IN_BMP + +#include "gensio.hpp" +#include "input-bmp.ci" + +static Image::Sampled *in_bmp_reader(Image::Loader::UFD *ufd, SimBuffer::Flat const&) { + Image::Sampled *ret=0; + bitmap_type bitmap=bmp_load_image(((Filter::UngetFILED*)ufd)->getFILE(/*seekable:*/false)); + /* Imp: Work without duplicated memory allocation */ + if (BITMAP_PLANES(bitmap)==1) { + Image::Gray *img=new Image::Gray(BITMAP_WIDTH(bitmap), BITMAP_HEIGHT(bitmap), 8); + memcpy(img->getRowbeg(), BITMAP_BITS(bitmap), (slen_t)BITMAP_WIDTH(bitmap)*BITMAP_HEIGHT(bitmap)); + ret=img; + } else if (BITMAP_PLANES(bitmap)==3) { + Image::RGB *img=new Image::RGB(BITMAP_WIDTH(bitmap), BITMAP_HEIGHT(bitmap), 8); + memcpy(img->getRowbeg(), BITMAP_BITS(bitmap), (slen_t)3*BITMAP_WIDTH(bitmap)*BITMAP_HEIGHT(bitmap)); + ret=img; + } else assert(0 && "invalid BMP depth"); + delete [] BITMAP_BITS(bitmap); + return ret; +} + +static Image::Loader::reader_t in_bmp_checker(char buf[Image::Loader::MAGIC_LEN], char [Image::Loader::MAGIC_LEN], SimBuffer::Flat const&, Image::Loader::UFD*) { + return (buf[0]=='B' && buf[1]=='M' + && buf[6]==0 && buf[7]==0 && buf[8]==0 && buf[9]==0 + && (unsigned char)(buf[14])<=64 && buf[15]==0 && buf[16]==0 && buf[17]==0) + ? in_bmp_reader : 0; +} + +#else +#define in_bmp_checker NULLP +#endif /* USE_IN_BMP */ + +Image::Loader in_bmp_loader = { "BMP", in_bmp_checker, 0 }; |