diff --git a/CSJ2K/J2KEncoder.cs b/CSJ2K/J2KEncoder.cs new file mode 100644 index 00000000..6d86b9c3 --- /dev/null +++ b/CSJ2K/J2KEncoder.cs @@ -0,0 +1,232 @@ +#region Using Statements +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using CSJ2K.j2k.quantization.quantizer; +using CSJ2K.j2k.image.forwcomptransf; +using CSJ2K.j2k.codestream.writer; +using CSJ2K.j2k.fileformat.writer; +using CSJ2K.j2k.wavelet.analysis; +using CSJ2K.j2k.entropy.encoder; +using CSJ2K.j2k.entropy; +using CSJ2K.j2k.quantization; +using CSJ2K.j2k.image.input; +using CSJ2K.j2k.roi.encoder; +using CSJ2K.j2k.roi; +using CSJ2K.j2k.codestream; +using CSJ2K.j2k.image; +using CSJ2K.j2k.util; +using CSJ2K.j2k.encoder; +using CSJ2K.j2k; +#endregion + +namespace CSJ2K +{ + public static class J2KEncoder + { + #region Default Encoding Parameters + + private readonly static string[][] pinfo = { + 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[] { "pfile", "", + "Loads the arguments from the specified file. Arguments that are "+ + "specified on the command line override the ones from the file.\n"+ + "The arguments file is a simple text file with one argument per "+ + "line of the following form:\n" + + " =\n"+ + "If the argument is of boolean type (i.e. its presence turns a "+ + "feature on), then the 'on' value turns it on, while the 'off' "+ + "value turns it off. The argument name does not include the '-' "+ + "or '+' character. Long lines can be broken into several lines "+ + "by terminating them with '\'. Lines starting with '#' are "+ + "considered as comments. This option is not recursive: any 'pfile' "+ + "argument appearing in the file is ignored.",null}, + 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.\n"+ + "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[] { "i", " [, [, ... ]]", + "Mandatory argument. This option specifies the name of the input "+ + "image files. If several image files are provided, they have to be"+ + " separated by commas in the command line. Supported formats are "+ + "PGM (raw), PPM (raw) and PGX, "+ + "which is a simple extension of the PGM file format for single "+ + "component data supporting arbitrary bitdepths. If the extension "+ + "is '.pgm', PGM-raw file format is assumed, if the extension is "+ + "'.ppm', PPM-raw file format is assumed, otherwise PGX file "+ + "format is assumed. PGM and PPM files are assumed to be 8 bits "+ + "deep. A multi-component image can be specified by either "+ + "specifying several PPM and/or PGX files, or by specifying one "+ + "PPM file.",null}, + new string[] { "o", "", + "Mandatory argument. This option specifies the name of the output "+ + "file to which the codestream will be written.",null}, + new string[] { "verbose", null, + "Prints information about the obtained bit stream.","on"}, + 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"}, + }; + + #endregion Default Encoding Parameters + + private readonly static ParameterList pl; + + static J2KEncoder() + { + pl = new ParameterList(); + string[][] parameters = GetAllParameters(); + for (int i = 0; i < parameters.Length; i++) + { + string[] param = parameters[i]; + pl.Set(param[0], param[3]); + } + + // Custom parameters + pl.Set("Aptype", "layer"); + pl.Set("Qguard_bits", "1"); + pl.Set("Alayers", "sl"); + //pl.Set("lossless", "on"); + } + + public static byte[] EncodeJPEG(Image jpgImage) + { + Tiler imgtiler; + ForwCompTransf fctransf; + ImgDataConverter converter; + EncoderSpecs encSpec; + ForwardWT dwt; + Quantizer quant; + ROIScaler rois; + EntropyCoder ecoder; + PostCompRateAllocator ralloc; + HeaderEncoder headenc; + CodestreamWriter bwriter; + + float rate = Single.MaxValue; + + ImgReaderGDI imgsrc = new ImgReaderGDI(jpgImage); + + imgtiler = new Tiler(imgsrc, 0, 0, 0, 0, jpgImage.Width, jpgImage.Height); + int ntiles = imgtiler.getNumTiles(); + + encSpec = new EncoderSpecs(ntiles, 3, imgsrc, pl); + + fctransf = new ForwCompTransf(imgtiler, encSpec); + converter = new ImgDataConverter(fctransf); + dwt = ForwardWT.createInstance(converter, pl, encSpec); + quant = Quantizer.createInstance(dwt, encSpec); + rois = ROIScaler.createInstance(quant, pl, encSpec); + ecoder = EntropyCoder.createInstance(rois, pl, encSpec.cblks, + encSpec.pss, encSpec.bms, + encSpec.mqrs, encSpec.rts, + encSpec.css, encSpec.sss, + encSpec.lcs, encSpec.tts); + + using (MemoryStream stream = new MemoryStream()) + { + bwriter = new FileCodestreamWriter(stream, Int32.MaxValue); + ralloc = PostCompRateAllocator.createInstance(ecoder, pl, rate, bwriter, encSpec); + + headenc = new HeaderEncoder(imgsrc, new bool[3], dwt, imgtiler, encSpec, rois, ralloc, pl); + ralloc.HeaderEncoder = headenc; + headenc.encodeMainHeader(); + ralloc.initialize(); + headenc.reset(); + headenc.encodeMainHeader(); + bwriter.commitBitstreamHeader(headenc); + + ralloc.runAndWrite(); + bwriter.close(); + + return stream.ToArray(); + } + } + + private static string[][] GetAllParameters() + { + List parameters = new List(); + + string[][] str = pinfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = ForwCompTransf.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = AnWTFilter.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = ForwardWT.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = Quantizer.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = ROIScaler.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = EntropyCoder.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = HeaderEncoder.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = PostCompRateAllocator.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + str = PktEncoder.ParameterInfo; + for (int i = 0; i < str.Length; i++) + parameters.Add(str[i]); + + return parameters.ToArray(); + } + } +} diff --git a/OpenMetaverse/Helpers.cs b/OpenMetaverse/Helpers.cs index e7d86cd3..73660597 100644 --- a/OpenMetaverse/Helpers.cs +++ b/OpenMetaverse/Helpers.cs @@ -399,7 +399,7 @@ namespace OpenMetaverse /// Flags /// Next owner mask (permissions) /// Group mask (permissions) - /// Owner mask (permisions) + /// Owner mask (permissions) /// The calculated CRC public static uint InventoryCRC(int creationDate, byte saleType, sbyte invType, sbyte type, UUID assetID, UUID groupID, int salePrice, UUID ownerID, UUID creatorID, diff --git a/OpenMetaverse/Permissions.cs b/OpenMetaverse/Permissions.cs index 84312cbb..a0a4b3d3 100644 --- a/OpenMetaverse/Permissions.cs +++ b/OpenMetaverse/Permissions.cs @@ -107,29 +107,27 @@ namespace OpenMetaverse public OSD GetOSD() { OSDMap permissions = new OSDMap(5); - permissions["BaseMask"] = OSD.FromUInteger((uint)BaseMask); - permissions["EveryoneMask"] = OSD.FromUInteger((uint)EveryoneMask); - permissions["GroupMask"] = OSD.FromUInteger((uint)GroupMask); - permissions["NextOwnerMask"] = OSD.FromUInteger((uint)NextOwnerMask); - permissions["OwnerMask"] = OSD.FromUInteger((uint)OwnerMask); + permissions["base_mask"] = OSD.FromInteger((uint)BaseMask); + permissions["everyone_mask"] = OSD.FromInteger((uint)EveryoneMask); + permissions["group_mask"] = OSD.FromInteger((uint)GroupMask); + permissions["next_owner_mask"] = OSD.FromInteger((uint)NextOwnerMask); + permissions["owner_mask"] = OSD.FromInteger((uint)OwnerMask); return permissions; } public static Permissions FromOSD(OSD llsd) { Permissions permissions = new Permissions(); - OSDMap map = (OSDMap)llsd; + OSDMap map = llsd as OSDMap; - byte[] bytes = map["BaseMask"].AsBinary(); - permissions.BaseMask = (PermissionMask)Utils.BytesToUInt(bytes); - bytes = map["EveryoneMask"].AsBinary(); - permissions.EveryoneMask = (PermissionMask)Utils.BytesToUInt(bytes); - bytes = map["GroupMask"].AsBinary(); - permissions.GroupMask = (PermissionMask)Utils.BytesToUInt(bytes); - bytes = map["NextOwnerMask"].AsBinary(); - permissions.NextOwnerMask = (PermissionMask)Utils.BytesToUInt(bytes); - bytes = map["OwnerMask"].AsBinary(); - permissions.OwnerMask = (PermissionMask)Utils.BytesToUInt(bytes); + if (map != null) + { + permissions.BaseMask = (PermissionMask)map["base_mask"].AsUInteger(); + permissions.EveryoneMask = (PermissionMask)map["everyone_mask"].AsUInteger(); + permissions.GroupMask = (PermissionMask)map["group_mask"].AsUInteger(); + permissions.NextOwnerMask = (PermissionMask)map["next_owner_mask"].AsUInteger(); + permissions.OwnerMask = (PermissionMask)map["owner_mask"].AsUInteger(); + } return permissions; } diff --git a/OpenMetaverse/Primitives/ParticleSystem.cs b/OpenMetaverse/Primitives/ParticleSystem.cs index 8623483a..d7d9490b 100644 --- a/OpenMetaverse/Primitives/ParticleSystem.cs +++ b/OpenMetaverse/Primitives/ParticleSystem.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using OpenMetaverse.StructuredData; namespace OpenMetaverse { @@ -279,6 +280,58 @@ namespace OpenMetaverse return bytes; } + + public OSD GetOSD() + { + OSDMap map = new OSDMap(); + + map["crc"] = OSD.FromInteger(CRC); + map["part_flags"] = OSD.FromInteger(PartFlags); + map["pattern"] = OSD.FromInteger((int)Pattern); + map["max_age"] = OSD.FromReal(MaxAge); + map["start_age"] = OSD.FromReal(StartAge); + map["inner_angle"] = OSD.FromReal(InnerAngle); + map["outer_angle"] = OSD.FromReal(OuterAngle); + map["burst_rate"] = OSD.FromReal(BurstRate); + map["burst_radius"] = OSD.FromReal(BurstRadius); + map["burst_speed_min"] = OSD.FromReal(BurstSpeedMin); + map["burst_speed_max"] = OSD.FromReal(BurstSpeedMax); + map["burst_part_count"] = OSD.FromInteger(BurstPartCount); + map["ang_velocity"] = OSD.FromVector3(AngularVelocity); + map["part_acceleration"] = OSD.FromVector3(PartAcceleration); + map["texture"] = OSD.FromUUID(Texture); + map["target"] = OSD.FromUUID(Target); + + return map; + } + + public static ParticleSystem FromOSD(OSD osd) + { + ParticleSystem partSys = new ParticleSystem(); + OSDMap map = osd as OSDMap; + + if (map != null) + { + partSys.CRC = map["crc"].AsUInteger(); + partSys.PartFlags = map["part_flags"].AsUInteger(); + partSys.Pattern = (SourcePattern)map["pattern"].AsInteger(); + partSys.MaxAge = (float)map["max_age"].AsReal(); + partSys.StartAge = (float)map["start_age"].AsReal(); + partSys.InnerAngle = (float)map["inner_angle"].AsReal(); + partSys.OuterAngle = (float)map["outer_angle"].AsReal(); + partSys.BurstRate = (float)map["burst_rate"].AsReal(); + partSys.BurstRadius = (float)map["burst_radius"].AsReal(); + partSys.BurstSpeedMin = (float)map["burst_speed_min"].AsReal(); + partSys.BurstSpeedMax = (float)map["burst_speed_max"].AsReal(); + partSys.BurstPartCount = (byte)map["burst_part_count"].AsInteger(); + partSys.AngularVelocity = map["ang_velocity"].AsVector3(); + partSys.PartAcceleration = map["part_acceleration"].AsVector3(); + partSys.Texture = map["texture"].AsUUID(); + partSys.Target = map["target"].AsUUID(); + } + + return partSys; + } } #endregion Subclasses diff --git a/OpenMetaverse/Primitives/TextureEntry.cs b/OpenMetaverse/Primitives/TextureEntry.cs index 729b5a64..2b062b30 100644 --- a/OpenMetaverse/Primitives/TextureEntry.cs +++ b/OpenMetaverse/Primitives/TextureEntry.cs @@ -1281,6 +1281,40 @@ namespace OpenMetaverse return data; } + + public OSD GetOSD() + { + OSDMap map = new OSDMap(); + + map["face"] = OSD.FromInteger(Face); + map["flags"] = OSD.FromInteger((uint)Flags); + map["length"] = OSD.FromReal(Length); + map["rate"] = OSD.FromReal(Rate); + map["size_x"] = OSD.FromInteger(SizeX); + map["size_y"] = OSD.FromInteger(SizeY); + map["start"] = OSD.FromReal(Start); + + return map; + } + + public static TextureAnimation FromOSD(OSD osd) + { + TextureAnimation anim = new TextureAnimation(); + OSDMap map = osd as OSDMap; + + if (map != null) + { + anim.Face = map["face"].AsUInteger(); + anim.Flags = (TextureAnimMode)map["flags"].AsUInteger(); + anim.Length = (float)map["length"].AsReal(); + anim.Rate = (float)map["rate"].AsReal(); + anim.SizeX = map["size_x"].AsUInteger(); + anim.SizeY = map["size_y"].AsUInteger(); + anim.Start = (float)map["start"].AsReal(); + } + + return anim; + } } #endregion Subclasses