/** Reserve space to write the size of chunk and remember the position * for a later call to chunkEndWriteSize(). * Several levels of chunkSizeHere() and chunkEndWriteSize() may be nested. */ private void chunkSizeHere() throws IOException { sizePointers[stackPointer] = raFile.getFilePointer(); writeInt(0); //for now, write 0 to reserve space for "size" item stackPointer++; }
/** Reserve space to write the size of chunk and remember the position * for a later call to chunkEndWriteSize(). * Several levels of chunkSizeHere() and chunkEndWriteSize() may be nested. */ private void chunkSizeHere() throws IOException { sizePointers[stackPointer] = raFile.getFilePointer(); writeInt(0); //for now, write 0 to reserve space for "size" item stackPointer++; }
/** At the end of a chunk, calculate its size and write it to the * position remembered previously. Also pads to 2-byte boundaries. */ private void chunkEndWriteSize() throws IOException { stackPointer--; long position = raFile.getFilePointer(); raFile.seek(sizePointers[stackPointer]); writeInt((int)(position - (sizePointers[stackPointer]+4))); raFile.seek(((position+1)/2)*2); //pad to 2-byte boundary //IJ.log("chunk at 0x"+Long.toHexString(sizePointers[stackPointer]-4)+"-0x"+Long.toHexString(position)); }
/** At the end of a chunk, calculate its size and write it to the * position remembered previously. Also pads to 2-byte boundaries. */ private void chunkEndWriteSize() throws IOException { stackPointer--; long position = raFile.getFilePointer(); raFile.seek(sizePointers[stackPointer]); writeInt((int)(position - (sizePointers[stackPointer]+4))); raFile.seek(((position+1)/2)*2); //pad to 2-byte boundary //IJ.log("chunk at 0x"+Long.toHexString(sizePointers[stackPointer]-4)+"-0x"+Long.toHexString(position)); }
/** Enter a local index 'ix00' to 'indx', the index of indices */ private void writeMainIndxEntry(long ix00pointer, int dwSize, int nFrames) throws IOException { if (pointer2indxNextEntry + 16 + 8 > MAX_INDX_SIZE) { raFile.close(); throw new RuntimeException("AVI_Writer ERROR: Index Size Overflow"); } long savePosition = raFile.getFilePointer(); raFile.seek(pointer2indxNextEntry); writeLong(ix00pointer); writeInt(dwSize); writeInt(nFrames); pointer2indxNextEntry += 16; nIndxEntries++; writeString("JUNK"); // write a JUNK chunk for padding chunkSizeHere(); // size of 'JUNK' for padding goes here raFile.seek(endHeadPointer);// end of the padded range chunkEndWriteSize(); // 'JUNK' finished (nesting level 3) raFile.seek(pointer2indx+4); writeInt((int)(pointer2indxNextEntry - pointer2indx - 8)); //write new size of 'indx' raFile.seek(pointer2indxNEntriesInUse); writeInt(nIndxEntries); //write new number of 'indx' entries raFile.seek(savePosition); }
/** Enter a local index 'ix00' to 'indx', the index of indices */ private void writeMainIndxEntry(long ix00pointer, int dwSize, int nFrames) throws IOException { if (pointer2indxNextEntry + 16 + 8 > MAX_INDX_SIZE) { raFile.close(); throw new RuntimeException("AVI_Writer ERROR: Index Size Overflow"); } long savePosition = raFile.getFilePointer(); raFile.seek(pointer2indxNextEntry); writeLong(ix00pointer); writeInt(dwSize); writeInt(nFrames); pointer2indxNextEntry += 16; nIndxEntries++; writeString("JUNK"); // write a JUNK chunk for padding chunkSizeHere(); // size of 'JUNK' for padding goes here raFile.seek(endHeadPointer);// end of the padded range chunkEndWriteSize(); // 'JUNK' finished (nesting level 3) raFile.seek(pointer2indx+4); writeInt((int)(pointer2indxNextEntry - pointer2indx - 8)); //write new size of 'indx' raFile.seek(pointer2indxNEntriesInUse); writeInt(nIndxEntries); //write new number of 'indx' entries raFile.seek(savePosition); }
writeInt(0x38); // length of the avih sub-CHUNK (38H) not including the writeInt(microSecPerFrame); // dwMicroSecPerFrame - Write the microseconds per frame writeInt(0); // dwMaxBytesPerSec (maximum data rate of the file in bytes per second) writeInt(0); // dwPaddingGranularity (for header length?), previously dwReserved1, usually set to zero. writeInt(0x10); // dwFlags - just set the bit for AVIF_HASINDEX writeInt(zDim); // dwTotalFrames - total frame number writeInt(0); // dwInitialFrames -Initial frame for interleaved files. writeInt(1); // dwStreams - number of streams in the file - here 1 video and zero audio. writeInt(0); // dwSuggestedBufferSize writeInt(xDim); // dwWidth - image width in pixels writeInt(yDim); // dwHeight - image height in pixels writeInt(0); // dwReserved[4] writeInt(0); writeInt(0); writeInt(0); writeInt(56); // Write the length of the strh sub-CHUNK writeString("vids"); // fccType - type of data stream - here 'vids' for video stream writeString("DIB "); // 'DIB ' for Microsoft Device Independent Bitmap. writeInt(0); // dwFlags writeInt(0); // wPriority, wLanguage writeInt(0); // dwInitialFrames writeInt(1); // dwScale writeInt((int)Math.round(getFrameRate(imp))); // dwRate - frame rate for video streams writeInt(0); // dwStart - this field is usually set to zero writeInt(zDim); // dwLength - playing time of AVI file as defined by scale and rate
writeInt(0x38); // length of the avih sub-CHUNK (38H) not including the writeInt(microSecPerFrame); // dwMicroSecPerFrame - Write the microseconds per frame writeInt(0); // dwMaxBytesPerSec (maximum data rate of the file in bytes per second) writeInt(0); // dwPaddingGranularity (for header length?), previously dwReserved1, usually set to zero. writeInt(0x10); // dwFlags - just set the bit for AVIF_HASINDEX writeInt(zDim); // dwTotalFrames - total frame number writeInt(0); // dwInitialFrames -Initial frame for interleaved files. writeInt(1); // dwStreams - number of streams in the file - here 1 video and zero audio. writeInt(0); // dwSuggestedBufferSize writeInt(xDim); // dwWidth - image width in pixels writeInt(yDim); // dwHeight - image height in pixels writeInt(0); // dwReserved[4] writeInt(0); writeInt(0); writeInt(0); writeInt(56); // Write the length of the strh sub-CHUNK writeString("vids"); // fccType - type of data stream - here 'vids' for video stream writeString("DIB "); // 'DIB ' for Microsoft Device Independent Bitmap. writeInt(0); // dwFlags writeInt(0); // wPriority, wLanguage writeInt(0); // dwInitialFrames writeInt(1); // dwScale writeInt((int)Math.round(getFrameRate(imp))); // dwRate - frame rate for video streams writeInt(0); // dwStart - this field is usually set to zero writeInt(zDim); // dwLength - playing time of AVI file as defined by scale and rate