这篇教程C++ swap_endian函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中swap_endian函数的典型用法代码示例。如果您正苦于以下问题:C++ swap_endian函数的具体用法?C++ swap_endian怎么用?C++ swap_endian使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了swap_endian函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: swap_endian_gridsvoid swap_endian_grids(const char *filename_in,const char *filename_out,int mode){ SID_log("Swapping endian of grids...",SID_LOG_OPEN); // Sanity check if(check_mode_for_flag(mode,SWAP_SSIMPL_ENDIAN_FROM_NATIVE) && check_mode_for_flag(mode,SWAP_SSIMPL_ENDIAN_FROM_NATIVE)) SID_trap_error("Invalid mode flag (%d) in swap_endian_grids().",ERROR_LOGIC,mode); // Open input and output files FILE *fp_in =NULL; FILE *fp_out=NULL; if((fp_in=fopen(filename_in,"r"))==NULL) SID_log("not present.",SID_LOG_CLOSE,filename_in); else{ if((fp_out=fopen(filename_out,"w"))==NULL) SID_trap_error("Could not open {%s} for writing.",ERROR_IO_OPEN,filename_out); // Read the needed header information and rewind int n[3]; double L[3]; int n_grids; int scheme; fread_verify(&(n[0]), sizeof(int), 1,fp_in); fread_verify(&(n[1]), sizeof(int), 1,fp_in); fread_verify(&(n[2]), sizeof(int), 1,fp_in); fread_verify(&(L[0]), sizeof(double),1,fp_in); fread_verify(&(L[1]), sizeof(double),1,fp_in); fread_verify(&(L[2]), sizeof(double),1,fp_in); fread_verify(&n_grids,sizeof(int), 1,fp_in); fread_verify(&scheme, sizeof(int), 1,fp_in); if(check_mode_for_flag(mode,SWAP_SSIMPL_ENDIAN_TO_NATIVE)){ swap_endian((char *)(n), 3,sizeof(int)); swap_endian((char *)(&n_grids),1,sizeof(int)); } int grid_size=n[0]*n[1]*n[2]; rewind(fp_in); // Create a read buffer char *buffer=(char *)SID_malloc(sizeof(char)*grid_size*sizeof(fftw_real)); // Process the file rewrite_swap_endian(fp_in,fp_out,3,sizeof(int), buffer); rewrite_swap_endian(fp_in,fp_out,3,sizeof(double),buffer); rewrite_swap_endian(fp_in,fp_out,2,sizeof(int), buffer); for(int i_grid=0;i_grid<n_grids;i_grid++){ rewrite_swap_endian(fp_in,fp_out,GRID_IDENTIFIER_SIZE,sizeof(char), buffer); rewrite_swap_endian(fp_in,fp_out,grid_size, sizeof(fftw_real),buffer); } // Free the read buffer SID_free(SID_FARG buffer); // Close files fclose(fp_in); fclose(fp_out); SID_log("Done.",SID_LOG_CLOSE); }}
开发者ID:manodeep,项目名称:gbpCode,代码行数:59,
示例2: swap_endian_halos_subgroups_localvoid swap_endian_halos_subgroups_local(const char *filename_in_root, const char *filename_out_root, const char *filename_halo_type, int snap_number, int mode) { SID_log("Swapping endian of subgroup file...", SID_LOG_OPEN); // Sanity check if(SID_CHECK_BITFIELD_SWITCH(mode, SWAP_SSIMPL_ENDIAN_FROM_NATIVE) && SID_CHECK_BITFIELD_SWITCH(mode, SWAP_SSIMPL_ENDIAN_FROM_NATIVE)) SID_exit_error("Invalid mode flag (%d) in swap_endian_halos_subgroups_local().", SID_ERROR_LOGIC, mode); // Set filenames char filename_in[SID_MAX_FILENAME_LENGTH]; char filename_out[SID_MAX_FILENAME_LENGTH]; sprintf(filename_in, "%s/%s_%03d.catalog_subgroups", filename_in_root, filename_halo_type, snap_number); sprintf(filename_out, "%s/%s_%03d.catalog_subgroups", filename_out_root, filename_halo_type, snap_number); // Open input and output files FILE *fp_in = NULL; FILE *fp_out = NULL; if((fp_in = fopen(filename_in, "r")) == NULL) SID_exit_error("Could not open {%s} for reading.", SID_ERROR_IO_OPEN, filename_in); if((fp_out = fopen(filename_out, "w")) == NULL) SID_exit_error("Could not open {%s} for writing.", SID_ERROR_IO_OPEN, filename_out); // Read the needed header information and rewind int n_subgroups; int offset_size_bytes; SID_fread_verify(&n_subgroups, sizeof(int), 1, fp_in); SID_fread_verify(&offset_size_bytes, sizeof(int), 1, fp_in); if(SID_CHECK_BITFIELD_SWITCH(mode, SWAP_SSIMPL_ENDIAN_TO_NATIVE)) { swap_endian((char *)(&n_subgroups), 1, sizeof(int)); swap_endian((char *)(&offset_size_bytes), 1, sizeof(int)); } rewind(fp_in); // Create a read buffer char *buffer = (char *)SID_malloc(sizeof(char) * offset_size_bytes); // Process the file rewrite_swap_endian(fp_in, fp_out, 2, sizeof(int), buffer); for(int i_subgroup = 0; i_subgroup < n_subgroups; i_subgroup++) rewrite_swap_endian(fp_in, fp_out, 1, sizeof(int), buffer); for(int i_subgroup = 0; i_subgroup < n_subgroups; i_subgroup++) rewrite_swap_endian(fp_in, fp_out, 1, offset_size_bytes, buffer); for(int i_subgroup = 0; i_subgroup < n_subgroups; i_subgroup++) rewrite_swap_endian(fp_in, fp_out, 1, sizeof(int), buffer); // Free the read buffer SID_free(SID_FARG buffer); // Close files fclose(fp_in); fclose(fp_out); SID_log("Done.", SID_LOG_CLOSE);}
开发者ID:gbpoole,项目名称:gbpCode,代码行数:58,
示例3: sizeofboolSgiInput::read_header(){ if (!fread(&m_sgi_header.magic, sizeof(m_sgi_header.magic), 1) || !fread(&m_sgi_header.storage, sizeof(m_sgi_header.storage), 1) || !fread(&m_sgi_header.bpc, sizeof(m_sgi_header.bpc), 1) || !fread(&m_sgi_header.dimension, sizeof(m_sgi_header.dimension), 1) || !fread(&m_sgi_header.xsize, sizeof(m_sgi_header.xsize), 1) || !fread(&m_sgi_header.ysize, sizeof(m_sgi_header.ysize), 1) || !fread(&m_sgi_header.zsize, sizeof(m_sgi_header.zsize), 1) || !fread(&m_sgi_header.pixmin, sizeof(m_sgi_header.pixmin), 1) || !fread(&m_sgi_header.pixmax, sizeof(m_sgi_header.pixmax), 1) || !fread(&m_sgi_header.dummy, sizeof(m_sgi_header.dummy), 1) || !fread(&m_sgi_header.imagename, sizeof(m_sgi_header.imagename), 1)) return false; m_sgi_header.imagename[79] = '/0'; if (! fread(&m_sgi_header.colormap, sizeof(m_sgi_header.colormap), 1)) return false; //don't read dummy bytes fseek (m_fd, 404, SEEK_CUR); if (littleendian()) { swap_endian(&m_sgi_header.magic); swap_endian(&m_sgi_header.dimension); swap_endian(&m_sgi_header.xsize); swap_endian(&m_sgi_header.ysize); swap_endian(&m_sgi_header.zsize); swap_endian(&m_sgi_header.pixmin); swap_endian(&m_sgi_header.pixmax); swap_endian(&m_sgi_header.colormap); } return true;}
开发者ID:Chifoncake,项目名称:oiio,代码行数:35,
示例4: lockboolZfileInput::read_native_scanline(int subimage, int miplevel, int y, int z, void* data){ lock_guard lock(m_mutex); if (!seek_subimage(subimage, miplevel)) return false; if (m_next_scanline > y) { // User is trying to read an earlier scanline than the one we're // up to. Easy fix: close the file and re-open. ImageSpec dummyspec; int subimage = current_subimage(); if (!close() || !open(m_filename, dummyspec) || !seek_subimage(subimage, miplevel)) return false; // Somehow, the re-open failed ASSERT(m_next_scanline == 0 && current_subimage() == subimage); } while (m_next_scanline <= y) { // Keep reading until we're read the scanline we really need gzread(m_gz, data, m_spec.width * sizeof(float)); ++m_next_scanline; } if (m_swab) swap_endian((float*)data, m_spec.width); return true;}
开发者ID:AtomicFiction,项目名称:oiio,代码行数:27,
示例5: readLittleT readLittle(std::istream &is){ T x; is.read(reinterpret_cast<char *>(&x), sizeof(T)); x = swap_endian(x); return x;}
开发者ID:ajaskier,项目名称:gerbil,代码行数:7,
示例6: specboolPNGOutput::write_scanline(int y, int z, TypeDesc format, const void* data, stride_t xstride){ y -= m_spec.y; m_spec.auto_stride(xstride, format, spec().nchannels); const void* origdata = data; data = to_native_scanline(format, data, xstride, m_scratch, m_dither, y, z); if (data == origdata) { m_scratch.assign((unsigned char*)data, (unsigned char*)data + m_spec.scanline_bytes()); data = &m_scratch[0]; } // PNG specifically dictates unassociated (un-"premultiplied") alpha if (m_convert_alpha) { if (m_spec.format == TypeDesc::UINT16) deassociateAlpha((unsigned short*)data, m_spec.width, m_spec.nchannels, m_spec.alpha_channel, m_gamma); else deassociateAlpha((unsigned char*)data, m_spec.width, m_spec.nchannels, m_spec.alpha_channel, m_gamma); } // PNG is always big endian if (littleendian() && m_spec.format == TypeDesc::UINT16) swap_endian((unsigned short*)data, m_spec.width * m_spec.nchannels); if (!PNG_pvt::write_row(m_png, (png_byte*)data)) { error("PNG library error"); return false; } return true;}
开发者ID:OpenImageIO,项目名称:oiio,代码行数:35,
示例7: font_loadint font_load(FONT *font, const char *filename){ FONT_DATA font_data; IOHANDLE file; file = engine_openfile(filename, IOFLAG_READ); if(file) { int i; io_read(file, &font_data, sizeof(FONT_DATA)); io_close(file);#if defined(CONF_ARCH_ENDIAN_BIG) swap_endian(&font_data, 2, sizeof(FONT_DATA)/2);#endif { float scale_factor_x = 1.0f/font_data.size; float scale_factor_y = 1.0f/font_data.size; float scale_factor_tex_x = 1.0f/font_data.width; float scale_factor_tex_y = 1.0f/font_data.height; for (i = 0; i < 256; i++) { float tex_x0 = font_data.characters[i].x*scale_factor_tex_x; float tex_y0 = font_data.characters[i].y*scale_factor_tex_y; float tex_x1 = (font_data.characters[i].x+font_data.characters[i].width)*scale_factor_tex_x; float tex_y1 = (font_data.characters[i].y+font_data.characters[i].height)*scale_factor_tex_y; float width = font_data.characters[i].width*scale_factor_x; float height = font_data.characters[i].height*scale_factor_y; float x_offset = font_data.characters[i].x_offset*scale_factor_x; float y_offset = font_data.characters[i].y_offset*scale_factor_y; float x_advance = (font_data.characters[i].x_advance)*scale_factor_x; font->characters[i].tex_x0 = tex_x0; font->characters[i].tex_y0 = tex_y0; font->characters[i].tex_x1 = tex_x1; font->characters[i].tex_y1 = tex_y1; font->characters[i].width = width; font->characters[i].height = height; font->characters[i].x_offset = x_offset; font->characters[i].y_offset = y_offset; font->characters[i].x_advance = x_advance; } for (i = 0; i < 256*256; i++) { font->kerning[i] = (char)font_data.kerning[i]; } } return 0; } else return -1;}
开发者ID:gerich-home,项目名称:zteeworlds,代码行数:60,
示例8: gzdopenboolZfileInput::open (const std::string &name, ImageSpec &newspec){ m_filename = name; FILE *fd = Filesystem::fopen (name, "rb"); m_gz = (fd) ? gzdopen (fileno (fd), "rb") : NULL; if (! m_gz) { if (fd) fclose (fd); error ("Could not open file /"%s/"", name.c_str()); return false; } ZfileHeader header; ASSERT (sizeof(header) == 136); gzread (m_gz, &header, sizeof(header)); if (header.magic != zfile_magic && header.magic != zfile_magic_endian) { error ("Not a valid Zfile"); return false; } m_swab = (header.magic == zfile_magic_endian); if (m_swab) { swap_endian (&header.width); swap_endian (&header.height); swap_endian ((float *)&header.worldtoscreen, 16); swap_endian ((float *)&header.worldtocamera, 16); } m_spec = ImageSpec (header.width, header.height, 1, TypeDesc::FLOAT); if (m_spec.channelnames.size() == 0) m_spec.channelnames.emplace_back("z"); else m_spec.channelnames[0] = "z"; m_spec.z_channel = 0; m_spec.attribute ("worldtoscreen", TypeDesc::TypeMatrix, (float *)&header.worldtoscreen); m_spec.attribute ("worldtocamera", TypeDesc::TypeMatrix, (float *)&header.worldtocamera); newspec = spec (); return true;}
开发者ID:KelSolaar,项目名称:oiio,代码行数:46,
示例9: ifboolSgiOutput::create_and_write_header(){ sgi_pvt::SgiHeader sgi_header; sgi_header.magic = sgi_pvt::SGI_MAGIC; sgi_header.storage = sgi_pvt::VERBATIM; sgi_header.bpc = m_spec.format.size(); if (m_spec.height == 1 && m_spec.nchannels == 1) sgi_header.dimension = sgi_pvt::ONE_SCANLINE_ONE_CHANNEL; else if (m_spec.nchannels == 1) sgi_header.dimension = sgi_pvt::MULTI_SCANLINE_ONE_CHANNEL; else sgi_header.dimension = sgi_pvt::MULTI_SCANLINE_MULTI_CHANNEL; sgi_header.xsize = m_spec.width; sgi_header.ysize = m_spec.height; sgi_header.zsize = m_spec.nchannels; sgi_header.pixmin = 0; sgi_header.pixmax = (sgi_header.bpc == 1) ? 255 : 65535; sgi_header.dummy = 0; ParamValue* ip = m_spec.find_attribute("ImageDescription", TypeDesc::STRING); if (ip && ip->data()) { const char** img_descr = (const char**)ip->data(); strncpy(sgi_header.imagename, *img_descr, 80); sgi_header.imagename[79] = 0; } sgi_header.colormap = sgi_pvt::NORMAL; if (littleendian()) { swap_endian(&sgi_header.magic); swap_endian(&sgi_header.dimension); swap_endian(&sgi_header.xsize); swap_endian(&sgi_header.ysize); swap_endian(&sgi_header.zsize); swap_endian(&sgi_header.pixmin); swap_endian(&sgi_header.pixmax); swap_endian(&sgi_header.colormap); } char dummy[404] = { 0 }; if (!fwrite(&sgi_header.magic) || !fwrite(&sgi_header.storage) || !fwrite(&sgi_header.bpc) || !fwrite(&sgi_header.dimension) || !fwrite(&sgi_header.xsize) || !fwrite(&sgi_header.ysize) || !fwrite(&sgi_header.zsize) || !fwrite(&sgi_header.pixmin) || !fwrite(&sgi_header.pixmax) || !fwrite(&sgi_header.dummy) || !fwrite(sgi_header.imagename, 1, 80) || !fwrite(&sgi_header.colormap) || !fwrite(dummy, 404, 1)) { error("Error writing to /"%s/"", m_filename); return false; } return true;}
开发者ID:OpenImageIO,项目名称:oiio,代码行数:56,
示例10: GetDataSizevoid *CDataFileReader::GetDataImpl(int Index, int Swap){ if(!m_pDataFile) { return 0; } // load it if needed if(!m_pDataFile->m_ppDataPtrs[Index]) { // fetch the data size int DataSize = GetDataSize(Index);#if defined(CONF_ARCH_ENDIAN_BIG) int SwapSize = DataSize;#endif if(m_pDataFile->m_Header.m_Version == 4) { // v4 has compressed data void *pTemp = (char *)mem_alloc(DataSize, 1); unsigned long UncompressedSize = m_pDataFile->m_Info.m_pDataSizes[Index]; unsigned long s; dbg_msg("datafile", "loading data index=%d size=%d uncompressed=%d", Index, DataSize, UncompressedSize); m_pDataFile->m_ppDataPtrs[Index] = (char *)mem_alloc(UncompressedSize, 1); // read the compressed data io_seek(m_pDataFile->m_File, m_pDataFile->m_DataStartOffset+m_pDataFile->m_Info.m_pDataOffsets[Index], IOSEEK_START); io_read(m_pDataFile->m_File, pTemp, DataSize); // decompress the data, TODO: check for errors s = UncompressedSize; uncompress((Bytef*)m_pDataFile->m_ppDataPtrs[Index], &s, (Bytef*)pTemp, DataSize); // ignore_convention#if defined(CONF_ARCH_ENDIAN_BIG) SwapSize = s;#endif // clean up the temporary buffers mem_free(pTemp); } else { // load the data dbg_msg("datafile", "loading data index=%d size=%d", Index, DataSize); m_pDataFile->m_ppDataPtrs[Index] = (char *)mem_alloc(DataSize, 1); io_seek(m_pDataFile->m_File, m_pDataFile->m_DataStartOffset+m_pDataFile->m_Info.m_pDataOffsets[Index], IOSEEK_START); io_read(m_pDataFile->m_File, m_pDataFile->m_ppDataPtrs[Index], DataSize); }#if defined(CONF_ARCH_ENDIAN_BIG) if(Swap && SwapSize) swap_endian(m_pDataFile->m_ppDataPtrs[Index], sizeof(int), SwapSize/sizeof(int));#endif } return m_pDataFile->m_ppDataPtrs[Index];}
开发者ID:PJK136,项目名称:teeworlds-wDM,代码行数:57,
示例11: read_nbool read_n(FILE * file, T * data, size_t n){ if (fread(data, sizeof(*data), n, file) != n) return false; if (is_bigendian()) { for (size_t i = 0; i < n; ++i) data[i] = swap_endian(data[i]); } return true;}
开发者ID:arvinyang,项目名称:VirtualGlasses,代码行数:10,
示例12: data_tmpboolFitsInput::read_native_scanline (int y, int z, void *data){ // we return true just to support 0x0 images if (!m_naxes) return true; std::vector<unsigned char> data_tmp (m_spec.scanline_bytes ()); long scanline_off = (m_spec.height - y) * m_spec.scanline_bytes (); fseek (m_fd, scanline_off, SEEK_CUR); size_t n = fread (&data_tmp[0], 1, m_spec.scanline_bytes(), m_fd); if (n != m_spec.scanline_bytes()) { if (feof (m_fd)) error ("Hit end of file unexpectedly"); else error ("read error"); return false; // Read failed } // in FITS image data is stored in big-endian so we have to switch to // little-endian on little-endian machines if (littleendian ()) { if (m_spec.format == TypeDesc::USHORT) swap_endian ((unsigned short*)&data_tmp[0], data_tmp.size () / sizeof (unsigned short)); else if (m_spec.format == TypeDesc::UINT) swap_endian ((unsigned int*)&data_tmp[0], data_tmp.size () / sizeof (unsigned int)); else if (m_spec.format == TypeDesc::FLOAT) swap_endian ((float*)&data_tmp[0], data_tmp.size () / sizeof (float)); else if (m_spec.format == TypeDesc::DOUBLE) swap_endian ((double*)&data_tmp[0], data_tmp.size () / sizeof (double)); } memcpy (data, &data_tmp[0], data_tmp.size ()); // after reading scanline we set file pointer to the start of image data fsetpos (m_fd, &m_filepos); return true;};
开发者ID:Chifoncake,项目名称:oiio,代码行数:42,
示例13: swap_endianboolBmpFileHeader::read_header(FILE* fd){ if (!fread(fd, &magic) || !fread(fd, &fsize) || !fread(fd, &res1) || !fread(fd, &res2) || !fread(fd, &offset)) { return false; } if (bigendian()) swap_endian(); return true;}
开发者ID:AtomicFiction,项目名称:oiio,代码行数:12,
示例14: freadboolPicFileHeader::read_header (FILE* fd){ int byte_count = 0; byte_count += fread (this, 1, sizeof (PicFileHeader), fd); // Check if we're running on a little endian processor if (littleendian ()) swap_endian(); return (byte_count == sizeof (PicFileHeader));}
开发者ID:400notout,项目名称:oiio,代码行数:12,
示例15: channeldataboolSgiInput::read_native_scanline (int y, int z, void *data){ if (y < 0 || y > m_spec.height) return false; y = m_spec.height - y - 1; int bpc = m_sgi_header.bpc; std::vector<std::vector<unsigned char> > channeldata (m_spec.nchannels); if (m_sgi_header.storage == sgi_pvt::RLE) { // reading and uncompressing first channel (red in RGBA images) for (int c = 0; c < m_spec.nchannels; ++c) { int off = y + c*m_spec.height; // offset for this scanline/channel int scanline_offset = start_tab[off]; int scanline_length = length_tab[off]; channeldata[c].resize (m_spec.width * bpc); uncompress_rle_channel (scanline_offset, scanline_length, &(channeldata[c][0])); } } else { // non-RLE case -- just read directly into our channel data for (int c = 0; c < m_spec.nchannels; ++c) { int off = y + c*m_spec.height; // offset for this scanline/channel int scanline_offset = sgi_pvt::SGI_HEADER_LEN + off * m_spec.width * bpc; fseek (m_fd, scanline_offset, SEEK_SET); channeldata[c].resize (m_spec.width * bpc); if (! fread (&(channeldata[c][0]), 1, m_spec.width * bpc)) return false; } } if (m_spec.nchannels == 1) { // If just one channel, no interleaving is necessary, just memcpy memcpy (data, &(channeldata[0][0]), channeldata[0].size()); } else { unsigned char *cdata = (unsigned char *)data; for (int x = 0; x < m_spec.width; ++x) { for (int c = 0; c < m_spec.nchannels; ++c) { *cdata++ = channeldata[c][x*bpc]; if (bpc == 2) *cdata++ = channeldata[c][x*bpc+1]; } } } // Swap endianness if needed if (bpc == 2 && littleendian()) swap_endian ((unsigned short *)data, m_spec.width*m_spec.nchannels); return true;}
开发者ID:Chifoncake,项目名称:oiio,代码行数:52,
示例16: datafile_add_data_swappedint datafile_add_data_swapped(DATAFILE_OUT *df, int size, void *data){#if defined(CONF_ARCH_ENDIAN_BIG) void *swapped = mem_alloc(size, 1); /* temporary buffer that we use duing compression */ int index; mem_copy(swapped, data, size); swap_endian(&swapped, sizeof(int), size/sizeof(int)); index = datafile_add_data(df, size, swapped); mem_free(swapped); return index;#else return datafile_add_data(df, size, data);#endif}
开发者ID:Amor,项目名称:Clientmod,代码行数:14,
示例17: read_stream_float unsigned int read_stream_float(T &var) { std::vector<unsigned char> data; // assign type T from stream for(unsigned int i = 0; i < sizeof(T); ++i) { if(available() == END_OF_STREAM) return END_OF_STREAM; data.push_back(buff.at(pos++)); } if(swap) swap_endian(data); var = atof((char *) data.data()); return SUCCESS; }
开发者ID:GrumbleFish,项目名称:libanvil,代码行数:14,
示例18: definedint CDataFileWriter::AddDataSwapped(int Size, void *pData){#if defined(CONF_ARCH_ENDIAN_BIG) void *pSwapped = mem_alloc(Size, 1); // temporary buffer that we use duing compression int Index; mem_copy(pSwapped, pData, Size); swap_endian(&pSwapped, sizeof(int), Size/sizeof(int)); Index = AddData(Size, Swapped); mem_free(pSwapped); return Index;#else return AddData(Size, pData);#endif}
开发者ID:magnet,项目名称:teeworlds,代码行数:14,
示例19: write_nbool write_n(FILE * file, const T * data, size_t n){ if (is_bigendian()) { // This is not optimized for speed, however it's only big endian writing.... bool okay = true; for (size_t i = 0; i < n; ++i) { T swapped = swap_endian(data[i]); okay &= fwrite(&swapped, sizeof(swapped), 1, file) == 1; } return okay; } else { return fwrite(data, sizeof(*data), n, file) == n; }}
开发者ID:arvinyang,项目名称:VirtualGlasses,代码行数:14,
示例20: dbg_assertint CDataFileWriter::AddDataSwapped(int Size, void *pData){ dbg_assert(Size%sizeof(int) == 0, "incorrect boundary");#if defined(CONF_ARCH_ENDIAN_BIG) void *pSwapped = mem_alloc(Size, 1); // temporary buffer that we use during compression mem_copy(pSwapped, pData, Size); swap_endian(pSwapped, sizeof(int), Size/sizeof(int)); int Index = AddData(Size, pSwapped); mem_free(pSwapped); return Index;#else return AddData(Size, pData);#endif}
开发者ID:Berzzzebub,项目名称:teeworlds,代码行数:15,
示例21: datafile_get_datasizestatic void *datafile_get_data_impl(DATAFILE *df, int index, int swap){ /* load it if needed */ if(!df->data_ptrs[index]) { /* fetch the data size */ int datasize = datafile_get_datasize(df, index); int swapsize = datasize; if(df->header.version == 4) { /* v4 has compressed data */ void *temp = (char *)mem_alloc(datasize, 1); unsigned long uncompressed_size = df->info.data_sizes[index]; unsigned long s; dbg_msg("datafile", "loading data index=%d size=%d uncompressed=%d", index, datasize, uncompressed_size); df->data_ptrs[index] = (char *)mem_alloc(uncompressed_size, 1); /* read the compressed data */ io_seek(df->file, df->data_start_offset+df->info.data_offsets[index], IOSEEK_START); io_read(df->file, temp, datasize); /* decompress the data, TODO: check for errors */ s = uncompressed_size; uncompress((Bytef*)df->data_ptrs[index], &s, (Bytef*)temp, datasize); swapsize = s; /* clean up the temporary buffers */ mem_free(temp); } else { /* load the data */ dbg_msg("datafile", "loading data index=%d size=%d", index, datasize); df->data_ptrs[index] = (char *)mem_alloc(datasize, 1); io_seek(df->file, df->data_start_offset+df->info.data_offsets[index], IOSEEK_START); io_read(df->file, df->data_ptrs[index], datasize); }#if defined(CONF_ARCH_ENDIAN_BIG) if(swap && swapsize) swap_endian(df->data_ptrs[index], sizeof(int), swapsize/sizeof(int));#endif } return df->data_ptrs[index];}
开发者ID:Amor,项目名称:Clientmod,代码行数:48,
示例22: ifboolDibInformationHeader::read_header(FILE* fd){ if (!fread(fd, &size)) return false; if (size == WINDOWS_V3 || size == WINDOWS_V4 || size == WINDOWS_V5) { if (!fread(fd, &width) || !fread(fd, &height) || !fread(fd, &cplanes) || !fread(fd, &bpp) || !fread(fd, &compression) || !fread(fd, &isize) || !fread(fd, &hres) || !fread(fd, &vres) || !fread(fd, &cpalete) || !fread(fd, &important)) { return false; } if (size == WINDOWS_V4 || size == WINDOWS_V5) { if (!fread(fd, &red_mask) || !fread(fd, &blue_mask) || !fread(fd, &green_mask) || !fread(fd, &alpha_mask) || !fread(fd, &cs_type) || !fread(fd, &red_x) || !fread(fd, &red_y) || !fread(fd, &red_z) || !fread(fd, &green_x) || !fread(fd, &green_y) || !fread(fd, &green_z) || !fread(fd, &blue_x) || !fread(fd, &blue_y) || !fread(fd, &blue_z) || !fread(fd, &gamma_x) || !fread(fd, &gamma_y) || !fread(fd, &gamma_z)) { return false; } } if (size == WINDOWS_V5) { if (!fread(fd, &intent) || !fread(fd, &profile_data) || !fread(fd, &profile_size) || !fread(fd, &reserved)) { return false; } } } else if (size == OS2_V1) { // some of theses fields are smaller then in WINDOWS_Vx headers, // so we use hardcoded counts width = 0; height = 0; if (!fread(fd, &width, 2) || !fread(fd, &height, 2) || !fread(fd, &cplanes) || !fread(fd, &bpp)) { return false; } } if (bigendian()) swap_endian(); return true;}
开发者ID:AtomicFiction,项目名称:oiio,代码行数:48,
示例23: freadboolTIFFInput::valid_file (const std::string &filename) const{ FILE *file = Filesystem::fopen (filename, "r"); if (! file) return false; // needs to be able to open unsigned short magic[2] = { 0, 0 }; fread (magic, sizeof(unsigned short), 2, file); fclose (file); if (magic[0] != TIFF_LITTLEENDIAN && magic[0] != TIFF_BIGENDIAN) return false; // not the right byte order if ((magic[0] == TIFF_LITTLEENDIAN) != littleendian()) swap_endian (&magic[1], 1); return (magic[1] == 42 /* Classic TIFF */ || magic[1] == 43 /* Big TIFF */);}
开发者ID:willzhou,项目名称:oiio,代码行数:16,
示例24: read_stream unsigned int read_stream(T &var) { std::vector<unsigned char> data; // assign type T from stream unsigned int width = sizeof(T); for(unsigned int i = 0; i < width; ++i) { if(available() == END_OF_STREAM) return END_OF_STREAM; data.push_back(buff.at(pos++)); } if(swap) swap_endian(data); var = 0; for(unsigned int i = 0; i < width; ++i) var |= (data.at(i) << (8 * ((width - 1) - i))); return SUCCESS; }
开发者ID:GrumbleFish,项目名称:libanvil,代码行数:17,
示例25: to_native_scanlineboolSgiOutput::write_scanline (int y, int z, TypeDesc format, const void *data, stride_t xstride){ y = m_spec.height - y - 1; data = to_native_scanline (format, data, xstride, m_scratch, m_dither, y, z); // In SGI format all channels are saved to file separately: firsty all // channel 1 scanlines are saved, then all channel2 scanlines are saved // and so on. // // Note that since SGI images are pretty archaic and most probably // people won't be too picky about full flexibility writing them, we // content ourselves with only writing uncompressed data, and don't // attempt to write with RLE encoding. int bpc = m_spec.format.size(); // bytes per channel std::vector<unsigned char> channeldata (m_spec.width * bpc); for (int c = 0; c < m_spec.nchannels; ++c) { unsigned char *cdata = (unsigned char *)data + c*bpc; for (int x = 0; x < m_spec.width; ++x) { channeldata[x*bpc] = cdata[0]; if (bpc == 2) channeldata[x*bpc+1] = cdata[1]; cdata += m_spec.nchannels * bpc; // advance to next pixel } if (bpc == 2 && littleendian()) swap_endian ((unsigned short *)&channeldata[0], m_spec.width); long scanline_offset = sgi_pvt::SGI_HEADER_LEN + (c * m_spec.height + y) * m_spec.width * bpc; fseek (m_fd, scanline_offset, SEEK_SET); if (!fwrite (&channeldata[0], 1, m_spec.width * bpc)) { return false; } } return true; }
开发者ID:LumaPictures,项目名称:oiio,代码行数:40,
示例26: convert_pack_bitsstatic voidconvert_pack_bits (T *data, int nvals){ const int BITS_FROM = sizeof(T)*8; T *in = data; T *out = in - 1; // because we'll increment first time through int bitstofill = 0; // Invariant: the next value to convert is *in. We're going to write // the result of the conversion starting at *out, which still has // bitstofill bits left before moving on to the next slot. for (int i = 0; i < nvals; ++i) { // Grab the next value and convert it T val = bit_range_convert<BITS_FROM,BITS_TO> (*in++); // If we have no more bits to fill in the slot, move on to the // next slot. if (bitstofill == 0) { ++out; *out = 0; // move to next slot and clear its bits bitstofill = BITS_FROM; // all bits are for the taking } if (bitstofill >= BITS_TO) { // we can fit the whole val in this slot *out |= val << (bitstofill - BITS_TO); bitstofill -= BITS_TO; // printf ("/t/t%d bits left/n", bitstofill); } else { // not enough bits -- will need to split across slots int bitsinnext = BITS_TO - bitstofill; *out |= val >> bitsinnext; val &= (1 << bitsinnext) - 1; // mask out bits we saved ++out; *out = 0; // move to next slot and clear its bits *out |= val << (BITS_FROM - bitsinnext); bitstofill = BITS_FROM - bitsinnext; } } // Because we filled in a big-endian way, swap bytes if we need to if (littleendian()) swap_endian (data, nvals);}
开发者ID:jainpiyush26,项目名称:oiio,代码行数:39,
示例27: main//.........这里部分代码省略......... ret = SKP_Silk_SDK_InitEncoder( psEnc, &encStatus ); if( ret ) { printf( "/nError: SKP_Silk_reset_encoder returned %d/n", ret ); exit( 0 ); } /* Set Encoder parameters */ encControl.API_sampleRate = API_fs_Hz; encControl.maxInternalSampleRate = max_internal_fs_Hz; encControl.packetSize = ( packetSize_ms * API_fs_Hz ) / 1000; encControl.packetLossPercentage = packetLoss_perc; encControl.useInBandFEC = INBandFEC_enabled; encControl.useDTX = DTX_enabled; encControl.complexity = complexity_mode; encControl.bitRate = ( targetRate_bps > 0 ? targetRate_bps : 0 ); if( API_fs_Hz > MAX_API_FS_KHZ * 1000 || API_fs_Hz < 0 ) { printf( "/nError: API sampling rate = %d out of range, valid range 8000 - 48000 /n /n", API_fs_Hz ); exit( 0 ); } tottime = 0; totPackets = 0; totActPackets = 0; smplsSinceLastPacket = 0; sumBytes = 0.0; sumActBytes = 0.0; smplsSinceLastPacket = 0; while( 1 ) { /* Read input from file */ counter = fread( in, sizeof( SKP_int16 ), ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000, speechInFile );#ifdef _SYSTEM_IS_BIG_ENDIAN swap_endian( in, counter );#endif if( ( SKP_int )counter < ( ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000 ) ) { break; } /* max payload size */ nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES; starttime = GetHighResolutionTime(); /* Silk Encoder */ ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, payload, &nBytes ); if( ret ) { printf( "/nSKP_Silk_Encode returned %d", ret ); } tottime += GetHighResolutionTime() - starttime; /* Get packet size */ packetSize_ms = ( SKP_int )( ( 1000 * ( SKP_int32 )encControl.packetSize ) / encControl.API_sampleRate ); smplsSinceLastPacket += ( SKP_int )counter; if( ( ( 1000 * smplsSinceLastPacket ) / API_fs_Hz ) == packetSize_ms ) { /* Sends a dummy zero size packet in case of DTX period */ /* to make it work with the decoder test program. */ /* In practice should be handled by RTP sequence numbers */ totPackets++; sumBytes += nBytes; nrg = 0.0; for( k = 0; k < ( SKP_int )counter; k++ ) { nrg += in[ k ] * (double)in[ k ];
开发者ID:Archipov,项目名称:android-client,代码行数:67,
注:本文中的swap_endian函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ swap_free函数代码示例 C++ swap_bytes函数代码示例 |