public unsafe void PixelHighRes(RasterBuffer buf, RGBA_Bytes* p, int x, int y) { int r, g, b, a; r = g = b = a = LineAABasics.LineSubPixelScale * LineAABasics.LineSubPixelScale / 2; int weight; int x_lr = x >> LineAABasics.LineSubPixelShift; int y_lr = y >> LineAABasics.LineSubPixelShift; x &= LineAABasics.LineSubPixelMask; y &= LineAABasics.LineSubPixelMask; RGBA_Bytes* ptr = (RGBA_Bytes*)buf.GetPixelPointer(x_lr, y_lr); weight = (LineAABasics.LineSubPixelScale - x) * (LineAABasics.LineSubPixelScale - y); r += weight * ptr->R; g += weight * ptr->G; b += weight * ptr->B; a += weight * ptr->A; ++ptr; weight = x * (LineAABasics.LineSubPixelScale - y); r += weight * ptr->R; g += weight * ptr->G; b += weight * ptr->B; a += weight * ptr->A; ptr = (RGBA_Bytes*)buf.GetPixelPointer(x_lr, y_lr + 1); weight = (LineAABasics.LineSubPixelScale - x) * y; r += weight * ptr->R; g += weight * ptr->G; b += weight * ptr->B; a += weight * ptr->A; ++ptr; weight = x * y; r += weight * ptr->R; g += weight * ptr->G; b += weight * ptr->B; a += weight * ptr->A; //p->R = (byte)(r >> LineAABasics.LineSubPixelShift * 2); //p->G = (byte)(g >> LineAABasics.LineSubPixelShift * 2); //p->B = (byte)(b >> LineAABasics.LineSubPixelShift * 2); //p->A = (byte)(a >> LineAABasics.LineSubPixelShift * 2); (*p) = new RGBA_Bytes( (byte)(r >> LineAABasics.LineSubPixelShift * 2), (byte)(g >> LineAABasics.LineSubPixelShift * 2), (byte)(b >> LineAABasics.LineSubPixelShift * 2), (byte)(a >> LineAABasics.LineSubPixelShift * 2)); }
//-------------------------------------------------------------------- unsafe public void CopyColorVSpan(int x, int y, uint len, RGBA_Bytes* colors) { byte* p = m_rbuf.GetPixelPointer(y) + x * m_Step + m_Offset; int ScanWidth = m_rbuf.StrideInBytes; do { *p = colors[0].R; p = &p[ScanWidth]; ++colors; } while (--len != 0); }
//-------------------------------------------------------------------- public unsafe void BlendColorVSpan(int x, int y, uint len, RGBA_Bytes* colors, byte* covers, byte cover) { byte* p = m_rbuf.GetPixelPointer(y) + x + x + x; int ScanWidth = m_rbuf.StrideInBytes; if (covers != null) { do { CopyOrBlendBGRWrapper.CopyOrBlendPix(m_Blender, p, colors->R, colors->G, colors->B, colors->A, *covers++); p = &p[ScanWidth]; ++colors; } while (--len != 0); } else { if (cover == 255) { do { CopyOrBlendBGRWrapper.CopyOrBlendPix(m_Blender, p, colors->R_Byte, colors->G_Byte, colors->B_Byte, colors->A_Byte); p = &p[ScanWidth]; ++colors; } while (--len != 0); } else { do { CopyOrBlendBGRWrapper.CopyOrBlendPix(m_Blender, p, colors->R_Byte, colors->G_Byte, colors->B_Byte, colors->A_Byte, cover); p = &p[ScanWidth]; ++colors; } while (--len != 0); } } }
//-------------------------------------------------------------------- unsafe public void BlendSolidHSpan(int x, int y, uint len, RGBA_Bytes c, byte* covers) { if (c.A != 0) { unchecked { byte* p = (byte*)m_rbuf.GetPixelPointer(y) + x + x + x; do { uint alpha = ((uint)(c.A) * ((uint)(*covers) + 1)) >> 8; if (alpha == BaseMask) { p[OrderR] = c.R; p[OrderG] = c.G; p[OrderB] = c.B; } else { #if false m_Blender.blend_pix(p, c.m_R, c.m_G, c.m_B, alpha); #else // testing performance. This is not noticibly faster. unchecked { uint r = p[2]; uint g = p[1]; uint b = p[0]; p[0] = (byte)(((c.B - b) * alpha + (b << (int)ColorConstants.BaseShift)) >> (int)ColorConstants.BaseShift); p[1] = (byte)(((c.G - g) * alpha + (g << (int)ColorConstants.BaseShift)) >> (int)ColorConstants.BaseShift); p[2] = (byte)(((c.R - r) * alpha + (r << (int)ColorConstants.BaseShift)) >> (int)ColorConstants.BaseShift); } #endif } p += 3; ++covers; } while (--len != 0); } } }
//-------------------------------------------------------------------- unsafe public void CopyColorHSpan(int x, int y, uint len, RGBA_Bytes* colors) { byte* p = m_rbuf.GetPixelPointer(y) + x + x + x; do { p[OrderR] = colors[0].R; p[OrderG] = colors[0].G; p[OrderB] = colors[0].B; ++colors; p += 3; } while (--len != 0); }
//-------------------------------------------------------------------- public unsafe void CopyHLine(int x, int y, uint len, RGBA_Bytes c) { unsafe { byte* p = (byte*)m_rbuf.GetPixelPointer(y) + x + x + x; byte cr = c.R; byte cg = c.G; byte cb = c.B; do { p[OrderR] = (byte)cr; p[OrderG] = (byte)cg; p[OrderB] = (byte)cb; p += 3; } while (--len != 0); } }
//-------------------------------------------------------------------- public void BlendHLine(int x1, int y, int x2, RGBA_Bytes c, byte cover) { if (c.A != 0) { unsafe { int len = x2 - x1 + 1; byte* p = (byte*)m_rbuf.GetPixelPointer(y) + x1 * 3; uint alpha = (uint)(((int)(c.A_Byte) * (cover + 1)) >> 8); if (alpha == BaseMask) { byte cr = c.R; byte cg = c.G; byte cb = c.B; do { p[OrderR] = (byte)cr; p[OrderG] = (byte)cg; p[OrderB] = (byte)cb; p += 3; } while (--len != 0); } else { if (cover == 255) { do { m_Blender.BlendPix(p, c.R, c.G, c.B, alpha); p += 3; } while (--len != 0); } else { do { #if USE_BLENDER m_Blender.blend_pix(p, c.m_R, c.m_G, c.m_B, alpha); #else unchecked { uint b = p[0]; uint g = p[1]; uint r = p[2]; uint a = p[3]; p[0] = (byte)(((c.B - b) * alpha + (b << (int)ColorConstants.BaseShift)) >> (int)ColorConstants.BaseShift); p[1] = (byte)(((c.G - g) * alpha + (g << (int)ColorConstants.BaseShift)) >> (int)ColorConstants.BaseShift); p[2] = (byte)(((uint)(c.R - r) * alpha + (r << (int)ColorConstants.BaseShift)) >> (int)ColorConstants.BaseShift); p[3] = (byte)((alpha + a) - ((alpha * a + BaseMask) >> (int)ColorConstants.BaseShift)); } #endif p += 3; } while (--len != 0); } } } } }
//-------------------------------------------------------------------- public RGBA_Bytes Gradient(RGBA_Bytes c, double k) { //RGBA_Bytes ret = new RGBA_Bytes(); uint ik = Basics.RoundUint(k * ColorConstants.BaseScale); //ret.R_Byte = (byte)((uint)(R_Byte) + ((((uint)(c.R_Byte) - R_Byte) * ik) >> ColorConstants.BaseShift)); //ret.G_Byte = (byte)((uint)(G_Byte) + ((((uint)(c.G_Byte) - G_Byte) * ik) >> ColorConstants.BaseShift)); //ret.B_Byte = (byte)((uint)(B_Byte) + ((((uint)(c.B_Byte) - B_Byte) * ik) >> ColorConstants.BaseShift)); //ret.A_Byte = (byte)((uint)(A_Byte) + ((((uint)(c.A_Byte) - A_Byte) * ik) >> ColorConstants.BaseShift)); //return ret; return new RGBA_Bytes( (byte)((uint)(R_Byte) + ((((uint)(c.R_Byte) - R_Byte) * ik) >> ColorConstants.BaseShift)), (byte)((uint)(G_Byte) + ((((uint)(c.G_Byte) - G_Byte) * ik) >> ColorConstants.BaseShift)), (byte)((uint)(B_Byte) + ((((uint)(c.B_Byte) - B_Byte) * ik) >> ColorConstants.BaseShift)), (byte)((uint)(A_Byte) + ((((uint)(c.A_Byte) - A_Byte) * ik) >> ColorConstants.BaseShift))); }
//-------------------------------------------------------------------- public RGBA_Bytes Add(RGBA_Bytes c, uint cover) { uint cr, cg, cb, ca; if (cover == ColorConstants.CoverMask) { if (c.A_Byte == ColorConstants.BaseMask) { return c; //this = c; } else { cr = R_Byte + c.R_Byte; //R_Byte = (cr > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cr; cg = G_Byte + c.G_Byte; //G_Byte = (cg > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cg; cb = B_Byte + c.B_Byte; //B_Byte = (cb > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cb; ca = A_Byte + c.A_Byte; //A_Byte = (ca > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : ca; return new RGBA_Bytes( (cr > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cr, (cg > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cg, (cb > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cb, (ca > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : ca); } } else { cr = R_Byte + ((c.R_Byte * cover + ColorConstants.CoverMask / 2) >> ColorConstants.CoverShift); cg = G_Byte + ((c.G_Byte * cover + ColorConstants.CoverMask / 2) >> ColorConstants.CoverShift); cb = B_Byte + ((c.B_Byte * cover + ColorConstants.CoverMask / 2) >> ColorConstants.CoverShift); ca = A_Byte + ((c.A_Byte * cover + ColorConstants.CoverMask / 2) >> ColorConstants.CoverShift); //R_Byte = (cr > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cr; //G_Byte = (cg > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cg; //B_Byte = (cb > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cb; //A_Byte = (ca > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : ca; return new RGBA_Bytes( (cr > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cr, (cg > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cg, (cb > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : cb, (ca > (uint)(ColorConstants.BaseMask)) ? (uint)(ColorConstants.BaseMask) : ca ); } }
public unsafe void BlendColorVSpan(int x, int y, uint len, RGBA_Bytes* colors, byte* covers, byte cover) { int ScanWidth = m_rbuf.StrideInBytes; byte* p = m_rbuf.GetPixelPointer(y) + x * m_Step + m_Offset; if (covers != null) { do { CopyOrBlendPix(p, *colors++, *covers++); p = &p[ScanWidth]; } while (--len != 0); } else { if (cover == 255) { do { if (colors[0].A == (byte)BaseMask) { *p = colors[0].A; } else { CopyOrBlendPix(p, *colors); } p = &p[ScanWidth]; ++colors; } while (--len != 0); } else { do { CopyOrBlendPix(p, *colors++, cover); p = &p[ScanWidth]; } while (--len != 0); } } }
//-------------------------------------------------------------------- RGBA_Bytes(RGBA_Bytes c, uint a_) { m_R = (byte)c.m_R; m_G = (byte)c.m_G; m_B = (byte)c.m_B; m_A = (byte)a_; }
private unsafe void CopyOrBlendPix(byte* p, RGBA_Bytes c) { if (c.A != 0) { if (c.A == BaseMask) { *p = c.A; } else { m_Blender.BlendPix(p, c.A, c.A_Byte); } } }
//-------------------------------------------------------------------- private unsafe void CopyOrBlendPix(byte* p, RGBA_Bytes c, uint cover) { if (c.A != 0) { uint alpha = (uint)((c.A) * (cover + 1)) >> 8; if (alpha == BaseMask) { *p = c.A; } else { m_Blender.BlendPix(p, c.A, alpha, cover); } } }
//-------------------------------------------------------------------- unsafe public void BlendColorHSpan(int x, int y, uint len, RGBA_Bytes* colors, byte* covers, byte cover) { byte* p = m_rbuf.GetPixelPointer(y) + x * m_Step + m_Offset; if (covers != null) { do { CopyOrBlendPix(p, *colors++, *covers++); p += m_Step; } while (--len != 0); } else { if (cover == 255) { do { if (colors[0].A == (byte)BaseMask) { *p = colors[0].A; } else { CopyOrBlendPix(p, *colors); } p += m_Step; ++colors; } while (--len != 0); } else { do { CopyOrBlendPix(p, *colors++, cover); p += m_Step; } while (--len != 0); } } }
public unsafe virtual void BlendColorVSpan(int x, int y, uint len, RGBA_Bytes* colors, byte* covers, byte cover) { m_pixf.BlendColorVSpan(x, y, len, colors, covers, cover); }
public static RGBA_Bytes ModifyComponent(RGBA_Bytes color, Component comp, uint value) { return new RGBA_Bytes( comp == Component.R ? value : color.R_Byte, comp == Component.G ? value : color.G_Byte, comp == Component.B ? value : color.B_Byte, comp == Component.A ? value : color.A_Byte); }
//-------------------------------------------------------------------- public void BlendPixel(int x, int y, RGBA_Bytes c, byte cover) { /* cob_type::copy_or_blend_pix( (value_type*)m_rbuf->row_ptr(x, y, 1) + x + x + x, c.r, c.g, c.b, c.a, cover);*/ }
public virtual void BlendPixel(int x, int y, RGBA_Bytes c, byte cover) { m_pixf.BlendPixel(x, y, c, cover); }
//-------------------------------------------------------------------- public unsafe void CopyVLine(int x, int y, uint len, RGBA_Bytes c) { int ScanWidth = m_rbuf.StrideInBytes; byte* p = (byte*)m_rbuf.GetPixelPointer(y) + x + x + x; byte cr = c.R; byte cg = c.G; byte cb = c.B; do { p[OrderR] = (byte)cr; p[OrderG] = (byte)cg; p[OrderB] = (byte)cb; p = &p[ScanWidth]; } while (--len != 0); }
public virtual void CopyVLine(int x, int y, uint len, RGBA_Bytes c) { m_pixf.CopyVLine(x, y, len, c); }
//-------------------------------------------------------------------- public void BlendVLine(int x, int y1, int y2, RGBA_Bytes c, byte cover) { int ScanWidth = m_rbuf.StrideInBytes; if (c.A != 0) { unsafe { int len = y2 - y1 + 1; byte* p = (byte*)m_rbuf.GetPixelPointer(y1) + x + x + x; uint alpha = (uint)(((int)(c.A) * (cover + 1)) >> 8); if (alpha == BaseMask) { byte cr = c.R; byte cg = c.G; byte cb = c.B; do { p[OrderR] = (byte)cr; p[OrderG] = (byte)cg; p[OrderB] = (byte)cb; p = &p[ScanWidth]; } while (--len != 0); } else { if (cover == 255) { do { m_Blender.BlendPix(p, c.R, c.G, c.B, alpha); p = &p[ScanWidth]; } while (--len != 0); } else { do { m_Blender.BlendPix(p, c.R, c.G, c.B, alpha); p = &p[ScanWidth]; } while (--len != 0); } } } } }
public virtual void BlendHLine(int x1, int y, int x2, RGBA_Bytes c, byte cover) { m_pixf.BlendHLine(x1, y, x2, c, cover); }
//-------------------------------------------------------------------- unsafe public void BlendSolidVSpan(int x, int y, uint len, RGBA_Bytes c, byte* covers) { if (c.A != 0) { int ScanWidth = m_rbuf.StrideInBytes; unchecked { byte* p = (byte*)m_rbuf.GetPixelPointer(y) + x + x + x; do { uint alpha = ((uint)(c.A) * ((uint)(*covers) + 1)) >> 8; if (alpha == BaseMask) { p[OrderR] = c.R; p[OrderG] = c.G; p[OrderB] = c.B; } else { m_Blender.BlendPix(p, c.R, c.G, c.B, alpha); } p = &p[ScanWidth]; ++covers; } while (--len != 0); } } }
public virtual void BlendVLine(int x, int y1, int y2, RGBA_Bytes c, byte cover) { m_pixf.BlendVLine(x, y1, y2, c, cover); }
//-------------------------------------------------------------------- public unsafe void CopyColorVSpan(int x, int y, uint len, RGBA_Bytes* colors) { int ScanWidth = m_rbuf.StrideInBytes; byte* p = m_rbuf.GetPixelPointer(y) + x + x + x; do { p[OrderR] = colors[0].R; p[OrderG] = colors[0].G; p[OrderB] = colors[0].B; p = &p[ScanWidth]; ++colors; } while (--len != 0); }
public unsafe virtual void BlendSolidVSpan(int x, int y, uint len, RGBA_Bytes c, byte* covers) { m_pixf.BlendSolidVSpan(x, y, len, c, covers); }
public unsafe void PixelLowRes(RGBA_Bytes** buf, RGBA_Bytes* p, int x, int y) { *p = buf[y][x]; }
public unsafe virtual void CopyColorVSpan(int x, int y, uint len, RGBA_Bytes* colors) { m_pixf.CopyColorVSpan(x, y, len, colors); }
//-------------------------------------------------------------------- public RGBA_Bytes Gradient(RGBA_Bytes c_8, double k) { RGBA_Doubles c = c_8.GetAsRGBA_Doubles(); return new RGBA_Doubles( R + (c.R - R) * k, G + (c.G - G) * k, B + (c.B - B) * k, A + (c.A - A) * k).GetAsRGBA_Bytes(); //return ret.GetAsRGBA_Bytes(); }
unsafe public void CopyColorHSpan(int x, int y, uint len, RGBA_Bytes* colors) { byte* p = m_rbuf.GetPixelPointer(y) + x * m_Step + m_Offset; do { *p = colors[0].R; p += m_Step; ++colors; } while (--len != 0); }