internal void Read(BinaryReader _reader, bool _decompressImage) { m_contentRectangle = new Rectangle(_reader.ReadInt32(), _reader.ReadInt32(), _reader.ReadInt32(), _reader.ReadInt32()); m_compressedImageFormat = (ImageFile.FILE_FORMAT)_reader.ReadInt32(); // Read compressed image int compressedImageLength = _reader.ReadInt32(); m_compressedImage = new byte[compressedImageLength]; _reader.Read(m_compressedImage, 0, compressedImageLength); if (!_decompressImage) { return; } // Attempt to read the image file try { using (NativeByteArray imageContent = new NativeByteArray(m_compressedImage)) { m_image = new ImageFile(imageContent, m_compressedImageFormat); } } catch (Exception _e) { throw new Exception("An error occurred while attempting to decompress image from byte[] (length = " + compressedImageLength + " format = " + m_compressedImageFormat + ")", _e); } }
void XRSetAppEnvironment() { NativeByteArray bytes = Serialize.allocNativeByteArrayAndWrite(xrAppEnvironment); c8XRIos_setXRAppEnvironment(ref bytes); Serialize.freeAllocedNativeByteArray(bytes); }
void XRConfigure(MessageBuilder configMessageBuilder) { NativeByteArray b = Serialize.allocNativeByteArrayAndWrite(configMessageBuilder); c8XRIos_configureXR(ref b); Serialize.freeAllocedNativeByteArray(b); }
protected new void CreateGreyscaleFromAlpha(Texture2D tex) { Color32[] pixels32 = tex.GetPixels32(); Image = new NativeByteArray(pixels32.Length); for (Int32 i = 0; i < pixels32.Length; i++) { Image[i] = pixels32[i].a; } }
private void CreateGreyscaleFromRgb(Texture2D tex) { Color32[] pixels32 = tex.GetPixels32(); Image = new NativeByteArray(pixels32.Length); for (Int32 i = 0; i < pixels32.Length; i++) { Image[i] = pixels32[i].r; } }
void XRGetAppEnvironment() { NativeByteArray bytes = new NativeByteArray(); c8XRIos_getXRAppEnvironment(ref bytes); byte[] ret = new byte[bytes.size]; Marshal.Copy(bytes.bytes, ret, 0, bytes.size); XRAppEnvironment.Reader r = Serialize.read(bytes).getRoot(XRAppEnvironment.factory); xrAppEnvironment.setRoot(XRAppEnvironment.factory, r); }
private new void CreateHeightAlpha(Texture2D tex) { Color32[] pixels32 = tex.GetPixels32(); Image = new NativeByteArray(pixels32.Length * 2); for (Int32 i = 0; i < pixels32.Length; i++) { Image[i * 2] = pixels32[i].r; Image[i * 2 + 1] = pixels32[i].a; } }
public ImageId GetImage() { using (var buffer = new NativeByteArray(20)) { if (NativeMethods.sp_playlist_get_image(_handle, buffer.IntPtr)) { return new ImageId(buffer.Value()); } return null; } }
protected new void CreateRGB(Texture2D tex) { Color32[] pixels32 = tex.GetPixels32(); _image = new NativeByteArray(pixels32.Length * 3); for (Int32 i = 0; i < pixels32.Length; i++) { _image[i * 3] = pixels32[i].r; _image[i * 3 + 1] = pixels32[i].g; _image[i * 3 + 2] = pixels32[i].b; } }
public void Reset() { Form = 0; Parts = 0; Scheme = default(NativeByteArray); UserInfo = default(NativeByteArray); Host.Reset(); Port = 0; Path.Clear(); Query = default(NativeByteArray); }
void XRGetCurrentReality() { NativeByteArray bytes = new NativeByteArray(); c8XRIos_getCurrentRealityXR(ref bytes); byte[] ret = new byte[bytes.size]; Marshal.Copy(bytes.bytes, ret, 0, bytes.size); MessageReader r = Serialize.read(bytes); xrResponse = r.getRoot(RealityResponse.factory); }
static XREnvironment.Reader XRGetEnvironment() { NativeByteArray bytes = new NativeByteArray(); c8XRStreaming_getXREnvironment(ref bytes); byte[] ret = new byte[bytes.size]; Marshal.Copy(bytes.bytes, ret, 0, bytes.size); MessageReader r = Serialize.read(bytes); return(r.getRoot(XREnvironment.factory)); }
private void CreateRgb(Texture2D tex) { Color32[] pixels32 = tex.GetPixels32(); Image = new NativeByteArray(pixels32.Length * 3); for (Int32 i = 0; i < pixels32.Length; i++) { Image[i * 3] = pixels32[i].r; Image[i * 3 + 1] = pixels32[i].g; Image[i * 3 + 2] = pixels32[i].b; } }
XrQueryResponse.Reader XRQuery(MessageBuilder m) { NativeByteArray requestBytes = Serialize.allocNativeByteArrayAndWrite(m); NativeByteArray responseBytes = new NativeByteArray(); c8XRStreaming_query(ref requestBytes, ref responseBytes); Serialize.freeAllocedNativeByteArray(requestBytes); byte[] ret = new byte[responseBytes.size]; Marshal.Copy(responseBytes.bytes, ret, 0, responseBytes.size); return(Serialize.read(responseBytes).getRoot(XrQueryResponse.factory)); }
void XRConfigure(MessageBuilder configMessageBuilder) { if (!XRIsStreamingSupported()) { XRConfigureUnsupported(); return; } NativeByteArray b = Serialize.allocNativeByteArrayAndWrite(configMessageBuilder); c8XRStreaming_configureXR(ref b); Serialize.freeAllocedNativeByteArray(b); }
void XRSetAppEnvironment() { if (!XRIsStreamingSupported()) { XRSetAppEnvironmentUnsupported(); return; } NativeByteArray bytes = Serialize.allocNativeByteArrayAndWrite(xrAppEnvironment); c8XRStreaming_setXRAppEnvironment(ref bytes); Serialize.freeAllocedNativeByteArray(bytes); }
public override void Write(BinaryWriter _writer) { if (m_compressedContent == null) { // We need to compress content if (m_thumbnail == null) { throw new Exception("Attempting to save an ampty thumbnail chunk! Don't create the chunk if it's normal to be empty..."); } using (NativeByteArray content = m_thumbnail.Save(ImageFile.FILE_FORMAT.JPEG, ImageFile.SAVE_FLAGS.SF_JPEG_FAST)) { m_compressedContent = content.AsByteArray; } } _writer.Write(m_compressedContent); }
void XRGetRemote() { if (!XRIsStreamingSupported()) { XRGetRemoteUnsupported(); return; } NativeByteArray bytes = new NativeByteArray(); c8XRStreaming_getXRRemote(ref bytes); byte[] ret = new byte[bytes.size]; Marshal.Copy(bytes.bytes, ret, 0, bytes.size); MessageReader r = Serialize.read(bytes); xrRemote = r.getRoot(XrRemoteApp.factory); }
void XRGetCurrentReality() { if (!XRIsStreamingSupported()) { XRGetCurrentRealityUnsupported(); return; } NativeByteArray bytes = new NativeByteArray(); c8XRStreaming_getCurrentRealityXR(ref bytes); if (bytes.bytes == IntPtr.Zero) { return; } byte[] ret = new byte[bytes.size]; Marshal.Copy(bytes.bytes, ret, 0, bytes.size); MessageReader r = Serialize.read(bytes); xrResponse = r.getRoot(RealityResponse.factory); }
void XRGetAppEnvironment() { if (!XRIsStreamingSupported()) { XRGetAppEnvironmentUnsupported(); return; } NativeByteArray bytes = new NativeByteArray(); c8XRStreaming_getXRAppEnvironment(ref bytes); if (bytes.bytes == IntPtr.Zero) { return; } byte[] ret = new byte[bytes.size]; Marshal.Copy(bytes.bytes, ret, 0, bytes.size); XRAppEnvironment.Reader r = Serialize.read(bytes).getRoot(XRAppEnvironment.factory); xrAppEnvironment.setRoot(XRAppEnvironment.factory, r); }
internal WebPageImagePart(Rectangle _contentRectangle, ImageFile _image, ImageFile.FILE_FORMAT _compressedImageFormat) { if (_image == null) { throw new Exception("Invalid image part!"); } m_contentRectangle = _contentRectangle; m_image = _image; m_compressedImageFormat = _compressedImageFormat; // Compress the image try { NativeByteArray content = null; switch (m_compressedImageFormat) { case ImageFile.FILE_FORMAT.PNG: content = m_image.Save(ImageFile.FILE_FORMAT.PNG, ImageFile.SAVE_FLAGS.SF_PNG_Z_BEST_COMPRESSION); break; case ImageFile.FILE_FORMAT.JPEG: content = m_image.Save(ImageFile.FILE_FORMAT.JPEG, ImageFile.SAVE_FLAGS.SF_JPEG_QUALITYNORMAL); break; default: content = m_image.Save(m_compressedImageFormat, ImageFile.SAVE_FLAGS.NONE); break; } if (content == null) { throw new Exception("Failed to save image using \"" + m_compressedImageFormat + "\" format! Image library returned null..."); } m_compressedImage = content.AsByteArray; content.Dispose(); } catch (Exception _e) { throw new Exception("An error occurred during image compression!", _e); } }
internal override void Threaded_LoadContent(BinaryReader _reader, bool _prepareContent) { try { m_compressedContent = new byte[m_size]; _reader.Read(m_compressedContent, 0, (int)m_size); if (_prepareContent) { // Attempt to read the JPEG file ImageFile temp = null; using (NativeByteArray imageContent = new NativeByteArray(m_compressedContent)) { temp = new ImageFile(imageContent, ImageFile.FILE_FORMAT.JPEG); } // Replace current thumbnail m_thumbnail.Dispose(); m_thumbnail = temp; } } catch (Exception _e) { m_owner.m_database.AsyncMain_LogError("An error occurred while attempting to read thumbnail chunk for fiche \"" + m_owner.ToString() + "\": " + _e.Message); } }
private static extern IntPtr c8XRStreaming_setEditorAppInfo(ref NativeByteArray preview);
private static extern void c8XRIos_query( ref NativeByteArray request, ref NativeByteArray response);
private static extern void c8XRIos_getCurrentRealityXR(ref NativeByteArray reality);
private static extern void c8XRStreaming_configureXR(ref NativeByteArray config);
private static extern void c8XRStreaming_getCurrentRealityXR(ref NativeByteArray response);
private static extern void c8XRStreaming_getXRRemote(ref NativeByteArray remote);
private static extern void c8XRStreaming_query( ref NativeByteArray request, ref NativeByteArray response);
private static extern void c8XRIos_getXRAppEnvironment(ref NativeByteArray env);
// These textures are potentially too big to make a Texture2D of, so just load directly into the byte array private void LoadTexture(String path) { path = KSPUtil.ApplicationRootPath + "GameData/" + path; if (File.Exists(path)) { try { if (path.ToLower().EndsWith(".dds")) { // Borrowed from stock KSP 1.0 DDS loader (hi Mike!) // Also borrowed the extra bits from Sarbian. BinaryReader binaryReader = new BinaryReader(File.OpenRead(path)); UInt32 num = binaryReader.ReadUInt32(); if (num == DDSValues.uintMagic) { DDSHeader ddsHeader = new DDSHeader(binaryReader); if (ddsHeader.ddspf.dwFourCC == DDSValues.uintDX10) { // ReSharper disable once ObjectCreationAsStatement new DDSHeaderDX10(binaryReader); } Boolean alpha = (ddsHeader.ddspf.dwFlags & 0x00000002) != 0; Boolean fourcc = (ddsHeader.ddspf.dwFlags & 0x00000004) != 0; Boolean rgb = (ddsHeader.ddspf.dwFlags & 0x00000040) != 0; Boolean alphapixel = (ddsHeader.ddspf.dwFlags & 0x00000001) != 0; Boolean luminance = (ddsHeader.ddspf.dwFlags & 0x00020000) != 0; Boolean mipmap = (ddsHeader.dwCaps & DDSPixelFormatCaps.MIPMAP) != 0u; if (fourcc) { Debug.Log("[Kopernicus]: Compressed textures are not are supported for large maps."); } else { TextureFormat textureFormat = TextureFormat.ARGB32; Boolean ok = true; if (!rgb && alpha != luminance && (ddsHeader.ddspf.dwRGBBitCount == 8 || ddsHeader.ddspf.dwRGBBitCount == 16)) { if (ddsHeader.ddspf.dwRGBBitCount == 8) { // A8 format or Luminance 8 if (alpha) { textureFormat = TextureFormat.Alpha8; } else { textureFormat = TextureFormat.R8; } } else if (ddsHeader.ddspf.dwRGBBitCount == 16) { // R16 format textureFormat = TextureFormat.R16; } } else { ok = false; Debug.Log("[Kopernicus]: Only A8, R8, and R16 are supported"); } if (ok) { _name = name; _width = (Int32)ddsHeader.dwWidth; _height = (Int32)ddsHeader.dwHeight; _isCompiled = false; if (textureFormat == TextureFormat.R16) { _bpp = (Int32)MapDepth.HeightAlpha; } else { _bpp = (Int32)MapDepth.Greyscale; } _rowWidth = _width * _bpp; Int32 dataSize = _rowWidth * _height; Image = new NativeByteArray(dataSize); byte[] ddsData = binaryReader.ReadBytes(dataSize); for (Int32 i = 0; i < dataSize; i++) { Image[i] = ddsData[i]; } Debug.Log("[Kopernicus]: Loaded large map: " + path); } } } else { Debug.Log("[Kopernicus]: Bad DDS header."); } } else { Debug.Log("[Kopernicus]: Only DDS is supported for large maps."); } } catch (Exception ex) { Debug.Log("[Kopernicus]: failed to load " + path + " with exception " + ex.Message); } } else { Debug.Log("[Kopernicus]: texture does not exist! " + path); } }
private static extern void c8XRStreaming_setXRAppEnvironment(ref NativeByteArray env);