Exemple #1
0
        public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
            int bytesBetweenPixelsInclusive    = srcRW.BytesBetweenPixelsInclusive;
            ISpanInterpolator spanInterpolator = Interpolator;

            spanInterpolator.Begin(x + dx, y + dy, len);
            int x_hr;
            int y_hr;

            spanInterpolator.GetCoord(out x_hr, out y_hr);
            int x_lr = x_hr >> img_subpix_const.SHIFT;
            int y_lr = y_hr >> img_subpix_const.SHIFT;
            int bufferIndex;

            bufferIndex = srcRW.GetByteBufferOffsetXY(x_lr, y_lr);

            unsafe
            {
                TempMemPtr srcBuffPtr = srcRW.GetBufferPtr();
                byte *     pSource    = (byte *)srcBuffPtr.Ptr;
                {
                    do
                    {
                        //outputColors[startIndex].red = pSource[bufferIndex];
                        //outputColors[startIndex].green = pSource[bufferIndex];
                        //outputColors[startIndex].blue = pSource[bufferIndex];
                        //outputColors[startIndex].alpha = 255;

                        byte grayValue = pSource[bufferIndex];
                        outputColors[startIndex] = Drawing.Color.FromArgb(255,
                                                                          grayValue,
                                                                          grayValue,
                                                                          grayValue);

                        startIndex++;
                        bufferIndex += bytesBetweenPixelsInclusive;
                    } while (--len != 0);
                }
                srcBuffPtr.Release();
            }
        }
Exemple #2
0
        public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
#if DEBUG
            int tmp_len = len;
#endif
            unsafe
            {
                //TODO: review here

                if (_mode0)
                {
                    TempMemPtr srcBufferPtr = srcRW.GetBufferPtr();
                    byte *     srcBuffer    = (byte *)srcBufferPtr.BytePtr;
                    int        bufferIndex  = srcRW.GetByteBufferOffsetXY(x, y);
                    //unsafe
                    {
#if true
                        do
                        {
                            //TODO: review here, match component?
                            //ORDER IS IMPORTANT!
                            //TODO : use CO (color order instead)
                            byte b = (byte)srcBuffer[bufferIndex++];
                            byte g = (byte)srcBuffer[bufferIndex++];
                            byte r = (byte)srcBuffer[bufferIndex++];
                            byte a = (byte)srcBuffer[bufferIndex++];

                            outputColors[startIndex] = Drawing.Color.FromArgb(a, r, g, b);

                            ++startIndex;
                        } while (--len != 0);
#else
                        fixed(byte *pSource = &fg_ptr[bufferIndex])
                        {
                            int *pSourceInt = (int *)pSource;

                            fixed(RGBA_Bytes *pDest = &span[spanIndex])
                            {
                                int *pDestInt = (int *)pDest;

                                do
                                {
                                    *pDestInt++ = *pSourceInt++;
                                } while (--len != 0);
                            }
                        }
#endif
                    }
                    srcBufferPtr.Release();
                    return;
                }
                else
                {
                    try
                    {
                        ISpanInterpolator spanInterpolator = base.Interpolator;
                        TempMemPtr        srcBufferPtr     = srcRW.GetBufferPtr();
                        byte *            srcBuffer        = (byte *)srcBufferPtr.BytePtr;

                        spanInterpolator.Begin(x + base.dx, y + base.dy, len);
                        int accColor0, accColor1, accColor2, accColor3;
                        int back_r = m_bgcolor.red;
                        int back_g = m_bgcolor.green;
                        int back_b = m_bgcolor.blue;
                        int back_a = m_bgcolor.alpha;
                        int maxx   = srcRW.Width - 1;
                        int maxy   = srcRW.Height - 1;

                        unchecked
                        {
                            do
                            {
                                int x_hr;
                                int y_hr;
                                spanInterpolator.GetCoord(out x_hr, out y_hr);
                                x_hr -= base.dxInt;
                                y_hr -= base.dyInt;
                                int x_lr = x_hr >> img_subpix_const.SHIFT;
                                int y_lr = y_hr >> img_subpix_const.SHIFT;
                                int weight;
                                if (x_lr >= 0 && y_lr >= 0 &&
                                    x_lr < maxx && y_lr < maxy)
                                {
                                    int bufferIndex = srcRW.GetByteBufferOffsetXY(x_lr, y_lr);


                                    accColor0             =
                                        accColor1         =
                                            accColor2     =
                                                accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2;
                                    x_hr       &= (int)img_subpix_const.MASK;
                                    y_hr       &= (int)img_subpix_const.MASK;
                                    bufferIndex = srcRW.GetByteBufferOffsetXY(x_lr, y_lr);
                                    weight      = (((int)img_subpix_const.SCALE - x_hr) *
                                                   ((int)img_subpix_const.SCALE - y_hr));
                                    if (weight > BASE_MASK)
                                    {
                                        accColor0 += weight * srcBuffer[bufferIndex + CO.R];
                                        accColor1 += weight * srcBuffer[bufferIndex + CO.G];
                                        accColor2 += weight * srcBuffer[bufferIndex + CO.B];
                                        accColor3 += weight * srcBuffer[bufferIndex + CO.A];
                                    }

                                    weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr));
                                    if (weight > BASE_MASK)
                                    {
                                        bufferIndex += bytesBetweenPixelInclusive;
                                        accColor0   += weight * srcBuffer[bufferIndex + CO.R];
                                        accColor1   += weight * srcBuffer[bufferIndex + CO.G];
                                        accColor2   += weight * srcBuffer[bufferIndex + CO.B];
                                        accColor3   += weight * srcBuffer[bufferIndex + CO.A];
                                    }

                                    weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr);
                                    if (weight > BASE_MASK)
                                    {
                                        ++y_lr;
                                        bufferIndex = srcRW.GetByteBufferOffsetXY(x_lr, y_lr);
                                        accColor0  += weight * srcBuffer[bufferIndex + CO.R];
                                        accColor1  += weight * srcBuffer[bufferIndex + CO.G];
                                        accColor2  += weight * srcBuffer[bufferIndex + CO.B];
                                        accColor3  += weight * srcBuffer[bufferIndex + CO.A];
                                    }
                                    weight = (x_hr * y_hr);
                                    if (weight > BASE_MASK)
                                    {
                                        bufferIndex += bytesBetweenPixelInclusive;
                                        accColor0   += weight * srcBuffer[bufferIndex + CO.R];
                                        accColor1   += weight * srcBuffer[bufferIndex + CO.G];
                                        accColor2   += weight * srcBuffer[bufferIndex + CO.B];
                                        accColor3   += weight * srcBuffer[bufferIndex + CO.A];
                                    }
                                    accColor0 >>= img_subpix_const.SHIFT * 2;
                                    accColor1 >>= img_subpix_const.SHIFT * 2;
                                    accColor2 >>= img_subpix_const.SHIFT * 2;
                                    accColor3 >>= img_subpix_const.SHIFT * 2;
                                }
                                else
                                {
                                    if (x_lr < -1 || y_lr < -1 ||
                                        x_lr > maxx || y_lr > maxy)
                                    {
                                        accColor0 = back_r;
                                        accColor1 = back_g;
                                        accColor2 = back_b;
                                        accColor3 = back_a;
                                    }
                                    else
                                    {
                                        accColor0             =
                                            accColor1         =
                                                accColor2     =
                                                    accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2;
                                        x_hr  &= (int)img_subpix_const.MASK;
                                        y_hr  &= (int)img_subpix_const.MASK;
                                        weight = (((int)img_subpix_const.SCALE - x_hr) *
                                                  ((int)img_subpix_const.SCALE - y_hr));
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(
                                                    ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                    srcBuffer,
                                                    srcRW.GetByteBufferOffsetXY(x_lr, y_lr),
                                                    weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr++;
                                        weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr));
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   srcRW.GetByteBufferOffsetXY(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr--;
                                        y_lr++;
                                        weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr);
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   srcRW.GetByteBufferOffsetXY(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr++;
                                        weight = (x_hr * y_hr);
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   srcRW.GetByteBufferOffsetXY(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        accColor0 >>= img_subpix_const.SHIFT * 2;
                                        accColor1 >>= img_subpix_const.SHIFT * 2;
                                        accColor2 >>= img_subpix_const.SHIFT * 2;
                                        accColor3 >>= img_subpix_const.SHIFT * 2;
                                    }
                                }

#if DEBUG
                                if (startIndex >= outputColors.Length)
                                {
                                }
#endif
                                outputColors[startIndex] = PixelFarm.Drawing.Color.FromArgb(
                                    (byte)accColor3,
                                    (byte)accColor0,
                                    (byte)accColor1,
                                    (byte)accColor2
                                    );

                                //outputColors[startIndex].red = (byte)accColor0;
                                //outputColors[startIndex].green = (byte)accColor1;
                                //outputColors[startIndex].blue = (byte)accColor2;
                                //outputColors[startIndex].alpha = (byte)accColor3;
                                ++startIndex;
                                spanInterpolator.Next();
                            } while (--len != 0);
                        }

                        srcBufferPtr.Release();
                    }
                    catch (Exception ex1)
                    {
                    }
                }
            }
        }