Browse Source

Use direct access to Color to get/set pixels.

Former-commit-id: 38f45a1ac9325aabbeb25c0422f973bf44d7fe65
Former-commit-id: 55b3f1b83610fe278d3af85a855689319c37eba9
Former-commit-id: a2e726b811db365bbb164d3b30b8232da842636b
af/merge-core
James Jackson-South 10 years ago
parent
commit
f0f0749851
  1. 8
      Rebracer.xml
  2. 25
      src/ImageProcessorCore/PixelAccessor.cs

8
Rebracer.xml

@ -22,8 +22,12 @@
</ToolsOptionsCategory>
<ToolsOptionsCategory name="TextEditor">
<ToolsOptionsSubCategory name="CSharp-Specific">
<PropertyValue name="AddImport_SuggestForTypesInNuGetPackages">0</PropertyValue>
<PropertyValue name="AddImport_SuggestForTypesInReferenceAssemblies">0</PropertyValue>
<PropertyValue name="AutoComment">1</PropertyValue>
<PropertyValue name="ClosedFileDiagnostics">1</PropertyValue>
<PropertyValue name="AutoInsertAsteriskForNewLinesOfBlockComments">1</PropertyValue>
<PropertyValue name="CSharpClosedFileDiagnostics">-1</PropertyValue>
<PropertyValue name="ClosedFileDiagnostics">-1</PropertyValue>
<PropertyValue name="DisplayLineSeparators">0</PropertyValue>
<PropertyValue name="EnableHighlightRelatedKeywords">1</PropertyValue>
<PropertyValue name="ExtractMethod_AllowMovingDeclaration">0</PropertyValue>
@ -81,7 +85,7 @@
<PropertyValue name="Style_PreferIntrinsicPredefinedTypeKeywordInMemberAccess">1</PropertyValue>
<PropertyValue name="Style_QualifyMemberAccessWithThisOrMe">0</PropertyValue>
<PropertyValue name="Style_UseVarWhenDeclaringLocals">1</PropertyValue>
<PropertyValue name="WarnOnBuildErrors">1</PropertyValue>
<PropertyValue name="WarnOnBuildErrors">0</PropertyValue>
<PropertyValue name="Wrapping_IgnoreSpacesAroundBinaryOperators">0</PropertyValue>
<PropertyValue name="Wrapping_IgnoreSpacesAroundVariableDeclaration">0</PropertyValue>
<PropertyValue name="Wrapping_KeepStatementsOnSingleLine">1</PropertyValue>

25
src/ImageProcessorCore/PixelAccessor.cs

@ -16,7 +16,7 @@ namespace ImageProcessorCore
/// <summary>
/// The position of the first pixel in the bitmap.
/// </summary>
private float* pixelsBase;
private Color* pixelsBase;
/// <summary>
/// Provides a way to access the pixels from unmanaged memory.
@ -48,27 +48,12 @@ namespace ImageProcessorCore
Guard.MustBeGreaterThan(image.Width, 0, "image width");
Guard.MustBeGreaterThan(image.Height, 0, "image height");
int size = image.Pixels.Length;
this.Width = image.Width;
this.Height = image.Height;
// Assign the pointer.
// If buffer is allocated on Large Object Heap i.e > 85Kb, then we are going to pin it instead of making a copy.
if (size > 87040)
{
this.pixelsHandle = GCHandle.Alloc(image.Pixels, GCHandleType.Pinned);
this.pixelsBase = (float*)this.pixelsHandle.AddrOfPinnedObject().ToPointer();
}
else
{
fixed (float* pbuffer = image.Pixels)
{
// TODO: This isn't actually copying.
// We need to allocate and copy the pixels into unmanaged memory.
// Will need to research how to do this.
this.pixelsBase = pbuffer;
}
}
this.pixelsHandle = GCHandle.Alloc(image.Pixels, GCHandleType.Pinned);
this.pixelsBase = (Color*)this.pixelsHandle.AddrOfPinnedObject().ToPointer();
}
/// <summary>
@ -116,7 +101,7 @@ namespace ImageProcessorCore
throw new ArgumentOutOfRangeException(nameof(y), "Value cannot be less than zero or greater than the bitmap height.");
}
#endif
return *((Color*)(this.pixelsBase + (((y * this.Width) + x) * 4)));
return *(this.pixelsBase + ((y * this.Width) + x));
}
set
@ -132,7 +117,7 @@ namespace ImageProcessorCore
throw new ArgumentOutOfRangeException(nameof(y), "Value cannot be less than zero or greater than the bitmap height.");
}
#endif
*(Color*)(this.pixelsBase + (((y * this.Width) + x) * 4)) = value;
*(this.pixelsBase + ((y * this.Width) + x)) = value;
}
}

Loading…
Cancel
Save