diff --git a/LibreMetaverse.GUI/MiniMap.cs b/LibreMetaverse.GUI/MiniMap.cs index e4d170a5..8a03dd88 100644 --- a/LibreMetaverse.GUI/MiniMap.cs +++ b/LibreMetaverse.GUI/MiniMap.cs @@ -1,5 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -28,9 +29,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; -using OpenMetaverse.Imaging; using OpenMetaverse.Assets; -using LibreMetaverse.Imaging; namespace OpenMetaverse.GUI { @@ -204,7 +203,7 @@ namespace OpenMetaverse.GUI { if (state == TextureRequestState.Finished) { - using (J2KReader reader = new J2KReader(asset.AssetData)) + using (var reader = new OpenJpegDotNet.IO.Reader(asset.AssetData)) { if (!reader.ReadHeader()) { return; } _MapLayer = reader.DecodeToBitmap(); diff --git a/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs b/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs index be3e1399..ffbfbb7e 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2006-2016, openmetaverse.co * Copyright (c) 2021, Sjofn LLC. * All rights reserved. @@ -26,8 +26,6 @@ */ using System; -using System.Runtime.InteropServices; -using LibreMetaverse.Imaging; using OpenMetaverse.Imaging; namespace OpenMetaverse.Assets @@ -80,7 +78,7 @@ namespace OpenMetaverse.Assets /// public override void Encode() { - using (J2KWriter writer = new J2KWriter(Image.ExportBitmap())) + using (var writer = new OpenJpegDotNet.IO.Writer(Image.ExportBitmap())) { AssetData = writer.Encode(); } @@ -97,7 +95,7 @@ namespace OpenMetaverse.Assets this.Components = 0; - using (J2KReader reader = new J2KReader(AssetData)) + using (var reader = new OpenJpegDotNet.IO.Reader(AssetData)) { // *hack: decode from ManagedImage directly or better yet, get rid of ManagedImage entirely! if (!reader.ReadHeader()) { return false; } diff --git a/LibreMetaverse/Imaging/ImageHelper.cs b/LibreMetaverse/Imaging/ImageHelper.cs deleted file mode 100644 index 7bc036f5..00000000 --- a/LibreMetaverse/Imaging/ImageHelper.cs +++ /dev/null @@ -1,251 +0,0 @@ -/** - * Copyright (c) 2021, Sjofn LLC. - * All rights reserved. - * - * - Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - Neither the name of the openmetaverse.co nor the names - * of its contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Drawing; -using System.Drawing.Imaging; -using OpenJpegDotNet; - -namespace LibreMetaverse.Imaging -{ - - internal static class ImageHelper - { - - #region Methods - - public static OpenJpegDotNet.Image FromRaw(byte[] raw, int width, int height, int stride, int channels, bool interleaved) - { - if (raw == null) - throw new ArgumentNullException(nameof(raw)); - - var byteAllocated = 1; - var colorSpace = ColorSpace.Srgb; - var precision = 24u / (uint)channels; - var gap = stride - width * channels; - - using (var compressionParameters = new CompressionParameters()) - { - OpenJpeg.SetDefaultEncoderParameters(compressionParameters); - - var subsamplingDx = compressionParameters.SubsamplingDx; - var subsamplingDy = compressionParameters.SubsamplingDy; - - var componentParametersArray = new ImageComponentParameters[channels]; - for (var i = 0; i < channels; i++) - { - componentParametersArray[i] = new ImageComponentParameters - { - Precision = precision, - Bpp = precision, - Signed = false, - Dx = (uint)subsamplingDx, - Dy = (uint)subsamplingDy, - Width = (uint)width, - Height = (uint)height - }; - } - - var image = OpenJpeg.ImageCreate((uint)channels, componentParametersArray, colorSpace); - if (image == null) - return null; - - image.X0 = (uint)compressionParameters.ImageOffsetX0; - image.Y0 = (uint)compressionParameters.ImageOffsetY0; - image.X1 = image.X0 == 0 ? (uint)(width - 1) * (uint)subsamplingDx + 1 : image.X0 + (uint)(width - 1) * (uint)subsamplingDx + 1; - image.Y1 = image.Y0 == 0 ? (uint)(height - 1) * (uint)subsamplingDy + 1 : image.Y0 + (uint)(height - 1) * (uint)subsamplingDy + 1; - - unsafe - { - fixed (byte* pRaw = &raw[0]) - { - // Bitmap data is interleave. - // Convert it to planer - if (byteAllocated == 1) - { - if (interleaved) - { - for (var i = 0; i < channels; i++) - { - var target = image.Components[i].Data; - var pTarget = (int*)target; - var source = pRaw + i; - for (var y = 0; y < height; y++) - { - for (var x = 0; x < width; x++) - { - *pTarget = *source; - pTarget++; - source += channels; - } - - source += gap; - } - } - } - else - { - for (var i = 0; i < channels; i++) - { - var target = image.Components[i].Data; - var pTarget = (int*)target; - var source = pRaw + i * (stride * height); - for (var y = 0; y < height; y++) - { - for (var x = 0; x < width; x++) - { - *pTarget = *source; - pTarget++; - source++; - } - - source += gap; - } - } - } - } - } - } - - return image; - } - } - - public static OpenJpegDotNet.Image FromBitmap(Bitmap bitmap) - { - if (bitmap == null) - throw new ArgumentNullException(nameof(bitmap)); - - var width = bitmap.Width; - var height = bitmap.Height; - var format = bitmap.PixelFormat; - int channels; - var byteAllocated = 0; - ColorSpace colorSpace; - switch (format) - { - case PixelFormat.Format24bppRgb: - channels = 3; - colorSpace = ColorSpace.Srgb; - byteAllocated = 1; - break; - case PixelFormat.Format32bppArgb: - channels = 4; - colorSpace = ColorSpace.Srgb; - byteAllocated = 1; - break; - case PixelFormat.Format8bppIndexed: - channels = 1; - colorSpace = ColorSpace.Srgb; - byteAllocated = 1; - break; - default: - throw new NotSupportedException(); - } - var precision = 24u / (uint)channels; - - BitmapData bitmapData = null; - - try - { - bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, format); - var stride = bitmapData.Stride; - var gap = stride - width * channels; - var scan0 = bitmapData.Scan0; - - using (var compressionParameters = new CompressionParameters()) - { - OpenJpeg.SetDefaultEncoderParameters(compressionParameters); - - var subsamplingDx = compressionParameters.SubsamplingDx; - var subsamplingDy = compressionParameters.SubsamplingDy; - - var componentParametersArray = new ImageComponentParameters[channels]; - for (var i = 0; i < channels; i++) - { - componentParametersArray[i] = new ImageComponentParameters - { - Precision = precision, - Bpp = precision, - Signed = false, - Dx = (uint)subsamplingDx, - Dy = (uint)subsamplingDy, - Width = (uint)width, - Height = (uint)height - }; - } - - var image = OpenJpeg.ImageCreate((uint)channels, componentParametersArray, colorSpace); - if (image == null) - return null; - - image.X0 = (uint)compressionParameters.ImageOffsetX0; - image.Y0 = (uint)compressionParameters.ImageOffsetY0; - image.X1 = image.X0 == 0 ? (uint)(width - 1) * (uint)subsamplingDx + 1 : image.X0 + (uint)(width - 1) * (uint)subsamplingDx + 1; - image.Y1 = image.Y0 == 0 ? (uint)(height - 1) * (uint)subsamplingDy + 1 : image.Y0 + (uint)(height - 1) * (uint)subsamplingDy + 1; - - unsafe - { - // Bitmap data is interleave. - // Convert it to planer - if (byteAllocated == 1) - { - for (var i = 0; i < channels; i++) - { - var target = image.Components[i].Data; - var pTarget = (int*)target; - var source = (byte*)scan0; - source += i; - for (var y = 0; y < height; y++) - { - for (var x = 0; x < width; x++) - { - *pTarget = *source; - pTarget++; - source += channels; - } - - source += gap; - } - } - } - } - - return image; - } - } - finally - { - if (bitmapData != null) - bitmap.UnlockBits(bitmapData); - } - } - - #endregion - - } - -} \ No newline at end of file diff --git a/LibreMetaverse/Imaging/J2KBuffer.cs b/LibreMetaverse/Imaging/J2KBuffer.cs deleted file mode 100644 index 3b8e18af..00000000 --- a/LibreMetaverse/Imaging/J2KBuffer.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace LibreMetaverse.Imaging -{ - [StructLayout(LayoutKind.Sequential)] - internal struct J2KBuffer - { - - public IntPtr Data; - - public int Length; - - public int Position; - - } -} diff --git a/LibreMetaverse/Imaging/J2KReader.cs b/LibreMetaverse/Imaging/J2KReader.cs deleted file mode 100644 index ac3f27e4..00000000 --- a/LibreMetaverse/Imaging/J2KReader.cs +++ /dev/null @@ -1,259 +0,0 @@ -/** - * Copyright (c) 2021, Sjofn LLC. - * All rights reserved. - * - * - Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - Neither the name of the openmetaverse.co nor the names - * of its contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Drawing; -using System.Runtime.InteropServices; -using OpenJpegDotNet; - -namespace LibreMetaverse.Imaging -{ - public sealed class J2KReader : IDisposable - { - - #region Fields - - private readonly J2KBuffer _Buffer; - - private readonly IntPtr _UserData; - - private readonly DelegateHandler _ReadCallback; - - private readonly DelegateHandler _SeekCallback; - - private readonly DelegateHandler _SkipCallback; - - private Codec _Codec; - - private DecompressionParameters _DecompressionParameters; - - private OpenJpegDotNet.Image _Image; - - private readonly Stream _Stream; - - #endregion - - #region Constructors - - public J2KReader(byte[] data) - { - this._Buffer = new J2KBuffer - { - Data = Marshal.AllocHGlobal(data.Length), - Length = data.Length, - Position = 0 - }; - - Marshal.Copy(data, 0, this._Buffer.Data, this._Buffer.Length); - - var size = Marshal.SizeOf(this._Buffer); - this._UserData = Marshal.AllocHGlobal(size); - Marshal.StructureToPtr(this._Buffer, this._UserData, false); - - this._ReadCallback = new DelegateHandler(Read); - this._SeekCallback = new DelegateHandler(Seek); - this._SkipCallback = new DelegateHandler(Skip); - - this._Stream = OpenJpeg.StreamDefaultCreate(true); - OpenJpeg.StreamSetUserData(this._Stream, this._UserData); - OpenJpeg.StreamSetUserDataLength(this._Stream, this._Buffer.Length); - OpenJpeg.StreamSetReadFunction(this._Stream, this._ReadCallback); - OpenJpeg.StreamSetSeekFunction(this._Stream, this._SeekCallback); - OpenJpeg.StreamSetSkipFunction(this._Stream, this._SkipCallback); - } - - #endregion - - #region Properties - - public int Height - { - get; - private set; - } - - /// - /// Gets a value indicating whether this instance has been disposed. - /// - /// true if this instance has been disposed; otherwise, false. - public bool IsDisposed - { - get; - private set; - } - - public int Width - { - get; - private set; - } - - #endregion - - #region Methods - - public bool ReadHeader() - { - this._Codec?.Dispose(); - this._DecompressionParameters?.Dispose(); - this._Image?.Dispose(); - - this._Codec = null; - this._DecompressionParameters = null; - this._Image = null; - - this._Codec = OpenJpeg.CreateDecompress(CodecFormat.J2k); - this._DecompressionParameters = new DecompressionParameters(); - OpenJpeg.SetDefaultDecoderParameters(this._DecompressionParameters); - - if (!OpenJpeg.SetupDecoder(this._Codec, this._DecompressionParameters)) - return false; - - if (!OpenJpeg.ReadHeader(this._Stream, this._Codec, out var image)) - return false; - - this.Width = (int)(image.X1 - image.X0); - this.Height = (int)(image.Y1 - image.Y0); - this._Image = image; - - return true; - } - - public OpenJpegDotNet.Image Decode() - { - if (this._Image == null || this._Image.IsDisposed) - throw new InvalidOperationException(); - - if (!OpenJpeg.Decode(this._Codec, this._Stream, this._Image)) - throw new InvalidOperationException(); - - return this._Image; - } - - public Bitmap DecodeToBitmap() - { - if (this._Image == null || this._Image.IsDisposed) - throw new InvalidOperationException(); - - if (!OpenJpeg.Decode(this._Codec, this._Stream, this._Image)) - throw new InvalidOperationException(); - - return this._Image.ToBitmap(); - } - - #region Event Handlers - - private static ulong Read(IntPtr buffer, ulong bytes, IntPtr userData) - { - unsafe - { - var buf = (J2KBuffer*)userData; - var bytesToRead = (int)Math.Min((ulong)(buf->Length - buf->Position), bytes); - if (bytesToRead > 0) - { - NativeMethods.cstd_memcpy(buffer, IntPtr.Add(buf->Data, buf->Position), bytesToRead); - buf->Position += bytesToRead; - return (ulong)bytesToRead; - } - else - { - return unchecked((ulong)-1); - } - } - } - - private static int Seek(ulong bytes, IntPtr userData) - { - unsafe - { - var buf = (J2KBuffer*)userData; - var position = Math.Min((ulong)buf->Length, bytes); - buf->Position = (int)position; - return 1; - } - } - - private static long Skip(ulong bytes, IntPtr userData) - { - unsafe - { - var buf = (J2KBuffer*)userData; - var bytesToSkip = (int)Math.Min((ulong)buf->Length, bytes); - if (bytesToSkip > 0) - { - buf->Position += bytesToSkip; - return bytesToSkip; - } - else - { - return unchecked(-1); - } - } - } - - #endregion - - #endregion - - #region IDisposable Members - - /// - /// Releases all resources used by this . - /// - public void Dispose() - { - this.Dispose(true); - //GC.SuppressFinalize(this); - } - - /// - /// Releases all resources used by this . - /// - /// Indicate value whether method was called. - private void Dispose(bool disposing) - { - if (this.IsDisposed) - { - return; - } - - this.IsDisposed = true; - - if (disposing) - { - this._Codec?.Dispose(); - this._DecompressionParameters?.Dispose(); - this._Stream.Dispose(); - - Marshal.FreeHGlobal(this._Buffer.Data); - Marshal.FreeHGlobal(this._UserData); - } - } - - #endregion - - } -} diff --git a/LibreMetaverse/Imaging/J2KWriter.cs b/LibreMetaverse/Imaging/J2KWriter.cs deleted file mode 100644 index 8492de78..00000000 --- a/LibreMetaverse/Imaging/J2KWriter.cs +++ /dev/null @@ -1,254 +0,0 @@ -/** - * Copyright (c) 2021, Sjofn LLC. - * All rights reserved. - * - * - Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - Neither the name of the openmetaverse.co nor the names - * of its contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Drawing; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; -using OpenJpegDotNet; - -namespace LibreMetaverse.Imaging -{ - public sealed class J2KWriter : IDisposable - { - - #region Fields - - private readonly J2KBuffer _Buffer; - - private readonly IntPtr _UserData; - - private readonly DelegateHandler _WriteCallback; - - private readonly DelegateHandler _SeekCallback; - - private readonly DelegateHandler _SkipCallback; - - private Codec _Codec; - - private CompressionParameters _CompressionParameters; - - private OpenJpegDotNet.Image _Image; - - private readonly Stream _Stream; - - #endregion - - #region Constructors - - public J2KWriter(Bitmap bitmap) - { - _Image = ImageHelper.FromBitmap(bitmap); - int datalen = (int)(_Image.X1 * _Image.Y1 * _Image.NumberOfComponents + 1024); - - this._Buffer = new J2KBuffer - { - Data = Marshal.AllocHGlobal(datalen), - Length = datalen, - Position = 0 - }; - - var size = Marshal.SizeOf(this._Buffer); - this._UserData = Marshal.AllocHGlobal(size); - Marshal.StructureToPtr(this._Buffer, this._UserData, false); - - this._WriteCallback = new DelegateHandler(Write); - this._SeekCallback = new DelegateHandler(Seek); - this._SkipCallback = new DelegateHandler(Skip); - - this._Stream = OpenJpeg.StreamCreate((ulong)_Buffer.Length, false); - OpenJpeg.StreamSetUserData(this._Stream, this._UserData); - OpenJpeg.StreamSetUserDataLength(this._Stream, this._Buffer.Length); - OpenJpeg.StreamSetWriteFunction(this._Stream, this._WriteCallback); - OpenJpeg.StreamSetSeekFunction(this._Stream, this._SeekCallback); - OpenJpeg.StreamSetSkipFunction(this._Stream, this._SkipCallback); - - var compressionParameters = new CompressionParameters(); - OpenJpeg.SetDefaultEncoderParameters(compressionParameters); - compressionParameters.TcpNumLayers = 1; - compressionParameters.CodingParameterDistortionAllocation = 1; - - _Codec = OpenJpeg.CreateCompress(CodecFormat.J2k); - OpenJpeg.SetupEncoder(_Codec, compressionParameters, _Image); - } - - #endregion - - #region Properties - - public int Height - { - get; - private set; - } - - /// - /// Gets a value indicating whether this instance has been disposed. - /// - /// true if this instance has been disposed; otherwise, false. - public bool IsDisposed - { - get; - private set; - } - - public int Width - { - get; - private set; - } - - #endregion - - #region Methods - - public byte[] Encode() - { - OpenJpeg.StartCompress(_Codec, _Image, _Stream); - OpenJpeg.Encode(_Codec, _Stream); - OpenJpeg.EndCompress(_Codec, _Stream); - - var datast = Marshal.PtrToStructure(_UserData); - var output = new byte[datast.Position]; - Marshal.Copy(_Buffer.Data, output, 0, output.Length); - - return output; - } - - #region Event Handlers - - private static int Seek(ulong bytes, IntPtr userData) - { - unsafe - { - var buf = (J2KBuffer*)userData; - var position = Math.Min((ulong)buf->Length, bytes); - buf->Position = (int)position; - return 1; - } - } - - private static long Skip(ulong bytes, IntPtr userData) - { - unsafe - { - var buf = (J2KBuffer*)userData; - var bytesToSkip = (int)Math.Min((ulong)buf->Length, bytes); - if (bytesToSkip > 0) - { - buf->Position += bytesToSkip; - return bytesToSkip; - } - else - { - return unchecked(-1); - } - } - } - - private static ulong Write(IntPtr buffer, ulong bytes, IntPtr userData) - { - unsafe - { - var buf = (J2KBuffer*)userData; - var bytesToRead = (int)Math.Min((ulong)buf->Length, bytes); - if (bytesToRead > 0) - { - NativeMethods.cstd_memcpy(buffer, IntPtr.Add(buf->Data, buf->Position), bytesToRead); - buf->Position += bytesToRead; - return (ulong)bytesToRead; - } - else - { - return unchecked((ulong)-1); - } - } - } - - #endregion - - #region Helpers - - private CompressionParameters SetupEncoderParameters(OpenJpegDotNet.IO.Parameter parameter) - { - var compressionParameters = new CompressionParameters(); - OpenJpeg.SetDefaultEncoderParameters(compressionParameters); - - if (parameter.Compression.HasValue) - compressionParameters.TcpRates[0] = 1000f / Math.Min(Math.Max(parameter.Compression.Value, 1), 1000); - - compressionParameters.TcpNumLayers = 1; - compressionParameters.CodingParameterDistortionAllocation = 1; - - if (!parameter.Compression.HasValue) - compressionParameters.TcpRates[0] = 4; - - return compressionParameters; - } - - #endregion - - #endregion - - #region IDisposable Members - - /// - /// Releases all resources used by this . - /// - public void Dispose() - { - this.Dispose(true); - //GC.SuppressFinalize(this); - } - - /// - /// Releases all resources used by this . - /// - /// Indicate value whether method was called. - private void Dispose(bool disposing) - { - if (this.IsDisposed) - { - return; - } - - this.IsDisposed = true; - - if (disposing) - { - this._Codec?.Dispose(); - this._CompressionParameters?.Dispose(); - this._Stream.Dispose(); - - Marshal.FreeHGlobal(this._Buffer.Data); - Marshal.FreeHGlobal(this._UserData); - } - } - - #endregion - - } -} diff --git a/LibreMetaverse/ImportExport/ColladalLoader.cs b/LibreMetaverse/ImportExport/ColladalLoader.cs index 110bd9a8..ea11e411 100644 --- a/LibreMetaverse/ImportExport/ColladalLoader.cs +++ b/LibreMetaverse/ImportExport/ColladalLoader.cs @@ -1,5 +1,6 @@ -/* +/** * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -164,7 +165,7 @@ namespace OpenMetaverse.ImportExport bitmap = resized; } - using (var writer = new LibreMetaverse.Imaging.J2KWriter(bitmap)) + using (var writer = new OpenJpegDotNet.IO.Writer(bitmap)) { material.TextureData = writer.Encode(); } diff --git a/LibreMetaverse/LibreMetaverse.csproj b/LibreMetaverse/LibreMetaverse.csproj index 3e59cd34..42d88085 100644 --- a/LibreMetaverse/LibreMetaverse.csproj +++ b/LibreMetaverse/LibreMetaverse.csproj @@ -125,7 +125,7 @@ - + diff --git a/Programs/examples/TestClient/Commands/Inventory/DumpOutfitCommand.cs b/Programs/examples/TestClient/Commands/Inventory/DumpOutfitCommand.cs index 0fc152a9..4fa1a049 100644 --- a/Programs/examples/TestClient/Commands/Inventory/DumpOutfitCommand.cs +++ b/Programs/examples/TestClient/Commands/Inventory/DumpOutfitCommand.cs @@ -1,11 +1,35 @@ +/** + * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + using System; using System.Text; using System.IO; using System.Collections.Generic; -using OpenMetaverse; -using OpenMetaverse.Imaging; using OpenMetaverse.Assets; -using LibreMetaverse.Imaging; namespace OpenMetaverse.TestClient { @@ -92,13 +116,11 @@ namespace OpenMetaverse.TestClient File.WriteAllBytes(assetTexture.AssetID + ".jp2", assetTexture.AssetData); Console.WriteLine("Wrote JPEG2000 image " + assetTexture.AssetID + ".jp2"); - using (J2KReader reader = new J2KReader(assetTexture.AssetData)) + using (var reader = new OpenJpegDotNet.IO.Reader(assetTexture.AssetData)) { reader.ReadHeader(); - System.Drawing.Bitmap bitmap = reader.DecodeToBitmap(); - ManagedImage imgData = new ManagedImage(bitmap); - byte[] tgaFile = imgData.ExportTGA(); - File.WriteAllBytes(assetTexture.AssetID + ".tga", tgaFile); + OpenJpegDotNet.RawImage tga = reader.Decode().ToTarga(); + File.WriteAllBytes(assetTexture.AssetID + ".tga", tga.Bytes); } Console.WriteLine("Wrote TGA image " + assetTexture.AssetID + ".tga"); } diff --git a/Programs/examples/TestClient/Commands/Inventory/UploadImageCommand.cs b/Programs/examples/TestClient/Commands/Inventory/UploadImageCommand.cs index de21ef1d..3c53e033 100644 --- a/Programs/examples/TestClient/Commands/Inventory/UploadImageCommand.cs +++ b/Programs/examples/TestClient/Commands/Inventory/UploadImageCommand.cs @@ -1,3 +1,30 @@ +/** + * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + using System; using System.Threading; using System.Drawing; @@ -88,7 +115,7 @@ namespace OpenMetaverse.TestClient // Upload JPEG2000 images untouched UploadData = System.IO.File.ReadAllBytes(fileName); - using (var reader = new LibreMetaverse.Imaging.J2KReader(UploadData)) + using (var reader = new OpenJpegDotNet.IO.Reader(UploadData)) { reader.ReadHeader(); bitmap = reader.DecodeToBitmap(); @@ -137,7 +164,7 @@ namespace OpenMetaverse.TestClient bitmap.Dispose(); bitmap = resized; } - using (var writer = new LibreMetaverse.Imaging.J2KWriter(bitmap)) + using (var writer = new OpenJpegDotNet.IO.Writer(bitmap)) { UploadData = writer.Encode(); }