public virtual Graphics.PixelMap GetPixmap() { if (_ymap == null) { return null; } int w = _ymap.Iw; int h = _ymap.Ih; int pixsep = 3; int rowsep = w * pixsep; sbyte[] bytes = new sbyte[h * rowsep]; _ymap.Image(0, bytes, rowsep, pixsep, false); if ((_crmap != null) && (_cbmap != null) && (_crcbDelay >= 0)) { _cbmap.Image(1, bytes, rowsep, pixsep, _crcbHalf); _crmap.Image(2, bytes, rowsep, pixsep, _crcbHalf); } // Convert image to RGB Graphics.PixelMap ppm = new Graphics.PixelMap().Init(bytes, h, w); PixelReference pixel = ppm.CreateGPixelReference(0); for (int i = 0; i < h; ) { pixel.SetOffset(i++, 0); if ((_crmap != null) && (_cbmap != null) && (_crcbDelay >= 0)) { pixel.YCC_to_RGB(w); } else { for (int x = w; x-- > 0; pixel.IncOffset()) { pixel.SetGray((sbyte)(127 - pixel.Blue)); } } } return ppm; }
public virtual Graphics.PixelMap GetPixmap(int subsample, Rectangle rect, Graphics.PixelMap retval) { if (_ymap == null) { return null; } if (retval == null) { retval = new Graphics.PixelMap(); } int w = rect.Width; int h = rect.Height; int pixsep = 3; int rowsep = w * pixsep; sbyte[] bytes = retval.Init(h, w, null).Data; _ymap.Image(subsample, rect, 0, bytes, rowsep, pixsep, false); if ((_crmap != null) && (_cbmap != null) && (_crcbDelay >= 0)) { _cbmap.Image(subsample, rect, 1, bytes, rowsep, pixsep, _crcbHalf); _crmap.Image(subsample, rect, 2, bytes, rowsep, pixsep, _crcbHalf); } PixelReference pixel = retval.CreateGPixelReference(0); for (int i = 0; i < h; ) { pixel.SetOffset(i++, 0); if ((_crmap != null) && (_cbmap != null) && (_crcbDelay >= 0)) { pixel.YCC_to_RGB(w); } else { for (int x = w; x-- > 0; pixel.IncOffset()) { pixel.SetGray((sbyte)(127 - pixel.Blue)); } } } return retval; }
/// <summary> /// Ok button clicked. /// </summary> private void tsb_Ok_Click(object sender, EventArgs e) { // Set dialog result and close. DialogResult = DialogResult.OK; // Create new pixel map. Graphics.PixelMap image = new Graphics.PixelMap(pnl_Image.Image); if (_room.Columns != (int)nud_Columns.Value || _room.Name != tb_Name.Text || _room.Rows != (int)nud_Rows.Value || _room.TileWidth != (int)nud_TileX.Value || _room.TileHeight != (int)nud_TileY.Value || _room.OffsetX != (int)nud_OffsetX.Value || _room.OffsetY != (int)nud_OffsetY.Value || _room.SeparationX != (int)nud_SeperationX.Value || _room.SeparationY != (int)nud_SeperationY.Value ) _changed = true; // Check background data change. if (_room.Background != null) { if (_room.Background.UseKey != tsb_SetColorKey.Checked || _room.Background.ColorKey.ToArgb() != pnl_Image.ColorKey.ToArgb() || Graphics.PixelMap.Same(_room.Background, image) == false) _changed = true; } // Set room data. _room.Columns = (int)nud_Columns.Value; _room.Name = tb_Name.Text; _room.Rows = (int)nud_Rows.Value; _room.TileWidth = (int)nud_TileX.Value; _room.TileHeight = (int)nud_TileY.Value; _room.OffsetX = (int)nud_OffsetX.Value; _room.OffsetY = (int)nud_OffsetY.Value; _room.SeparationX = (int)nud_SeperationX.Value; _room.SeparationY = (int)nud_SeperationY.Value; _room.Background = image; _room.Background.UseKey = tsb_SetColorKey.Checked; _room.Background.ColorKey = pnl_Image.ColorKey; // If the room has no layers, add one. if (_room.Layers.Count == 0) _room.Layers.Add(new GMareLayer("Layer", 0, GMareLayer.GetEmptyLayer(_room.Columns, _room.Rows))); // Close form. Close(); }