/// <summary> /// Determine how many bytes will be necessary to render the specified region in page units at the specified zoom level, using the the specified pixel format. /// </summary> /// <param name="region">The region that will be rendered.</param> /// <param name="zoom">The scale at which the region will be rendered. This will determine the size in pixel of the image.</param> /// <param name="pixelFormat">The format of the pixels data.</param> /// <returns>An integer representing the number of bytes that will be necessary to store the pixel data of the rendered image.</returns> public static int GetRenderedSize(Rectangle region, double zoom, PixelFormats pixelFormat) { float x0 = region.X0 * (float)zoom; float y0 = region.Y0 * (float)zoom; float x1 = region.X1 * (float)zoom; float y1 = region.Y1 * (float)zoom; Rectangle scaledRect = new Rectangle(x0, y0, x1, y1); RoundedRectangle bounds = scaledRect.Round(); int width = bounds.Width; int height = bounds.Height; switch (pixelFormat) { case PixelFormats.RGB: case PixelFormats.BGR: return(width * height * 3); case PixelFormats.RGBA: case PixelFormats.BGRA: return(width * height * 4); } return(-1); }
public static bool IsCompressedFormat(PixelFormats format) { switch (format) { case PixelFormats.BC1_TYPELESS: case PixelFormats.BC1_UNORM: case PixelFormats.BC1_UNORM_SRGB: case PixelFormats.BC2_TYPELESS: case PixelFormats.BC2_UNORM: case PixelFormats.BC2_UNORM_SRGB: case PixelFormats.BC3_TYPELESS: case PixelFormats.BC3_UNORM: case PixelFormats.BC3_UNORM_SRGB: case PixelFormats.BC4_TYPELESS: case PixelFormats.BC4_UNORM: case PixelFormats.BC4_SNORM: case PixelFormats.BC5_TYPELESS: case PixelFormats.BC5_UNORM: case PixelFormats.BC5_SNORM: case PixelFormats.BC6H_TYPELESS: case PixelFormats.BC6H_UF16: case PixelFormats.BC6H_SF16: case PixelFormats.BC7_TYPELESS: case PixelFormats.BC7_UNORM: case PixelFormats.BC7_UNORM_SRGB: return(true); default: return(false); } }
public rounded_rect_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_idx = (-1); m_radius = new AGG.UI.SliderWidget <T>(10, 10, 600 - 10, 19); m_gamma = new AGG.UI.SliderWidget <T>(10, 10 + 20, 600 - 10, 19 + 20); m_offset = new AGG.UI.SliderWidget <T>(10, 10 + 40, 600 - 10, 19 + 40); m_white_on_black = new cbox_ctrl <T>(10, 10 + 60, "White on black"); m_DrawAsOutlineCheckBox = new cbox_ctrl <T>(10 + 180, 10 + 60, "Fill Rounded Rect"); m_x[0] = M.New <T>(100); m_y[0] = M.New <T>(100); m_x[1] = M.New <T>(500); m_y[1] = M.New <T>(350); AddChild(m_radius); AddChild(m_gamma); AddChild(m_offset); AddChild(m_white_on_black); AddChild(m_DrawAsOutlineCheckBox); m_gamma.label("gamma={0:F3}"); m_gamma.range(0.0, 3.0); m_gamma.value(1.8); m_radius.label("radius={0:F3}"); m_radius.range(0.0, 50.0); m_radius.value(25.0); m_offset.label("subpixel offset={0:F3}"); m_offset.range(-2.0, 3.0); m_white_on_black.text_color(new RGBA_Bytes(127, 127, 127)); m_white_on_black.inactive_color(new RGBA_Bytes(127, 127, 127)); m_DrawAsOutlineCheckBox.text_color(new RGBA_Doubles(.5, .5, .5)); m_DrawAsOutlineCheckBox.inactive_color(new RGBA_Bytes(127, 127, 127)); }
image_resample_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_gamma_lut = new GammaLut(2.0); m_quad = new AGG.UI.polygon_ctrl <T>(4, 5.0); m_trans_type = new AGG.UI.rbox_ctrl <T>(400, 5.0, 430 + 170.0, 100.0); m_gamma = new AGG.UI.SliderWidget <T>(5.0, 5.0 + 15 * 0, 400 - 5, 10.0 + 15 * 0); m_blur = new AGG.UI.SliderWidget <T>(5.0, 5.0 + 15 * 1, 400 - 5, 10.0 + 15 * 1); m_old_gamma = M.New <T>(2); g_rasterizer = new RasterizerScanlineAA <T>(); g_scanline = new ScanlineUnpacked8(); m_trans_type.text_size(7); m_trans_type.add_item("Affine No Resample"); m_trans_type.add_item("Affine Resample"); m_trans_type.add_item("Perspective No Resample LERP"); m_trans_type.add_item("Perspective No Resample Exact"); m_trans_type.add_item("Perspective Resample LERP"); m_trans_type.add_item("Perspective Resample Exact"); m_trans_type.cur_item(4); AddChild(m_trans_type); m_gamma.range(0.5, 3.0); m_gamma.value(2.0); m_gamma.label("Gamma={0:F3}"); AddChild(m_gamma); m_blur.range(0.5, 5.0); m_blur.value(1.0); m_blur.label("Blur={0:F3}"); AddChild(m_blur); }
/// <summary> /// Write (part of) a page to an image stream in the specified format. /// </summary> /// <param name="pageNumber">The number of the page to render (starting at 0).</param> /// <param name="region">The region of the page to render in page units.</param> /// <param name="zoom">The scale at which the page will be rendered. This will determine the size in pixel of the image.</param> /// <param name="pixelFormat">The format of the pixel data.</param> /// <param name="outputStream">The stream to which the image data will be written.</param> /// <param name="fileType">The output format of the image.</param> /// <param name="includeAnnotations">If this is <see langword="true" />, annotations (e.g. signatures) are included in the display list that is generated. Otherwise, only the page contents are included.</param> public void WriteImage(int pageNumber, Rectangle region, double zoom, PixelFormats pixelFormat, Stream outputStream, RasterOutputFileTypes fileType, bool includeAnnotations = true) { if (pixelFormat == PixelFormats.RGBA && fileType == RasterOutputFileTypes.PNM) { throw new ArgumentException("Cannot save an image with alpha channel in PNM format!", nameof(fileType)); } if (DisplayLists[pageNumber] == null) { DisplayLists[pageNumber] = new MuPDFDisplayList(this.OwnerContext, this.Pages[pageNumber], includeAnnotations); } if (zoom < 0.000001 | zoom * region.Width <= 0.001 || zoom * region.Height <= 0.001) { throw new ArgumentOutOfRangeException(nameof(zoom), zoom, "The zoom factor is too small!"); } if (this.ImageXRes != 72 || this.ImageYRes != 72) { zoom *= Math.Sqrt(this.ImageXRes * this.ImageYRes) / 72; region = new Rectangle(region.X0 * 72 / this.ImageXRes, region.Y0 * 72 / this.ImageYRes, region.X1 * 72 / this.ImageXRes, region.Y1 * 72 / this.ImageYRes); } float fzoom = (float)zoom; IntPtr outputBuffer = IntPtr.Zero; IntPtr outputData = IntPtr.Zero; ulong outputDataLength = 0; ExitCodes result = (ExitCodes)NativeMethods.WriteImage(OwnerContext.NativeContext, DisplayLists[pageNumber].NativeDisplayList, region.X0, region.Y0, region.X1, region.Y1, fzoom, (int)pixelFormat, (int)fileType, ref outputBuffer, ref outputData, ref outputDataLength); switch (result) { case ExitCodes.EXIT_SUCCESS: break; case ExitCodes.ERR_CANNOT_RENDER: throw new MuPDFException("Cannot render page", result); case ExitCodes.ERR_CANNOT_CREATE_CONTEXT: throw new MuPDFException("Cannot create the output buffer", result); default: throw new MuPDFException("Unknown error", result); } byte[] buffer = new byte[1024]; while (outputDataLength > 0) { int bytesToCopy = (int)Math.Min(buffer.Length, (long)outputDataLength); Marshal.Copy(outputData, buffer, 0, bytesToCopy); outputData = IntPtr.Add(outputData, bytesToCopy); outputStream.Write(buffer, 0, bytesToCopy); outputDataLength -= (ulong)bytesToCopy; } NativeMethods.DisposeBuffer(OwnerContext.NativeContext, outputBuffer); }
public GamePlatform(double SecondsPerUpdate, int MaxUpdatesPerDraw, PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_ShowFrameRate = true; m_SecondsPerUpdate = SecondsPerUpdate; m_MaxUpdatesPerDraw = MaxUpdatesPerDraw; wait_mode(false); AudioSystem <T> .Startup(); }
// Format - see enum e {}; // FlipY - true if you want to have the Y-axis flipped vertically. public PlatformSupportAbstract(PixelFormats format, PlatformSupportAbstract.ERenderOrigin RenderOrigin) { m_format = format; m_bpp = GetBitDepthForPixelFormat(format); m_RenderOrigin = RenderOrigin; m_initial_width = 10; m_initial_height = 10; m_resize_mtx = Affine.NewIdentity(); m_rbuf_img = new List <RasterBuffer>(); }
public lion_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_AlphaSlider = new UI.SliderWidget <T>(M.New <T>(5), M.New <T>(5), M.New <T>(512 - 5), M.New <T>(12)); parse_lion(); AddChild(m_AlphaSlider); m_AlphaSlider.SetTransform(MatrixFactory <T> .NewIdentity(VectorDimension.Two)); m_AlphaSlider.label("Alpha {0:F3}"); m_AlphaSlider.value(M.New <T>(0.1)); }
// format - see enum pix_format_e {}; // flip_y - true if you want to have the Y-axis flipped vertically. public PlatformSupportAbstract(PixelFormats format, ERenderOrigin RenderOrigin) { m_format = format; m_bpp = GetBitDepthForPixelFormat(format); m_RenderOrigin = RenderOrigin; m_initial_width = 10; m_initial_height = 10; m_resize_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); m_rbuf_img = new List <RasterBuffer>(); }
public component_rendering_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_alpha = new AGG.UI.SliderWidget <T>(5, 5, 320 - 5, 10 + 5); m_UseBlackBackground = new UI.cbox_ctrl <T>(5, 5 + 18, "Draw Black Background"); m_alpha.label("Alpha={0:F0}"); m_alpha.range(0, 255); m_alpha.value(255); AddChild(m_alpha); AddChild(m_UseBlackBackground); m_UseBlackBackground.text_color(new RGBA_Bytes(127, 127, 127)); }
/// <summary> /// Equality comparision /// </summary> public override bool Equals(object obj) { bool result = false; if (obj is PixelFormats) { PixelFormats dst = (PixelFormats)obj; result = (dst.AlphaOffset == AlphaOffset) && (dst.BlueOffset == BlueOffset) && (dst.GreenOffset == GreenOffset) && (dst.RedOffset == RedOffset); } return(result); }
line_patterns_application(PixelFormats format, AGG.UI.PlatformSupportAbstract.ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_ctrl_color = new RGBA_Bytes(0, 0.3, 0.5, 0.3); m_scale_x = new SliderWidget(5.0, 5.0, 240.0, 12.0); m_start_x = new SliderWidget(250.0, 5.0, 495.0, 12.0); m_approximation_method = new cbox_ctrl(10, 30, "Approximation Method = curve_div"); m_curve1.line_color(m_ctrl_color); m_curve2.line_color(m_ctrl_color); m_curve3.line_color(m_ctrl_color); m_curve4.line_color(m_ctrl_color); m_curve5.line_color(m_ctrl_color); m_curve6.line_color(m_ctrl_color); m_curve7.line_color(m_ctrl_color); m_curve8.line_color(m_ctrl_color); m_curve9.line_color(m_ctrl_color); m_curve1.curve(64, 19, 14, 126, 118, 266, 19, 265); m_curve2.curve(112, 113, 178, 32, 200, 132, 125, 438); m_curve3.curve(401, 24, 326, 149, 285, 11, 177, 77); m_curve4.curve(188, 427, 129, 295, 19, 283, 25, 410); m_curve5.curve(451, 346, 302, 218, 265, 441, 459, 400); m_curve6.curve(454, 198, 14, 13, 220, 291, 483, 283); m_curve7.curve(301, 398, 355, 231, 209, 211, 170, 353); m_curve8.curve(484, 101, 222, 33, 486, 435, 487, 138); m_curve9.curve(143, 147, 11, 45, 83, 427, 132, 197); AddChild(m_curve1); AddChild(m_curve2); AddChild(m_curve3); AddChild(m_curve4); AddChild(m_curve5); AddChild(m_curve6); AddChild(m_curve7); AddChild(m_curve8); AddChild(m_curve9); AddChild(m_approximation_method); m_scale_x.label("Scale X=%.2f"); m_scale_x.range(0.2, 3.0); m_scale_x.value(1.0); AddChild(m_scale_x); m_start_x.label("Start X=%.2f"); m_start_x.range(0.0, 10.0); m_start_x.value(0.0); AddChild(m_start_x); }
image1_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_angle = new AGG.UI.SliderWidget <T>(5, 5, 300, 12); m_scale = new AGG.UI.SliderWidget <T>(5, 5 + 15, 300, 12 + 15); AddChild(m_angle); AddChild(m_scale); m_angle.label("Angle={0:F2}"); m_scale.label("Scale={0:F2}"); m_angle.range(-180.0, 180.0); m_angle.value(0.0); m_scale.range(0.1, 5.0); m_scale.value(1.0); }
public lion_outline_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_width_slider = new AGG.UI.SliderWidget <T>(5, 5, 150, 12); m_scanline = new AGG.UI.cbox_ctrl <T>(160, 5, "Use Scanline Rasterizer"); m_scanline.status(true); parse_lion(); AddChild(m_width_slider); m_width_slider.SetTransform(MatrixFactory <T> .NewIdentity(VectorDimension.Two)); m_width_slider.range(0.0, 4.0); m_width_slider.value(1.0); m_width_slider.label("Width {0:F2}"); AddChild(m_scanline); m_scanline.SetTransform(MatrixFactory <T> .NewIdentity(VectorDimension.Two)); }
//------------------------------------------------------------------------ public PlatformSupport(PixelFormats format, PlatformSupportAbstract.ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_specific = new PlatformSpecificWindow(this, format, RenderOrigin); m_format = format; //m_bpp(m_specific->m_bpp), //m_window_flags(0), m_wait_mode = true; m_RenderOrigin = RenderOrigin; m_initial_width = 10; m_initial_height = 10; Caption = "Anti-Grain Geometry Application"; Focus(); }
public static uint GetBitDepthForPixelFormat(PixelFormats pixelFormat) { switch (pixelFormat) { case PixelFormats.Bgr24: case PixelFormats.Rgb24: return(24); case PixelFormats.Bgra32: case PixelFormats.Rgba32: return(32); default: throw new System.NotImplementedException(); } }
/// <summary> /// Render (part of) a page to the specified destination. /// </summary> /// <param name="pageNumber">The number of the page to render (starting at 0).</param> /// <param name="region">The region of the page to render in page units.</param> /// <param name="zoom">The scale at which the page will be rendered. This will determine the size in pixel of the image.</param> /// <param name="pixelFormat">The format of the pixel data.</param> /// <param name="destination">The address of the buffer where the pixel data will be written. There must be enough space available to write the values for all the pixels, otherwise this will fail catastrophically!</param> /// <param name="includeAnnotations">If this is <see langword="true" />, annotations (e.g. signatures) are included in the display list that is generated. Otherwise, only the page contents are included.</param> public void Render(int pageNumber, Rectangle region, double zoom, PixelFormats pixelFormat, IntPtr destination, bool includeAnnotations = true) { if (DisplayLists[pageNumber] == null) { DisplayLists[pageNumber] = new MuPDFDisplayList(this.OwnerContext, this.Pages[pageNumber], includeAnnotations); } if (zoom < 0.000001 | zoom * region.Width <= 0.001 || zoom * region.Height <= 0.001) { throw new ArgumentOutOfRangeException(nameof(zoom), zoom, "The zoom factor is too small!"); } if (this.ImageXRes != 72 || this.ImageYRes != 72) { zoom *= Math.Sqrt(this.ImageXRes * this.ImageYRes) / 72; region = new Rectangle(region.X0 * 72 / this.ImageXRes, region.Y0 * 72 / this.ImageYRes, region.X1 * 72 / this.ImageXRes, region.Y1 * 72 / this.ImageYRes); } float fzoom = (float)zoom; ExitCodes result = (ExitCodes)NativeMethods.RenderSubDisplayList(OwnerContext.NativeContext, DisplayLists[pageNumber].NativeDisplayList, region.X0, region.Y0, region.X1, region.Y1, fzoom, (int)pixelFormat, destination, IntPtr.Zero); switch (result) { case ExitCodes.EXIT_SUCCESS: break; case ExitCodes.ERR_CANNOT_RENDER: throw new MuPDFException("Cannot render page", result); default: throw new MuPDFException("Unknown error", result); } RoundedRectangle roundedRegion = region.Round(fzoom); RoundedSize roundedSize = new RoundedSize(roundedRegion.Width, roundedRegion.Height); if (pixelFormat == PixelFormats.RGBA || pixelFormat == PixelFormats.BGRA) { Utils.UnpremultiplyAlpha(destination, roundedSize); } if (this.ClipToPageBounds && !Pages[pageNumber].Bounds.Contains(DisplayLists[pageNumber].Bounds.Intersect(region))) { Utils.ClipImage(destination, roundedSize, region, Pages[pageNumber].Bounds, pixelFormat); } }
public alpha_mask2_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_alpha_mask_rbuf = new RasterBuffer(); #if USE_CLIPPING_ALPHA_MASK m_alpha_mask = new AlphaMaskByteClipped(m_alpha_mask_rbuf, 1, 0); #else m_alpha_mask = new AlphaMaskByteUnclipped(m_alpha_mask_rbuf, 1, 0); #endif m_num_cb = new UI.SliderWidget <T>(5, 5, 150, 12); m_slider_value = M.Zero <T>(); parse_lion(); AddChild(m_num_cb); m_num_cb.range(5, 100); m_num_cb.value(10); m_num_cb.label("N={0:F3}"); m_num_cb.SetTransform(MatrixFactory <T> .NewIdentity(VectorDimension.Two)); }
/// <summary> /// Save (part of) a page to an image file in the specified format. /// </summary> /// <param name="pageNumber">The number of the page to render (starting at 0).</param> /// <param name="region">The region of the page to render in page units.</param> /// <param name="zoom">The scale at which the page will be rendered. This will determine the size in pixel of the image.</param> /// <param name="pixelFormat">The format of the pixel data.</param> /// <param name="fileName">The path to the output file.</param> /// <param name="fileType">The output format of the file.</param> /// <param name="includeAnnotations">If this is <see langword="true" />, annotations (e.g. signatures) are included in the display list that is generated. Otherwise, only the page contents are included.</param> public void SaveImage(int pageNumber, Rectangle region, double zoom, PixelFormats pixelFormat, string fileName, RasterOutputFileTypes fileType, bool includeAnnotations = true) { if (pixelFormat == PixelFormats.RGBA && fileType == RasterOutputFileTypes.PNM) { throw new ArgumentException("Cannot save an image with alpha channel in PNM format!", nameof(fileType)); } if (DisplayLists[pageNumber] == null) { DisplayLists[pageNumber] = new MuPDFDisplayList(this.OwnerContext, this.Pages[pageNumber], includeAnnotations); } if (zoom < 0.000001 | zoom * region.Width <= 0.001 || zoom * region.Height <= 0.001) { throw new ArgumentOutOfRangeException(nameof(zoom), zoom, "The zoom factor is too small!"); } if (this.ImageXRes != 72 || this.ImageYRes != 72) { zoom *= Math.Sqrt(this.ImageXRes * this.ImageYRes) / 72; region = new Rectangle(region.X0 * 72 / this.ImageXRes, region.Y0 * 72 / this.ImageYRes, region.X1 * 72 / this.ImageXRes, region.Y1 * 72 / this.ImageYRes); } float fzoom = (float)zoom; ExitCodes result = (ExitCodes)NativeMethods.SaveImage(OwnerContext.NativeContext, DisplayLists[pageNumber].NativeDisplayList, region.X0, region.Y0, region.X1, region.Y1, fzoom, (int)pixelFormat, fileName, (int)fileType); switch (result) { case ExitCodes.EXIT_SUCCESS: break; case ExitCodes.ERR_CANNOT_RENDER: throw new MuPDFException("Cannot render page", result); case ExitCodes.ERR_CANNOT_SAVE: throw new MuPDFException("Cannot save to the output file", result); default: throw new MuPDFException("Unknown error", result); } }
/// <summary> /// Creates a new <see cref="RasterImage"/> instance copying the specified pixel data. /// </summary> /// <param name="data">The image pixel data that will be copied.</param> /// <param name="width">The width in pixels of the image.</param> /// <param name="height">The height in pixels of the image.</param> /// <param name="pixelFormat">The format of the pixel data.</param> /// <param name="interpolate">Whether the image should be interpolated when it is resized.</param> public RasterImage(byte[] data, int width, int height, PixelFormats pixelFormat, bool interpolate) { this.ImageDataAddress = Marshal.AllocHGlobal(data.Length); GC.AddMemoryPressure(data.Length); this.DataHolder = new DisposableIntPtr(this.ImageDataAddress); this.Id = Guid.NewGuid().ToString(); this.Width = width; this.Height = height; this.Interpolate = interpolate; switch (pixelFormat) { case PixelFormats.RGB: case PixelFormats.RGBA: Marshal.Copy(data, 0, this.ImageDataAddress, data.Length); this.HasAlpha = pixelFormat == PixelFormats.RGBA; break; case PixelFormats.BGRA: case PixelFormats.BGR: this.HasAlpha = pixelFormat == PixelFormats.BGRA; int pixelSize = pixelFormat == PixelFormats.BGRA ? 4 : 3; int pixelCount = width * height; unsafe { byte *dataPointer = (byte *)this.ImageDataAddress; for (int i = 0; i < pixelCount; i++) { dataPointer[i * pixelSize] = data[i * pixelSize + 2]; dataPointer[i * pixelSize + 1] = data[i * pixelSize + 1]; dataPointer[i * pixelSize + 2] = data[i * pixelSize]; if (pixelSize == 4) { dataPointer[i * pixelSize + 3] = data[i * pixelSize + 3]; } } } break; } }
/// <summary> /// Render (part of) a page to an array of bytes. /// </summary> /// <param name="pageNumber">The number of the page to render (starting at 0).</param> /// <param name="region">The region of the page to render in page units.</param> /// <param name="zoom">The scale at which the page will be rendered. This will determine the size in pixel of the image.</param> /// <param name="pixelFormat">The format of the pixel data.</param> /// <param name="includeAnnotations">If this is <see langword="true" />, annotations (e.g. signatures) are included in the display list that is generated. Otherwise, only the page contents are included.</param> /// <returns>A byte array containing the raw values for the pixels of the rendered image.</returns> public byte[] Render(int pageNumber, Rectangle region, double zoom, PixelFormats pixelFormat, bool includeAnnotations = true) { int bufferSize = MuPDFDocument.GetRenderedSize(region, zoom, pixelFormat); byte[] buffer = new byte[bufferSize]; GCHandle bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr bufferPointer = bufferHandle.AddrOfPinnedObject(); try { Render(pageNumber, region, zoom, pixelFormat, bufferPointer, includeAnnotations); } finally { bufferHandle.Free(); } return(buffer); }
//typedef agg.renderer_base<pixfmt> renderer_base; //typedef agg.renderer_scanline_aa_solid<renderer_base> renderer_solid; public perspective_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { parse_lion(); m_quad = new AGG.UI.polygon_ctrl <T>(4, 5.0); m_trans_type = new AGG.UI.rbox_ctrl <T>(420, 5.0, 420 + 130.0, 55.0); m_quad.SetXN(0, g_x1); m_quad.SetYN(0, g_y1); m_quad.SetXN(1, g_x2); m_quad.SetYN(1, g_y1); m_quad.SetXN(2, g_x2); m_quad.SetYN(2, g_y2); m_quad.SetXN(3, g_x1); m_quad.SetYN(3, g_y2); m_trans_type.add_item("Bilinear"); m_trans_type.add_item("Perspective"); m_trans_type.cur_item(0); AddChild(m_trans_type); }
public EmulatorDemo(PixelFormats format, Pictor.UI.PlatformSupportAbstract.ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_idx = (-1); background = new Pictor.RGBA_Bytes(127, 127, 127); m_x[0] = 100; m_y[0] = 100; m_x[1] = 500; m_y[1] = 350; button = Pictor.UI.UIManager.CreateButton(8.0, 130.0, "Quit", 8, 1, 1, 3); button.ButtonClick += Quit; AddChild(button); white = Pictor.UI.UIManager.CreateButton(8.0, 110.0, "Gray", 8, 1, 1, 3); blue = Pictor.UI.UIManager.CreateButton(8.0, 90.0, "Blue", 8, 1, 1, 3); reset = Pictor.UI.UIManager.CreateButton(8.0, 70.0, "Reset", 8, 1, 1, 3); border = new Pictor.UI.CheckBoxWidget(8.0, 50.0, "Draw as outline"); alpha = new Pictor.UI.SliderWidget(10, 10, 590, 19); radius = new Pictor.UI.SliderWidget(10, 30, 590, 39); alpha.Range(0, 255); alpha.Value(255); //alpha.BackgroundColor(new Pictor.RGBA_Doubles(255, 255, 255)); radius.Label("Radius = {0:F3}"); radius.Range(0.0, 50.0); radius.Value(25.0); border.Status(false); white.ButtonClick += White; blue.ButtonClick += Blue; reset.ButtonClick += Reset; AddChild(white); AddChild(blue); AddChild(reset); AddChild(border); AddChild(alpha); AddChild(radius); }
gouraud_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_idx = (-1); m_dilation = new AGG.UI.SliderWidget <T>(5, 5, 400 - 5, 11); m_gamma = new AGG.UI.SliderWidget <T>(5, 5 + 15, 400 - 5, 11 + 15); m_alpha = new AGG.UI.SliderWidget <T>(5, 5 + 30, 400 - 5, 11 + 30); m_x[0] = M.New <T>(57); m_y[0] = M.New <T>(60); m_x[1] = M.New <T>(369); m_y[1] = M.New <T>(170); m_x[2] = M.New <T>(143); m_y[2] = M.New <T>(310); AddChild(m_dilation); AddChild(m_gamma); AddChild(m_alpha); m_dilation.label("Dilation={0:F2}"); m_gamma.label("Linear gamma={0:F2}"); m_alpha.label("Opacity={0:F2}"); m_dilation.value(0.175); m_gamma.value(0.809); m_alpha.value(1.0); }
public void GetSpecifications(out int screenWidth, out int screenHeight, out int refreshRate, out PixelFormats pixelFormat) { screenWidth = 256; screenHeight = 192; refreshRate = 60; pixelFormat = PixelFormats.Bgr565; }
public static uint GetBitDepthForPixelFormat(PixelFormats pixelFormat) { switch (pixelFormat) { case PixelFormats.Bgr24: case PixelFormats.Rgb24: return 24; case PixelFormats.Bgra32: case PixelFormats.Rgba32: return 32; default: throw new System.NotImplementedException(); } }
// Format - see enum e {}; // FlipY - true if you want to have the Y-axis flipped vertically. public PlatformSupportAbstract(PixelFormats format, PlatformSupportAbstract.ERenderOrigin RenderOrigin) { m_format = format; m_bpp = GetBitDepthForPixelFormat(format); m_RenderOrigin = RenderOrigin; m_initial_width = 10; m_initial_height = 10; m_resize_mtx = Affine.NewIdentity(); m_rbuf_img = new List<RasterBuffer>(); }
/// <summary> /// Initializes a new instance of the <see cref="LegacyMap" /> struct. /// </summary> /// <param name="format">The format.</param> /// <param name="conversionFlags">The conversion flags.</param> /// <param name="pixelFormat">The pixel format.</param> public LegacyMap(PixelFormats format, ConversionFlags conversionFlags, DDS.PixelFormat pixelFormat) { Format = format; ConversionFlags = conversionFlags; PixelFormat = pixelFormat; }
public static PixelFormat PixelFormatFromDXGIFormat(PixelFormats format) { PixelFormat ddpf = default(PixelFormat); switch (format) { case PixelFormats.R8G8B8A8_UNORM: ddpf = PixelFormat.A8B8G8R8; break; case PixelFormats.R16G16_UNORM: ddpf = PixelFormat.G16R16; break; case PixelFormats.R8G8_UNORM: ddpf = PixelFormat.A8L8; break; case PixelFormats.R16_UNORM: ddpf = PixelFormat.L16; break; case PixelFormats.R8_UNORM: ddpf = PixelFormat.L8; break; case PixelFormats.A8_UNORM: ddpf = PixelFormat.A8; break; case PixelFormats.R8G8_B8G8_UNORM: ddpf = PixelFormat.R8G8_B8G8; break; case PixelFormats.G8R8_G8B8_UNORM: ddpf = PixelFormat.G8R8_G8B8; break; case PixelFormats.BC1_UNORM: case PixelFormats.BC1_UNORM_SRGB: ddpf = PixelFormat.DXT1; break; case PixelFormats.BC2_UNORM: case PixelFormats.BC2_UNORM_SRGB: ddpf = PixelFormat.DXT3; break; case PixelFormats.BC3_UNORM: case PixelFormats.BC3_UNORM_SRGB: ddpf = PixelFormat.DXT5; break; case PixelFormats.BC4_UNORM: ddpf = PixelFormat.BC4_UNorm; break; case PixelFormats.BC4_SNORM: ddpf = PixelFormat.BC4_SNorm; break; case PixelFormats.BC5_UNORM: ddpf = PixelFormat.BC5_UNorm; break; case PixelFormats.BC5_SNORM: ddpf = PixelFormat.BC5_SNorm; break; case PixelFormats.B5G6R5_UNORM: ddpf = PixelFormat.R5G6B5; break; case PixelFormats.B5G5R5A1_UNORM: ddpf = PixelFormat.A1R5G5B5; break; case PixelFormats.B8G8R8A8_UNORM: ddpf = PixelFormat.A8R8G8B8; break; // DXGI 1.1 case PixelFormats.B8G8R8X8_UNORM: ddpf = PixelFormat.X8R8G8B8; break; // DXGI 1.1 // Legacy D3DX formats using D3DFMT enum value as FourCC case PixelFormats.R32G32B32A32_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 116; // D3DFMT_A32B32G32R32F break; case PixelFormats.R16G16B16A16_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 113; // D3DFMT_A16B16G16R16F break; case PixelFormats.R16G16B16A16_UNORM: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 36; // D3DFMT_A16B16G16R16 break; case PixelFormats.R16G16B16A16_SNORM: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 110; // D3DFMT_Q16W16V16U16 break; case PixelFormats.R32G32_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 115; // D3DFMT_G32R32F break; case PixelFormats.R16G16_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 112; // D3DFMT_G16R16F break; case PixelFormats.R32_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 114; // D3DFMT_R32F break; case PixelFormats.R16_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 111; // D3DFMT_R16F break; } return ddpf; }
/// <summary> /// /// </summary> /// <param name="mipWidth"></param> /// <param name="mipHeight"></param> /// <param name="format"></param> /// <returns>// The following code is a port of DirectXTex</returns> /// <see cref="http://directxtex.codeplex.com"/> public static int GetMipMapBytesCount(int mipWidth, int mipHeight, PixelFormats format) { bool bc = false; bool packed = false; bool planar = false; int bpe = 0; switch (format) { case PixelFormats.BC1_TYPELESS: case PixelFormats.BC1_UNORM: case PixelFormats.BC1_UNORM_SRGB: case PixelFormats.BC4_TYPELESS: case PixelFormats.BC4_UNORM: case PixelFormats.BC4_SNORM: bc = true; bpe = 8; break; case PixelFormats.BC2_TYPELESS: case PixelFormats.BC2_UNORM: case PixelFormats.BC2_UNORM_SRGB: case PixelFormats.BC3_TYPELESS: case PixelFormats.BC3_UNORM: case PixelFormats.BC3_UNORM_SRGB: case PixelFormats.BC5_TYPELESS: case PixelFormats.BC5_UNORM: case PixelFormats.BC5_SNORM: case PixelFormats.BC6H_TYPELESS: case PixelFormats.BC6H_UF16: case PixelFormats.BC6H_SF16: case PixelFormats.BC7_TYPELESS: case PixelFormats.BC7_UNORM: case PixelFormats.BC7_UNORM_SRGB: bc = true; bpe = 16; break; case PixelFormats.R8G8_B8G8_UNORM: case PixelFormats.G8R8_G8B8_UNORM: case PixelFormats.YUY2: packed = true; bpe = 4; break; case PixelFormats.Y210: case PixelFormats.Y216: packed = true; bpe = 8; break; case PixelFormats.NV12: planar = true; bpe = 2; break; case PixelFormats.P010: case PixelFormats.P016: planar = true; bpe = 4; break; } if (bc) { int numBlocksWide = 0; if (mipWidth > 0) { numBlocksWide = Math.Max(1, (mipWidth + 3) / 4); } int numBlocksHigh = 0; if (mipHeight > 0) { numBlocksHigh = Math.Max(1, (mipHeight + 3) / 4); } int rowBytes = numBlocksWide * bpe; //int numRows = numBlocksHigh; int numBytes = rowBytes * numBlocksHigh; return(numBytes); } else if (packed) { int rowBytes = ((mipWidth + 1) >> 1) * bpe; //int numRows = mipHeight; int numBytes = rowBytes * mipHeight; return(numBytes); } else if (format == PixelFormats.NV11) { int rowBytes = ((mipWidth + 3) >> 2) * 4; // Direct3D makes this simplifying assumption, although it is larger than the 4:1:1 data int numRows = mipHeight * 2; int numBytes = rowBytes * numRows; return(numBytes); } else if (planar) { int rowBytes = ((mipWidth + 1) >> 1) * bpe; int numBytes = (rowBytes * mipHeight) + ((rowBytes * mipHeight + 1) >> 1); //int numRows = mipHeight + ((mipHeight + 1) >> 1); return(numBytes); } else { int bpp = DDSFormat.GetBitsPerPixel(format); // round up to nearest byte int rowBytes = (mipWidth * bpp + 7) / 8; int numBytes = rowBytes * mipHeight; return(numBytes); } }
public TeselateTestApplication(PixelFormats format, PlatformSupportAbstract.ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { }
protected string TranslatePixelFormatBack(PixelFormats pixelFormat) { switch (pixelFormat) { case PixelFormats.R8G8B8A8_UNORM: return("A8R8G8B8"); case PixelFormats.B8G8R8X8_UNORM: return("X8R8G8B8"); case PixelFormats.B8G8R8X8_UNORM_SRGB: return("X8R8G8B8_SRGB"); case PixelFormats.R8G8B8A8_UNORM_SRGB: return("A8R8G8B8_SRGB"); case PixelFormats.R16G16B16A16_UNORM: return("A16B16G16R16"); case PixelFormats.R16G16B16A16_FLOAT: return("A16B16G16R16F"); case PixelFormats.R32G32B32A32_FLOAT: return("A32B32G32R32F"); case PixelFormats.A8_UNORM: return("A8"); case PixelFormats.A8P8: return("A8P8"); case PixelFormats.P8: return("P8"); case PixelFormats.R8_UNORM: return("L8"); case PixelFormats.R16_UNORM: return("L16"); case PixelFormats.D16_UNORM: return("D16"); case PixelFormats.R8G8_SNORM: return("V8U8"); case PixelFormats.R16G16_SNORM: return("V16U16"); case PixelFormats.BC1_UNORM: return("DXT1"); case PixelFormats.BC1_UNORM_SRGB: return("DXT1_SRGB"); case PixelFormats.BC2_UNORM: return("DXT3"); case PixelFormats.BC2_UNORM_SRGB: return("DXT3_SRGB"); case PixelFormats.BC3_UNORM: return("DXT5"); case PixelFormats.BC3_UNORM_SRGB: return("DXT5_SRGB"); default: throw new NotSupportedException(string.Format("Unsupported PixelFormat {0}", pixelFormat)); } }
public static bool IsCompressedFormat(PixelFormats format) { switch (format) { case PixelFormats.BC1_TYPELESS: case PixelFormats.BC1_UNORM: case PixelFormats.BC1_UNORM_SRGB: case PixelFormats.BC2_TYPELESS: case PixelFormats.BC2_UNORM: case PixelFormats.BC2_UNORM_SRGB: case PixelFormats.BC3_TYPELESS: case PixelFormats.BC3_UNORM: case PixelFormats.BC3_UNORM_SRGB: case PixelFormats.BC4_TYPELESS: case PixelFormats.BC4_UNORM: case PixelFormats.BC4_SNORM: case PixelFormats.BC5_TYPELESS: case PixelFormats.BC5_UNORM: case PixelFormats.BC5_SNORM: case PixelFormats.BC6H_TYPELESS: case PixelFormats.BC6H_UF16: case PixelFormats.BC6H_SF16: case PixelFormats.BC7_TYPELESS: case PixelFormats.BC7_UNORM: case PixelFormats.BC7_UNORM_SRGB: return true; default: return false; } }
//[StructLayout(LayoutKind.Sequential, Pack = 1)] //public struct HeaderDXT10 //{ // public DXGI.Format DXGIFormat; // public ResourceDimension ResourceDimension; // public ResourceOptionFlags MiscFlags; // see DDS_RESOURCE_MISC_FLAG // public int ArraySize; // private readonly uint Unused; //} /// <summary> /// http://www.getcodesamples.com/src/16371480/B0244AD5 /// </summary> /// <param name="format"></param> /// <returns></returns> public static int GetBitsPerPixel(PixelFormats format) { switch (format) { case PixelFormats.R32G32B32A32_TYPELESS: case PixelFormats.R32G32B32A32_FLOAT: case PixelFormats.R32G32B32A32_UINT: case PixelFormats.R32G32B32A32_SINT: return 128; case PixelFormats.R32G32B32_TYPELESS: case PixelFormats.R32G32B32_FLOAT: case PixelFormats.R32G32B32_UINT: case PixelFormats.R32G32B32_SINT: return 96; case PixelFormats.R16G16B16A16_TYPELESS: case PixelFormats.R16G16B16A16_FLOAT: case PixelFormats.R16G16B16A16_UNORM: case PixelFormats.R16G16B16A16_UINT: case PixelFormats.R16G16B16A16_SNORM: case PixelFormats.R16G16B16A16_SINT: case PixelFormats.R32G32_TYPELESS: case PixelFormats.R32G32_FLOAT: case PixelFormats.R32G32_UINT: case PixelFormats.R32G32_SINT: case PixelFormats.R32G8X24_TYPELESS: case PixelFormats.D32_FLOAT_S8X24_UINT: case PixelFormats.R32_FLOAT_X8X24_TYPELESS: case PixelFormats.X32_TYPELESS_G8X24_UINT: return 64; case PixelFormats.R10G10B10A2_TYPELESS: case PixelFormats.R10G10B10A2_UNORM: case PixelFormats.R10G10B10A2_UINT: case PixelFormats.R11G11B10_FLOAT: case PixelFormats.R8G8B8A8_TYPELESS: case PixelFormats.R8G8B8A8_UNORM: case PixelFormats.R8G8B8A8_UNORM_SRGB: case PixelFormats.R8G8B8A8_UINT: case PixelFormats.R8G8B8A8_SNORM: case PixelFormats.R8G8B8A8_SINT: case PixelFormats.R16G16_TYPELESS: case PixelFormats.R16G16_FLOAT: case PixelFormats.R16G16_UNORM: case PixelFormats.R16G16_UINT: case PixelFormats.R16G16_SNORM: case PixelFormats.R16G16_SINT: case PixelFormats.R32_TYPELESS: case PixelFormats.D32_FLOAT: case PixelFormats.R32_FLOAT: case PixelFormats.R32_UINT: case PixelFormats.R32_SINT: case PixelFormats.R24G8_TYPELESS: case PixelFormats.D24_UNORM_S8_UINT: case PixelFormats.R24_UNORM_X8_TYPELESS: case PixelFormats.X24_TYPELESS_G8_UINT: case PixelFormats.R9G9B9E5_SHAREDEXP: case PixelFormats.R8G8_B8G8_UNORM: case PixelFormats.G8R8_G8B8_UNORM: case PixelFormats.B8G8R8A8_UNORM: case PixelFormats.B8G8R8X8_UNORM: case PixelFormats.R10G10B10_XR_BIAS_A2_UNORM: case PixelFormats.B8G8R8A8_TYPELESS: case PixelFormats.B8G8R8A8_UNORM_SRGB: case PixelFormats.B8G8R8X8_TYPELESS: case PixelFormats.B8G8R8X8_UNORM_SRGB: return 32; case PixelFormats.R8G8_TYPELESS: case PixelFormats.R8G8_UNORM: case PixelFormats.R8G8_UINT: case PixelFormats.R8G8_SNORM: case PixelFormats.R8G8_SINT: case PixelFormats.R16_TYPELESS: case PixelFormats.R16_FLOAT: case PixelFormats.D16_UNORM: case PixelFormats.R16_UNORM: case PixelFormats.R16_UINT: case PixelFormats.R16_SNORM: case PixelFormats.R16_SINT: case PixelFormats.B5G6R5_UNORM: case PixelFormats.B5G5R5A1_UNORM: case PixelFormats.B4G4R4A4_UNORM: return 16; case PixelFormats.R8_TYPELESS: case PixelFormats.R8_UNORM: case PixelFormats.R8_UINT: case PixelFormats.R8_SNORM: case PixelFormats.R8_SINT: case PixelFormats.A8_UNORM: return 8; case PixelFormats.R1_UNORM: return 1; case PixelFormats.BC1_TYPELESS: case PixelFormats.BC1_UNORM: case PixelFormats.BC1_UNORM_SRGB: case PixelFormats.BC4_TYPELESS: case PixelFormats.BC4_UNORM: case PixelFormats.BC4_SNORM: return 4; case PixelFormats.BC2_TYPELESS: case PixelFormats.BC2_UNORM: case PixelFormats.BC2_UNORM_SRGB: case PixelFormats.BC3_TYPELESS: case PixelFormats.BC3_UNORM: case PixelFormats.BC3_UNORM_SRGB: case PixelFormats.BC5_TYPELESS: case PixelFormats.BC5_UNORM: case PixelFormats.BC5_SNORM: case PixelFormats.BC6H_TYPELESS: case PixelFormats.BC6H_UF16: case PixelFormats.BC6H_SF16: case PixelFormats.BC7_TYPELESS: case PixelFormats.BC7_UNORM: case PixelFormats.BC7_UNORM_SRGB: return 8; default: return 0; } }
protected string TranslatePixelFormatBack(PixelFormats pixelFormat) { switch (pixelFormat) { case PixelFormats.R8G8B8A8_UNORM: return "A8R8G8B8"; case PixelFormats.B8G8R8X8_UNORM: return "X8R8G8B8"; case PixelFormats.B8G8R8X8_UNORM_SRGB: return "X8R8G8B8_SRGB"; case PixelFormats.R8G8B8A8_UNORM_SRGB: return "A8R8G8B8_SRGB"; case PixelFormats.R16G16B16A16_UNORM: return "A16B16G16R16"; case PixelFormats.R16G16B16A16_FLOAT: return "A16B16G16R16F"; case PixelFormats.R32G32B32A32_FLOAT: return "A32B32G32R32F"; case PixelFormats.A8_UNORM: return "A8"; case PixelFormats.A8P8: return "A8P8"; case PixelFormats.P8: return "P8"; case PixelFormats.R8_UNORM: return "L8"; case PixelFormats.R16_UNORM: return "L16"; case PixelFormats.D16_UNORM: return "D16"; case PixelFormats.R8G8_SNORM: return "V8U8"; case PixelFormats.R16G16_SNORM: return "V16U16"; case PixelFormats.BC1_UNORM: return "DXT1"; case PixelFormats.BC1_UNORM_SRGB: return "DXT1_SRGB"; case PixelFormats.BC2_UNORM: return "DXT3"; case PixelFormats.BC2_UNORM_SRGB: return "DXT3_SRGB"; case PixelFormats.BC3_UNORM: return "DXT5"; case PixelFormats.BC3_UNORM_SRGB: return "DXT5_SRGB"; default: throw new NotSupportedException(string.Format("Unsupported PixelFormat {0}", pixelFormat)); } }
public static bool IsPacked(PixelFormats fmt) { return ((fmt == PixelFormats.R8G8_B8G8_UNORM) || (fmt == PixelFormats.G8R8_G8B8_UNORM)); }
image_filters_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_step = new SliderWidget <T>(115, 5, 400, 11); m_radius = new SliderWidget <T>(115, 5 + 15, 400, 11 + 15); m_filters = new rbox_ctrl <T>(0.0, 0.0, 110.0, 210.0); m_normalize = new cbox_ctrl <T>(8.0, 215.0, "Normalize Filter"); m_refresh = new ButtonWidget <T>(8.0, 273.0, "Refresh", 8, 1, 1, 3); m_refresh.ButtonClick += RefreshImage; m_run = new ButtonWidget <T>(8.0, 253.0, "RUN Test!", 8, 1, 1, 3); m_run.ButtonClick += RunTest; m_single_step = new ButtonWidget <T>(8.0, 233.0, "Single Step", 8, 1, 1, 3); m_single_step.ButtonClick += SingleStep; m_cur_angle = (0.0); m_cur_filter = (1); m_num_steps = (0); m_num_pix = (0.0); m_time1 = (0); m_time2 = (0); m_ScanlinePacked = new ScanlinePacked8(); m_Rasterizer = new RasterizerScanlineAA <T>(); m_ScanlineUnpacked = new ScanlineUnpacked8(); m_SpanAllocator = new SpanAllocator(); AddChild(m_radius); AddChild(m_step); AddChild(m_filters); AddChild(m_run); AddChild(m_single_step); AddChild(m_normalize); AddChild(m_refresh); //m_single_step.text_size(7.5); m_normalize.SetFontSize(7.5); m_normalize.status(true); m_radius.label("Filter Radius={0:F2}"); m_step.label("Step={0:F2}"); m_radius.range(2.0, 8.0); m_radius.value(4.0); m_step.range(1.0, 10.0); m_step.value(5.0); m_filters.add_item("simple (NN)"); m_filters.add_item("bilinear"); m_filters.add_item("bicubic"); m_filters.add_item("spline16"); m_filters.add_item("spline36"); m_filters.add_item("hanning"); m_filters.add_item("hamming"); m_filters.add_item("hermite"); m_filters.add_item("kaiser"); m_filters.add_item("quadric"); m_filters.add_item("catrom"); m_filters.add_item("gaussian"); m_filters.add_item("bessel"); m_filters.add_item("mitchell"); m_filters.add_item("sinc"); m_filters.add_item("lanczos"); m_filters.add_item("blackman"); m_filters.cur_item(1); m_filters.border_width(0, 0); m_filters.background_color(new RGBA_Doubles(0.0, 0.0, 0.0, 0.1)); m_filters.text_size(6.0); m_filters.text_thickness(0.85); }
public static PixelFormat PixelFormatFromDXGIFormat(PixelFormats format) { PixelFormat ddpf = default(PixelFormat); switch (format) { case PixelFormats.R8G8B8A8_UNORM: ddpf = PixelFormat.A8B8G8R8; break; case PixelFormats.R16G16_UNORM: ddpf = PixelFormat.G16R16; break; case PixelFormats.R8G8_UNORM: ddpf = PixelFormat.A8L8; break; case PixelFormats.R16_UNORM: ddpf = PixelFormat.L16; break; case PixelFormats.R8_UNORM: ddpf = PixelFormat.L8; break; case PixelFormats.A8_UNORM: ddpf = PixelFormat.A8; break; case PixelFormats.R8G8_B8G8_UNORM: ddpf = PixelFormat.R8G8_B8G8; break; case PixelFormats.G8R8_G8B8_UNORM: ddpf = PixelFormat.G8R8_G8B8; break; case PixelFormats.BC1_UNORM: case PixelFormats.BC1_UNORM_SRGB: ddpf = PixelFormat.DXT1; break; case PixelFormats.BC2_UNORM: case PixelFormats.BC2_UNORM_SRGB: ddpf = PixelFormat.DXT3; break; case PixelFormats.BC3_UNORM: case PixelFormats.BC3_UNORM_SRGB: ddpf = PixelFormat.DXT5; break; case PixelFormats.BC4_UNORM: ddpf = PixelFormat.BC4_UNorm; break; case PixelFormats.BC4_SNORM: ddpf = PixelFormat.BC4_SNorm; break; case PixelFormats.BC5_UNORM: ddpf = PixelFormat.BC5_UNorm; break; case PixelFormats.BC5_SNORM: ddpf = PixelFormat.BC5_SNorm; break; case PixelFormats.B5G6R5_UNORM: ddpf = PixelFormat.R5G6B5; break; case PixelFormats.B5G5R5A1_UNORM: ddpf = PixelFormat.A1R5G5B5; break; case PixelFormats.B8G8R8A8_UNORM: ddpf = PixelFormat.A8R8G8B8; break; // DXGI 1.1 case PixelFormats.B8G8R8X8_UNORM: ddpf = PixelFormat.X8R8G8B8; break; // DXGI 1.1 // Legacy D3DX formats using D3DFMT enum value as FourCC case PixelFormats.R32G32B32A32_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 116; // D3DFMT_A32B32G32R32F break; case PixelFormats.R16G16B16A16_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 113; // D3DFMT_A16B16G16R16F break; case PixelFormats.R16G16B16A16_UNORM: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 36; // D3DFMT_A16B16G16R16 break; case PixelFormats.R16G16B16A16_SNORM: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 110; // D3DFMT_Q16W16V16U16 break; case PixelFormats.R32G32_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 115; // D3DFMT_G32R32F break; case PixelFormats.R16G16_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 112; // D3DFMT_G16R16F break; case PixelFormats.R32_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 114; // D3DFMT_R32F break; case PixelFormats.R16_FLOAT: ddpf.Size = 32; ddpf.Flags = PixelFormatFlags.FourCC; ddpf.FourCC = 111; // D3DFMT_R16F break; } return(ddpf); }
public IRenderingSource Create(Int32 width, Int32 height, PixelFormats pixelFormat) { RenderingSurfaceInformation _renderingSurfaceInformation; IntPtr memorySection; IntPtr renderingSurface; Int32 bitsPerPixel = 0; uint numPixels = (uint)(width * height); switch (pixelFormat) { case PixelFormats.Bgr101010: break; case PixelFormats.Bgr24: break; case PixelFormats.Bgr32: break; case PixelFormats.Bgr555: break; case PixelFormats.Bgr565: bitsPerPixel = 16; break; case PixelFormats.Bgra32: break; case PixelFormats.BlackWhite: break; case PixelFormats.Cmyk32: break; case PixelFormats.Default: break; case PixelFormats.Gray16: break; case PixelFormats.Gray2: break; case PixelFormats.Gray32Float: break; case PixelFormats.Gray4: break; case PixelFormats.Gray8: break; case PixelFormats.Indexed1: break; case PixelFormats.Indexed2: break; case PixelFormats.Indexed4: break; case PixelFormats.Indexed8: break; case PixelFormats.Pbgra32: break; case PixelFormats.Prgba128Float: break; case PixelFormats.Prgba64: break; case PixelFormats.Rgb128Float: break; case PixelFormats.Rgb24: break; case PixelFormats.Rgb48: break; case PixelFormats.Rgba128Float: break; case PixelFormats.Rgba64: break; default: break; } uint numBytes = numPixels * (uint)(bitsPerPixel / 8); memorySection = CreateFileMapping(INVALID_HANDLE_VALUE, IntPtr.Zero, PAGE_READWRITE, 0, numBytes, null); renderingSurface = MapViewOfFile(memorySection, FILE_MAP_ALL_ACCESS, 0, 0, numBytes); _renderingSurfaceInformation = new RenderingSurfaceInformation(width, height, bitsPerPixel, pixelFormat); return new RenderingSource(memorySection, renderingSurface, _renderingSurfaceInformation); }
public static bool IsPacked(PixelFormats fmt) { return((fmt == PixelFormats.R8G8_B8G8_UNORM) || (fmt == PixelFormats.G8R8_G8B8_UNORM)); }
public static void ComputePitch(PixelFormats fmt, int width, int height, out int rowPitch, out int slicePitch, out int widthCount, out int heightCount, PitchFlags flags = PitchFlags.None) { widthCount = width; heightCount = height; if (IsCompressedFormat(fmt)) { int bpb = (fmt == PixelFormats.BC1_TYPELESS || fmt == PixelFormats.BC1_UNORM || fmt == PixelFormats.BC1_UNORM_SRGB || fmt == PixelFormats.BC4_TYPELESS || fmt == PixelFormats.BC4_UNORM || fmt == PixelFormats.BC4_SNORM) ? 8 : 16; widthCount = Math.Max(1, (width + 3)/4); heightCount = Math.Max(1, (height + 3)/4); rowPitch = widthCount*bpb; slicePitch = rowPitch*heightCount; } else if (IsPacked(fmt)) { rowPitch = ((width + 1) >> 1)*4; slicePitch = rowPitch*height; } else { int bpp; if ((flags & PitchFlags.Bpp24) != 0) bpp = 24; else if ((flags & PitchFlags.Bpp16) != 0) bpp = 16; else if ((flags & PitchFlags.Bpp8) != 0) bpp = 8; else bpp = GetBitsPerPixel(fmt); if ((flags & PitchFlags.LegacyDword) != 0) { // Special computation for some incorrectly created DDS files based on // legacy DirectDraw assumptions about pitch alignment rowPitch = ((width*bpp + 31)/32)*sizeof (int); slicePitch = rowPitch*height; } else { rowPitch = (width*bpp + 7)/8; slicePitch = rowPitch*height; } } }
public RenderingSurfaceInformation(Int32 width, Int32 height, Int32 bitsPerPixel, PixelFormats pixelFormat) { Width = width; Height = height; BitsPerPixel = bitsPerPixel; PixelFormat = pixelFormat; }