public static unsafe PixelData* GetRowAddressUnchecked(this FastBitmap surf, PixelData* surfDataPtr, int surfWidth, int y) { PixelData* dstPtr = surfDataPtr; dstPtr += y * surfWidth; return dstPtr; }
// This isn't really an extension method, since it doesn't use // the passed in argument, but it's nice to have the same calling // convention as the uncached version. If you can use this one // over the other, it is much faster in tight loops (like effects). public static unsafe PixelData GetPointUnchecked(this FastBitmap surf, PixelData* surfDataPtr, int surfWidth, int x, int y) { PixelData* dstPtr = surfDataPtr; dstPtr += (x) + (y * surfWidth); return *dstPtr; }
public unsafe virtual void Apply(PixelData* ptr, int length) { unsafe { while (length > 0) { *ptr = Apply (*ptr); ++ptr; --length; } } }
public unsafe override void Apply(PixelData* dst, PixelData* src, int length) { unsafe { while (length > 0) { *dst = Apply (*src); ++dst; ++src; --length; } } }
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"); } }
/// <summary> /// Constructor used for deserialization /// </summary> /// <param name="info"></param> /// <param name="context"></param> public PlanarImage(SerializationInfo info, StreamingContext context) { Width = info.GetInt32("Width"); Height = info.GetInt32("Height"); BitsPerPixel = info.GetInt32("BitsPerPixel"); PixelType = (PixelAlignmentType)info.GetValue("PixelType", typeof(PixelAlignmentType)); PlaneSizes = (int[])info.GetValue("PlaneSizes", typeof(int[])); Pitches = (int[])info.GetValue("Pitches", typeof(int[])); Lines = (int[])info.GetValue("Lines", typeof(int[])); byte[] pixelData = (byte[])info.GetValue("PixelData", typeof(byte[])); NumberOfPlanes = info.GetInt32("NumberOfPlanes"); PixelData px = new PixelData(PlaneSizes, pixelData); Planes = px.Load(); }
public void SetPixel(int x, int y, PixelData colour) { PixelData* pixel = PixelAt(x, y); *pixel = colour; }
/// <summary> /// Used for serialization /// </summary> /// <param name="info"></param> /// <param name="context"></param> public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Width", Width); info.AddValue("Height", Height); info.AddValue("BitsPerPixel", BitsPerPixel); info.AddValue("PixelType", PixelType); info.AddValue("PlaneSizes", PlaneSizes); info.AddValue("Pitches", Pitches); info.AddValue("Lines", Lines); info.AddValue("NumberOfPlanes", NumberOfPlanes); PixelData px = new PixelData(this.PlaneSizes, this.Planes); info.AddValue("PixelData", px.Save()); }
////////////////////////////////////////////////// // Function to load a texture from file private bool LoadTexture(Stream fileStream, string path) { if (fileStream == null) { fileStream = File.OpenRead(path); } ////////////////////////////////////////////////// // Reset frontend label2.Text = "Name: -"; label3.Text = "Resolution: -"; label4.Text = "Pixel count: -"; textFileInput.Text = ""; textBox1.Text = ""; textBox2.Text = ""; preview.Width = 0; preview.Height = 0; preview.Image = null; buttonScan.Enabled = true; buttonEdit.Enabled = true; button2x.Enabled = true; buttonSaveTexture.Enabled = true; buttonExportDDS.Enabled = true; _path = path; FileInfo fi = new FileInfo(_path); _fileSize = (int)fi.Length; _fileName = fi.Name; _fileBytes = new byte[fi.Length]; fileStream.Read(_fileBytes, 0, _fileSize); fileStream.Close(); ////////////////////////////////////////////////// // Parse ST texture files if (_fileBytes[0] == 'S' && _fileBytes[1] == 'T') { _textureName = ""; for (int i = 0x40; _fileBytes[i] != 0; i++) { _textureName += (char)_fileBytes[i]; } label2.Text = "Name: " + _textureName; string type = _textureName.Split('_')[0]; // Get the texture type from the file name switch (type) { case "AM": label5.Text = "Type: Mural"; break; case "AT": label5.Text = "Type: Throw-up"; break; case "AW": label5.Text = "Type: Wildstyle"; break; case "CA": label5.Text = "Type: Roll-up"; break; case "CR": label5.Text = "Type: Roll-up"; break; case "CW": label5.Text = "Type: Roll-up"; break; case "FF": label5.Text = "Type: Freeform"; break; case "RU": label5.Text = "Type: Roll-up"; break; case "WP": label5.Text = "Type: Wheat paste"; break; default: label5.Text = "Type: ?"; break; } _width = _fileBytes[0xC] | _fileBytes[0xD] << 8 | _fileBytes[0xE] << 16 | _fileBytes[0xF] << 24; _height = _fileBytes[0x10] | _fileBytes[0x11] << 8 | _fileBytes[0x12] << 16 | _fileBytes[0x13] << 24; Text = _fileBytes[0x36].ToString("X2"); _pixels = new PixelData[(_fileSize - 0x184) / 16]; string tmpString = ""; int p = 0; for (int i = 0x184; i < _fileSize; i += 16) { _pixels[p++] = new PixelData(_fileBytes, i); if (checkLog.Checked) { for (int n = 0; n < 16; n++) { tmpString += _fileBytes[i + n].ToString("X2") + " "; } tmpString += Environment.NewLine; } } p = p * 16; label4.Text = "Pixel count: " + p; label3.Text = "Dimensions: " + _width + "x" + _height; UpdatePreviews(); textBox1.Text = tmpString; } else if (_fileBytes[0] == 'B' && _fileBytes[1] == 'I' && _fileBytes[2] == 'R') { ////////////////////////////////////////////////// // BIR parser MessageBox.Show("No BIR support yet!"); return false; } else { ////////////////////////////////////////////////// // Other file extension } return true; }
public void SetPixel(int x, int y, PixelData colour) { PixelData *pixel = PixelAt(x, y); *pixel = colour; }
////////////////////////////////////////////////// // Import texture from file private void buttonImport_Click(object sender, EventArgs e) { ofd.Filter = "DDS files|*.dds";//|PNG files|*.png|All files|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { try { switch (Path.GetExtension(ofd.FileName).ToLower()) { case ".dds": using (Stream fileStream = ofd.OpenFile()) { FileInfo fi = new FileInfo(ofd.FileName); int fileSize = (int) fi.Length; byte[] fileBytes = new byte[fi.Length]; fileStream.Read(fileBytes, 0, fileSize); fileStream.Close(); _pixels = new PixelData[(fileSize - 0x80)/16]; int p = 0; for (int i = 0x80; i < fileSize; i += 16) { _pixels[p++] = new PixelData(fileBytes, i); } UpdatePreviews(); } break; case ".png": // @TODO: PNG to DDS (DXT) conversion Bitmap bmp = new Bitmap(ofd.FileName); bmp.Save("temp.bmp", ImageFormat.Bmp); /* using (MemoryStream stream = new MemoryStream()) { bmp.Save(stream, ImageFormat.Bmp); } */ break; case ".bmp": // @TODO: BMP to DDS (DXT) conversion // Bitmap bmp = new Bitmap(ofd.FileName); break; default: MessageBox.Show("Unknown file format " + Path.GetExtension(ofd.FileName)); break; } } catch (ArgumentException ex) { MessageBox.Show("Error: Could not read file from disk." + Environment.NewLine + "Exception: " + ex.Message); } } }
public static int ColorDifferenceSquared(PixelData a, PixelData b) { int diffSq = 0, tmp; tmp = a.R - b.R; diffSq += tmp * tmp; tmp = a.G - b.G; diffSq += tmp * tmp; tmp = a.B - b.B; diffSq += tmp * tmp; return diffSq / 3; }
public void SetPixel(int x, int y, PixelData color) { var data = (PixelData*)(_pBase + y * _width + x * sizeof(PixelData)); *data = color; }
public void UseTool(int X, int Y, PixelData Canvas, ref Color CurrentColor) { Canvas[X, Y] = CurrentColor; }
public virtual void Apply(PixelData* dst, PixelData* src, int length) { throw new System.NotImplementedException ("Derived class must implement Apply(PixelData*,PixelData*,int)"); }
public abstract PixelData Apply(PixelData color);
public static PixelData FromBgra(byte b, byte g, byte r, byte a) { PixelData d = new PixelData (); d.B = b; d.G = g; d.R = r; return d; }
public static PixelData FromUInt32(uint value) { PixelData d = new PixelData (); d.Bgra = value; return d; }
public static int ColorDifference(PixelData a, PixelData b) { return (int)Math.Ceiling (Math.Sqrt (ColorDifferenceSquared (a, b))); }
protected virtual PixelData RenderPixel(PixelData color) { return color; }
public void CopyFrom(int x, int y, PixelData* other) { pixelData = (PixelData*)(pBase + y * width + x * sizeof(PixelData)); *pixelData = *other; }
protected unsafe virtual void RenderLine(PixelData* src, PixelData* dst, int length) { while (length > 0) { *dst = RenderPixel (*src); ++dst; ++src; --length; } }
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 PixelData GetPixel(int x, int y) { PixelData returnValue = *PixelAt(x, y); return(returnValue); }