FileSystemImageSource.cc
Go to the documentation of this file.00001 #include "FileSystemImageSource.h"
00002 #include "Shared/ImageUtil.h"
00003 #include "Shared/debuget.h"
00004 #include <sys/types.h>
00005 #include <sys/mman.h>
00006
00007
00008 using namespace std;
00009
00010 void FileSystemImageSource::ImageInfo::prepare() {
00011 if(prepared)
00012 return;
00013 if(data==NULL) {
00014
00015 FileInfo::prepare();
00016 if(data==NULL)
00017 return;
00018
00019
00020 width=height=components=0;
00021 size_t totalSize=0;
00022 char * imgbuf = ((char*)NULL)-1;
00023
00024 image_util::decodeImage(data,size,width,height,components,imgbuf,totalSize);
00025
00026 totalSize = width*height*components;
00027
00028 imgbuf = static_cast<char*>(mmap(NULL,totalSize,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0));
00029 if(imgbuf==MAP_FAILED) {
00030 std::string err="FileSystemImageSource::ImageInfo::prepare() unable to mmap allocation for image decompression of ";
00031 err+=filename;
00032 perror(err.c_str());
00033 FileInfo::release();
00034 return;
00035 }
00036
00037
00038 if(!image_util::decodeImage(data,size,width,height,components,imgbuf,totalSize)) {
00039 cerr << "Image decompression failed for " << filename << endl;
00040 munmap(imgbuf,totalSize);
00041 FileInfo::release();
00042 return;
00043 }
00044
00045
00046 FileInfo::release();
00047 setData(imgbuf,totalSize);
00048 }
00049 FileInfo::prepare();
00050 }
00051
00052
00053
00054
00055