diff --git a/LibreMetaverse.Tests/LibreMetaverse.Tests.csproj b/LibreMetaverse.Tests/LibreMetaverse.Tests.csproj index c17712d0..d431557f 100644 --- a/LibreMetaverse.Tests/LibreMetaverse.Tests.csproj +++ b/LibreMetaverse.Tests/LibreMetaverse.Tests.csproj @@ -37,9 +37,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/LibreMetaverse.Types/Utils.cs b/LibreMetaverse.Types/Utils.cs index 1263cfd7..9bd6af32 100644 --- a/LibreMetaverse.Types/Utils.cs +++ b/LibreMetaverse.Types/Utils.cs @@ -401,7 +401,9 @@ namespace OpenMetaverse { var salt = new byte[32]; using (var generator = RandomNumberGenerator.Create()) { generator.GetBytes(salt); } +#pragma warning disable SYSLIB0041 var derivebytes = new Rfc2898DeriveBytes(str, salt, 10000); +#pragma warning restore SYSLIB0041 byte[] hash = derivebytes.GetBytes(20); return Convert.ToBase64String(salt) + "|" + Convert.ToBase64String(hash); } diff --git a/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs b/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs index eaa2141c..059dcb0b 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs @@ -78,7 +78,7 @@ namespace OpenMetaverse.Assets /// public sealed override void Encode() { - AssetData = J2kImage.ToBytes(Image.ExportBitmap()); + AssetData = J2K.ToBytes(Image.ExportBitmap()); } /// diff --git a/LibreMetaverse/Imaging/J2K.cs b/LibreMetaverse/Imaging/J2K.cs new file mode 100644 index 00000000..9a3cebd2 --- /dev/null +++ b/LibreMetaverse/Imaging/J2K.cs @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2024, 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 CoreJ2K; +using CoreJ2K.j2k.util; +using SkiaSharp; + +namespace OpenMetaverse.Imaging +{ + public static class J2K + { + private static readonly string[][] EncoderPInfo = + { + new string[] + { + "debug", null, + "Print debugging messages when an error is encountered.", + "off" + }, + new string[] + { + "disable_jp2_extension", "[on|off]", + "JJ2000 automatically adds .jp2 extension when using 'file_format' option. This option disables it when on.", + "off" + }, + new string[] + { + "file_format", "[on|off]", + "Puts the JPEG 2000 codestream in a JP2 file format wrapper.", + "off" + }, + new string[] + { + "pph_tile", "[on|off]", + "Packs the packet headers in the tile headers.", + "off" + }, + new string[] + { + "pph_main", "[on|off]", + "Packs the packet headers in the main header.", + "off" + }, + new string[] + { + "tile_parts", "", + "This option specifies the maximum number of packets to have in one tile-part. 0 means include all packets in first tile-part of each tile", + "0" + }, + new string[] + { + "tiles", " ", + "This option specifies the maximum tile dimensions to use. If both dimensions are 0 then no tiling is used.", + "0 0" + }, + new string[] + { + "ref", " ", + "Sets the origin of the image in the canvas system. It sets the coordinate of the top-left corner of the image reference grid, with respect to the canvas origin", + "0 0" + }, + new string[] + { + "tref", " ", + "Sets the origin of the tile partitioning on the reference grid, with respect to the canvas origin. The value of 'x' ('y') specified can not be larger than the 'x' one specified in the ref option.", + "0 0" + }, + new string[] + { + "rate", "", + "This is the output bitrate of the codestream in bits per pixel. When equal to -1, no image information (beside quantization effects) is discarded during compression. Note: In the case where '-file_format' option is used, the resulting file may have a larger bitrate.", + "-1" + }, + new string[] + { + "lossless", "[on|off]", + "Specifies a lossless compression for the encoder. This options is equivalent to use reversible quantization ('-Qtype reversible') and 5x3 wavelet filters pair ('-Ffilters w5x3'). Note that this option cannot be used with '-rate'. When this option is off, the quantization type and the filters pair is defined by '-Qtype' and '-Ffilters' respectively.", + "off" + }, + new string[] + { + "verbose", null, + "Prints information about the obtained bit stream.", + "off" + }, + new string[] + { + "v", "[on|off]", "Prints version and copyright information.", + "off" + }, + new string[] + { + "u", "[on|off]", + "Prints usage information. " + + "If specified all other arguments (except 'v') are ignored", + "off" + }, + }; + + public static ParameterList GetDefaultEncoderParameterList() + { + return J2kImage.GetDefaultEncoderParameterList(EncoderPInfo); + } + + public static byte[] ToBytes(SKBitmap bitmap) + { + return J2kImage.ToBytes(bitmap, GetDefaultEncoderParameterList()); + } + } +} \ No newline at end of file diff --git a/LibreMetaverse/ImportExport/ColladalLoader.cs b/LibreMetaverse/ImportExport/ColladalLoader.cs index ff3d6d39..a14316b5 100644 --- a/LibreMetaverse/ImportExport/ColladalLoader.cs +++ b/LibreMetaverse/ImportExport/ColladalLoader.cs @@ -152,7 +152,8 @@ namespace OpenMetaverse.ImportExport width = width > 1024 ? 1024 : width; height = height > 1024 ? 1024 : height; - Logger.Log("Image has irregular dimensions " + origWidth + "x" + origHieght + ". Resizing to " + width + "x" + height, Helpers.LogLevel.Info); + Logger.Log($"Image has irregular dimensions {origWidth}x{origHieght}. Resizing to {width}x{height}", + Helpers.LogLevel.Info); var info = new SKImageInfo(width, height); var scaledImage = new SKBitmap(info); @@ -161,9 +162,9 @@ namespace OpenMetaverse.ImportExport bitmap = scaledImage; } - material.TextureData = J2kImage.ToBytes(bitmap); + material.TextureData = Imaging.J2K.ToBytes(bitmap); - Logger.Log("Successfully encoded " + fname, Helpers.LogLevel.Info); + Logger.Log($"Successfully encoded {fname}", Helpers.LogLevel.Info); } catch (Exception ex) { diff --git a/LibreMetaverse/LibreMetaverse.csproj b/LibreMetaverse/LibreMetaverse.csproj index 6238720b..5dd7e7d0 100644 --- a/LibreMetaverse/LibreMetaverse.csproj +++ b/LibreMetaverse/LibreMetaverse.csproj @@ -43,12 +43,12 @@ True - - - - + + + + - + diff --git a/Programs/GridProxy/GridProxy.csproj b/Programs/GridProxy/GridProxy.csproj index f3ae4824..9ef4d35c 100644 --- a/Programs/GridProxy/GridProxy.csproj +++ b/Programs/GridProxy/GridProxy.csproj @@ -11,7 +11,7 @@ false - + diff --git a/Programs/examples/TestClient/Commands/Inventory/UploadImageCommand.cs b/Programs/examples/TestClient/Commands/Inventory/UploadImageCommand.cs index 6e4e060b..3e5254b0 100644 --- a/Programs/examples/TestClient/Commands/Inventory/UploadImageCommand.cs +++ b/Programs/examples/TestClient/Commands/Inventory/UploadImageCommand.cs @@ -28,6 +28,7 @@ using System; using System.Threading; using CoreJ2K; +using CoreJ2K.j2k.util; using SkiaSharp; namespace OpenMetaverse.TestClient @@ -150,7 +151,8 @@ namespace OpenMetaverse.TestClient bitmap = scaledImage; } } - uploadData = J2kImage.ToBytes(bitmap); + + uploadData = Imaging.J2K.ToBytes(bitmap); } catch (Exception ex) { diff --git a/Programs/examples/TestClient/TestClient.csproj b/Programs/examples/TestClient/TestClient.csproj index ea42c4ca..cb7e4ed0 100644 --- a/Programs/examples/TestClient/TestClient.csproj +++ b/Programs/examples/TestClient/TestClient.csproj @@ -16,7 +16,7 @@ - +