本文整理汇总了C++中FileObject::seek方法的典型用法代码示例。如果您正苦于以下问题:C++ FileObject::seek方法的具体用法?C++ FileObject::seek怎么用?C++ FileObject::seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileObject
的用法示例。
在下文中一共展示了FileObject::seek方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
//-------------------------------------------------------------------------------------
bool FileDataDownload::process()
{
ResourceObjectPtr fptr = Resmgr::getSingleton().openResource(path_.c_str(), "rb");
if(fptr == NULL || !fptr->valid())
{
ERROR_MSG(fmt::format("FileDataDownload::process(): can't open {}.\n",
Resmgr::getSingleton().matchRes(path_).c_str()));
error_ = true;
return false;
}
FileObject* f = static_cast<FileObject*>(fptr.get());
if(totalBytes_ == 0)
{
f->seek(0, SEEK_END);
totalBytes_ = f->tell();
}
f->seek(totalSentBytes_, SEEK_SET);
remainSent_ = f->read(stream_, 65535);
currSent_ = 0;
if(remainSent_ == 0)
remainSent_ = totalBytes_ - totalSentBytes_;
return false;
}
示例2: load
void ImageFilter_PNG::load(FileObject &file, Drawable &surface, IMAGE &img)
{
#ifdef HAVE_PNG
file.seek(0);
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL ,NULL, NULL);
if (!png_ptr) throw IllegalImageFormatException();
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL);
throw IllegalImageFormatException();
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
throw IllegalImageFormatException();
}
png_set_read_fn(png_ptr, &file, (png_rw_ptr) user_read_data);
//png_set_write_fn(png_structp write_ptr, voidp write_io_ptr, png_rw_ptr write_data_fn,
// png_flush_ptr output_flush_fn);
png_read_info(png_ptr, info_ptr);
//png_read_png(png_ptr, info_ptr,0,NULL);
png_bytep row_pointer=(png_bytep) png_malloc(png_ptr,img.pitch);
RGBFormat zformat=surface.rgbformat(); // Zielformat holen
if (row_pointer!=NULL) {
int bpp;
switch (png_get_color_type(png_ptr, info_ptr)) {
case PNG_COLOR_TYPE_RGB_ALPHA:
//bpp=png_get_bit_depth(png_ptr, info_ptr);
bpp=4; // TODO: Bittiefe kann auch 16 Bit pro Farbkanal sein
//printf ("PNG RGBA, bpp=%i\n",bpp);
for (int y=0;y<img.height;y++) {
png_read_row(png_ptr, row_pointer, NULL);
for (int x=0;x<img.width;x++) {
int r=row_pointer[x*bpp+0];
int g=row_pointer[x*bpp+1];
int b=row_pointer[x*bpp+2];
int a=row_pointer[x*bpp+3];
surface.putPixel(x,y,Color(r,g,b,a));
}
}
break;
case PNG_COLOR_TYPE_RGB:
//bpp=png_get_bit_depth(png_ptr, info_ptr)/8;
bpp=3;
for (int y=0;y<img.height;y++) {
png_read_row(png_ptr, row_pointer, NULL);
for (int x=0;x<img.width;x++) {
int r=row_pointer[x*bpp+0];
int g=row_pointer[x*bpp+1];
int b=row_pointer[x*bpp+2];
surface.putPixel(x,y,Color(r,g,b,255));
}
}
break;
case PNG_COLOR_TYPE_GRAY:
//bpp=png_get_bit_depth(png_ptr, info_ptr)/8;
bpp=1;
// Ist das Zielformat auch Greyscale?
if (zformat==RGBFormat::A8 || zformat==RGBFormat::GREY8) {
for (int y=0;y<img.height;y++) {
png_read_row(png_ptr, row_pointer, NULL);
for (int x=0;x<img.width;x++) {
int r=row_pointer[x*bpp+0];
surface.putPixel(x,y,Color(r,r,r));
}
}
} else {
for (int y=0;y<img.height;y++) {
png_read_row(png_ptr, row_pointer, NULL);
for (int x=0;x<img.width;x++) {
int r=row_pointer[x*bpp+0];
surface.putPixel(x,y,Color(r,r,r));
}
}
}
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
bpp=2;
//bpp=png_get_bit_depth(png_ptr, info_ptr)/8;
for (int y=0;y<img.height;y++) {
png_read_row(png_ptr, row_pointer, NULL);
for (int x=0;x<img.width;x++) {
int r=row_pointer[x*bpp+0];
int a=row_pointer[x*bpp+1];
surface.putPixel(x,y,Color(r,r,r,a));
}
}
break;
//.........这里部分代码省略.........
示例3: save
void ImageFilter_PNG::save (const Drawable &surface, FileObject &file, const AssocArray ¶m)
{
#ifdef HAVE_PNG
Color farbe;
int pitch,colortype;
//int r,g,b,a;
int width,height;
png_byte *buffer;
png_color pc[256];
//RGBA rgb;
if (surface.isEmpty()) throw EmptyImageException();
file.seek(0);
width=surface.width();
height=surface.height();
pitch=colortype=0;
int png_color_type=PNG_COLOR_TYPE_GRAY;
int compression_level=Z_BEST_COMPRESSION;
RGBFormat srgb=surface.rgbformat();
if (srgb==RGBFormat::A8R8G8B8) png_color_type=PNG_COLOR_TYPE_RGB_ALPHA;
if (param.exists("colortype")) png_color_type=param.getString("colortype").toInt();
if (!png_color_type) png_color_type=PNG_COLOR_TYPE_RGB;
switch (png_color_type) {
case PNG_COLOR_TYPE_GRAY:
colortype=PNG_COLOR_TYPE_GRAY;
pitch=width*1;
break;
case PNG_COLOR_TYPE_PALETTE:
colortype=PNG_COLOR_TYPE_PALETTE;
pitch=width*1;
break;
case PNG_COLOR_TYPE_RGB:
colortype=PNG_COLOR_TYPE_RGB;
pitch=width*3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
colortype=PNG_COLOR_TYPE_RGB_ALPHA;
pitch=width*4;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
colortype=PNG_COLOR_TYPE_GRAY_ALPHA;
pitch=width*2;
break;
default:
colortype=PNG_COLOR_TYPE_RGB;
pitch=width*3;
break;
};
png_structp png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
if (!png_ptr) throw OperationFailedException("ImageFilter_PNG::save");
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr,(png_infopp)NULL);
throw OperationFailedException("ImageFilter_PNG::save");
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr,&info_ptr);
throw OperationFailedException("ImageFilter_PNG::save");
}
//png_set_read_fn(png_ptr,(voidp) file, (png_rw_ptr) user_read_data);
png_set_write_fn(png_ptr, &file, (png_rw_ptr) user_write_data, (png_flush_ptr) user_flush_data);
// Compression-Level setzen
png_set_compression_level (png_ptr, compression_level);
png_set_IHDR(png_ptr, info_ptr, width,height,8,colortype,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
buffer=(png_byte*)png_malloc(png_ptr,pitch);
if (!buffer) {
png_destroy_write_struct(&png_ptr,&info_ptr);
throw OutOfMemoryException();
}
if (buffer!=NULL) {
// png_write_row(png_ptr, row_pointer);
int bpp;
switch (colortype) {
case PNG_COLOR_TYPE_PALETTE:
bpp=1;
if (surface.rgbformat()==RGBFormat::Palette) { // Surface verwendet Palette
for (int i=0;i<256;i++) {
// TODO:
//surface->GetColor(i,&rgb);
//pc[i].red=rgb.red;
//pc[i].green=rgb.green;
//.........这里部分代码省略.........
示例4: ident
int ImageFilter_PNG::ident(FileObject &file, IMAGE &img)
{
#ifdef HAVE_PNG
try {
const char *address=file.map(0,256);
file.seek(0);
if (address==NULL) return 0;
if (png_sig_cmp((png_byte*)address, 0, 8)!=0) { // Ist es ein PNG-File?
return 0;
}
png_structp png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, NULL ,NULL, NULL);
if (!png_ptr) return 0;
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL);
return 0;
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
return 0;
}
png_set_read_fn(png_ptr,&file, (png_rw_ptr) user_read_data);
//png_set_write_fn(png_structp write_ptr, voidp write_io_ptr, png_rw_ptr write_data_fn,
// png_flush_ptr output_flush_fn);
png_read_info(png_ptr, info_ptr);
img.width=png_get_image_width(png_ptr, info_ptr);
img.height=png_get_image_height(png_ptr, info_ptr);
img.bitdepth=png_get_bit_depth(png_ptr, info_ptr);
img.colors=0;
img.pitch=png_get_rowbytes(png_ptr, info_ptr);
//img->pfp.header_version=0;
bool supported=true;
img.format=RGBFormat::unknown;
if (img.bitdepth!=8) supported=false; // Nur 8-Bit/Farbwert wird unterstützt
switch (png_get_color_type(png_ptr, info_ptr)) {
case PNG_COLOR_TYPE_GRAY:
img.bitdepth=8;
img.colors=256;
img.format=RGBFormat::GREY8;
break;
case PNG_COLOR_TYPE_PALETTE:
img.bitdepth=8;
img.colors=256;
img.format=RGBFormat::Palette;
//supported=false;
break;
case PNG_COLOR_TYPE_RGB:
img.colors=0xffffff;
img.bitdepth=24;
img.format=RGBFormat::X8R8G8B8;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
img.colors=0xffffff;
img.bitdepth=32;
img.format=RGBFormat::A8R8G8B8;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
img.colors=256;
img.bitdepth=32;
img.format=RGBFormat::GREYALPHA32;
break;
};
if (png_get_interlace_type(png_ptr,info_ptr)!=PNG_INTERLACE_NONE) { // Interlaced wird nicht unterstützt
supported=false;
}
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
if (!supported) {
return 0;
}
return 1;
} catch (...) {
return 0;
}
return 0;
#else
return 0;
#endif
}