Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
smourier committed Feb 21, 2024
1 parent b9040b0 commit d11c2ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion WicNet.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class Program
{
static void Main(string[] args)
{
ConvertSvgAsPng("tiger.svg");
Posterize(256);
return;
ConvertToBW();
return;
ConvertSvgAsPng("tiger.svg");
return;
ExtractGif();
return;
LoadFromIcon();
Expand Down Expand Up @@ -466,6 +468,26 @@ static void RotateAndGrayscale()
Process.Start(new ProcessStartInfo("gray.jpg") { UseShellExecute = true });
}

static void Posterize(uint numberOfColors)
{
using var bmp = WicBitmapSource.Load("SamsungSGH-P270.jpg");
bmp.ConvertTo(WicPixelFormat.GUID_WICPixelFormat32bppBGR);
using var newBmp = new WicBitmapSource(bmp.Width, bmp.Height, WicPixelFormat.GUID_WICPixelFormat32bppPRGBA);
using var rt = newBmp.CreateDeviceContext();
using var fx = rt.CreateEffect(Direct2DEffects.CLSID_D2D1Posterize);
using var cb = rt.CreateBitmapFromWicBitmap(bmp.ComObject);
fx.SetInput(cb);
fx.SetValue((int)D2D1_POSTERIZE_PROP.D2D1_POSTERIZE_PROP_RED_VALUE_COUNT, numberOfColors);
fx.SetValue((int)D2D1_POSTERIZE_PROP.D2D1_POSTERIZE_PROP_GREEN_VALUE_COUNT, numberOfColors);
fx.SetValue((int)D2D1_POSTERIZE_PROP.D2D1_POSTERIZE_PROP_BLUE_VALUE_COUNT, numberOfColors);
rt.BeginDraw();
rt.DrawImage(fx);
rt.EndDraw();
var name = "posterize" + numberOfColors + ".jpg";
newBmp.Save(name);
Process.Start(new ProcessStartInfo(name) { UseShellExecute = true });
}

static void ConvertToBW()
{
using var bmp = WicBitmapSource.Load("SamsungSGH-P270.jpg");
Expand Down
2 changes: 1 addition & 1 deletion WicNet.Tests/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"WicNet.Tests": {
"commandName": "Project",
"nativeDebugging": true
"nativeDebugging": false
}
}
}

0 comments on commit d11c2ac

Please sign in to comment.