示例#1
0
        private void WriteQuantizationTables(ref JpegWriter writer)
        {
            List <JpegQuantizationTable>?quantizationTables = _quantizationTables;

            if (quantizationTables is null)
            {
                throw new InvalidOperationException();
            }

            writer.WriteMarker(JpegMarker.DefineQuantizationTable);

            ushort totalByteCount = 0;

            foreach (JpegQuantizationTable table in quantizationTables)
            {
                totalByteCount += table.BytesRequired;
            }

            writer.WriteLength(totalByteCount);

            foreach (JpegQuantizationTable table in quantizationTables)
            {
                Span <byte> buffer = writer.GetSpan(table.BytesRequired);
                table.TryWrite(buffer, out int bytesWritten);
                writer.Advance(bytesWritten);
            }
        }
示例#2
0
        private void WriteHuffmanTables(ref JpegWriter writer)
        {
            if (_encodingTables.IsEmpty)
            {
                throw new InvalidOperationException();
            }

            writer.WriteMarker(JpegMarker.DefineHuffmanTable);
            ushort totalByteCoubt = _encodingTables.GetTotalBytesRequired();

            writer.WriteLength(totalByteCoubt);
            _encodingTables.Write(ref writer);
        }
示例#3
0
        private static ReadOnlySequence <byte> CopyMarkerData(ref JpegReader reader, ref JpegWriter writer)
        {
            if (!reader.TryReadLength(out ushort length))
            {
                ThrowInvalidDataException(reader.ConsumedByteCount, "Unexpected end of input data when reading segment length.");
            }

            if (!reader.TryReadBytes(length, out ReadOnlySequence <byte> buffer))
            {
                ThrowInvalidDataException(reader.ConsumedByteCount, "Unexpected end of input data when reading segment content.");
            }
            writer.WriteLength(length);
            writer.WriteBytes(buffer);
            return(buffer);
        }