public override void Apply() { unsafe { using (PixelFarm.CpuBlit.TempMemPtr bufferPtr = _target.GetBufferPtr()) { int[] output = new int[bufferPtr.LengthInBytes / 4]; //TODO: review here again fixed(int *outputPtr = &output[0]) { byte *srcBuffer = (byte *)bufferPtr.Ptr; int * srcBuffer1 = (int *)srcBuffer; int * outputBuffer1 = (int *)outputPtr; int stride = _target.Stride; int w = _target.Width; int h = _target.Height; MemHolder srcMemHolder = new MemHolder((IntPtr)srcBuffer1, bufferPtr.LengthInBytes / 4);// Surface srcSurface = new Surface(stride, w, h, srcMemHolder); // MemHolder destMemHolder = new MemHolder((IntPtr)outputPtr, bufferPtr.LengthInBytes / 4); Surface destSurface = new Surface(stride, w, h, destMemHolder); // _shRenderer1.Amount = Radius; _shRenderer1.Render(srcSurface, destSurface, new PixelFarm.Drawing.Rectangle[] { new PixelFarm.Drawing.Rectangle(0, 0, w, h) }, 0, 1); } _target.WriteBuffer(output); } } }
//public static void InvertColor(this MemBitmap memBmp) //{ // //temp fix // unsafe // { // Imaging.TempMemPtr tmp = MemBitmap.GetBufferPtr(memBmp); // int* buffer = (int*)tmp.Ptr; // int len32 = tmp.LengthInBytes / 4; // unsafe // { // { // int* head_i32 = (int*)buffer; // for (int n = len32 - 1; n >= 0; --n) // { // int value = *head_i32; // int r = (value >> CO.R_SHIFT) & 0xff; // int g = (value >> CO.G_SHIFT) & 0xff; // int b = (value >> CO.B_SHIFT) & 0xff; // int a = (value >> CO.A_SHIFT) & 0xff; // *head_i32 = ((255 - r) << CO.R_SHIFT) | ((255 - g) << CO.G_SHIFT) | ((255 - b) << CO.B_SHIFT) | ((255 - a) << CO.A_SHIFT); // head_i32++; // } // } // } // } //} internal static void Clear(PixelFarm.CpuBlit.TempMemPtr tmp, Color color) { unsafe { int *buffer = (int *)tmp.Ptr; int len32 = tmp.LengthInBytes / 4; //------------------------------ //fast clear buffer //skip clipping **** //TODO: reimplement clipping*** //------------------------------ if (color == Color.White) { //fast cleat with white color int n = len32; unsafe { //fixed (void* head = &buffer[0]) { uint *head_i32 = (uint *)buffer; for (int i = n - 1; i >= 0; --i) { *head_i32 = 0xffffffff; //white (ARGB) head_i32++; } } } } else if (color == Color.Black) { //fast clear with black color int n = len32; unsafe { //fixed (void* head = &buffer[0]) { uint *head_i32 = (uint *)buffer; for (int i = n - 1; i >= 0; --i) { *head_i32 = 0xff000000; //black (ARGB) head_i32++; } } } } else if (color == Color.Empty) { int n = len32; unsafe { //fixed (void* head = &buffer[0]) { uint *head_i32 = (uint *)buffer; for (int i = n - 1; i >= 0; --i) { *head_i32 = 0x00000000; //empty head_i32++; } } } } else { //other color //#if WIN32 // uint colorARGB = (uint)((color.alpha << 24) | ((color.red << 16) | (color.green << 8) | color.blue)); //#else // uint colorARGB = (uint)((color.alpha << 24) | ((color.blue << 16) | (color.green << 8) | color.red)); //#endif //ARGB uint colorARGB = (uint)((color.A << CO.A_SHIFT) | ((color.R << CO.R_SHIFT) | (color.G << CO.G_SHIFT) | color.B << CO.B_SHIFT)); int n = len32; unsafe { //fixed (void* head = &buffer[0]) { uint *head_i32 = (uint *)buffer; for (int i = n - 1; i >= 0; --i) { *head_i32 = colorARGB; head_i32++; } } } } } }