/************* * DESCRIPTION: write texture to scene file * INPUT: iff iff handler * OUTPUT: FALSE if failed else TRUE *************/ BOOL RAYSTORM_TEXTURE::Write(struct IFFHandle *iff) { if(PushChunk(iff, ID_RTXT, ID_FORM, IFFSIZE_UNKNOWN)) return FALSE; if(!WriteChunk(iff, ID_NAME, name, strlen(name)+1)) return FALSE; if(!WriteChunk(iff, ID_PARM, data, datasize)) return FALSE; if(PopChunk(iff)) return FALSE; return TRUE; }
// Polygon list bool CLwoWriter::WritePolygons() { MSG_DEBUG("POLS | FACE"); // "POLS" + size WriteChunk(CLwoFile::CHUNK_POLS); // type : "FACE" WriteTag(CLwoFile::CHUNK_FACE); CLwoFile::CLayer::FaceVector& faces = m_curLayer.GetFaceVector(); CLwoFile::CLayer::FaceVector::iterator faceIt, faceBegin, faceEnd; faceBegin = faces.begin(); faceEnd = faces.end(); for(faceIt = faceBegin; faceIt != faceEnd; ++faceIt) // For each LWO face { ushort vertexCount = faceIt->VertexCount(); WriteShort(vertexCount); for(ushort v=0; v<vertexCount; ++v) // For each vertex in LWO face { ushort vertexIndex = faceIt->GetVertexIndexVector()[v]; // Retreive vertex index WriteShort(vertexIndex); } } return true; }
// Layer bool CLwoWriter::WriteLayer() { MSG_DEBUG("LAYR"); // "LAYR" + size WriteChunk(CLwoFile::CHUNK_LAYR); // layer ID ushort layerID = 0; // hack, only support first layer WriteShort(layerID); // layer Flag ushort layerFlag = 0; // hack WriteShort(layerFlag); // layer Pivot Vector3D pivot(3); // Pivot pivot[0] = 0.0f; pivot[1] = 0.0f; pivot[2] = 0.0f; WriteVector3D(pivot); // layer Name WriteString(""); // Layer Name // no parent return true; }
/*---------------------------------------------------------------------- | main +---------------------------------------------------------------------*/ int main(int /*argc*/, char** /*argv*/) { // setup debugging #if defined(WIN32) && defined(_DEBUG) int flags = _crtDbgFlag | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF; _CrtSetDbgFlag(flags); //AllocConsole(); //freopen("CONOUT$", "w", stdout); #endif NPT_RingBuffer buffer(BUFFER_SIZE); for (int i=0; i<100000000; i++) { if (NPT_FAILED(WriteChunk(buffer))) { printf("WriteChunk failed\n"); return 1; } if (NPT_FAILED(ReadChunk(buffer))) { printf("ReadChunk failed\n"); return 1; } } printf("RingBufferTest1 passed\n"); return 0; }
status_t BMediaTrack::WriteChunk(const void* data, size_t size, uint32 flags) { media_encode_info encodeInfo; encodeInfo.flags = flags; return WriteChunk(data, size, &encodeInfo); }
bool CLwoWriter::WriteHeader() { MSG_DEBUG("FORM | LWO2"); // "FORM" + size WriteChunk(CLwoFile::CHUNK_FORM); // "LWO2" WriteTag(CLwoFile::CHUNK_LWO2); return true; }
// Discontinuous Vertex Mapping bool CLwoWriter::WriteDiscVertexMapping() { CLwoFile::CLayer::TexCoordMap& texCoords = m_curLayer.GetTexCoordMap(); if(texCoords.size() == 0) return true; MSG_DEBUG("VMAD | TXUV"); // "VMAD" + size WriteChunk(CLwoFile::CHUNK_VMAD); // type : "TXUV" WriteTag(CLwoFile::CHUNK_TXUV); ushort dimension = 2; // UVs are 2D WriteShort(dimension); std::string name("txuv00"); WriteString(name); CLwoFile::CLayer::TexCoordMap::iterator texCoordIt, texCoordEnd; texCoordEnd = texCoords.end(); std::vector< CLwoFile::CLayer::CTexCoord > uvVector; ushort pointIndex = 0; ushort polyIndex = 0; Vector3D uv(3); for(texCoordIt = texCoords.begin(); texCoordIt != texCoordEnd; ++texCoordIt) // For each LWO texCoord { uvVector = texCoordIt->second; std::vector< CLwoFile::CLayer::CTexCoord >::iterator uvVectorIt, uvVectorEnd; uvVectorEnd = uvVector.end(); for(uvVectorIt = uvVector.begin(); uvVectorIt != uvVectorEnd; ++uvVectorIt) // For each LWO face { if(uvVectorIt == uvVector.begin()) // skip the first one since it was written in the VMAP continue; pointIndex = texCoordIt->first; WriteShort(pointIndex); // vertex position index ushort polyIndex = uvVectorIt->m_faceIndex; WriteShort(polyIndex); // face index uv = uvVectorIt->m_texCoord; WriteVector2D(uv); // Write UV } } return true; }
status_t MP3Encoder::Flush() { if (m_cookie == 0) return B_OK; if (m_bufAvail > 0) { memset(m_buffer+m_bufAvail, 0, m_chunkSize-m_bufAvail); status_t err = EncodeBuffer(m_buffer, m_chunkSize); if (err < B_OK) return err; } return WriteChunk(m_buffer, mp3_encode(m_cookie, NULL, 0, m_buffer), m_LastEncodeInfo); }
/************* * DESCRIPTION: write texture to scene file * INPUT: iff iff handler * OUTPUT: FALSE if failed else TRUE *************/ BOOL HYPER_TEXTURE::Write(struct IFFHandle *iff) { if(PushChunk(iff, ID_HTXT, ID_FORM, IFFSIZE_UNKNOWN)) return FALSE; if(!WriteChunk(iff, ID_NAME, name, strlen(name)+1)) return FALSE; if(PopChunk(iff)) return FALSE; return TRUE; }
/** \fn writeDummyChunk \brief write a placeholder dummy chunk */ bool AviListAvi::writeDummyChunk(int size, uint64_t *pos) { // save file position *pos=Tell(); aprintf("[ODML]write dummy chunk at file position %" PRIu64" with data size %" PRIu32"\n",*pos, size); // generate dummy data uint8_t* dummy=(uint8_t*)ADM_alloc (size); memset(dummy,0,size); // write dummy chunk WriteChunk ( (const uint8_t *)"JUNK", size, dummy); // clean up ADM_dealloc (dummy); return true; }
status_t MP3Encoder::EncodeBuffer( const char *src, int32 src_length) { assert(src_length == 1152*m_format.channel_count*2); char * output = (char *)alloca(src_length); /* assume each packet will shrink, which is safe for the blade codec */ int outputSize = mp3_encode(m_cookie, src, src_length, output); if (outputSize > 0) { m_LastEncodeInfo->flags |= B_MEDIA_KEY_FRAME; return WriteChunk(output, outputSize, m_LastEncodeInfo); } return B_OK; }
/************* * DESCRIPTION: write texture to scene file * INPUT: iff iff handler * OUTPUT: FALSE if failed else TRUE *************/ BOOL IMAGINE_TEXTURE::Write(struct IFFHandle *iff) { if(PushChunk(iff, ID_ITXT, ID_FORM, IFFSIZE_UNKNOWN)) return FALSE; if(!WriteChunk(iff, ID_NAME, name, strlen(name)+1)) return FALSE; if(!WriteLongChunk(iff, ID_PARM, ¶ms, 16)) return FALSE; if(PopChunk(iff)) return FALSE; return TRUE; }
//================================================================================ // WriteChunks //================================================================================ geBoolean WriteChunks(GBSP_ChunkData *Data, int32 NumChunkData, geVFile *f) { int32 i; GBSP_Chunk Chunk; for (i=0; i< NumChunkData; i++) { Chunk.Type = Data[i].Type; Chunk.Size = Data[i].Size; Chunk.Elements = Data[i].Elements; if (!WriteChunk(&Chunk, Data[i].Data, f)) return GE_FALSE; } return GE_TRUE; }
bool CLwoWriter::WriteTagStrings() { MSG_DEBUG("TAGS"); // "TAGS" + size WriteChunk(CLwoFile::CHUNK_TAGS); // Surface tag names CLwoFile::CLayer::SurfaceMap& surfaces = m_curLayer.GetSurfaceMap(); CLwoFile::CLayer::SurfaceMap::iterator surfaceIt, surfaceEnd; surfaceEnd = surfaces.end(); for(surfaceIt = surfaces.begin(); surfaceIt != surfaceEnd; ++surfaceIt) // For each surface { WriteString(surfaceIt->first); // Write surface name } // Part tag names (OBJ groups) CLwoFile::CLayer::PartVector& parts = m_curLayer.GetPartVector(); CLwoFile::CLayer::PartVector::iterator partIt, partEnd; partEnd = parts.end(); for(partIt = parts.begin(); partIt != partEnd; ++partIt) // For each part name { WriteString(*partIt); // Write part name } // Smoothing groups tag names CLwoFile::CLayer::SGVector& sgs = m_curLayer.GetSGVector(); CLwoFile::CLayer::SGVector::iterator sgIt, sgEnd; sgEnd = sgs.end(); std::stringstream ssSG; for(sgIt = sgs.begin(); sgIt != sgEnd; ++sgIt) // For each sg name { ssSG.str(""); ssSG << "sg"; if(*sgIt < 10) ssSG << "0"; ssSG << *sgIt; WriteString(ssSG.str()); // Write smoothing group name } return true; }
bool PutChunk ( LFA_FileRef inFileRef, RiffState & inOutRiffState, long riffType, long tagID, const char * inBuffer, UInt32 inBufferSize ) { UInt32 len; UInt64 pos; atag tag; // Make sure we're writting an even number of bytes. Required by the RIFF specification. XMP_Assert ( (inBufferSize & 1) == 0 ); try { bool found = FindChunk ( inOutRiffState, tagID, 0, 0, NULL, &len, &pos ); if ( found ) { if ( len == inBufferSize ) { LFA_Seek ( inFileRef, pos, SEEK_SET ); LFA_Write ( inFileRef, inBuffer, inBufferSize ); return true; } pos -= 8; tag.id = MakeUns32LE ( ckidPremierePadding ); LFA_Seek ( inFileRef, pos, SEEK_SET ); LFA_Write ( inFileRef, &tag, 4 ); if ( len > inBufferSize ) { pos += 8; AddTag ( inOutRiffState, ckidPremierePadding, len, pos, 0, 0, 0 ); } } } catch ( ... ) { // If a write fails, it throws, so we return false return false; } bool ok = MakeChunk ( inFileRef, inOutRiffState, riffType, (inBufferSize + 8) ); if ( ! ok ) return false; return WriteChunk ( inFileRef, tagID, inBuffer, inBufferSize ); }
// Point list bool CLwoWriter::WritePoints() { MSG_DEBUG("PNTS"); // "PNTS" + size WriteChunk(CLwoFile::CHUNK_PNTS); Vector3DVector& vertices = m_curLayer.GetVertexPositionVector(); Vector3DVector::iterator vertexIt, vertexBegin, VertexEnd; vertexBegin = vertices.begin(); VertexEnd = vertices.end(); for(vertexIt = vertexBegin; vertexIt != VertexEnd; ++vertexIt) // For each LWO point { WriteVector3D(*vertexIt); } return true; }
status_t AVCodecEncoder::_EncodeAudio(const uint8* buffer, size_t bufferSize, int64 frameCount, media_encode_info* info) { // Encode one audio chunk/frame. The bufferSize has already been adapted // to the needed size for fContext->frame_size, or we are writing raw // audio. int usedBytes = avcodec_encode_audio(fContext, fChunkBuffer, bufferSize, reinterpret_cast<const short*>(buffer)); if (usedBytes < 0) { TRACE(" avcodec_encode_audio() failed: %d\n", usedBytes); return B_ERROR; } if (usedBytes == 0) return B_OK; // // Maybe we need to use this PTS to calculate start_time: // if (fContext->coded_frame->pts != kNoPTSValue) { // TRACE(" codec frame PTS: %lld (codec time_base: %d/%d)\n", // fContext->coded_frame->pts, fContext->time_base.num, // fContext->time_base.den); // } else { // TRACE(" codec frame PTS: N/A (codec time_base: %d/%d)\n", // fContext->time_base.num, fContext->time_base.den); // } // Setup media_encode_info, most important is the time stamp. info->start_time = (bigtime_t)(fFramesWritten * 1000000LL / fInputFormat.u.raw_audio.frame_rate); info->flags = B_MEDIA_KEY_FRAME; // Write the chunk status_t ret = WriteChunk(fChunkBuffer, usedBytes, info); if (ret != B_OK) { TRACE(" error writing chunk: %s\n", strerror(ret)); return ret; } fFramesWritten += frameCount; return B_OK; }
void CClassifyGrid::NotifyCCSRefined( int ix, int iy ) { for ( int x = MinBound( ix ); x <= MaxBound( ix ); x++ ) for ( int y = MinBound( iy ); y <= MaxBound( iy ); y++ ) { bool bAllRefined = true; for ( int xx = MinBound( x ); xx <= MaxBound( x ) && bAllRefined; xx++ ) for ( int yy = MinBound( y ); yy <= MaxBound( y ) && bAllRefined; yy++ ) { if ( InBound( xx, yy ) && CheckCCSRefined( Index( xx, yy ) ) == false ) { bAllRefined = false; } } if ( bAllRefined ) { WriteChunk( m_vecPointer[ Index( x, y ) ] ); delete m_vecPointer[ Index( x, y ) ]; m_vecPointer[ Index( x, y ) ] = NULL; } } }
/************* * DESCRIPTION: write brush to scene file * INPUT: iff iff handle * OUTPUT: FALSE if failed else TRUE *************/ BOOL BRUSH::Write(struct IFFHandle *iff) { if(PushChunk(iff, ID_BRSH, ID_FORM, IFFSIZE_UNKNOWN)) return FALSE; if(!WriteChunk(iff, ID_NAME, file, strlen(file)+1)) return FALSE; if(!WriteLongChunk(iff, ID_FLGS, &flags, 1)) return FALSE; if(!WriteLongChunk(iff, ID_TYPE, &type, 1)) return FALSE; if(!WriteLongChunk(iff, ID_WRAP, &wrap, 1)) return FALSE; if(PopChunk(iff)) return FALSE; return TRUE; }
// Callback function for timer expiry TInt CActiveConsole::Callback(TAny* aControl) { switch (((CActiveConsole*)aControl)->iActions & 0x0F) { case ENoaction : break; case EFlush : PRINT(_L("Flush\n")); // drop through to quiet case EFlushQuiet : test_KErrNone(DPTest::FlushCache()); break; default : break; } switch (((CActiveConsole*)aControl)->iActions & 0xF0) { TUint i; case EMemScheme1 : for (i = 0; i < gNextChunk; i++) ReadChunk (&gChunk[i]); break; case EMemScheme2 : for (i = 0; i < gNextChunk; i++) WriteChunk (&gChunk[i]); break; default : break; } return KErrNone; }
void Programmer::WriteMainBlock(const std::string& hexfilename) { FlashMemory flash(flashSize); flash.LoadHex(hexfilename); // read the HEX file printf("Loaded %i bytes from HEX file %s\n\n", flash.GetFlashLastByte() + 1, hexfilename.c_str()); EraseAll(); // erase the chip's MainBlock // do the flash writing ProgressBar pb("Writing MB"); // start writing the flash int address = 0; while (address < flash.GetFlashSize()) { const uint8_t* pChunk = flash.GetFlash() + address; // Check all the bytes of the chunk to see if we have any non-0xff bytes. This is // good because we don't want to waste time sending an empty block for programming. int bytes = 0, c; for (c = 0; c < PROG_CHUNK_SIZE; c++) { if (pChunk[c] != 0xff) bytes = c + 1; } // do we have a non-empty block? if (bytes) WriteChunk(false, flash, address); address += PROG_CHUNK_SIZE; // update the progress bar pb.Refresh(address / double(flash.GetFlashSize())); } }
// Vertex Mapping, We use it in association with VMADs, see WriteDiscVertexMapping below bool CLwoWriter::WriteVertexMapping() { CLwoFile::CLayer::TexCoordMap& texCoords = m_curLayer.GetTexCoordMap(); if(texCoords.size() == 0) return true; MSG_DEBUG("VMAP | TXUV"); // "VMAP" + size WriteChunk(CLwoFile::CHUNK_VMAP); // type : "TXUV" WriteTag(CLwoFile::CHUNK_TXUV); ushort dimension = 2; // UVs are 2D WriteShort(dimension); std::string name("txuv00"); WriteString(name); CLwoFile::CLayer::TexCoordMap::iterator texCoordIt, texCoordEnd; texCoordEnd = texCoords.end(); ushort pointIndex; Vector3D uv(3); for(texCoordIt = texCoords.begin(); texCoordIt != texCoordEnd; ++texCoordIt) // For each LWO texCoord { pointIndex = texCoordIt->first; WriteShort(pointIndex); // vertex position index uv = (texCoordIt->second)[0].m_texCoord; // Retreive the first UV coordinate for this control point (the one assigned to the first face) WriteVector2D(uv); // Write UV } return true; }
/*---------------------------------------------------------------------- | main +---------------------------------------------------------------------*/ int main(int argc, char** argv) { ATX_Result result; ATX_RingBuffer* buffer; int i; /* setup debugging */ #if defined(_DEBUG) && defined(WIN32) int flags = _crtDbgFlag | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF; _CrtSetDbgFlag(flags); /*AllocConsole(); freopen("CONOUT$", "w", stdout);*/ #endif ATX_COMPILER_UNUSED(argc); ATX_COMPILER_UNUSED(argv); result = ATX_RingBuffer_Create(BUFFER_SIZE, &buffer); if (ATX_FAILED(result)) { fprintf(stderr, "ATX_RingBufferConstruct failed (%d)\n", result); return 1; } /* test a few basic functions */ ATX_RingBuffer_Write(buffer, (ATX_ByteBuffer)"ab", 2); { ATX_ByteBuffer bb = ATX_RingBuffer_GetIn(buffer); *bb = 'c'; ATX_RingBuffer_MoveIn(buffer, 1); } ATX_ASSERT(ATX_RingBuffer_GetSpace(buffer) == BUFFER_SIZE-3-1); ATX_ASSERT(ATX_RingBuffer_GetAvailable(buffer) == 3); ATX_ASSERT(ATX_RingBuffer_PeekByte(buffer, 2) == 'c'); ATX_ASSERT(ATX_RingBuffer_ReadByte(buffer) == 'a'); ATX_ASSERT(ATX_RingBuffer_ReadByte(buffer) == 'b'); ATX_ASSERT(ATX_RingBuffer_ReadByte(buffer) == 'c'); ATX_ASSERT(ATX_RingBuffer_GetAvailable(buffer) == 0); ATX_ASSERT(ATX_RingBuffer_GetSpace(buffer) == BUFFER_SIZE-1); ATX_ASSERT(ATX_RingBuffer_GetContiguousSpace(buffer) == BUFFER_SIZE-3); ATX_RingBuffer_Reset(buffer); for (i=0; i<100000000; i++) { if (ATX_FAILED(WriteChunk(buffer))) { printf("WriteChunk failed\n"); return 1; } if (ATX_FAILED(ReadChunk(buffer))) { printf("ReadChunk failed\n"); return 1; } } ATX_RingBuffer_Destroy(buffer); printf("RingBufferTest passed\n"); return 0; }
status_t AVCodecEncoder::_EncodeAudio(const uint8* buffer, size_t bufferSize, int64 frameCount, media_encode_info* info) { status_t ret; // Encode one audio chunk/frame. AVPacket packet; av_init_packet(&packet); // By leaving these NULL, we let the encoder allocate memory as it needs. // This way we don't risk iving a too small buffer. packet.data = NULL; packet.size = 0; // We need to wrap our input data into an AVFrame structure. AVFrame frame; int gotPacket = 0; if (buffer) { avcodec_get_frame_defaults(&frame); frame.nb_samples = frameCount; ret = avcodec_fill_audio_frame(&frame, fContext->channels, fContext->sample_fmt, (const uint8_t *) buffer, bufferSize, 1); if (ret != 0) return B_ERROR; /* Set the presentation time of the frame */ frame.pts = (bigtime_t)(fFramesWritten * 1000000LL / fInputFormat.u.raw_audio.frame_rate); fFramesWritten += frame.nb_samples; ret = avcodec_encode_audio2(fContext, &packet, &frame, &gotPacket); } else { // If called with NULL, ask the encoder to flush any buffers it may // have pending. ret = avcodec_encode_audio2(fContext, &packet, NULL, &gotPacket); } if (buffer && frame.extended_data != frame.data) av_freep(&frame.extended_data); if (ret != 0) { TRACE(" avcodec_encode_audio() failed: %ld\n", ret); return B_ERROR; } fFramesWritten += frameCount; if (gotPacket) { if (fContext->coded_frame) { // Store information about the coded frame in the context. fContext->coded_frame->pts = packet.pts; fContext->coded_frame->key_frame = !!(packet.flags & AV_PKT_FLAG_KEY); } // Setup media_encode_info, most important is the time stamp. info->start_time = packet.pts; if (packet.flags & AV_PKT_FLAG_KEY) info->flags = B_MEDIA_KEY_FRAME; else info->flags = 0; // We got a packet out of the encoder, write it to the output stream ret = WriteChunk(packet.data, packet.size, info); if (ret != B_OK) { TRACE(" error writing chunk: %s\n", strerror(ret)); av_free_packet(&packet); return ret; } } av_free_packet(&packet); return B_OK; }
bool Md2::ConvertToMesh(const std::string &file, float scaleFactor) { FILE *fp = fopen(file.c_str(), "wb"); if (fp == NULL) return false; WriteFileHeader(fp); KeyFramesChunk *keyFramesChunk = new KeyFramesChunk(); keyFramesChunk->numVertices = m_numVertices; for (long i = 0; i < m_numFrames; ++i) { KeyFrame *frame = keyFramesChunk->AddFrame(); for (int j = 0; j < m_numVertices; ++j) frame->vertices[j] = m_frames[i].vertices[j] * scaleFactor; for (int j = 0; j < m_numVertices; ++j) frame->normals[j] = m_frames[i].normals[j]; } WriteChunk(keyFramesChunk, fp); TexCoordsChunk *texCoordsChunk = new TexCoordsChunk(); for (long i = 0; i < m_numTexCoords; ++i) texCoordsChunk->texCoords.push_back(m_texCoords[i]); WriteChunk(texCoordsChunk, fp); KeyFrameTrianglesChunk *trianglesChunk = new KeyFrameTrianglesChunk(); for (long i = 0; i < m_numPolys; ++i) { KeyFrameTriangle t; t.vertices[0] = m_polys[i].vertex[0]; t.vertices[1] = m_polys[i].vertex[1]; t.vertices[2] = m_polys[i].vertex[2]; t.texCoords[0] = m_polys[i].texCoord[0]; t.texCoords[1] = m_polys[i].texCoord[1]; t.texCoords[2] = m_polys[i].texCoord[2]; trianglesChunk->triangles.push_back(t); } WriteChunk(trianglesChunk, fp); if (m_animations.size() > 0) { AnimationsChunk *animationsChunk = new AnimationsChunk(); for (unsigned int i = 0; i < m_animations.size(); ++i) { AnimationSequence a; a.name = m_animations[i].name; a.start = m_animations[i].startFrame; a.end = m_animations[i].endFrame; animationsChunk->animations.push_back(a); } WriteChunk(animationsChunk, fp); } fclose(fp); return true; }
void CCellView::Write(BPositionIO& stream) { // Collect the information needed to write the file, fonts first... int *fontList, usedFonts; fontList = (int *)MALLOC(gFontSizeTable.Count() * sizeof(int)); FailNil(fontList); usedFonts = fContainer->CollectFontList(fontList); if (GetOffsetOf(fontList, fBorderFontID, usedFonts) == -1) fontList[usedFonts++] = fBorderFontID; // ...then the styles int *styleList, usedStyles; styleList = (int *)CALLOC(gStyleTable.Count(), sizeof(int)); FailNil(styleList); usedStyles = fContainer->CollectStyles(styleList); // Write the version number scVersion vers; vers.major = 3; vers.minor = 0; WriteChunk(stream, kscVersion, sizeof(vers), &vers); // Write some header info, global to the document scHeader head; head.defaultFormat = 0; head.flags = htonl(fAutoRecalc ? kscAutoRecalc : 0); head.functionCount = htons(gFuncCount); head.cellCount = htonl(fContainer->GetCellCount()); WriteChunk(stream, kscHeader, sizeof(head), &head); // Write a view scView view; view.windowRect = Window()->Frame(); swap_order(view.windowRect); view.position = fPosition; swap_order(view.position); view.frozen = fFrozen; swap_order(view.frozen); view.curCell = fCurCell; swap_order(view.curCell); view.selection = fSelection; swap_order(view.selection); view.headingFont = htons(GetOffsetOf(fontList, fBorderFontID, usedFonts)); if (fShowGrid) view.flags |= kscShowGrid; if (fShowBorders) view.flags |= kscShowHeadings; if (fDisplayZero) view.flags |= kscDisplayZero; swap_order(view.flags); WriteChunk(stream, kscView, sizeof(view), &view); short size; // Write the widths of the last view size = fCellWidths.Count() * sizeof(short) * 2; void *p = MALLOC(size); FailNil(p); fCellWidths.Write(p); WriteChunk(stream, kscWidths, size, p); FREE(p); // And the heights of course size = fCellHeights.Count() * sizeof(short) * 2; p = MALLOC(size); FailNil(p); fCellHeights.Write(p); WriteChunk(stream, kscHeights, size, p); FREE(p); // Then write the styles for the columns size = fContainer->GetColumnStyles().Count() * sizeof(short) * 2; p = MALLOC(size); FailNil(p); scCSElement *sp = (scCSElement *)p; fContainer->GetColumnStyles().Write(p); for (int i = 0; i < fContainer->GetColumnStyles().Count(); i++) { swap_order(sp[i].index); sp[i].style = htons(GetOffsetOf(styleList, sp[i].style, usedStyles)); } WriteChunk(stream, kscColStyles, size, p); FREE(p); // Continue with the names namemap::iterator ni; for (ni = fNames->begin(); ni != fNames->end(); ni++) { scName name; char c; ushort k = htons(kscName); memset(name.name, 0, 32); CHECKWRITE(stream, &k, 2); strcpy(name.name, (*ni).first); if ((*ni).second.BotRight() == (*ni).second.TopLeft()) { k = htons(32 + 6); CHECKWRITE(stream, &k, 2); CHECKWRITE(stream, name.name, 32); c = valCell; CHECKWRITE(stream, &c, sizeof(c)); cell C = (*ni).second.BotRight(); swap_order(C); CHECKWRITE(stream, &C, sizeof(cell)); } else { k = htons(32 + 10); CHECKWRITE(stream, &k, 2); CHECKWRITE(stream, name.name, 32); c = valRange; CHECKWRITE(stream, &c, sizeof(c)); range r = (*ni).second; swap_order(r); CHECKWRITE(stream, &r, sizeof(range)); } c = opEnd; CHECKWRITE(stream, &c, sizeof(c)); } // Then there are the functions used in this document CSet funcs; fContainer->CollectFunctionNrs(funcs); for (int i = kFunctionCount; i < gFuncCount; i++) if (funcs[i]) { scFunc func; memset(func.name, 0, 10); strcpy(func.name, gFuncArrayByNr[i].funcName); func.argCnt = htons(gFuncArrayByNr[i].argCnt); func.funcNr = htons(gFuncArrayByNr[i].funcNr); WriteChunk(stream, kscFunc, sizeof(func), &func); } // Followed by the formatting information. Fonts first for (int i = 0; i < usedFonts; i++) { CFontMetrics fm = gFontSizeTable[fontList[i]]; scFont *font; font_family fam; font_style sty; fm.Font().GetFamilyAndStyle(&fam, &sty); ulong size = sizeof(scFont) + strlen(fam) + strlen(sty) + 2; font = (scFont *)CALLOC(1, size); FailNil(font); font->size = B_HOST_TO_BENDIAN_FLOAT(fm.Font().Size()); font->color = fm.FontColor(); char *p = (char *)font + sizeof(scFont); strcpy(p, sty); p += strlen(sty) + 1; strcpy(p, fam); WriteChunk(stream, kscFont, size, font); FREE(font); } // Then we get the number formats int *formatList, usedFormats; formatList = (int *)MALLOC(gFormatTable.Count() * sizeof(int)); FailNil(formatList); usedFormats = fContainer->CollectFormats(formatList); for (int i = 0; i < usedFormats; i++) { CFormatter nf; if (formatList[i] < eFirstNewFormat) nf = CFormatter(formatList[i]); else nf = gFormatTable[formatList[i]]; scFormat format; format.nr = htons(nf.FormatID()); format.info[0] = 0; format.info[1] = 0; format.info[2] = 0; format.info[3] = 0; WriteChunk(stream, kscFormat, sizeof(format)-1, &format); } // The style table for (int i = 0; i < usedStyles; i++) { CellStyle cs = gStyleTable[styleList[i]]; scStyle style; memset(&style, 0, sizeof(style)); style.font = htons(GetOffsetOf(fontList, cs.fFont, usedFonts)); style.format = htons(GetOffsetOf(formatList, cs.fFormat, usedFormats)); style.align = cs.fAlignment; style.lowColor = cs.fLowColor; WriteChunk(stream, kscStyle, sizeof(style), &style); } FREE(fontList); FREE(formatList); int *t = (int *)CALLOC(gStyleTable.Count(), sizeof(int)); FailNil(t); for (int i = 0; i < usedStyles; i++) t[styleList[i]] = i; FREE(styleList); styleList = t; // And now its time for some data StProgress progress(this, fContainer->GetCellCount(), pColorYellow, false); CCellIterator iter(fContainer); cell c; while (iter.NextExisting(c)) { scCell cl; cl.loc = c; swap_order(cl.loc); cl.style = htons(styleList[fContainer->GetCellStyleNr(c)]); Value val; fContainer->GetValue(c, val); switch (val.fType) { case eNoData: WriteChunk(stream, kscCellEmpty, kscCellSize, &cl); break; case eNumData: { double d = B_HOST_TO_BENDIAN_DOUBLE(val.fDouble); memcpy(cl.num, &d, sizeof(double)); WriteChunk(stream, kscCellNumber, kscCellSize+sizeof(double), &cl); break; } case eBoolData: memcpy(cl.num, &val.fBool, sizeof(bool)); WriteChunk(stream, kscCellBool, kscCellSize+sizeof(bool), &cl); break; case eTimeData: { time_t t = htonl(val.fTime); memcpy(cl.num, &t, sizeof(time_t)); WriteChunk(stream, kscCellDateTime, kscCellSize+sizeof(time_t), &cl); break; } case eTextData: { WriteChunk(stream, kscCellText, kscCellSize, &cl); const char *t = val; WriteChunk(stream, kscString, strlen(t) + 1, t); break; } default: // there was a warning about not all enum values handled in // switch statement. break; } CFormula form = fContainer->GetCellFormula(c); if (form.IsFormula()) { BMallocIO buf; form.Write(buf); WriteChunk(stream, kscFormula, buf.BufferLength(), buf.Buffer()); } progress.Step(); } WriteCharts(stream); // cleanup the mess WriteChunk(stream, kscEnd, 0, NULL); FREE(styleList); }
/** \fn writeChunkMem \brief */ bool AviListAvi::WriteChunkMem(const char *name,ADMMemio &mem) { return WriteChunk((const uint8_t *)name,mem.size(),mem.getBuffer()); }
status_t AVCodecEncoder::_EncodeVideo(const void* buffer, int64 frameCount, media_encode_info* info) { TRACE_IO("AVCodecEncoder::_EncodeVideo(%p, %lld, %p)\n", buffer, frameCount, info); if (fChunkBuffer == NULL) return B_NO_MEMORY; status_t ret = B_OK; while (frameCount > 0) { size_t bpr = fInputFormat.u.raw_video.display.bytes_per_row; size_t bufferSize = fInputFormat.u.raw_video.display.line_count * bpr; // We should always get chunky bitmaps, so this code should be safe. fSrcFrame.data[0] = (uint8_t*)buffer; fSrcFrame.linesize[0] = bpr; // Run the pixel format conversion sws_scale(fSwsContext, fSrcFrame.data, fSrcFrame.linesize, 0, fInputFormat.u.raw_video.display.line_count, fDstFrame.data, fDstFrame.linesize); // Encode one video chunk/frame. int usedBytes = avcodec_encode_video(fContext, fChunkBuffer, kDefaultChunkBufferSize, fFrame); // avcodec.h says we need to set it. fFrame->pts++; if (usedBytes < 0) { TRACE(" avcodec_encode_video() failed: %d\n", usedBytes); return B_ERROR; } // Maybe we need to use this PTS to calculate start_time: if (fContext->coded_frame->pts != kNoPTSValue) { TRACE(" codec frame PTS: %lld (codec time_base: %d/%d)\n", fContext->coded_frame->pts, fContext->time_base.num, fContext->time_base.den); } else { TRACE(" codec frame PTS: N/A (codec time_base: %d/%d)\n", fContext->time_base.num, fContext->time_base.den); } // Setup media_encode_info, most important is the time stamp. info->start_time = (bigtime_t)(fFramesWritten * 1000000LL / fInputFormat.u.raw_video.field_rate); info->flags = 0; if (fContext->coded_frame->key_frame) info->flags |= B_MEDIA_KEY_FRAME; // Write the chunk ret = WriteChunk(fChunkBuffer, usedBytes, info); if (ret != B_OK) { TRACE(" error writing chunk: %s\n", strerror(ret)); break; } // Skip to the next frame (but usually, there is only one to encode // for video). frameCount--; fFramesWritten++; buffer = (const void*)((const uint8*)buffer + bufferSize); } return ret; }
/************* * DESCRIPTION: write surface to scene file * INPUT: iff iff handler * OUTPUT: FALSE if failed else TRUE *************/ BOOL SURFACE::Write(struct IFFHandle *iff) { TEXTURE *texture; BRUSH *brush; if(PushChunk(iff, ID_SURF, ID_FORM, IFFSIZE_UNKNOWN)) return FALSE; if(name) { if(!WriteChunk(iff, ID_NAME, name, strlen(name)+1)) return FALSE; } if(!WriteLongChunk(iff, ID_FLGS, &flags, 1)) return FALSE; if(!WriteLongChunk(iff, ID_AMBT, &ambient, 3)) return FALSE; if(!WriteLongChunk(iff, ID_DIFU, &diffuse, 3)) return FALSE; if(!WriteLongChunk(iff, ID_SPEC, &specular, 3)) return FALSE; if(!WriteLongChunk(iff, ID_REFL, &reflect, 3)) return FALSE; if(!WriteLongChunk(iff, ID_TRNS, &transpar, 3)) return FALSE; if(!WriteLongChunk(iff, ID_DIFT, &difftrans, 3)) return FALSE; if(!WriteLongChunk(iff, ID_SPCT, &spectrans, 3)) return FALSE; if(!WriteLongChunk(iff, ID_RPHG, &refphong, 1)) return FALSE; if(!WriteLongChunk(iff, ID_TPHG, &transphong, 1)) return FALSE; if(!WriteLongChunk(iff, ID_FLEN, &foglength, 1)) return FALSE; if(!WriteLongChunk(iff, ID_IXOR, &refrindex, 1)) return FALSE; if(!WriteLongChunk(iff, ID_TNSL, &translucency, 1)) return FALSE; texture = this->texture; while(texture) { texture->Write(iff); texture = (TEXTURE*)texture->GetNext(); } brush = this->brush; while(brush) { brush->Write(iff); brush = (BRUSH*)brush->GetNext(); } if(PopChunk(iff)) return FALSE; return TRUE; }
// Polygon Tag mapping bool CLwoWriter::WritePolygonTagMapping() { CLwoFile::CLayer::FaceVector& faces = m_curLayer.GetFaceVector(); CLwoFile::CLayer::FaceVector::iterator faceIt, faceBegin, faceEnd; faceBegin = faces.begin(); faceEnd = faces.end(); // Surfaces ushort surfaceCount = m_curLayer.GetSurfaceMap().size(); { MSG_DEBUG("PTAG | SURF"); // "PTAG" + size for surface indices WriteChunk(CLwoFile::CHUNK_PTAG); // type : "SURF" WriteTag(CLwoFile::CHUNK_SURF); for(faceIt = faceBegin; faceIt != faceEnd; ++faceIt) // For each LWO face { // polygon index ushort faceIndex = (ushort)(faceIt - faceBegin); WriteShort(faceIndex); // 0-based index into TAGS chunk ushort surfIndex = (ushort)(faceIt->m_surface); OBJ_ASSERT(surfIndex == 0 || surfIndex < surfaceCount); WriteShort(surfIndex); // Write surface index, refers to TAGS } } // Parts, export this by default?, if only one part? ushort partCount = m_curLayer.GetPartVector().size(); { MSG_DEBUG("PTAG | PART"); // "PTAG" + size for surface indices WriteChunk(CLwoFile::CHUNK_PTAG); // type : "SURF" WriteTag(CLwoFile::CHUNK_PART); for(faceIt = faceBegin; faceIt != faceEnd; ++faceIt) // for each LWO face { // polygon index ushort faceIndex = (ushort)(faceIt - faceBegin); WriteShort(faceIndex); // 0-based index of the part ushort partIndex = (ushort)(faceIt->m_part) + surfaceCount; OBJ_ASSERT(partIndex == 0 || partIndex < surfaceCount + partCount); WriteShort(partIndex); // Write part index, refers to TAGS } } // Smoothing groups { MSG_DEBUG("PTAG | SMGP"); // "PTAG" + size for smoothing groups WriteChunk(CLwoFile::CHUNK_PTAG); // type : "SMGP" WriteTag(CLwoFile::CHUNK_SMGP); std::stringstream ssSG; CLwoFile::CLayer::SGVector& sgs = m_curLayer.GetSGVector(); for(faceIt = faceBegin; faceIt != faceEnd; ++faceIt) // For each LWO face { // polygon index ushort faceIndex = (ushort)(faceIt - faceBegin); WriteShort(faceIndex); // write Smoothing group index ushort sgIndex = (ushort)(faceIt->m_smoothingGroup.second); CLwoFile::CLayer::SGVector::iterator sgIt; CLwoFile::CLayer::SGVector::iterator sgEnd = sgs.end(); ushort sgSetPos = 0; for(sgIt = sgs.begin(); sgIt != sgEnd; ++sgIt) // For each SG { if(sgIndex == *sgIt) { sgIndex = sgSetPos + surfaceCount + partCount; WriteShort(sgIndex); // Write smoothing group, refers to TAGS break; } ++sgSetPos; } } } return true; }