private void okButton_Click(object sender, EventArgs e) { update_interval = (int)intervalNumericUpDown.Value; share_cursor = shareactiveRadioButton.Checked; switch (rgbmodeComboBox.SelectedIndex) { case 0: bmpformat = BitmapFormat.BMP_RGB8_PALETTE; break; case 1: bmpformat = BitmapFormat.BMP_RGB16_555; break; case 2: bmpformat = BitmapFormat.BMP_RGB24; break; case 3: bmpformat = BitmapFormat.BMP_RGB32; break; } if (!updintervalCheckBox.Checked) { update_interval = 0; } }
protected void CalculateLuminance(byte[] rgbRawBytes, BitmapFormat bitmapFormat) { if (bitmapFormat == BitmapFormat.Unknown) { bitmapFormat = DetermineBitmapFormat(rgbRawBytes, Width, Height); } switch (bitmapFormat) { case BitmapFormat.Gray8: Buffer.BlockCopy(rgbRawBytes, 0, luminances, 0, rgbRawBytes.Length < luminances.Length ? rgbRawBytes.Length : luminances.Length); break; case BitmapFormat.RGB24: case BitmapFormat.BGR24: CalculateLuminanceRGB24(rgbRawBytes); break; case BitmapFormat.RGB32: case BitmapFormat.BGR32: CalculateLuminanceRGB32(rgbRawBytes); break; case BitmapFormat.ARGB32: case BitmapFormat.BGRA32: CalculateLuminanceARGB32(rgbRawBytes); break; case BitmapFormat.RGB565: CalculateLuminanceRGB565(rgbRawBytes); break; default: throw new ArgumentException("The bitmap format isn't supported.", bitmapFormat.ToString()); } }
public static RGBLuminanceSource.BitmapFormat ToZXing(this BitmapFormat format) { switch (format) { case BitmapFormat.ARGB32: return(RGBLuminanceSource.BitmapFormat.ARGB32); case BitmapFormat.BGR24: return(RGBLuminanceSource.BitmapFormat.BGR24); case BitmapFormat.BGR32: return(RGBLuminanceSource.BitmapFormat.BGR32); case BitmapFormat.BGRA32: return(RGBLuminanceSource.BitmapFormat.BGRA32); case BitmapFormat.Gray8: return(RGBLuminanceSource.BitmapFormat.Gray8); case BitmapFormat.RGB24: return(RGBLuminanceSource.BitmapFormat.RGB24); case BitmapFormat.RGB32: return(RGBLuminanceSource.BitmapFormat.RGB32); case BitmapFormat.RGBA32: return(RGBLuminanceSource.BitmapFormat.RGBA32); case BitmapFormat.RGB565: return(RGBLuminanceSource.BitmapFormat.RGB565); default: return(RGBLuminanceSource.BitmapFormat.Unknown); } }
private async Task <Result> GetCameraImage(CancellationToken cancelToken) { if (cancelToken.IsCancellationRequested) { throw new OperationCanceledException(cancelToken); } imageStream = new InMemoryRandomAccessStream(); await capture.CapturePhotoToStreamAsync(encodingProps, imageStream); await imageStream.FlushAsync(); var decoder = await BitmapDecoder.CreateAsync(imageStream); byte[] pixels = (await decoder.GetPixelDataAsync(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Ignore, new BitmapTransform(), ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage)).DetachPixelData(); const BitmapFormat format = BitmapFormat.RGB32; imageStream.Dispose(); var result = await Task.Run( () => barcodeReader.Decode(pixels, (int)decoder.PixelWidth, (int)decoder.PixelHeight, format), cancelToken); return(result); }
public Texture(PakFile Pak, PakFile.PakTag Item) { var reader = Pak.Reader; reader.EndianType = EndianFormat.LittleEndian; reader.SeekTo(Item.Offset + 6); isLittleEndian = reader.ReadInt32() == 1346978644; //PICT if (!isLittleEndian) reader.EndianType = Endian.EndianFormat.BigEndian; reader.SeekTo(Item.Offset + (isLittleEndian ? 16 : 12)); Width = reader.ReadInt32(); Height = reader.ReadInt32(); reader.SeekTo(Item.Offset + (isLittleEndian ? 38 : 32)); Format = BitmapFormat.Dxt5; var intFormat = reader.ReadInt32(); switch (intFormat) { case 0: Format = BitmapFormat.A8R8G8B8; break; case 10: Format = BitmapFormat.A8Y8; break; case 12: Format = BitmapFormat.Dxt1; break; case 13: Format = BitmapFormat.Dxt1; break; case 15: Format = BitmapFormat.Dxt3; break; case 17: Format = BitmapFormat.Dxt5; break; case 22: Format = BitmapFormat.X8R8G8B8; break; case 36: Format = BitmapFormat.Dxn; break; case 37: Format = BitmapFormat.DXT5a; break; default: throw new Exception("CHECK THIS"); } reader.SeekTo(Item.Offset + (isLittleEndian ? 28 : 24)); int mapCount = reader.ReadInt32(); if (mapCount == 6) Type = BitmapType.CubeMap; else Type = BitmapType.Texture2D; if (mapCount > 1 && mapCount != 6) throw new Exception("CHECK THIS"); DataAddress = Item.Offset + (isLittleEndian ? 58 : 4096); reader.EndianType = Endian.EndianFormat.LittleEndian; //in case it was PICT }
/// <summary> /// Get the size in bytes of a block compressed format. /// </summary> /// <param name="format"></param> /// <returns></returns> public static int GetBlockSize(BitmapFormat format) { int blockSize = 0; switch (format) { case BitmapFormat.Dxt1: blockSize = 8; break; case BitmapFormat.Dxt3: case BitmapFormat.Dxt3aAlpha: case BitmapFormat.Dxt3aMono: case BitmapFormat.ReachDxt3aAlpha: case BitmapFormat.ReachDxt3aMono: case BitmapFormat.Dxt5: case BitmapFormat.Dxt5a: case BitmapFormat.Dxt5aAlpha: case BitmapFormat.Dxt5aMono: case BitmapFormat.ReachDxt5aAlpha: case BitmapFormat.ReachDxt5aMono: case BitmapFormat.Dxn: case BitmapFormat.Ctx1: blockSize = 16; break; default: blockSize = -1; break; } return(blockSize); }
/// <summary> /// When converting xbox bitmap formats (and other rare formats), get the standard format that it can be converted it without loss /// </summary> /// <param name="format"></param> /// <returns></returns> public static BitmapFormat GetEquivalentBitmapFormat(BitmapFormat format) { switch (format) { case BitmapFormat.Ctx1: return(BitmapFormat.Dxn); case BitmapFormat.DxnMonoAlpha: case BitmapFormat.Dxt5a: case BitmapFormat.AY8: return(BitmapFormat.A8Y8); case BitmapFormat.Dxt5aAlpha: case BitmapFormat.Dxt3aAlpha: return(BitmapFormat.A8); case BitmapFormat.Dxt5aMono: case BitmapFormat.Dxt3aMono: return(BitmapFormat.Y8); case BitmapFormat.A4R4G4B4: case BitmapFormat.R5G6B5: return(BitmapFormat.A8R8G8B8); default: return(format); } }
protected override void DefWndProc(ref Message m) { switch (m.Msg) { case MESSAGE_CAPTURED_OK: { MemoryStream ms = new MemoryStream(); BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms); Bitmap bmp = new Bitmap(ms); this.picFPImg.Image = bmp; foreach (RightingSys.Models.ACL_FingerPrint PF in AllFinger) { int ret = zkfp2.DBMatch(mDBHandle, CapTmp, PF.FingerData); if (50 < ret) { FingerUserId = PF.UserId; base.DialogResult = DialogResult.OK; this.bnClose_Click(null, null); return; } } textRes.Text = "\r\n没有找到匹配到用户指纹信息" + textRes.Text; } break; default: base.DefWndProc(ref m); break; } }
/// <summary> /// Procesa un node 'bitmap' /// </summary> /// <param name="bitmapNode">El node a procesar.</param> /// <returns>L'objecte 'Bitmap'</returns> /// private Bitmap ProcessBitmapNode(XmlNode bitmapNode) { string source = bitmapNode.Attributes["source"].Value; BitmapFormat format = (BitmapFormat)Enum.Parse(typeof(BitmapFormat), bitmapNode.Attributes["format"].Value, true); return(new Bitmap(source, format)); }
public Result DecodeImageBytes([In, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_UI1)] ref byte[] rawRGB, [In] int width, [In] int height, [In] BitmapFormat format) { return(new Result(wrappedReader.Decode(rawRGB, width, height, format.ToZXing()))); }
private async void Deocode(byte[] rawRgb, BitmapFormat bitmapFormat) { await Task.Run(() => { if (_decoding) { return; } _decoding = true; var decoded = _reader.Decode(rawRgb, (int)_width, (int)_height, bitmapFormat); if (decoded != null) { _scanStopped = true; if (_scanStopped) { var scannerViewModel = DataContext as ScannerViewModel; if (scannerViewModel != null) { scannerViewModel.GoResultCommand.Execute(null); } } } _decoding = false; }); }
private void CaptureDataFingerpint(int message) { switch (message) { case MESSAGE_CAPTURED_OK: { MemoryStream ms = new MemoryStream(); BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms); Bitmap bmp = new Bitmap(ms); // set image to Scan Finger's Form scanFinger.SetImage(bmp); String strShow = zkfp2.BlobToBase64(CapTmp, cbCapTmp); scanFinger.DataFinger = strShow; scanFinger.DataFingerLength = strShow.Length; Console.WriteLine(strShow); // set quality finger string present_quality_finger = tk.CalculatePercentageTemplateFingerprint(strShow.Length); scanFinger.SetPresentQuality(present_quality_finger); } break; default: Console.WriteLine("Error : Invalid Data Fingerprint."); break; } }
private BitmapFormat OnSetupCallback(BitmapFormat format) { m_videoFormat = new BitmapFormat(format.Width, format.Height, ChromaType.RV24); SetupInput(m_videoFormat); return m_videoFormat; }
private void SetTextureFormat(int mipMapCount, BitmapFormat format, BitmapFlags flags) { if (mipMapCount > 0) { MipMapCount = mipMapCount; Flags |= DDSFlags.MipMapCount; } else { MipMapCount = 0; } if (flags.HasFlag(BitmapFlags.Compressed)) { Flags |= DDSFlags.LinearSize; int blockSize = BitmapFormatUtils.GetBlockSize(format); int blockDimension = BitmapFormatUtils.GetBlockDimension(format); var nearestWidth = blockDimension * ((Height + (blockDimension - 1)) / blockDimension); var nearestHeight = blockDimension * ((Width + (blockDimension - 1)) / blockDimension);; PitchOrLinearSize = (nearestWidth * nearestHeight / 16) * blockSize; } else { Flags |= DDSFlags.Pitch; int bitsPerPixel = BitmapFormatUtils.GetBitsPerPixel(format); PitchOrLinearSize = (Width * bitsPerPixel + 7) / 8; } PixelFormat = new PixelFormat(format, flags); }
protected override void DefWndProc(ref Message m) { switch (m.Msg) { case MESSAGE_CAPTURED_OK: { MemoryStream ms = new MemoryStream(); BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms); Bitmap bmp = new Bitmap(ms); this.picFPImg.Image = bmp; foreach (Models.ACL_FingerPrint PF in AllFinger) { int ret = zkfp2.DBMatch(mDBHandle, CapTmp, PF.FingerData); if (50 < ret) { textRes.Text = string.Format("\r\n匹配率={0} 姓名:{1} 指纹ID:{2} ", ret, PF.FullName, PF.Id) + textRes.Text; return; } } textRes.Text = "\r\n没有找到匹配到用户指纹信息" + textRes.Text; } break; default: base.DefWndProc(ref m); break; } }
private void CaptureDataFingerpint(int message) { switch (message) { case MESSAGE_CAPTURED_OK: { MemoryStream ms = new MemoryStream(); BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms); Bitmap bmp = new Bitmap(ms); // this is for testing, to check whether it receives a proper Bitmap data. //bmp.Save("test.bmp", ImageFormat.Png); String strShow = zkfp2.BlobToBase64(CapTmp, cbCapTmp); String current_dt = tk.GetCurrentDatetime(); Console.WriteLine("----------------------"); Console.WriteLine(current_dt); Console.WriteLine("----------------------"); Console.WriteLine("captured data : " + strShow + "\n"); Keyboard.AutoCopyPasteEvent(strShow); } break; default: Console.WriteLine("Error : Invalid Data Fingerprint."); break; } }
private unsafe int OnFormatCallback(void** opaque, char* chroma, int* width, int* height, int* pitches, int* lines) { IntPtr pChroma = new IntPtr(chroma); string chromaStr = Marshal.PtrToStringAnsi(pChroma); ChromaType type; if (!Enum.TryParse<ChromaType>(chromaStr, out type)) { throw new ArgumentException("Unsupported chroma type " + chromaStr); } m_format = new BitmapFormat(*width, *height, type); if (m_formatSetupCB != null) { m_format = m_formatSetupCB(m_format); } Marshal.Copy(m_format.Chroma.ToUtf8(), 0, pChroma, 4); *width = m_format.Width; *height = m_format.Height; for (int i = 0; i < m_format.Planes; i++) { pitches[i] = m_format.Pitches[i]; lines[i] = m_format.Lines[i]; } m_pixelData = new PlanarPixelData(m_format.PlaneSizes); return m_format.Planes; }
private unsafe int OnFormatCallback(void **opaque, char *chroma, int *width, int *height, int *pitches, int *lines) { IntPtr pChroma = new IntPtr(chroma); string chromaStr = Marshal.PtrToStringAnsi(pChroma); ChromaType type; if (!Enum.TryParse <ChromaType>(chromaStr, out type)) { throw new ArgumentException("Unsupported chroma type " + chromaStr); } m_format = new BitmapFormat(*width, *height, type); if (m_formatSetupCB != null) { m_format = m_formatSetupCB(m_format); } Marshal.Copy(m_format.Chroma.ToUtf8(), 0, pChroma, 4); *width = m_format.Width; *height = m_format.Height; for (int i = 0; i < m_format.Planes; i++) { pitches[i] = m_format.Pitches[i]; lines[i] = m_format.Lines[i]; } m_pixelData = new PlanarPixelData(m_format.PlaneSizes); return(m_format.Planes); }
private void CreateHeaderCubemap(int mipMapCount, BitmapFormat format, BitmapFlags flags) { Caps |= DDSComplexityFlags.Complex; Caps2 |= DDSSurfaceInfoFlags.CubeMapAllFaces; SetTextureFormat(mipMapCount, format, flags); }
private void CreateHeaderVolume(int mipMapCount, int depth, BitmapFormat format, BitmapFlags flags) { Flags |= DDSFlags.Depth; Caps |= DDSComplexityFlags.Complex; Caps2 |= DDSSurfaceInfoFlags.Volume; Depth = depth; SetTextureFormat(mipMapCount, format, flags); }
public static Result DecodeBufferToQRCode( IBuffer buffer, int width, int height, BitmapFormat bitmapFormat) { return(DecodeBufferToQRCode(buffer.ToArray(), width, height, bitmapFormat)); }
public VisualizationInfoBitmaps() { this.bitmapField = BitmapFormat.PNG; this.guidField = System.Guid.NewGuid().ToString(); this.upField = new Direction(); this.normalField = new Direction(); this.locationField = new Point(); }
protected override void Run(Workbench workbench, ILogger logger) { string mapFmtName = FindUnnamedParameter(0).Values[0].ToString(); int baseTile = FindNamedParameter("--base-tile").Values[0].ToInt32(); long offset = FindNamedParameter("--offset").Values[0].ToInt64(); int tileCount = FindNamedParameter("--tile-count").Values[0].ToInt32(); if (!(BitmapFormat.GetFormat(mapFmtName) is BitmapFormat mapFmt)) { logger?.Log("Unknown bitmap format \"" + mapFmtName + "\".", LogLevel.Error); return; } if (offset < 0) { logger?.Log("Invalid offset.", LogLevel.Error); return; } if (tileCount < 0) { logger?.Log("Invalid tile count.", LogLevel.Error); return; } workbench.Stream.Position = Math.Min(offset, workbench.Stream.Length); // Bytes per tile entry. int bpe = (mapFmt.Bits + 7) / 8; byte[] buffer = new byte[bpe]; int tn = 0; while (tileCount > 0 && workbench.Stream.Read(buffer, 0, bpe) == bpe) { int scrn = 0; for (int i = 0; i < bpe; i++) { scrn |= buffer[i] << i * 8; } TileEntry te = new TileEntry( tileNumber: mapFmt.BitmapEncoding switch { BitmapEncoding.NintendoDSTexture => tn, _ => ((scrn & mapFmt.TileNumberMask) >> mapFmt.TileNumberShift) } -baseTile, hFlip: mapFmt.CanFlipHorizontal && (scrn & mapFmt.FlipHorizontalMask) != 0, vFlip: mapFmt.CanFlipVertical && (scrn & mapFmt.FlipVerticalMask) != 0, paletteNumber: (scrn & mapFmt.PaletteMask) >> mapFmt.PaletteShift, mode: (scrn & mapFmt.ModeMask) >> mapFmt.ModeShift ); workbench.Tilemap.Add(te); tileCount--; tn++; } workbench.Tilemap.BitmapFormat = mapFmt; }
public Result[] DecodeImageBytesMultiple([In, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_UI1)] ref byte[] rawRGB, [In] int width, [In] int height, [In] BitmapFormat format) { var results = wrappedReader.DecodeMultiple(rawRGB, width, height, format.ToZXing()); return(results?.Select(_ => new Result(_)).ToArray()); }
public void UpdateFormat(BitmapFormat format) { Format = format; BlockSize = BitmapFormatUtils.GetBlockSize(Format); BlockDimension = BitmapFormatUtils.GetBlockDimension(Format); CompressionFactor = BitmapFormatUtils.GetCompressionFactor(Format); NearestHeight = BlockDimension * ((Height + (BlockDimension - 1)) / BlockDimension); NearestWidth = BlockDimension * ((Width + (BlockDimension - 1)) / BlockDimension); }
private void SetupInput(BitmapFormat format) { var streamInfo = StreamInfo.FromBitmapFormat(format); streamInfo.ID = VIDEO_ID; streamInfo.FPS = (int)Math.Floor(m_sourcePlayer.FPS != 0 ? m_sourcePlayer.FPS : 24); m_inputMedia.AddOrUpdateStream(streamInfo, streamInfo.FPS); m_inputMedia.SetExceptionHandler(OnErrorCallback); }
/// <summary> /// Constructor de l'objecte. /// </summary> /// <param name="source">Origen del bitmap.</param> /// <param name="format">Format.</param> /// public Bitmap(string source, BitmapFormat format) { if (String.IsNullOrEmpty(source)) { throw new ArgumentNullException(nameof(source)); } this.source = source; this.format = format; }
public virtual void Load(ref BinaryReader input) { Type = (BitmapType)input.ReadInt16(); Format = (BitmapFormat)input.ReadInt16(); Usage = (BitmapUsage)input.ReadInt16(); input.BaseStream.Position += 16; ColorPlateWidth = input.ReadInt16(); ColorPlateHeight = input.ReadInt16(); ColorPlateData = input.ReadInt32(); }
public static bool IsCompressedFormat(BitmapFormat format) { switch (format) { case BitmapFormat.A8: case BitmapFormat.Y8: case BitmapFormat.AY8: case BitmapFormat.A8Y8: case BitmapFormat.Unused4: case BitmapFormat.Unused5: case BitmapFormat.R5G6B5: case BitmapFormat.R6G5B5: case BitmapFormat.A1R5G5B5: case BitmapFormat.A4R4G4B4: case BitmapFormat.X8R8G8B8: case BitmapFormat.A8R8G8B8: case BitmapFormat.UnusedC: case BitmapFormat.UnusedD: case BitmapFormat.A4R4G4B4Font: case BitmapFormat.P8: case BitmapFormat.ARGBFP32: case BitmapFormat.RGBFP32: case BitmapFormat.RGBFP16: case BitmapFormat.V8U8: case BitmapFormat.G8B8: case BitmapFormat.A32B32G32R32F: case BitmapFormat.A16B16G16R16F: case BitmapFormat.Q8W8V8U8: case BitmapFormat.A2R10G10B10: case BitmapFormat.A16B16G16R16: case BitmapFormat.V16U16: return(false); case BitmapFormat.Dxt1: case BitmapFormat.Dxt3: case BitmapFormat.Dxt5: case BitmapFormat.Unused1E: case BitmapFormat.Dxt5a: case BitmapFormat.Unused20: case BitmapFormat.Dxn: case BitmapFormat.Ctx1: case BitmapFormat.Dxt3aAlpha: case BitmapFormat.Dxt3aMono: case BitmapFormat.Dxt5aAlpha: case BitmapFormat.Dxt5aMono: case BitmapFormat.DxnMonoAlpha: case BitmapFormat.ReachDxt3aMono: case BitmapFormat.ReachDxt3aAlpha: case BitmapFormat.ReachDxt5aMono: case BitmapFormat.ReachDxt5aAlpha: case BitmapFormat.ReachDxnMonoAlpha: return(true); } return(false); }
/// <summary> /// Get the number of bits per pixel of a bitmap format. /// </summary> /// <param name="format"></param> /// <returns></returns> public static int GetBitsPerPixel(BitmapFormat format) { int bitsPerPixel = 0; switch (format) { case BitmapFormat.A8: case BitmapFormat.AY8: case BitmapFormat.Y8: case BitmapFormat.P8: bitsPerPixel = 8; break; case BitmapFormat.A8Y8: case BitmapFormat.R5G6B5: case BitmapFormat.A1R5G5B5: case BitmapFormat.A4R4G4B4: case BitmapFormat.A4R4G4B4Font: case BitmapFormat.V8U8: bitsPerPixel = 16; break; case BitmapFormat.A8R8G8B8: case BitmapFormat.X8R8G8B8: case BitmapFormat.Q8W8V8U8: case BitmapFormat.A2R10G10B10: case BitmapFormat.V16U16: bitsPerPixel = 32; break; case BitmapFormat.RGBFP16: bitsPerPixel = 48; break; case BitmapFormat.A16B16G16R16: case BitmapFormat.A16B16G16R16F: bitsPerPixel = 64; break; case BitmapFormat.RGBFP32: bitsPerPixel = 96; break; case BitmapFormat.ARGBFP32: case BitmapFormat.A32B32G32R32F: bitsPerPixel = 128; break; default: throw new Exception($"Unsupported uncompressed format {format}"); } return(bitsPerPixel); }
public void GetBitMap() { var expected = new BitmapFormat(); var i = new Imaging(); foreach (var extension in expected.FileExtensions) { var format = i.Get(extension); Assert.AreEqual(expected.GetType(), format.GetType()); } }
public void SetFormat(BitmapFormat format) { m_format = format; LibVlcMethods.libvlc_video_set_format(m_hMediaPlayer, m_format.Chroma.ToUtf8(), m_format.Width, m_format.Height, m_format.Pitch); m_pBuffer = MemoryHeap.Alloc(m_format.ImageSize); m_pixelData = new PixelData(m_format.ImageSize); m_pixelDataPtr = GCHandle.Alloc(m_pixelData, GCHandleType.Pinned); LibVlcMethods.libvlc_video_set_callbacks(m_hMediaPlayer, pLockCallback, pUnlockCallback, pDisplayCallback, m_pixelDataPtr.AddrOfPinnedObject()); }
public void SetFormat(BitmapFormat format) { if (m_data == default(PixelData)) { m_format = format; m_data = new PixelData(m_format.ImageSize); m_pData = GCHandle.Alloc(m_data, GCHandleType.Pinned); InitMedia(); } else { throw new InvalidOperationException("Bitmap format already set"); } }
public static void SetUpHeaderForFormat(BitmapFormat format, DdsHeader header) { BitmapFormatDefinition definition; if (!ExtractionDefinitions.TryGetValue(format, out definition)) throw new InvalidOperationException("Invalid bitmap format: " + format); header.FormatType = definition.FormatType; header.BitsPerPixel = definition.BitsPerPixel; header.RBitMask = definition.RBitMask; header.GBitMask = definition.GBitMask; header.BBitMask = definition.BBitMask; header.ABitMask = definition.ABitMask; header.FourCc = definition.FourCc; header.D3D10Format = definition.D3D10Format; }
private void okButton_Click(object sender, EventArgs e) { update_interval = (int)intervalNumericUpDown.Value; share_cursor = shareactiveRadioButton.Checked; switch(rgbmodeComboBox.SelectedIndex) { case 0 : bmpformat = BitmapFormat.BMP_RGB8_PALETTE; break; case 1 : bmpformat = BitmapFormat.BMP_RGB16_555; break; case 2 : bmpformat = BitmapFormat.BMP_RGB24; break; case 3 : bmpformat = BitmapFormat.BMP_RGB32; break; } if (!updintervalCheckBox.Checked) update_interval = 0; }
/// <summary> /// The decode bitm. /// </summary> /// <param name="bitmBytes">The bitm bytes.</param> /// <param name="height">The height.</param> /// <param name="width">The width.</param> /// <param name="depth">The depth.</param> /// <param name="bitsPerPixel">The bits per pixel.</param> /// <param name="type">The type.</param> /// <param name="format">The format.</param> /// <param name="swizzle">The swizzle.</param> /// <param name="map">The map.</param> /// <param name="visualchunkindex">The visualchunkindex.</param> /// <param name="ident">The ident.</param> /// <returns></returns> /// <exception cref="Exception"> /// </exception> /// /// <exception cref="Exception"> /// </exception> /// <remarks></remarks> public static Bitmap DecodeBitm( byte[] bitmBytes, int height, int width, int depth, int bitsPerPixel, BitmapType type, BitmapFormat format, bool swizzle, Map map, int visualchunkindex, int ident) { int stride = 0; #region Volume Textures / 3D if (type == BitmapType.BITM_TYPE_3D) { List<Bitmap> images = new List<Bitmap>(); Bitmap finalImage = null; List<IntPtr> tPtr = new List<IntPtr>(); if (swizzle) { bitmBytes = Swizzler.Swizzle(bitmBytes, width, height, depth, bitsPerPixel, true); } try { // Make our new image large enough to handle a square of all the images together with a 2 pixel pad between int imageSize = width * height * bitsPerPixel >> 3; int rCount = (int)(Math.Sqrt(depth) + 0.5); int tWidth = rCount * (width + 1); int tHeight = (int)Math.Round(depth / rCount + 0.5f, MidpointRounding.AwayFromZero) * (height + 2); // Display 3D bitmaps combined as a 2D bitmap if (visualchunkindex == 0) { for (int i = 0; i < depth; i++) { byte[] tempBytes = new byte[imageSize]; Array.Copy(bitmBytes, i * imageSize, tempBytes, 0, imageSize); stride = DecodeBitmap( ref tempBytes, height, width, 1, bitsPerPixel, type, format, false, map, visualchunkindex, ident); tPtr.Add(Marshal.AllocHGlobal(tempBytes.Length)); RtlMoveMemory(tPtr[tPtr.Count - 1], tempBytes, tempBytes.Length); Bitmap bitmap = new Bitmap( width, height, stride, PixelFormat.Format32bppArgb, tPtr[tPtr.Count - 1]); images.Add(bitmap); } } // Display only one of the 3D images else { byte[] tempBytes = new byte[imageSize]; Array.Copy(bitmBytes, (visualchunkindex - 1) * imageSize, tempBytes, 0, imageSize); stride = DecodeBitmap( ref tempBytes, height, width, 1, bitsPerPixel, type, format, false, map, visualchunkindex, ident); tPtr.Add(Marshal.AllocHGlobal(tempBytes.Length)); RtlMoveMemory(tPtr[tPtr.Count - 1], tempBytes, tempBytes.Length); images.Add(new Bitmap(width, height, stride, PixelFormat.Format32bppArgb, tPtr[tPtr.Count - 1])); tWidth = width; tHeight = height; } // create a bitmap to hold the combined image finalImage = new Bitmap(tWidth, tHeight); // get a graphics object from the image so we can draw on it using (Graphics g = Graphics.FromImage(finalImage)) { // set background color g.Clear(Color.Empty); // go through each image and draw it on the final image int offset = 0; foreach (Bitmap image in images) { g.DrawImage( image, new Rectangle( offset % tWidth, (offset / tWidth) * (image.Height + 1), image.Width, image.Height)); offset += image.Width + 1; } } return finalImage; } catch (Exception ex) { if (finalImage != null) { finalImage.Dispose(); } throw ex; //Global.ShowErrorMsg("Error loading bitmap", ex); } finally { // clean up memory foreach (Bitmap image in images) { image.Dispose(); } foreach (IntPtr p in tPtr) { Marshal.FreeHGlobal(p); } } } #endregion #region Cubemap else if (type == BitmapType.BITM_TYPE_CUBEMAP) { // stride = DecodeBitmap(ref bitmBytes, height, width, 1, bitsPerPixel, type, format, swizzle, map, visualchunkindex, ident); List<Bitmap> images = new List<Bitmap>(); Bitmap finalImage = null; List<IntPtr> tPtr = new List<IntPtr>(); // Don't think any cubemaps are swizzled, but... if (swizzle) { int imageSize = bitmBytes.Length / 6; // width * height * bitsPerPixel >> 3; for (int i = 0; i < 6; i++) { bitmBytes = Swizzler.Swizzle(bitmBytes, i * imageSize, width, height, depth, bitsPerPixel, true); } } try { // Make our new image large enough to handle a square of all the images together with a 2 pixel pad between //int tWidth = 2 * (width + 2) + 10; // Add some extras.. int tWidth = 4 * width; // Add some extras.. int tHeight = 3 * height; int imageSize = width * height * (bitsPerPixel >> 3); // Total image size has each image (including it's mipmaps) padded to 256 int tImageSize = bitmBytes.Length / 6; // Unused, just divide stream size by 6 as above int ttImageSize = imageSize + ((imageSize / 6) % 256 == 0 ? 0 : ((256 * 6) - (imageSize % (256 * 6)))); // All cubemaps should be DXT1... switch (format) { case BitmapFormat.BITM_FORMAT_DXT1: imageSize = Math.Max(imageSize / 8, 8); break; case BitmapFormat.BITM_FORMAT_DXT2AND3: case BitmapFormat.BITM_FORMAT_DXT4AND5: imageSize = Math.Max(imageSize / 4, 16); break; } //int mipmaps = 0; for (int i = 0; i < 6; i++) { int tw = width; int th = height; int tempSize = imageSize; int offset = 0; //while (tw > 2 & th > 2) { byte[] tempBytes = new byte[tempSize]; Array.Copy(bitmBytes, i * tImageSize + offset, tempBytes, 0, tempSize); stride = DecodeBitmap( ref tempBytes, th, tw, 1, bitsPerPixel, type, format, false, map, visualchunkindex, ident); tPtr.Add(Marshal.AllocHGlobal(tempBytes.Length)); RtlMoveMemory(tPtr[tPtr.Count - 1], tempBytes, tempBytes.Length); Bitmap bitmap = new Bitmap( tw, th, stride, PixelFormat.Format32bppArgb, tPtr[tPtr.Count - 1]); images.Add(bitmap); offset += tempSize; tempSize /= 4; tw /= 2; th /= 2; } } // create a bitmap to hold the combined image finalImage = new Bitmap(tWidth, tHeight); // get a graphics object from the image so we can draw on it using (Graphics g = Graphics.FromImage(finalImage)) { // set background color g.Clear(Color.Empty); // int[] crossX = new int[6] { 2, 0, 1, 1, 1, 3 }; // Right, Left, Top, Bottom, Front, Back int[] crossY = new int[6] { 1, 1, 0, 2, 1, 1 }; // Right, Left, Top, Bottom, Front, Back // go through each image and draw it on the final image int xOffset = 0; int yOffset = 0; int tempCount = 0; foreach (Bitmap image in images) { /* if (mipmapCount == 0) { xOffset = 0; yOffset += image.Height + 2; mipmapCount = images.Count / 6; } */ xOffset = crossX[tempCount] * image.Width; yOffset = crossY[tempCount] * image.Height; g.DrawImage(image, new Rectangle(xOffset, yOffset, image.Width, image.Height)); tempCount++; } } return finalImage; } catch (Exception ex) { if (finalImage != null) { finalImage.Dispose(); } throw ex; //Global.ShowErrorMsg("Error while processing bitmap", ex); } finally { // clean up memory foreach (Bitmap image in images) { image.Dispose(); } foreach (IntPtr p in tPtr) { Marshal.FreeHGlobal(p); } } } #endregion #region 2D Textures else { stride = DecodeBitmap( ref bitmBytes, height, width, 1, bitsPerPixel, type, format, swizzle, map, visualchunkindex, ident); } #endregion /* // This creates a memory leaks from HGlobal IntPtr intPtr = Marshal.AllocHGlobal(bitmBytes.Length); RtlMoveMemory(intPtr, bitmBytes, bitmBytes.Length); Bitmap temp = new Bitmap(width, height, stride, PixelFormat.Format32bppArgb, intPtr); temp.Tag = intPtr; // This NEEDS to be released when disposed */ Bitmap temp = new Bitmap(width, height, PixelFormat.Format32bppArgb); Rectangle rect = new Rectangle( 0, 0, width, height); BitmapData data = null; try { data = temp.LockBits(rect, ImageLockMode.WriteOnly, temp.PixelFormat); System.Runtime.InteropServices.Marshal.Copy(bitmBytes, 0, data.Scan0, Math.Min(bitmBytes.Length, data.Width * data.Height * 4)); } finally { if (data != null) temp.UnlockBits(data); } return temp; }
public void SetFormat(BitmapFormat format) { m_format = format; LibVlcMethods.libvlc_video_set_format(m_hMediaPlayer, m_format.Chroma.ToUtf8(), m_format.Width, m_format.Height, m_format.Pitch); m_pBuffer = MemoryHeap.Alloc(m_format.ImageSize); m_pixelData = new PixelData(m_format.ImageSize); m_pixelDataPtr = GCHandle.Alloc(m_pixelData, GCHandleType.Pinned); LibVlcMethods.libvlc_video_set_callbacks(m_hMediaPlayer, pLockCallback, pUnlockCallback, pDisplayCallback, m_pixelDataPtr.AddrOfPinnedObject()); }
/// <summary> /// Initializes a new instance of the <see cref="BitmapInfo"/> class. /// </summary> /// <param name="FormatName">Name of the format.</param> /// <param name="Swizzle">if set to <c>true</c> [swizzle].</param> /// <remarks></remarks> public BitmapInfo(BitmapFormat FormatName, bool Swizzle) { formatname = FormatName; swizzle = Swizzle; }
/// <summary> /// Initializes a new instance of the <see cref="BitmapInfo"/> class. /// </summary> /// <param name="offset">The offset.</param> /// <param name="meta">The meta.</param> /// <remarks></remarks> public BitmapInfo(int offset, ref Meta meta) { BinaryReader BR = new BinaryReader(meta.MS); BR.BaseStream.Position = offset; tagtype = BR.ReadChars(4); width = BR.ReadUInt16(); height = BR.ReadUInt16(); depth = BR.ReadUInt16(); type = BR.ReadUInt16(); typename = (BitmapType)type; // case BitmapFormat.BITM_TYPE_LIGHTMAP: format = BR.ReadUInt16(); formatname = (BitmapFormat)format; switch (formatname) { case BitmapFormat.BITM_FORMAT_A8: case BitmapFormat.BITM_FORMAT_P8: case BitmapFormat.BITM_FORMAT_Y8: case BitmapFormat.BITM_FORMAT_AY8: case BitmapFormat.BITM_FORMAT_LIGHTMAP: bitsPerPixel = 8; break; case BitmapFormat.BITM_FORMAT_A1R5G5B5: case BitmapFormat.BITM_FORMAT_A4R4G4B4: case BitmapFormat.BITM_FORMAT_A8Y8: case BitmapFormat.BITM_FORMAT_R5G6B5: case BitmapFormat.BITM_FORMAT_G8B8: case BitmapFormat.BITM_FORMAT_UNKNOWN: bitsPerPixel = 16; break; case BitmapFormat.BITM_FORMAT_X8R8G8B8: case BitmapFormat.BITM_FORMAT_A8R8G8B8: case BitmapFormat.BITM_FORMAT_DXT1: case BitmapFormat.BITM_FORMAT_DXT2AND3: case BitmapFormat.BITM_FORMAT_DXT4AND5: bitsPerPixel = 32; break; default: bitsPerPixel = 0; break; } flags = BR.ReadUInt16(); // if ((flags & 0x1000) == 0x1000) { swizzle = true; } if ((flags & 0x8) == 0x8) { swizzle = true; } regPointX = BR.ReadUInt16(); regPointY = BR.ReadUInt16(); mipMapCount = BR.ReadUInt16(); pixelOffset = BR.ReadUInt16(); }
/// <summary> /// Decodes the specified barcode bitmap. /// </summary> /// <param name="rawRGB">The image as byte[] array.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">The format.</param> /// <returns> /// the result data or null /// </returns> public Result[] DecodeMultiple([System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray]byte[] rawRGB, int width, int height, BitmapFormat format) { if (rawRGB == null) throw new ArgumentNullException("rawRGB"); var luminanceSource = createRGBLuminanceSource(rawRGB, width, height, format); return DecodeMultiple(luminanceSource); }
/// <summary> /// The decode bitmap. /// </summary> /// <param name="fart">The fart.</param> /// <param name="height">The height.</param> /// <param name="width">The width.</param> /// <param name="depth">The depth.</param> /// <param name="bitsPerPixel">The bits per pixel.</param> /// <param name="type">The type.</param> /// <param name="format">The format.</param> /// <param name="swizzle">The swizzle.</param> /// <param name="map">The map.</param> /// <param name="visualchunkindex">The visualchunkindex.</param> /// <param name="ident">The ident.</param> /// <returns>The decode bitmap.</returns> /// <remarks></remarks> private static int DecodeBitmap( ref byte[] fart, int height, int width, int depth, int bitsPerPixel, BitmapType type, BitmapFormat format, bool swizzle, Map map, int visualchunkindex, int ident) { byte[] poo = new byte[0]; int poolength; byte[] tempData; DecodeDXT decode = new DecodeDXT(); int stride = width; if (swizzle) { fart = Swizzler.Swizzle(fart, width, height, depth, bitsPerPixel, true); } switch (format) { #region DXT1 case (BitmapFormat)14: if (swizzle) { MessageBox.Show("Swizzled"); } fart = decode.DecodeDXT1(height, width, fart); stride *= 4; break; #endregion #region DXT2/3 case (BitmapFormat)15: if (swizzle) { MessageBox.Show("Swizzled"); } fart = decode.DecodeDXT23(height, width, fart); stride *= 4; break; #endregion #region DXT 4/5 case (BitmapFormat)16: if (swizzle) { MessageBox.Show("Swizzled"); } fart = decode.DecodeDXT45(height, width, fart); stride *= 4; break; #endregion #region A8R8G8B8 case (BitmapFormat)11: stride *= 4; break; #endregion #region X8R8G8B8 case (BitmapFormat)10: stride *= 4; /* poolength = fart.Length; tempData = new byte[poolength]; for (int e = 0; e < poolength; e++) tempData[e * 4 + 3] = 255; // Alpha always 255 fart = tempData; */ break; #endregion #region // 16 bit \\ #region A4R4G4B4 case (BitmapFormat)9: stride *= 4; poolength = fart.Length; tempData = new byte[poolength * 2]; for (int e = 0; e < poolength / 2; e++) { int r = e * 2; tempData[r * 2 + 0] = (byte)((fart[r + 1] & 0xFF) >> 0); // Blue tempData[r * 2 + 1] = (byte)((fart[r + 0] & 0xFF) >> 0); // Green tempData[r * 2 + 2] = (byte)((fart[r + 0] & 0xFF) >> 0); // Red tempData[r * 2 + 3] = 255; // (byte)(((fart[r + 1] & 0xFF) >> 0)); // Alpha } fart = tempData; break; #endregion #region G8B8 case (BitmapFormat)22: stride *= 4; poolength = fart.Length; tempData = new byte[poolength / 2 * 4]; // These are actually signed (+/-128), so convert to unsigned for (int e = 0; e < poolength / 2; e++) { int r = e * 2; tempData[r * 2 + 0] = (byte)(fart[r + 1] + 128); // Blue tempData[r * 2 + 1] = (byte)(fart[r + 1] + 128); // Green tempData[r * 2 + 2] = (byte)(fart[r + 0] + 128); // Red tempData[r * 2 + 3] = (byte)(fart[r + 0] + 128); // Alpha } fart = tempData; break; #endregion #region A1R5G5B5 case (BitmapFormat)8: stride *= 4; poolength = fart.Length; tempData = new byte[poolength / 2 * 4]; for (int r = 0; r < fart.Length; r += 2) { int temp = fart[r + 0] + (fart[r + 1] << 8); tempData[r * 2 + 0] = (byte)(((temp >> 0) & 0x1F) * 255 / 0x1F); // 5-bit Blue tempData[r * 2 + 1] = (byte)(((temp >> 5) & 0x1F) * 255 / 0x1F); // 5-bit Green tempData[r * 2 + 2] = (byte)(((temp >> 10) & 0x1F) * 255 / 0x1F); // 5-bit Red tempData[r * 2 + 3] = (byte)(((temp >> 15) & 0x01) * 255); // 1-bit Alpha } fart = tempData; break; #endregion #region R5G6B5 case (BitmapFormat)6: stride *= 4; poolength = fart.Length; tempData = new byte[poolength / 2 * 4]; for (int r = 0; r < fart.Length; r += 2) { int temp = fart[r + 0] + (fart[r + 1] << 8); tempData[r * 2 + 0] = (byte)(((temp >> 0) & 0x1F) * 255 / 0x1F); // 5-bit Blue tempData[r * 2 + 1] = (byte)(((temp >> 5) & 0x3F) * 255 / 0x3F); // 6-bit Green tempData[r * 2 + 2] = (byte)(((temp >> 11) & 0x1F) * 255 / 0x1F); // 5-bit Red tempData[r * 2 + 3] = 255; // Alpha always 255 } fart = tempData; break; #endregion #region A8Y8 case (BitmapFormat)3: poolength = fart.Length; tempData = new byte[poolength / 2 * 4]; for (int e = 0; e < poolength / 2; e++) { int r = e * 2; tempData[r * 2 + 0] = fart[r + 1]; // B tempData[r * 2 + 1] = fart[r + 1]; // G tempData[r * 2 + 2] = fart[r + 1]; // R tempData[r * 2 + 3] = fart[r + 0]; // A } fart = tempData; stride *= 4; break; #endregion #region Unknown - Very similar (exactly?) to G8B8 case (BitmapFormat)23: stride *= 4; poolength = fart.Length; tempData = new byte[poolength / 2 * 4]; // These are actually signed (+/-128), so convert to unsigned for (int e = 0; e < poolength / 2; e++) { int r = e * 2; tempData[r * 2 + 0] = (byte)(fart[r + 1] + 128); // Blue tempData[r * 2 + 1] = (byte)(fart[r + 1] + 128); // Green tempData[r * 2 + 2] = (byte)(fart[r + 0] + 128); // Red tempData[r * 2 + 3] = (byte)(fart[r + 0] + 128); // Alpha } fart = tempData; break; #endregion #endregion #region // 8 bit \\ #region P8 case BitmapFormat.BITM_FORMAT_P8: poolength = fart.Length; tempData = new byte[poolength * 4]; for (int e = 0; e < poolength; e++) { int r = e * 4; tempData[r + 0] = fart[e]; tempData[r + 1] = fart[e]; tempData[r + 2] = fart[e]; tempData[r + 3] = 255; } fart = tempData; stride *= 4; break; #endregion #region A8 case BitmapFormat.BITM_FORMAT_A8: poolength = fart.Length; tempData = new byte[poolength * 4]; for (int e = 0; e < poolength; e++) { int r = e * 4; tempData[r + 0] = fart[e]; tempData[r + 1] = fart[e]; tempData[r + 2] = fart[e]; tempData[r + 3] = 255; } fart = tempData; stride *= 4; break; #endregion #region AY8 case BitmapFormat.BITM_FORMAT_AY8: poolength = fart.Length; tempData = new byte[poolength * 4]; for (int e = 0; e < poolength; e++) { int r = e * 4; tempData[r + 0] = (byte)(fart[e]); tempData[r + 1] = (byte)(fart[e]); tempData[r + 2] = (byte)(fart[e]); tempData[r + 3] = (byte)(fart[e] == 0 ? 0 : 255); } fart = tempData; stride *= 4; break; #endregion #region Y8 case (BitmapFormat)1: poolength = fart.Length; tempData = new byte[poolength * 4]; for (int e = 0; e < poolength; e++) { int r = e * 4; tempData[r + 0] = fart[e]; tempData[r + 1] = fart[e]; tempData[r + 2] = fart[e]; tempData[r + 3] = 255; } fart = tempData; stride *= 4; break; #endregion #region LightMap case BitmapFormat.BITM_FORMAT_LIGHTMAP: poolength = fart.Length; tempData = new byte[poolength * 4]; int bspnumber = ident; int paletteindex = -1; if (visualchunkindex < 0) { int wtf = 0 - (visualchunkindex + 1); paletteindex = map.BSP.sbsp[bspnumber].SceneryChunk_LightMap_Index[wtf]; } if (paletteindex == -1) { for (int i = 0; i < map.BSP.sbsp[bspnumber].VisualChunk_Bitmap_Index.Length; i++) { if (map.BSP.sbsp[bspnumber].VisualChunk_Bitmap_Index[i] == visualchunkindex) { paletteindex = map.BSP.sbsp[bspnumber].VisualChunk_LightMap_Index[visualchunkindex]; break; } } } if (paletteindex == -1) { for (int i = 0; i < map.BSP.sbsp[bspnumber].SceneryChunk_Bitmap_Index.Length; i++) { if (map.BSP.sbsp[bspnumber].SceneryChunk_Bitmap_Index[i] == visualchunkindex) { paletteindex = map.BSP.sbsp[bspnumber].SceneryChunk_LightMap_Index[i]; break; } } } if (paletteindex != 255) { for (int e = 0; e < poolength; e++) { int r = e * 4; tempData[r + 0] = (byte)map.BSP.sbsp[bspnumber].LightMap_Palettes[paletteindex][fart[e]].r; tempData[r + 1] = (byte)map.BSP.sbsp[bspnumber].LightMap_Palettes[paletteindex][fart[e]].g; tempData[r + 2] = (byte)map.BSP.sbsp[bspnumber].LightMap_Palettes[paletteindex][fart[e]].b; tempData[r + 3] = (byte)map.BSP.sbsp[bspnumber].LightMap_Palettes[paletteindex][fart[e]].a; } fart = tempData; stride *= 4; } break; #endregion #endregion } return stride; }
/** * @brief Same as TeamTalk.AcquireUserDesktopWindow() except an extra * option for converting bitmap to a different format. * * It is highly adviced to use TeamTalk.AcquireUserDesktopWindow() since * converting to a different bitmap format is very inefficient. */ public DesktopWindow AcquireUserDesktopWindowEx(int nUserID, BitmapFormat nBitmapFormat) { IntPtr ptr = TTDLL.TT_AcquireUserDesktopWindowEx(m_ttInst, nUserID, nBitmapFormat); if (ptr == IntPtr.Zero) return new DesktopWindow(); DesktopWindow lpDesktopWindow = (DesktopWindow)Marshal.PtrToStructure(ptr, typeof(DesktopWindow)); desktopwindows.Add(lpDesktopWindow.frameBuffer, ptr); return lpDesktopWindow; }
/// <summary> /// Searches the bitmap for barcode. /// </summary> /// <param name="bitmap">Array of bytes, represents bitmap</param> /// <param name="format">Bitmap format, default is BGRA32</param> /// <returns>String, encoded with barcode or empty string if barcode not found</returns> private async Task<Result> DecodeBitmap(byte[] bitmap, BitmapFormat format = BitmapFormat.BGRA32) { Result result = null; try { await Task.Run( () => { var c = new BarcodeReader(); result = c.Decode( bitmap, (int)this.encodingProps.Width, (int)this.encodingProps.Height, format); }).ConfigureAwait(false); } catch (Exception) { } return result; }
public DefineBitsLosslessTag(SwfReader r, uint curTagLen, bool hasAlpha) { HasAlpha = hasAlpha; if (hasAlpha) { tagType = TagType.DefineBitsLossless2; } CharacterId = r.GetUI16(); BitmapFormat = (BitmapFormat)r.GetByte(); this.Width = r.GetUI16(); this.Height = r.GetUI16(); if (BitmapFormat == BitmapFormat.Colormapped8Bit) // 8-bit colormapped image { this.ColorCount = (uint)r.GetByte() + 1; this.isIndexedColors = true; uint colorBytes = hasAlpha ? (uint)4 : (uint)3; uint padWidth = this.Width + (4 - (this.Width % 4)); // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 8); r.Position = pos; // end temp uint unzippedSize = (this.ColorCount * colorBytes) + (padWidth * this.Height); byte[] mapData = r.Decompress(curTagLen - 8, unzippedSize); uint index = 0; this.ColorTable = new RGBA[this.ColorCount]; for (int i = 0; i < this.ColorCount; i++) { if (hasAlpha) { this.ColorTable[i] = new RGBA(mapData[index], mapData[index + 1], mapData[index + 2], mapData[index + 3]); } else { this.ColorTable[i] = new RGBA(mapData[index], mapData[index + 1], mapData[index + 2]); } index += colorBytes; } this.ColorData = new uint[this.Width * this.Height]; index = 0; int offset = (int)(this.ColorCount * colorBytes); for (int i = 0; i < padWidth * this.Height; i++) { if ((i % padWidth) < this.Width)// exclude padding { this.ColorData[index++] = mapData[i + offset]; } } } else if (BitmapFormat == BitmapFormat.RGB15Bit) // RGBx555 { // todo: find a test file for rgb555 uint colorBytes = 2; uint padWidth = this.Width * colorBytes; padWidth += (4 - padWidth) % 4; // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 7); r.Position = pos; // end temp uint unzippedSize = (padWidth * this.Height) * colorBytes; byte[] mapData = r.Decompress(curTagLen - 7, unzippedSize); int index = 0; this.BitmapData = new RGBA[this.Width * this.Height]; for (uint i = 0; i < unzippedSize; i += colorBytes) { if ((i % padWidth) < (this.Width * colorBytes)) // exclude padding { byte b0 = mapData[i]; byte b1 = mapData[i + 1]; byte rd = (byte)((b0 & 0x7C) << 1); byte gr = (byte)(((b0 & 0x03) << 6) | ((b1 & 0xE0) >> 2)); byte bl = (byte)((b1 & 0x1F) << 3); this.BitmapData[index++] = new RGBA(rd, gr, bl); } } } else if (BitmapFormat == BitmapFormat.RGB24Bit) // RGB 24 { // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 7); r.Position = pos; // end temp uint colorBytes = 4; // 4 bytes will always be byte aligned uint unzippedSize = (this.Width * this.Height) * colorBytes; byte[] mapData = r.Decompress(curTagLen - 7, unzippedSize); int index = 0; this.BitmapData = new RGBA[this.Width * this.Height]; for (uint i = 0; i < unzippedSize; i += colorBytes) { if (hasAlpha) { this.BitmapData[index++] = new RGBA(mapData[i + 1], mapData[i + 2], mapData[i + 3], mapData[i]); } else { this.BitmapData[index++] = new RGBA(mapData[i + 1], mapData[i + 2], mapData[i + 3]); } } } }
public override void Load(SwfStream stream, uint length, byte version) { CharacterID = stream.ReadUShort(); ImageData = BitmapUtils.RepairJpegMarkers(stream.ReadByteArray(length - 2)); Format = BitmapUtils.DetectFormat(ImageData); }
/// <summary> /// Initializes a new instance of the <see cref="RGBLuminanceSource"/> class. /// It supports a byte array with 3 bytes per pixel (RGB24). /// </summary> /// <param name="rgbRawBytes">The RGB raw bytes.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="bitmapFormat">The bitmap format.</param> public RGBLuminanceSource(byte[] rgbRawBytes, int width, int height, BitmapFormat bitmapFormat) : base(width, height) { CalculateLuminance(rgbRawBytes, bitmapFormat); }
private void enableDesktopSharingToolStripMenuItem_Click(object sender, EventArgs e) { if (ttclient.Flags.HasFlag(ClientFlag.CLIENT_DESKTOP_ACTIVE)) { ttclient.CloseDesktopWindow(); UpdateControls(); senddesktopTimer.Enabled = false; sendcursorTimer.Enabled = false; return; } DesktopShareDlg dlg = new DesktopShareDlg(); if (dlg.ShowDialog() != DialogResult.OK) return; //'hShareWnd' == IntPtr.Zero means share active window hShareWnd = dlg.hShareWnd; bmpShareFormat = dlg.bmpformat; if (sendDesktopWindow()) { if (dlg.update_interval > 0) { senddesktopTimer.Interval = dlg.update_interval; senddesktopTimer.Enabled = true; } //send desktop cursor every 50 msec if (dlg.share_cursor) { sendcursorTimer.Interval = 50; sendcursorTimer.Enabled = true; } } else MessageBox.Show("Failed to send shared window", "Desktop Sharing Error"); UpdateControls(); }
protected void CalculateLuminance(byte[] rgbRawBytes, BitmapFormat bitmapFormat) { if (bitmapFormat == BitmapFormat.Unknown) { bitmapFormat = DetermineBitmapFormat(rgbRawBytes, Width, Height); } switch (bitmapFormat) { case BitmapFormat.Gray8: Buffer.BlockCopy(rgbRawBytes, 0, luminances, 0, rgbRawBytes.Length < luminances.Length ? rgbRawBytes.Length : luminances.Length); break; case BitmapFormat.RGB24: case BitmapFormat.BGR24: CalculateLuminanceRGB24(rgbRawBytes); break; case BitmapFormat.RGB32: case BitmapFormat.BGR32: CalculateLuminanceRGB32(rgbRawBytes); break; case BitmapFormat.RGBA32: CalculateLuminanceRGBA32(rgbRawBytes); break; case BitmapFormat.ARGB32: CalculateLuminanceARGB32(rgbRawBytes); break; case BitmapFormat.BGRA32: CalculateLuminanceBGRA32(rgbRawBytes); break; case BitmapFormat.RGB565: CalculateLuminanceRGB565(rgbRawBytes); break; default: throw new ArgumentException("The bitmap format isn't supported.", bitmapFormat.ToString()); } }
/** * @brief Transmit the specified window in a desktop session. * * Same as TeamTalk.SendDesktopWindow() except the properties for the * #BearWare.DesktopWindow are extracted automatically. * * @param hWnd Windows handle for the window to transmit. * @param nBitmapFormat Bitmap format to use for the transmitted image. * @param nDesktopProtocol The protocol to use for transmitting the image. * @return See TeamTalk.SendDesktopWindow(). */ public int SendDesktopWindowFromHWND(System.IntPtr hWnd, BitmapFormat nBitmapFormat, DesktopProtocol nDesktopProtocol) { return TTDLL.TT_SendDesktopWindowFromHWND(m_ttInst, hWnd, nBitmapFormat, nDesktopProtocol); }
/** @} */ /** @addtogroup desktopshare * @{ */ /** * @brief Transmit a desktop window (bitmap) to users in the same * channel. * * When TeamTalk.SendDesktopWindow() is called the first time a new * desktop session will be started. To update the current desktop * session call TeamTalk.SendDesktopWindow() again once the previous * desktop transmission has finished. Tracking progress of the * current desktop transmission is done by checking for the * TeamTalk.OnDesktopTransferUpdate() event. While the desktop * transmission is active the flag #ClientFlag ::CLIENT_TX_DESKTOP will be set * on the local client instance. * * If the desktop window (bitmap) changes size (width/height) or * format a new desktop session will be started. Also if the user * changes channel a new desktop session will be started. Check @c * nSessionID of #BearWare.DesktopWindow to see if a new desktop session is * started or the TeamTalk.OnUserDesktopWindow() event. * * Remote users will get the TeamTalk.OnUserDesktopWindow() event * and can call TeamTalk.AcquireUserDesktopWindow() to retrieve the desktop * window. * * User rights required: * - ::USERRIGHT_TRANSMIT_DESKTOP * * @param lpDesktopWindow Properties of the bitmap. Set the @c nSessionID * property to 0. * @param nConvertBmpFormat Before transmission convert the bitmap to this * format. * @return TRUE if desktop window is queued for transmission. FALSE if * @c nBitmapSize is invalid or if a desktop transmission is already * active. * @return -1 on error. 0 if bitmap has no changes. Greater than 0 on * success. * @see TeamTalk.CloseDesktopWindow() * @see TeamTalk.SendDesktopCursorPosition() */ public int SendDesktopWindow(DesktopWindow lpDesktopWindow, BitmapFormat nConvertBmpFormat) { return TTDLL.TT_SendDesktopWindow(m_ttInst, ref lpDesktopWindow, nConvertBmpFormat); }
private async void Deocode(byte[] rawRgb, BitmapFormat bitmapFormat) { await Task.Run(() => { if (_decoding) return; _decoding = true; var decoded = _reader.Decode(rawRgb, (int)_width, (int)_height, bitmapFormat); if (decoded != null) { _eventAggregator.PublishOnUIThread(new QRDecodedMessage(decoded.Text)); //Stop(); } _decoding = false; }); }
/** * @brief Get RGB values of the palette for the bitmap format. * * This currently only applies to bitmaps of format #BitmapFormat ::BMP_RGB8_PALETTE. * * Note that the pointer returned is non-const which means the * palette can be overwritten with a custom palette. The custom * palette will then be used internally during bitmap * conversion. * * @param nBmpPalette The bitmap format. Currently only #BitmapFormat ::BMP_RGB8_PALETTE * is supported. * @param nIndex The index in the color table of the RGB values to * extract. * @return Pointer to RGB colors. First byte is Red, second Blue and * third Green. Returns NULL if the color-index is invalid. */ public static System.Drawing.Color Palette_GetColorTable(BitmapFormat nBmpPalette, int nIndex) { IntPtr ptr = TTDLL.TT_Palette_GetColorTable(nBmpPalette, nIndex); switch(nBmpPalette) { case BitmapFormat.BMP_RGB8_PALETTE: return Color.FromArgb(Marshal.ReadInt32(ptr)); } return new Color(); }