Пример #1
0
 /// <summary>
 /// Writes the MovedImageFragment to the data stream.
 /// </summary>
 /// <param name="s"></param>
 public void WriteToDataStream(IDataStream s)
 {
     s.WriteInt16((short)bounds.X);
     s.WriteInt16((short)bounds.Y);
     s.WriteUInt16((ushort)bounds.Width);
     s.WriteUInt16((ushort)bounds.Height);
     s.WriteInt16((short)source.X);
     s.WriteInt16((short)source.Y);
 }
Пример #2
0
        internal void WriteToDataStream(IDataStream s)
        {
            s.WriteByte(adapterIndex);
            s.WriteByte(outputIndex);

            byte[] strData = Encoding.UTF8.GetBytes(adapterName);
            s.WriteUInt16((ushort)strData.Length);
            s.Write(strData, 0, strData.Length);

            strData = Encoding.UTF8.GetBytes(outputName);
            s.WriteUInt16((ushort)strData.Length);
            s.Write(strData, 0, strData.Length);

            s.WriteInt16(X);
            s.WriteInt16(Y);
            s.WriteUInt16(Width);
            s.WriteUInt16(Height);
        }
Пример #3
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
            }
        }
Пример #4
0
        public void WriteToDataStream(IDataStream s, ref byte[] compressToBuffer, int jpegQuality = 80, turbojpegCLI.SubsamplingOption subsamp = turbojpegCLI.SubsamplingOption.SAMP_420)
        {
            if (movedFragments.Length > 65535)
            {
                throw new Exception("FragmentedImage has too many movedFragments: " + movedFragments.Length);
            }

            if (dirtyFragments.Length > 65535)
            {
                throw new Exception("FragmentedImage has too many dirtyFragments: " + dirtyFragments.Length);
            }

            s.WriteByte((byte)Command.GetScreenCapture); // Write command code

            s.WriteByte(streamId);                       // Write stream ID

            // Calculate buffer sizes

            s.WriteUInt16((ushort)movedFragments.Length);             // Write number of fragments
            s.WriteUInt16((ushort)dirtyFragments.Length);             // Write number of fragments

            if (movedFragments.Length == 0 && dirtyFragments.Length == 0)
            {
                return;
            }

            foreach (MovedImageFragment moveFrag in movedFragments)
            {
                moveFrag.WriteToDataStream(s);
            }

            if (dirtyFragments.Length > 0)
            {
                if (dirtyFragments[0].screenshot.BufferIsCompressed)
                {
                    foreach (DirtyImageFragment dirtyFrag in dirtyFragments)
                    {
                        dirtyFrag.WriteToDataStream(s, null, ref compressToBuffer);
                    }
                }
                else
                {
                    using (turbojpegCLI.TJCompressor compressor = new turbojpegCLI.TJCompressor())
                    {
                        compressor.setSubsamp(subsamp);
                        compressor.setJPEGQuality(jpegQuality);

                        int requiredBufferSize = 0;
                        foreach (DirtyImageFragment dirtyFrag in dirtyFragments)
                        {
                            int thisBufferSize = turbojpegCLI.TJ.bufSize(dirtyFrag.screenshot.Width, dirtyFrag.screenshot.Height, subsamp);
                            requiredBufferSize = Math.Max(requiredBufferSize, thisBufferSize);
                        }
                        if (compressToBuffer == null || compressToBuffer.Length < requiredBufferSize)
                        {
                            compressToBuffer = new byte[requiredBufferSize];
                        }

                        foreach (DirtyImageFragment dirtyFrag in dirtyFragments)
                        {
                            dirtyFrag.WriteToDataStream(s, compressor, ref compressToBuffer);
                        }
                    }
                }
            }
        }