mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 05:23:24 -07:00
Trying a different way of cutting the edges
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2235 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
d49a203b3a
commit
0fd12ae5fc
1 changed files with 47 additions and 26 deletions
|
@ -954,40 +954,61 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <param name="redBitmap">The bitmap taken with a red background</param>
|
/// <param name="redBitmap">The bitmap taken with a red background</param>
|
||||||
/// <param name="cornerColor">The background color</param>
|
/// <param name="cornerColor">The background color</param>
|
||||||
private void RemoveCorners(Bitmap normalBitmap, Bitmap redBitmap, Color cornerColor) {
|
private void RemoveCorners(Bitmap normalBitmap, Bitmap redBitmap, Color cornerColor) {
|
||||||
|
const int thresholdTopLeft = 60;
|
||||||
|
const int thresholdTopRight = 40;
|
||||||
|
const int thresholdBottomLeft = 45;
|
||||||
|
const int thresholdBottomRight = 35;
|
||||||
|
const int range = 15;
|
||||||
using (BitmapBuffer redBuffer = new BitmapBuffer(redBitmap, false)) {
|
using (BitmapBuffer redBuffer = new BitmapBuffer(redBitmap, false)) {
|
||||||
redBuffer.Lock();
|
redBuffer.Lock();
|
||||||
using (BitmapBuffer normalBuffer = new BitmapBuffer(normalBitmap, false)) {
|
using (BitmapBuffer normalBuffer = new BitmapBuffer(normalBitmap, false)) {
|
||||||
normalBuffer.Lock();
|
normalBuffer.Lock();
|
||||||
for (int y = 0; y < 8; y++) {
|
|
||||||
for (int x = 0; x < 8; x++) {
|
|
||||||
// top left
|
// top left
|
||||||
int cornerX = x;
|
for (int y = 0; y < range; y++) {
|
||||||
int cornerY = y;
|
for (int x = 0; x < range; x++) {
|
||||||
Color currentPixel = redBuffer.GetColorAt(cornerX, cornerY);
|
Color redBufferPixel = redBuffer.GetColorAt(x, y);
|
||||||
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) {
|
Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
|
||||||
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor);
|
int redDiff = redBufferPixel.R - normalBufferPixel.R;
|
||||||
|
if (redDiff < thresholdTopLeft) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
normalBuffer.SetColorAt(x, y, cornerColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// top right
|
// top right
|
||||||
cornerX = normalBitmap.Width - x;
|
for (int y = 0; y < range; y++) {
|
||||||
cornerY = y;
|
for (int x = normalBitmap.Width-1; x > normalBitmap.Width - range; x--) {
|
||||||
currentPixel = redBuffer.GetColorAt(cornerX, cornerY);
|
Color redBufferPixel = redBuffer.GetColorAt(x, y);
|
||||||
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) {
|
Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
|
||||||
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor);
|
int redDiff = redBufferPixel.R - normalBufferPixel.R;
|
||||||
|
if (redDiff < thresholdTopRight) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
normalBuffer.SetColorAt(x, y, cornerColor);
|
||||||
}
|
}
|
||||||
// bottom right
|
|
||||||
cornerX = normalBitmap.Width - x;
|
|
||||||
cornerY = normalBitmap.Height - y;
|
|
||||||
currentPixel = redBuffer.GetColorAt(cornerX, cornerY);
|
|
||||||
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) {
|
|
||||||
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor);
|
|
||||||
}
|
}
|
||||||
// bottom left
|
// bottom left
|
||||||
cornerX = x;
|
for (int y = normalBitmap.Height-1; y > normalBitmap.Height - range; y--) {
|
||||||
cornerY = normalBitmap.Height - y;
|
for (int x = 0; x < range; x++) {
|
||||||
currentPixel = redBuffer.GetColorAt(cornerX, cornerY);
|
Color redBufferPixel = redBuffer.GetColorAt(x, y);
|
||||||
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) {
|
Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
|
||||||
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor);
|
int redDiff = redBufferPixel.R - normalBufferPixel.R;
|
||||||
|
if (redDiff < thresholdBottomLeft) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
normalBuffer.SetColorAt(x, y, cornerColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Bottom right
|
||||||
|
for (int y = normalBitmap.Height-1; y > normalBitmap.Height - range; y--) {
|
||||||
|
for (int x = normalBitmap.Width-1; x > normalBitmap.Width - range; x--) {
|
||||||
|
Color redBufferPixel = redBuffer.GetColorAt(x, y);
|
||||||
|
Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
|
||||||
|
int redDiff = redBufferPixel.R - normalBufferPixel.R;
|
||||||
|
if (redDiff < thresholdBottomRight) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
normalBuffer.SetColorAt(x, y, cornerColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue