void ReadPalette() { VidBlockTypes blockType = (VidBlockTypes)reader.ReadByte(); if (blockType != VidBlockTypes.Palette) { throw new Exception("VidFile: Palette block not encountered after header."); } int pos = 0; byte[] data = reader.ReadBytes(paletteDataLength); palette = new Color32[paletteColorCount]; for (int i = 0; i < paletteColorCount; i++) { palette[i] = new Color32( (byte)(data[pos++] * paletteMultiplier), (byte)(data[pos++] * paletteMultiplier), (byte)(data[pos++] * paletteMultiplier), 255); } }
int ReadBlock() { if (endOfFileReached) { return(0); } reader.BaseStream.Position = streamPosition; // Read next block type VidBlockTypes blockType = (VidBlockTypes)reader.ReadByte(); lastBlockType = blockType; // Handle null block if (blockType == VidBlockTypes.Null) { //Debug.Log("Null block encountered."); streamPosition = reader.BaseStream.Position; return(0); } try { switch (blockType) { case VidBlockTypes.Palette: //Debug.Log("Skipping extra palette data"); streamPosition += paletteDataLength; break; case VidBlockTypes.Audio_StartFrame: //Debug.Log("Reading Audio_StartFrame"); ReadAudioStartFrame(reader); break; case VidBlockTypes.Audio_IncrementalFrame: //Debug.Log("Reading Audio_IncrementalFrame"); ReadAudioIncrementalFrame(reader); break; case VidBlockTypes.Video_StartFrame: //Debug.Log("Reading Video_StartFrame"); ReadVideoStartFrame(reader); break; case VidBlockTypes.Video_IncrementalFrame: //Debug.Log("Reading Video_IncrementalFrame"); ReadVideoIncrementalFrame(reader); break; case VidBlockTypes.Video_IncrementalRowOffsetFrame: //Debug.Log("Reading Video_IncrementalRowOffsetFrame"); ReadVideoRowOffsetFrame(reader); break; case VidBlockTypes.EndOfFile: Debug.Log("End of VID file reached"); endOfFileReached = true; break; default: throw new Exception("VidFile: Invalid/Unknown block type encountered."); } } catch (Exception ex) { Debug.Log(ex.Message); return(0); } // Calculate delay time for this frame // Generally equivalent to (float)audioBuffer.Length / (float)sampleRate // Seems to differ mainly at beginning and end of video //frameDelay = ((float)(header.GlobalDelay + (float)lastDelay) * (float)delayMultiplier) / (float)sampleRate; frameDelay = (double)audioBuffer.Length / (double)sampleRate; long bytesRead = reader.BaseStream.Position - streamPosition; streamPosition = reader.BaseStream.Position; currentBlock++; return((int)bytesRead); }
int ReadBlock() { if (endOfFileReached) { return(0); } reader.BaseStream.Position = streamPosition; // Read next block type VidBlockTypes blockType = (VidBlockTypes)reader.ReadByte(); lastBlockType = blockType; // Handle null block if (blockType == VidBlockTypes.Null) { //Debug.Log("Null block encountered."); streamPosition = reader.BaseStream.Position; return(0); } try { switch (blockType) { case VidBlockTypes.Palette: //Debug.Log("Skipping extra palette data"); streamPosition += paletteDataLength; break; case VidBlockTypes.Audio_StartFrame: //Debug.Log("Reading Audio_StartFrame"); ReadAudioStartFrame(); break; case VidBlockTypes.Audio_IncrementalFrame: //Debug.Log("Reading Audio_IncrementalFrame"); ReadAudioIncrementalFrame(); break; case VidBlockTypes.Video_StartFrame: //Debug.Log("Reading Video_StartFrame"); ReadVideoStartFrame(); break; case VidBlockTypes.Video_IncrementalFrame: //Debug.Log("Reading Video_IncrementalFrame"); ReadVideoIncrementalFrame(); break; case VidBlockTypes.Video_IncrementalRowOffsetFrame: //Debug.Log("Reading Video_IncrementalRowOffsetFrame"); ReadVideoRowOffsetFrame(); break; case VidBlockTypes.EndOfFile: Debug.Log("End of VID file reached"); endOfFileReached = true; break; default: throw new Exception("VidFile: Invalid/Unknown block type encountered."); } } catch (Exception ex) { Debug.Log(ex.Message); return(0); } // Calculate delay time for this frame // Generally equivalent to (float)audioBuffer.Length / (float)sampleRate // Seems to differ mainly at beginning and end of video //frameDelay = ((float)(header.GlobalDelay + (float)lastDelay) * (float)delayMultiplier) / (float)sampleRate; frameDelay = (double)audioBuffer.Length / (double)sampleRate; // Daggerfall .VID files always have at least an audioBuffer.Length of 740 while in the middle of audio portions. // As the audio portion ends, this length can be much shorter, causing frameDelay to become very short // and making playback speed up. Enforcing a minimum based on a length of 740 to fix this. // This fixes the ends of ANIM0000.VID and ANIM0005.VID. if (frameDelay < minFrameDelay) { frameDelay = minFrameDelay; } long bytesRead = reader.BaseStream.Position - streamPosition; streamPosition = reader.BaseStream.Position; currentBlock++; return((int)bytesRead); }
int ReadBlock() { if (endOfFileReached) return 0; reader.BaseStream.Position = streamPosition; // Read next block type VidBlockTypes blockType = (VidBlockTypes)reader.ReadByte(); lastBlockType = blockType; // Handle null block if (blockType == VidBlockTypes.Null) { //Debug.Log("Null block encountered."); streamPosition = reader.BaseStream.Position; return 0; } try { switch (blockType) { case VidBlockTypes.Palette: //Debug.Log("Skipping extra palette data"); streamPosition += paletteDataLength; break; case VidBlockTypes.Audio_StartFrame: //Debug.Log("Reading Audio_StartFrame"); ReadAudioStartFrame(reader); break; case VidBlockTypes.Audio_IncrementalFrame: //Debug.Log("Reading Audio_IncrementalFrame"); ReadAudioIncrementalFrame(reader); break; case VidBlockTypes.Video_StartFrame: //Debug.Log("Reading Video_StartFrame"); ReadVideoStartFrame(reader); break; case VidBlockTypes.Video_IncrementalFrame: //Debug.Log("Reading Video_IncrementalFrame"); ReadVideoIncrementalFrame(reader); break; case VidBlockTypes.Video_IncrementalRowOffsetFrame: //Debug.Log("Reading Video_IncrementalRowOffsetFrame"); ReadVideoRowOffsetFrame(reader); break; case VidBlockTypes.EndOfFile: Debug.Log("End of VID file reached"); endOfFileReached = true; break; default: throw new Exception("VidFile: Invalid/Unknown block type encountered."); } } catch (Exception ex) { Debug.Log(ex.Message); return 0; } // Calculate delay time for this frame // Generally equivalent to (float)audioBuffer.Length / (float)sampleRate // Seems to differ mainly at beginning and end of video //frameDelay = ((float)(header.GlobalDelay + (float)lastDelay) * (float)delayMultiplier) / (float)sampleRate; frameDelay = (double)audioBuffer.Length / (double)sampleRate; long bytesRead = reader.BaseStream.Position - streamPosition; streamPosition = reader.BaseStream.Position; currentBlock++; return (int)bytesRead; }