コード例 #1
0
ファイル: util.cpp プロジェクト: respu/grace-base
	std::tuple<size_t, IOEvent> read_until_event(IInputStream& is, IOutputStream& os) {
		if (os.is_write_nonblocking()) {
			raise<IOError>("read_until_event will lose data if writing to non-blocking socket. Use a buffered approach instead.");
		}
		bool reading = true;
		size_t total_read = 0;
		size_t total_written = 0;
		IOEvent reason;
		byte buffer[1024];
		while (reading) {
			auto r = is.read(buffer, 1024);
			either_switch(r,
				[&](size_t n) {
					total_written += n;
					either_switch(os.write(buffer, n),
						[&](size_t written) {
							total_written += written;
						},
						[&](IOEvent wev) {
							reason = wev;
							reading = false;
						}
					);
				},
				[&](IOEvent event) {
					reason = event;
					reading = false;
				}
			);
		}
		return {total_written, reason};
	}
コード例 #2
0
ファイル: hBmpFile.cpp プロジェクト: liujw/SceneEditor
void TBmpFileGray8Base::save_copy_line(IOutputStream& aOutputStream,const void* pixelsLine)const {
    long BmpByteWidth=this->get_bmp_byte_width();
    long pixelsWidth=this->get_width();
    aOutputStream.write(pixelsLine,pixelsWidth);
    if (pixelsWidth<BmpByteWidth)
        aOutputStream.skip_fill(BmpByteWidth-pixelsWidth);
}
コード例 #3
0
ファイル: hBmpFile.cpp プロジェクト: liujw/SceneEditor
void  TBmpFileBase::save_to(IOutputStream&  aOutputStream) const
{
    long BmpByteWidth=this->get_bmp_byte_width();

    WORD    bfType=csBmpTag;
    //写入类型信息
    aOutputStream.write(&bfType, sizeof(bfType));

    //填充BITMAPFILEHEADER结构
    BITMAPFILEHEADER_NO_TYPE bmFileHeader;//位图文件头结构和位图信息结构
    memset(&bmFileHeader,0,sizeof(bmFileHeader));
    DWORD dwDibBitsSize=this->get_height()*MyBase::abs(BmpByteWidth);
    DWORD dwOffBits =sizeof(bfType)+ sizeof(BITMAPFILEHEADER_NO_TYPE) + sizeof(BITMAPINFOHEADER) +this->get_palette_byte_size();

    DWORD dwFileSize = dwOffBits - dwDibBitsSize;
    bmFileHeader.bfSize = dwFileSize;
    bmFileHeader.bfReserved1 = 0;
    bmFileHeader.bfReserved2 = 0;
    bmFileHeader.bfOffBits = dwOffBits;

    //写入文件头和位图信息
    aOutputStream.write(&bmFileHeader, sizeof(BITMAPFILEHEADER_NO_TYPE));

    //
    BITMAPINFOHEADER bmpInfo;
    memset(&bmpInfo,0,sizeof(bmpInfo));
    bmpInfo.biSize= sizeof(BITMAPINFOHEADER);
    bmpInfo.biWidth=this->get_width();
    bmpInfo.biHeight=this->get_height();
    bmpInfo.biPlanes=1;
    bmpInfo.biBitCount=(WORD)this->get_bmp_bit_count();
    bmpInfo.biCompression=0;
    bmpInfo.biSizeImage=0;
    bmpInfo.biXPelsPerMeter=0;
    bmpInfo.biYPelsPerMeter=0;
    bmpInfo.biClrUsed=0;
    bmpInfo.biClrImportant=0;
    aOutputStream.write(&bmpInfo, sizeof(BITMAPINFOHEADER));

    this->write_palette(aOutputStream);

    //写入数据
    for (long y=bmpInfo.biHeight-1; y>=0; --y)
        save_copy_line(aOutputStream,this->get_pixels_line(y));
}
コード例 #4
0
ファイル: hBmpFile.cpp プロジェクト: liujw/SceneEditor
long  TBmpFileGray8Base::write_palette(IOutputStream&  aOutputStream) const {
    aOutputStream.write(gray_paltette256,256*4);
    return 256*4;
}
コード例 #5
0
ファイル: hBmpFile.cpp プロジェクト: liujw/SceneEditor
void TBmpFileColor32Base::save_copy_line(IOutputStream& aOutputStream,const void* pixelsLine)const {
    long BmpByteWidth=this->get_bmp_byte_width();
    aOutputStream.write(pixelsLine,BmpByteWidth);
}
コード例 #6
0
ssize_t
OutputStream_write(void *cookie, const char *buf, size_t size)
{
	IOutputStream* output = (IOutputStream*)cookie;
	return output->write(buf, size);
}