// encode public static byte[] Encode(libsecondlife.Image image, bool lossless) { if ( (image.Channels & ImageChannels.Color) == 0 || ((image.Channels & ImageChannels.Bump) != 0 && (image.Channels & ImageChannels.Alpha) == 0)) throw new ArgumentException("JPEG2000 encoding is not supported for this channel combination"); MarshalledImage marshalled = new MarshalledImage(); // allocate and copy to input buffer marshalled.width = image.Width; marshalled.height = image.Height; marshalled.components = 3; if ((image.Channels & ImageChannels.Alpha) != 0) marshalled.components++; if ((image.Channels & ImageChannels.Bump) != 0) marshalled.components++; if (!LibslAllocDecoded(ref marshalled)) throw new Exception("LibslAllocDecoded failed"); int n = image.Width * image.Height; if ((image.Channels & ImageChannels.Color) != 0) { Marshal.Copy(image.Red, 0, marshalled.decoded, n); Marshal.Copy(image.Green, 0, (IntPtr)(marshalled.decoded.ToInt64() + n), n); Marshal.Copy(image.Blue, 0, (IntPtr)(marshalled.decoded.ToInt64() + n * 2), n); } if ((image.Channels & ImageChannels.Alpha) != 0) Marshal.Copy(image.Alpha, 0, (IntPtr)(marshalled.decoded.ToInt64() + n * 3), n); if ((image.Channels & ImageChannels.Bump) != 0) Marshal.Copy(image.Bump, 0, (IntPtr)(marshalled.decoded.ToInt64() + n * 4), n); // codec will allocate output buffer if (!LibslEncode(ref marshalled, lossless)) throw new Exception("LibslEncode failed"); // copy output buffer byte[] encoded = new byte[marshalled.length]; Marshal.Copy(marshalled.encoded, encoded, 0, marshalled.length); // free buffers LibslFree(ref marshalled); return encoded; }
public static byte[] Encode(libsecondlife.Image image) { return Encode(image, false); }
private void SLChat(string message, ChatAudibleLevel audible, libsecondlife.ChatType type, ChatSourceType sourcetype, string fromName, LLUUID id, LLUUID ownerid, LLVector3 position) { // This is weird -- we get start/stop typing chats from // other avatars, and we get messages back that we sent. // (Tested on OpenSim r3187) // So we explicitly check for those cases here. if (OnChat != null && (int) type < 4 && id != m_user.Self.AgentID) { Vector3f pos = new Vector3f(position.X, position.Y, position.Z); OnChat(message, fromName, (ChatType) type, id.UUID, ownerid.UUID, pos); } }