예제 #1
0
        /// <summary>
        /// Writes the DirtyImageFragment to the data stream in compressed format.
        /// </summary>
        /// <param name="s">The stream to write the frame to.</param>
        /// <param name="compressor">A TJCompressor instance that is preconfigured with quality and subsampling options.  Can be null if the image is already compressed.</param>
        /// <param name="compressToBuffer">The buffer to compress to, not used if the image is already compressed.</param>
        public void WriteToDataStream(IDataStream s, TJCompressor compressor, ref byte[] compressToBuffer)
        {
            s.WriteInt16((short)bounds.X);
            s.WriteInt16((short)bounds.Y);
            s.WriteUInt16((ushort)bounds.Width);
            s.WriteUInt16((ushort)bounds.Height);

            if (screenshot.BufferIsCompressed)
            {
                s.WriteInt32(screenshot.Buffer.Length);                  // Write length of image
                s.Write(screenshot.Buffer, 0, screenshot.Buffer.Length); // Write image
            }
            else
            {
                turbojpegCLI.PixelFormat pixelFormat = screenshot.BitsPerPixel == 24 ? turbojpegCLI.PixelFormat.BGR : turbojpegCLI.PixelFormat.BGRX;
                compressor.setSourceImage(screenshot.Buffer, 0, 0, screenshot.Width, screenshot.Stride, screenshot.Height, pixelFormat);
                compressor.compress(ref compressToBuffer, turbojpegCLI.Flag.NONE);
                int compressedSize = compressor.getCompressedSize();
                s.WriteInt32(compressedSize);                 // Write length of image
                s.Write(compressToBuffer, 0, compressedSize); // Write image
            }
        }