-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds enough functionality to load a bitmap from a file and render it to a Direct2D rendering target.
- Loading branch information
1 parent
698f574
commit 80335ab
Showing
22 changed files
with
407 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\thirtytwo\thirtytwo.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Blue Marble 2012 Original.jpg"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Drawing; | ||
using Windows; | ||
using Windows.Win32.Graphics.Direct2D; | ||
using Windows.Win32.Graphics.Imaging; | ||
using Bitmap = Windows.Win32.Graphics.Direct2D.Bitmap; | ||
|
||
namespace ImagingDemo; | ||
|
||
internal class Program | ||
{ | ||
[STAThread] | ||
private static void Main() => Application.Run(new ImagingDemo()); | ||
|
||
private unsafe class ImagingDemo : MainWindow | ||
{ | ||
private FormatConverter? _converter; | ||
private Bitmap? _bitmap; | ||
|
||
|
||
public ImagingDemo() : base( | ||
title: "Simple Windows Imaging Application", | ||
backgroundColor: Color.Black, | ||
features: Features.EnableDirect2d) | ||
{ | ||
} | ||
|
||
[MemberNotNull(nameof(_converter))] | ||
private void CreateBitmapFromFile(string fileName) | ||
{ | ||
_converter?.Dispose(); | ||
_bitmap?.Dispose(); | ||
|
||
using BitmapDecoder decoder = new(fileName); | ||
using BitmapFrameDecode frame = decoder.GetFrame(0); | ||
_converter = new(frame); | ||
} | ||
|
||
protected override void RenderTargetCreated() | ||
{ | ||
if (_converter is null) | ||
{ | ||
CreateBitmapFromFile("Blue Marble 2012 Original.jpg"); | ||
} | ||
|
||
_bitmap?.Dispose(); | ||
_bitmap = RenderTarget.CreateBitmapFromWicBitmap(_converter); | ||
base.RenderTargetCreated(); | ||
} | ||
|
||
protected override void OnPaint() | ||
{ | ||
if (_bitmap is not null) | ||
{ | ||
RenderTarget.DrawBitmap(_bitmap); | ||
} | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
_converter?.Dispose(); | ||
_bitmap?.Dispose(); | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"Blue Marble 2012 Original"" image is in the public domain. | ||
Credit: NASA/NOAA/GSFC/Suomi NPP/VIIRS/Norman Kuring | ||
Source: https://flickr.com/photos/nasacommons/31258502484/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Windows.Support; | ||
|
||
namespace Windows.Win32.Graphics.Direct2D; | ||
|
||
public unsafe class Bitmap : Image, IPointer<ID2D1Bitmap> | ||
{ | ||
public unsafe new ID2D1Bitmap* Pointer => (ID2D1Bitmap*)base.Pointer; | ||
|
||
public Bitmap(ID2D1Bitmap* bitmap) : base((ID2D1Image*)bitmap) | ||
{ | ||
} | ||
|
||
public static implicit operator ID2D1Bitmap*(Bitmap bitmap) => bitmap.Pointer; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/thirtytwo/Win32/Graphics/Direct2D/BitmapInterpolationMode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Windows.Win32.Graphics.Direct2D; | ||
|
||
public enum BitmapInterpolationMode | ||
{ | ||
/// <inheritdoc cref="D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR"/> | ||
NearestNeighbor = D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, | ||
|
||
/// <inheritdoc cref="D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_LINEAR"/> | ||
Linear = D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_LINEAR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Windows.Support; | ||
|
||
namespace Windows.Win32.Graphics.Direct2D; | ||
|
||
public unsafe class Image : Resource, IPointer<ID2D1Image> | ||
{ | ||
public unsafe new ID2D1Image* Pointer => (ID2D1Image*)base.Pointer; | ||
|
||
public Image(ID2D1Image* image) : base((ID2D1Resource*)image) | ||
{ | ||
} | ||
|
||
public static implicit operator ID2D1Image*(Image image) => image.Pointer; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/thirtytwo/Win32/Graphics/Direct2D/InterpolationMode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Windows.Win32.Graphics.Direct2D; | ||
|
||
public enum InterpolationMode | ||
{ | ||
/// <inheritdoc cref="D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR"/> | ||
NearestNeighbor = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, | ||
|
||
/// <inheritdoc cref="D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_LINEAR"/> | ||
Linear = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_LINEAR, | ||
|
||
/// <inheritdoc cref="D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_CUBIC"/> | ||
Cubic = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_CUBIC, | ||
|
||
/// <inheritdoc cref="D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR"/> | ||
MultiSampleLinear = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR, | ||
|
||
/// <inheritdoc cref="D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_ANISOTROPIC"/> | ||
Anisotropic = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_ANISOTROPIC, | ||
|
||
/// <inheritdoc cref="D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC"/> | ||
HighQualityCubic = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.