public void UnlockImage() { if (bitmapData != null) { workingBitmap.UnlockBits(bitmapData); bitmapData = null; pBase = null; } }
public NumberBuffer(Byte* stackBuffer) { this.baseAddress = stackBuffer; this.digits = (((Char*)stackBuffer) + 6); this.precision = 0; this.scale = 0; this.sign = false; }
private void LockBits() { Width = _bitmap.Width; Height = _bitmap.Height; _pixelWidth = sizeof (Pixel); _lockData = _bitmap.LockBits(new Rectangle(0, 0, _bitmap.Width, _bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); _ptrBase = (Byte*)_lockData.Scan0.ToPointer(); }
public void Initialize(Byte* readBufferPtr, Int32 length, Boolean endOfStream) { _IsLastOfLine = false; _LastLine = _EmptyBytes; this._Start = null; this._Current = readBufferPtr; this._End = readBufferPtr + length * sizeof(Byte); this.EndOfStream = endOfStream; }
public void LockImage() { Rectangle bounds = new Rectangle(Point.Empty, workingBitmap.Size); width = (int)(bounds.Width * sizeof(PixelData)); if (width % 4 != 0) width = 4 * (width / 4 + 1); //Lock Image bitmapData = workingBitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); pBase = (Byte*)bitmapData.Scan0.ToPointer(); }
public void LockImage() { var bounds = new Rectangle(Point.Empty, _workingBitmap.Size); _width = bounds.Width * sizeof(PixelData); if (_width % 4 != 0) _width = 4 * (_width / 4 + 1); //Lock Image _bitmapData = _workingBitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); _pBase = (Byte*)_bitmapData.Scan0.ToPointer(); }
public void LockBitmap() { GraphicsUnit unit = GraphicsUnit.Pixel; RectangleF boundsF = mBitmap.GetBounds( ref unit ); Rectangle bounds = new Rectangle( (int)boundsF.X, (int)boundsF.Y, (int)boundsF.Width, (int)boundsF.Height ); mWidth = (int)boundsF.Width * sizeof( PixelData ); if( mWidth % 4 != 0 ) mWidth = 4 * ( mWidth / 4 + 1 ); BitmapData = mBitmap.LockBits( bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb ); mPBase = (Byte*)BitmapData.Scan0.ToPointer(); }
public unsafe ImageInt32 ToImageInt32() { ImageInt32 img32 = new ImageInt32(this.Width, this.Height); Byte * start = this.Start; Byte * end = this.Start + this.Length; Int32 * dst = img32.Start; while (start != end) { *dst = *start; start++; dst++; } return(img32); }
public static unsafe void memmove(Byte *pDest, Byte *pSource, int Count) { if (pSource > pDest || &pSource[Count] < pDest) { for (uint i = 0; i < Count; i++) { *pDest++ = *pSource++; } } else { throw new System.NotImplementedException(); } }
/// <inheritdoc/> protected override Byte[] ComputeHashInternal(Byte[] buffer, Int32 offset, Int32 count) { UInt64 hash; unsafe { fixed(Byte *pin = &buffer[offset]) { Byte *pointer = pin; if (count == 0) { hash = K2; } else if (count <= 3) { hash = Hash1To3(pointer, count); } else if (count <= 7) { hash = Hash4To7(pointer, count); } else if (count <= 16) { hash = Hash8To16(pointer, count); } else if (count <= 32) { hash = Hash17To32(pointer, count); } else if (count <= 64) { hash = Hash33To64(pointer, count); } else { hash = Hash65ToEnd(pointer, count); } if (m_Seeds.Count > 0) { hash = HashLength16(hash - m_Seeds[0], m_Seeds[1], K3); } } } return(ToByteArray64(hash)); }
private unsafe static MigrationResult FastAllocateStringMigrateInstruction(IntPtr src, IntPtr dst, int minimumCount) { Byte *pSrc = (Byte *)src; Byte *pDst = (Byte *)dst; // Works on... // x64 .NET Framework 4.5 ~ 4.8 // x64 .NET Core 2.0 ~ if ( pSrc[0] == 0x4C && pSrc[1] == 0x8B && pSrc[2] == 0x0D && pSrc[7] == 0x81 && pSrc[8] == 0xF9) { int srcOffset = 0; int dstOffset = 0; void *location = pSrc + *(Int32 *)(pSrc + 3) + 7; pDst[0] = 0x49; pDst[1] = 0xB9; *(void **)(pDst + 2) = location; pDst[10] = 0x4D; pDst[11] = 0x8B; pDst[12] = 0x09; srcOffset += 7; dstOffset += 13; RawMemoryManager.MemCpy(pDst + dstOffset, pSrc + srcOffset, 6); srcOffset += 6; dstOffset += 6; return(new MigrationResult(srcOffset, dstOffset)); } // Works on... // x86 .NET Framework 4.5 ~ 4.8 else if ( pSrc[0] == 0x51 && pSrc[1] == 0x8B && pSrc[2] == 0xC1 && pSrc[3] == 0x8B && pSrc[4] == 0x0D && pSrc[9] == 0x81 && pSrc[10] == 0xF8) { RawMemoryManager.MemCpy(pDst, pSrc, 15); return(new MigrationResult(15, 15)); } else { throw new NotImplementedException(); } }
/// <summary> /// Generates a key (Key) to use for the algorithm. /// </summary> public void GenerateKey(UInt32 Seed) { if (BufKey != null) { Kernel.free(BufKey); } BufKey = (Byte *)Kernel.malloc(COFAC_KEY); MSRandom Rand = new MSRandom(Seed); for (Int32 i = 0; i < COFAC_KEY; i++) { BufKey[i] = (Byte)(Rand.Next() % 0x100); } }
public unsafe void Copy(byte *from, void *to, int length) { if (length < 1) { return; } Byte * end = from + length; Int32 *dst = (Int32 *)to; while (from != end) { *dst = *from; from++; dst++; } }
static internal int crypto_secretbox_inplace_nopad(Byte *c, UInt64 mlen, Byte *n, Byte *k) { if (mlen < 0) { return(-1); } Byte *mc16 = stackalloc Byte[16]; for (int i = 0; i < 16; i += 4) { *(int *)(mc16 + i) = 0; } crypto_stream.xsalsa20.crypto_stream_xor_split(mc16, 16, c, c, mlen, n, k); crypto_onetimeauth.poly1305.crypto_onetimeauth(c, c + 16, mlen, mc16); return(0); }
public void LockBitmap() { GraphicsUnit unit = GraphicsUnit.Pixel; RectangleF boundsF = subject.GetBounds(ref unit); Rectangle bounds = new Rectangle((int)boundsF.X, (int)boundsF.Y, (int)boundsF.Width, (int)boundsF.Height); subject_width = (int)boundsF.Width * sizeof(int); if (subject_width % 4 != 0) { subject_width = 4 * (subject_width / 4 + 1); } bitmap_data = subject.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); p_base = (Byte *)bitmap_data.Scan0.ToPointer(); }
/// <summary> /// Locks the image so manipulation can be done. /// </summary> public void LockImage() { if (currentState == BitmapExState.Unlocked) { Rectangle bounds = new Rectangle(Point.Empty, workingBitmap.Size); width = (int)(bounds.Width * sizeof(PixelData)); if (width % 4 != 0) { width = 4 * (width / 4 + 1); } bitmapData = workingBitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); pBase = (Byte *)bitmapData.Scan0.ToPointer(); currentState = BitmapExState.Locked; } }
public unsafe Color GetPixel(Int32 x, Int32 y) { if (_bitmapData.PixelFormat == PixelFormat.Format32bppArgb) { Byte *b = (Byte *)_bitmapData.Scan0 + (y * _bitmapData.Stride) + (x * 4); return(Color.FromArgb(*(b + 3), *(b + 2), *(b + 1), *b)); } if (_bitmapData.PixelFormat == PixelFormat.Format24bppRgb) { Byte *b = (Byte *)_bitmapData.Scan0 + (y * _bitmapData.Stride) + (x * 3); return(Color.FromArgb(*(b + 2), *(b + 1), *b)); } return(Color.Empty); }
public static unsafe byte *EncodeMaxUtf8(out uint outCharsEncoded, String str, UInt32 offset, UInt32 charLength, Byte *dest, Byte *destLimit) { // NOTE: can't do the addition in the fixed statement, because it doesn't // do pointer arithmetic correctly fixed(char *originalStringPtr = str) { char *strPtr = originalStringPtr + offset; char *encodedTo; byte *writtenTo = EncodeMaxUtf8(out encodedTo, strPtr, strPtr + charLength, dest, destLimit); outCharsEncoded = (uint)(encodedTo - strPtr); //Console.WriteLine("[DEBUG] Encoded {0} chars: ---{1}---", outCharsEncoded, str.Substring((int)offset, (int)outCharsEncoded)); return(writtenTo); } }
internal static unsafe ZLibNative.ErrorCode DeflateInit2_( ref ZLibNative.ZStream stream, ZLibNative.CompressionLevel level, ZLibNative.CompressionMethod method, Int32 windowBits, Int32 memLevel, ZLibNative.CompressionStrategy strategy) { fixed(Byte *versionString = &ZLibVersion[0]) fixed(ZLibNative.ZStream * streamBytes = &stream) { Byte *pBytes = (Byte *)streamBytes; return((ZLibNative.ErrorCode)DeflateInit(pBytes, (Int32)level, (Int32)method, (Int32)windowBits, memLevel, (Int32)strategy, versionString, sizeof(ZLibNative.ZStream))); } }
public static void crypto_scalarmult(Byte* q, Byte* n, Byte* p) { UInt32[] work = new UInt32[96]; Byte[] e = new Byte[32]; for (int i = 0; i < 32; ++i) e[i] = n[i]; e[0] &= 248; e[31] &= 127; e[31] |= 64; for (int i = 0; i < 32; ++i) work[i] = p[i]; mainloop(work, e); fixed (UInt32* workp = work) { recip(workp + 32, workp + 32); mult(workp + 64, workp, workp + 32); freeze(workp + 64); } for (int i = 0; i < 32; ++i) q[i] = (Byte)work[64 + i]; }
public void LockBitmap() { GraphicsUnit unit = GraphicsUnit.Pixel; RectangleF boundsF = mBitmap.GetBounds(ref unit); Rectangle bounds = new Rectangle((int)boundsF.X, (int)boundsF.Y, (int)boundsF.Width, (int)boundsF.Height); mWidth = (int)boundsF.Width * sizeof(PixelData); if (mWidth % 4 != 0) { mWidth = 4 * (mWidth / 4 + 1); } BitmapData = mBitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); mPBase = (Byte *)BitmapData.Scan0.ToPointer(); }
public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); Byte localData = (byte)2; Byte *ptr = &localData; var result = Sse41.Insert( Sse2.LoadAlignedVector128((Byte *)(_dataTable.inArrayPtr)), *ptr, 129 ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); }
public MimeHeaderBufferByteArray ReadHeader(MimeHeaderBufferByteArray header) { this._Start = this._Current; Byte *start = this._Start; Byte *lastOfLine = this._Current; if (this._Current == this._End) { return(header); } if (*this._Current == 10)// \n { this._Current++; header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return(header); } //Find LineFeed char while (true) { // \n while (*this._Current != 10) { this._Current++; } if (this._Current == this._End) { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._End - start), false); return(header); } lastOfLine = this._Current - 2; this._Current++; //Empty line is start of body if (lastOfLine - this._Start < 1) { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return(header); } if (*this._Current != 9 && *this._Current != 32)// \t or white space { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return(header); } } }
public unsafe ImageU8 ToGrayscaleImage(double rCoeff, double gCoeff, double bCoeff) { ImageU8 img = new ImageU8(this.Width, this.Height); Argb32 *p = Start; Byte * to = img.Start; Argb32 *end = p + Length; if (Length < 1024) { while (p != end) { *to = (Byte)(p->Red * rCoeff + p->Green * gCoeff + p->Blue * bCoeff); p++; to++; } } else { int *bCache = stackalloc int[256]; int *gCache = stackalloc int[256]; int *rCache = stackalloc int[256]; const int shift = 1 << 10; int rShift = (int)(rCoeff * shift); int gShift = (int)(gCoeff * shift); int bShift = shift - rShift - gShift; int r = 0, g = 0, b = 0; for (int i = 0; i < 256; i++) { bCache[i] = b; gCache[i] = g; rCache[i] = r; b += bShift; g += gShift; r += rShift; } while (p != end) { *to = (Byte)((bCache[p->Red] + gCache[p->Green] + rCache[p->Red]) >> 10); p++; to++; } } return(img); }
// / / Public methods public BitmapEditor(Bitmap bitmap) { // Store original Bitmap object editorSource = new Bitmap(bitmap); // Get BitmapData object from original Bitmap editorSourceData = editorSource.LockBits((new Rectangle(0, 0, editorSource.Width, editorSource.Height)), ImageLockMode.ReadOnly, editorSource.PixelFormat); // Get pointer to bytes of BitmapData objects editorSourceBytes = (Byte *)(editorSourceData.Scan0.ToPointer()); // Get Bitmap stride editorSourceStride = editorSourceData.Stride; // Resolve BPP and pixel components offsets of the Bitmap switch (editorSource.PixelFormat) { case PixelFormat.Format24bppRgb: editorSourceBPP = 3; editorSourceOffsetR = 2; editorSourceOffsetG = 1; editorSourceOffsetB = 0; editorSourceOffsetA = -1; break; case PixelFormat.Format32bppArgb: editorSourceBPP = 4; editorSourceOffsetR = 2; editorSourceOffsetG = 1; editorSourceOffsetB = 0; editorSourceOffsetA = 3; break; default: throw new Exception("Unhandled pixel format " + editorSource.PixelFormat); } // Tunnel properties from Bitmap object Size = editorSource.Size; Width = editorSource.Width; Height = editorSource.Height; PixelFormat = editorSource.PixelFormat; }
public static unsafe Bitmap ToGrayscale(Bitmap colorBitmap) { int Width = colorBitmap.Width; int Height = colorBitmap.Height; Bitmap grayscaleBitmap = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed); grayscaleBitmap.SetResolution(colorBitmap.HorizontalResolution, colorBitmap.VerticalResolution); /////////////////////////////////////// // Set grayscale palette /////////////////////////////////////// ColorPalette colorPalette = grayscaleBitmap.Palette; for (int i = 0; i < colorPalette.Entries.Length; i++) { colorPalette.Entries[i] = Color.FromArgb(i, i, i); } grayscaleBitmap.Palette = colorPalette; /////////////////////////////////////// // Set grayscale palette /////////////////////////////////////// BitmapData bitmapData = grayscaleBitmap.LockBits( new Rectangle(Point.Empty, grayscaleBitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); Byte *pPixel = (Byte *)bitmapData.Scan0; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Color clr = colorBitmap.GetPixel(x, y); Byte byPixel = (byte)((30 * clr.R + 59 * clr.G + 11 * clr.B) / 100); pPixel[x] = byPixel; } pPixel += bitmapData.Stride; } grayscaleBitmap.UnlockBits(bitmapData); return(grayscaleBitmap); }
/// <summary> buffer callback, COULD BE FROM FOREIGN THREAD. </summary> unsafe int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) { // Performance is essential here. Use unsafe for fastest possible scanning. // If every pixel were absolutely black, *b would always be zero. However, few frames, // no matter how dark they appear, are *completely* black. I'm picking an arbitrary number. // If the Red, Green or Blue of any pixel is brighter than this, I'm asserting that the frame // isn't black. Adjust this number to suit. Set to zero to look for absolute blacks only. const int iMaxBright = 10; Debug.Assert(IntPtr.Size == 4, "Change all instances of IntPtr.ToInt32 to .ToInt64"); // Walk every Red/Green/Blue of every pixel in the image. // If any are greater than iMaxBrightness, it's too bright to be a black frame Byte *b = (byte *)pBuffer; for (int x = 0; x < m_videoHeight; x++) { for (int y = 0; (y < m_stride) && (*b <= iMaxBright); y++) { b++; } // Are we done? if (*b > iMaxBright) { break; } // If the image width isn't evenly divisable by 4, sometimes padding bytes // are added on the end of the rows. We need to make sure we skip those b = (byte *)(pBuffer); b += (x * m_stride); } // If we didn't exit due to brightness if (*b <= iMaxBright) { m_Blacks++; Debug.WriteLine(string.Format("Frame Number: {0} Blacks: {1}", m_Count, m_Blacks)); } // Increment frame number. Done this way, frame are zero indexed. m_Count++; return(0); }
/// <summary>Converts the given object into a byte array</summary> /// <param name="Receiver">The array that receives the final data.</param> /// <param name="Value">The object to convert</param> /// <param name="StartIndex">The startindex for the data</param> /// <returns>Converts the given object into a byte array</returns> public static Int32 OntoBytes(Byte[] Receiver, UInt64 Value, Int32 StartIndex = 0) { if (Receiver is null) { throw new ArgumentNullException(nameof(Receiver)); } Int32 Count = sizeof(UInt64); if (StartIndex + Count > Receiver.Length) { throw new ArgumentException("Receiver is not of proper length"); } #if UNSAFE unsafe { Byte *s = (Byte *)&Value; Receiver[7 + StartIndex] = *s; Receiver[6 + StartIndex] = *(s + 1); Receiver[5 + StartIndex] = *(s + 2); Receiver[4 + StartIndex] = *(s + 3); Receiver[3 + StartIndex] = *(s + 4); Receiver[2 + StartIndex] = *(s + 5); Receiver[1 + StartIndex] = *(s + 6); Receiver[StartIndex] = *(s + 7); } #else Receiver[7 + StartIndex] = (Byte)(Value); Value >>= 8; Receiver[6 + StartIndex] = (Byte)((Value)); Value >>= 8; Receiver[5 + StartIndex] = (Byte)((Value)); Value >>= 8; Receiver[4 + StartIndex] = (Byte)((Value)); Value >>= 8; Receiver[3 + StartIndex] = (Byte)((Value)); Value >>= 8; Receiver[2 + StartIndex] = (Byte)((Value)); Value >>= 8; Receiver[1 + StartIndex] = (Byte)((Value)); Value >>= 8; Receiver[StartIndex] = (Byte)((Value)); #endif return(Count); }
private void button1_Click(object sender, RoutedEventArgs e) { int a, b, c, d; a = 5; b = 5; c = 0; d = addValue(a, b, ref c); OpenFileDialog fDlg = new OpenFileDialog(); string strFileName = ""; fDlg.DefaultExt = "BMP"; fDlg.Filter = "그림파일(*.bmp, *.jpg, *.png)|*.bmp;*.jpg;*.png;|모든파일 *.*|*.*"; if (fDlg.ShowDialog() == true) { strFileName = fDlg.FileName; Mat imgSrc = new Mat(strFileName, ImreadModes.Color); WriteableBitmap bitImg = new WriteableBitmap(imgSrc.Width, imgSrc.Height, 96, 96, PixelFormats.Bgr24, null); unsafe { Byte *pBuffer = (Byte *)imgSrc.Data; for (a = 0; a < imgSrc.Height; a++) { for (b = 0; b < imgSrc.Width; b++) { for (c = 0; c < imgSrc.Channels(); c++) { pBuffer[a * imgSrc.Width * imgSrc.Channels() + b * imgSrc.Channels() + c] = (Byte)((a * b + c) % 255); //흑백물결무늬 //pBuffer[a * imgSrc.Width * imgSrc.Channels() + b * imgSrc.Channels() + c] = (Byte)((a + b + c) % 255); //흑백사선무늬 //pBuffer[a * imgSrc.Width * imgSrc.Channels() + b * imgSrc.Channels() + c] = (Byte)((a + b * c) % 255); //칼라줄무늬 } //칼러격자무늬 //pBuffer[a * imgSrc.Width * imgSrc.Channels() + b * imgSrc.Channels() + 0] = (Byte)((a) % 255); //pBuffer[a * imgSrc.Width * imgSrc.Channels() + b * imgSrc.Channels() + 1] = (Byte)((b) % 255); //pBuffer[a * imgSrc.Width * imgSrc.Channels() + b * imgSrc.Channels() + 2] = (Byte)((a + b) % 255); } } } WriteableBitmapConverter.ToWriteableBitmap(imgSrc, bitImg); image.Source = bitImg; } }
public static DecompressorContext PrepareDecompression(Byte *data, UInt32 compressedSize, UInt32 decompressedSize) { UInt32 *data32 = (UInt32 *)data; UInt32 magic = *data32++; if (magic != 0x1234) { throw new NotSupportedException("if (magic != 0x1234)"); } UInt32 blkCnt = *data32++; UInt32 blkSz = *data32++; UInt32 headerSz = *data32++; if (headerSz != 16 + 12 * blkCnt) { throw new NotSupportedException("if (header_sz != 16 + 12 * blk_cnt)"); } var info = new DecompressorContext(); info.SetInput(data, compressedSize); info.SetBlocks(blkCnt, blkSz); UInt32 outputSize = 0; for (Int32 i = 0; i < blkCnt; ++i) { UInt32 decSz = *data32++; UInt32 cmpSz = *data32++; UInt32 offset = *data32++; outputSize += decSz; info.SetDataChunk(i, decSz, cmpSz, offset); } if (decompressedSize != outputSize) { throw new NotSupportedException("if (uncompressedSize != output_size)"); } info.SetOutput(outputSize); return(info); }
internal unsafe VerticalBlockPair(Byte *b, out bool valid) { Raw r = *(Raw *)b; valid = (r._Header[0] == 0xFF) && (r._Header[1] == 0xEE); this._Azimuth = ((r._Azimuth[1] << 8) | (r._Azimuth[0])) / 100.0f; this._ChannelData = new SinglePoint[Raw._SinglePointsPerVerticalBlock]; for (int i = 0, byte_index = 0; i < Raw._SinglePointsPerVerticalBlock; i++, byte_index += SinglePoint.Raw._Size) { this._ChannelData[i] = new SinglePoint(&r._ChannelData[byte_index]); } }
/// <summary> /// Return the value for the current entry. /// REQUIRES: IsValid() /// </summary> public unsafe Byte[] Value() { IntPtr value = LevelDBInterop.leveldb_iter_value(this.Handle, out IntPtr length); this.Throw(); Byte[] bytes = new Byte[(Int64)length]; Byte * valueNative = (Byte *)value.ToPointer(); for (Int64 i = 0; i < (Int64)length; ++i) { bytes[i] = valueNative[i]; } GC.KeepAlive(this); return(bytes); }
/// <summary> /// Copies the C string pointed by source into the array pointed by destination, including the /// terminating null character. /// </summary> /// <param name="dest">Pointer to the destination array where the content is to be copied.</param> /// <param name="src">C string to be copied.</param> /// <returns>The destination is returned.</returns> public static Byte *strcpy(Byte *dest, String src) { var bytes = Encoding.Default.GetBytes(src); var i = 0; for (i = 0; i < bytes.Length; i++) { dest[i] = bytes[i]; if (bytes[i] == 0) //NUL character { return(dest); } } dest[i] = 0; return(dest); }
public void LockBits() { if (isLocked) { return; } try { bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat); stride = bitmapData.Stride; pBase = (byte *)bitmapData.Scan0.ToPointer(); } finally { isLocked = true; } }
unsafe public Int32 Enqueue <T>(T src) { Int32 size = Marshal.SizeOf <T>(); if (size > spaceSize) { // resize space } Marshal.StructureToPtr(src, space, false); ///////////// Int32 readHeadCapture = readHead; Int32 writeHeadCapture = writeHead; Int32 useSize = writeHeadCapture >= readHeadCapture ? writeHeadCapture - readHeadCapture : capacity - (readHeadCapture - writeHeadCapture); Int32 freeSize = capacity - (useSize + 1); if (freeSize == 0) { return(0); } Int32 directEnqueueSize = readHeadCapture > writeHeadCapture ? readHeadCapture - (writeHeadCapture + 1) : capacity - writeHeadCapture; Int32 sizeToStore = size > freeSize ? freeSize : size; Int32 firstSpaceSize = directEnqueueSize < sizeToStore ? directEnqueueSize : sizeToStore; Int32 secondSpaceSize = sizeToStore - firstSpaceSize; // first copy Marshal.Copy(space, buffer, writeHead, firstSpaceSize); // second copy. if (secondSpaceSize > 0) { Byte *temp = (Byte *)space.ToPointer(); temp += firstSpaceSize; Marshal.Copy((IntPtr)temp, buffer, 0, secondSpaceSize); } writeHeadCapture += sizeToStore; writeHeadCapture %= capacity; writeHead = writeHeadCapture; return(sizeToStore); }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { UnlockBitmap(); Bitmap.Dispose(); } subject = null; bitmap_data = null; p_base = null; disposed = true; } }
/* Reduce coefficients of r before calling reduce_add_sub */ static unsafe void reduce_add_sub(sc25519 *r) { int i, b = 0, pb = 0, nb; Byte *t = stackalloc Byte[32]; for (i = 0; i < 32; i++) { b = (r->v[i] < pb + m[i]) ? 1 : 0; t[i] = (Byte)(r->v[i] - pb - m[i] + b * 256); pb = b; } nb = 1 - b; for (i = 0; i < 32; i++) { r->v[i] = (uint)(r->v[i] * b + t[i] * nb); } }
public void LockBitmap() { GraphicsUnit unit = GraphicsUnit.Pixel; RectangleF boundsF = bitmap.GetBounds(ref unit); Rectangle bounds = new Rectangle((int) boundsF.X,(int) boundsF.Y,(int) boundsF.Width,(int) boundsF.Height); // Figure out the number of bytes in a row // This is rounded up to be a multiple of 4 // bytes, since a scan line in an image must always be a multiple of 4 bytes // in length. width = (int) boundsF.Width * sizeof(PixelData); if (width % 4 != 0) { width = 4 * (width / 4 + 1); } bitmapData = bitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); pBase = (Byte*) bitmapData.Scan0.ToPointer(); }
public void* RawSeekEnd() { Contract.Ensure(hasAcquiredPointers, NucleusStrings.UnsafeStreamMustAcquirePointers); positionInObjects = lengthInObjects; positionInBytes = lengthInBytes; pData = pData0 + lengthInBytes; return pData; }
internal void UnlockImage() { workingBitmap.UnlockBits(bitmapData); bitmapData = null; pBase = null; }
public MimeHeaderBufferByteArray ReadHeader(MimeHeaderBufferByteArray header) { this._Start = this._Current; Byte* start = this._Start; Byte* lastOfLine = this._Current; if (this._Current == this._End) { return header; } if (*this._Current == 10)// \n { this._Current++; header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return header; } //Find LineFeed char while (true) { // \n while (*this._Current != 10) { this._Current++; } if (this._Current == this._End) { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._End - start), false); return header; } lastOfLine = this._Current - 2; this._Current++; //Empty line is start of body if (lastOfLine - this._Start < 1) { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return header; } if (*this._Current != 9 && *this._Current != 32)// \t or white space { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return header; } } }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { UnlockBitmap(); bitmap.Dispose(); } bitmap = null; bitmapData = null; pBase = null; disposed = true; } }
public void UnlockImage() { _workingBitmap.UnlockBits(_bitmapData); _bitmapData = null; _pBase = null; }
static unsafe void FillPtr (int cycles) { var l = new List<Byte*[]> (); for (int i = 0; i < cycles; ++i) { var a = new Byte* [128]; for (int j = 0; j < a.Length; ++j) a [j] = (Byte*) new IntPtr (j).ToPointer (); if (i < 1000) l.Add (a); else l [i % 1000] = a; } }
/// <summary> /// Releases the pointers which were acquired by <see cref="AcquirePointers()"/> and unpins /// the stream's underlying buffers. /// </summary> public void ReleasePointers() { Contract.Ensure(hasAcquiredPointers, NucleusStrings.UnsafeStreamMustAcquirePointers); hasAcquiredPointers = false; gcData.Free(); pData0 = null; pData = null; }
private void LockBitmap(Bitmap image) { GraphicsUnit unit = GraphicsUnit.Pixel; RectangleF boundsF = Subject.GetBounds(ref unit); Rectangle bounds = new Rectangle((int)boundsF.X, (int)boundsF.Y, (int)boundsF.Width, (int)boundsF.Height); SubjectWidth = (int)boundsF.Width * sizeof(PixelData); if (SubjectWidth % 4 != 0) { SubjectWidth = 4 * (SubjectWidth / 4 + 1); } bitmapData = Subject.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); pBase = (Byte*)bitmapData.Scan0.ToPointer(); }
private void UnlockBitmap() { Subject.UnlockBits(bitmapData); bitmapData = null; pBase = null; }
public Byte[] ReadBody(Byte[] boundary, out CheckBoundaryResult result, out Boolean isEndOfBody) { result = CheckBoundaryResult.None; isEndOfBody = false; if (this._Current == this._End) { isEndOfBody = true; return _EmptyBytes; } Int32 boundaryLength = -1; if (boundary != null) { boundaryLength = boundary.Length; } this._Start = this._Current; var line_Start = this._Current; UInt32 bbbbXor = 0; while (true) { UInt32* bbbb = (UInt32*)this._Current; do { bbbbXor = *bbbb++ ^ 0x0A0A0A0A; } while (((bbbbXor - 0x01010101) & ~bbbbXor & 0x80808080) == 0); this._Current = (byte*)(bbbb - 1); // 10 is \n while (*this._Current != 10) { this._Current++; } if (*line_Start == 46)// . { var lastOfLine = this._Current - 2; if (line_Start == lastOfLine) { isEndOfBody = true; //Remove last period from bodydata return MimeParser.CreateNewBytes(new IntPtr(this._Start), lastOfLine - this._Start); } } // Check this line is started by '-' (Boundary). //That avoid method call of CheckBoundary and improve performance. if (*line_Start == 45 && boundaryLength > -1) { var lastOfLine = this._Current - 2; var length = lastOfLine - line_Start + 1; if (length == boundaryLength || length == boundaryLength + 2) { result = CheckBoundary(line_Start, lastOfLine + 1, boundary); if (result != CheckBoundaryResult.None) { if (result == CheckBoundaryResult.Boundary) { //Back to start of line.To read boundary line on MimeParser.ReadMimeContent method. this._Current = line_Start; } return MimeParser.CreateNewBytes(new IntPtr(this._Start), line_Start - this._Start); } } } if (this._Current == this._End) { //Contains only 1 line and end of buffer if (line_Start == this._Start) { this._Current = line_Start; _IsLastOfLine = true; _LastLine = MimeParser.CreateNewBytes(new IntPtr(this._Start), this._End - this._Start); return _EmptyBytes; } return MimeParser.CreateNewBytes(new IntPtr(this._Start), this._Current - this._Start); } this._Current++; line_Start = this._Current; } }
public void* RawSeekBeginning() { Contract.Ensure(hasAcquiredPointers, NucleusStrings.UnsafeStreamMustAcquirePointers); positionInObjects = 0; positionInBytes = 0; pData = pData0; return pData; }
public void* RawSeekObject(Int32 offset) { Contract.Ensure(hasAcquiredPointers, NucleusStrings.UnsafeStreamMustAcquirePointers); Contract.EnsureRange(offset >= 0 && offset <= lengthInObjects, nameof(offset)); positionInObjects = offset; positionInBytes = (offset == lengthInObjects) ? lengthInBytes : index[offset]; pData = pData0 + positionInBytes; return pData; }
public void* RawSeekBackward() { Contract.Ensure(hasAcquiredPointers, NucleusStrings.UnsafeStreamMustAcquirePointers); if (positionInObjects == 0) return pData; positionInObjects--; positionInBytes = index[positionInObjects]; pData = pData0 + positionInBytes; return pData; }
public void UnlockBitmap() { bitmap.UnlockBits(bitmapData); bitmapData = null; pBase = null; }
public void UnlockBitmap() { isLocked = false; if (bitmapData != null) { bitmap.UnlockBits(bitmapData); bitmapData = null; pBase = null; } }
private void UnlockBitmap() { if (_locked) { _subject.UnlockBits(_bitmapData); _bitmapData = null; _pBase = null; _locked = false; } }
/// <summary> /// Marks the current data pointer position as the beginning of an object and advances the data pointer by the specified number of bytes. /// </summary> /// <param name="numberOfBytes">The number of bytes by which to advance the pointer.</param> public void FinalizeObject(Int32 numberOfBytes) { Contract.EnsureRange(numberOfBytes > 0, nameof(numberOfBytes)); Contract.EnsureRange(positionInBytes + numberOfBytes <= CapacityInBytes, nameof(numberOfBytes)); Contract.Ensure(lengthInObjects + 1 <= CapacityInBytes, NucleusStrings.BufferLengthExceeded); if (positionInObjects < lengthInObjects && index[positionInObjects] != 0) throw new InvalidOperationException(NucleusStrings.UnsafeStreamWouldOverwriteObject); index[positionInObjects++] = positionInBytes; positionInBytes += numberOfBytes; if (hasAcquiredPointers) pData = pData0 + positionInBytes; lengthInObjects++; lengthInBytes += numberOfBytes; }
public Byte[] ReadLine() { this._Start = this._Current; //Find LineFeed char while (*this._Current != 10) { this._Current++; } if (this._Start == this._Current) { this._Current++; return _EmptyBytes; } this._Current++; return MimeParser.CreateNewBytes(new IntPtr(this._Start), this._Current - this._Start); }
private void LockBitmap() { if (!_locked) { GraphicsUnit unit = GraphicsUnit.Pixel; RectangleF boundsF = _subject.GetBounds(ref unit); Rectangle bounds = new Rectangle((int)boundsF.X, (int)boundsF.Y, (int)boundsF.Width, (int)boundsF.Height); _subjectHeight = bounds.Height; _subjectWidth = (int)boundsF.Width * sizeof(PixelData); if (_subjectWidth % 4 != 0) { _subjectWidth = 4 * (_subjectWidth / 4 + 1); } _bitmapData = _subject.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); _pBase = (Byte*)_bitmapData.Scan0.ToPointer(); _locked = true; } }
public void* RawSeekForward() { Contract.Ensure(hasAcquiredPointers, NucleusStrings.UnsafeStreamMustAcquirePointers); if (positionInObjects == lengthInObjects) return pData; positionInObjects++; positionInBytes = (positionInObjects == lengthInObjects) ? lengthInBytes : index[positionInObjects]; pData = pData0 + positionInBytes; return pData; }
public void UnlockImage(string saveto) { workingBitmap.UnlockBits(bitmapData); if (saveto != null) workingBitmap.Save(saveto); workingBitmap.Dispose(); workingBitmap = null; bitmapData = null; pBase = null; }
public void UnlockBitmap() { mBitmap.UnlockBits( BitmapData ); BitmapData = null; mPBase = null; }