Ejemplo n.º 1
0
        public static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
        {
            stbtt__hheap        hh     = new stbtt__hheap();
            stbtt__active_edge *active = (null);
            int    y             = 0;
            int    j             = 0;
            int    i             = 0;
            float *scanline_data = stackalloc float[129];
            float *scanline;
            float *scanline2;

            if ((result->w) > (64))
            {
                scanline = (float *)(CRuntime.Malloc((ulong)((result->w * 2 + 1) * sizeof(float))));
            }
            else
            {
                scanline = scanline_data;
            }
            scanline2 = scanline + result->w;
            y         = off_y;
            e[n].y0   = (float)(off_y + result->h) + 1;
            while ((j) < (result->h))
            {
                float scan_y_top          = y + 0.0f;
                float scan_y_bottom       = y + 1.0f;
                stbtt__active_edge **step = &active;
                CRuntime.Memset(scanline, 0, (ulong)(result->w * sizeof(float)));
                CRuntime.Memset(scanline2, 0, (ulong)((result->w + 1) * sizeof(float)));
                while ((*step) != null)
                {
                    stbtt__active_edge *z = *step;
                    if (z->ey <= scan_y_top)
                    {
                        *step = z->next;
                        z->direction = 0;
                        stbtt__hheap_free(&hh, z);
                    }
                    else
                    {
                        step = &((*step)->next);
                    }
                }
                while (e->y0 <= scan_y_bottom)
                {
                    if (e->y0 != e->y1)
                    {
                        stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
                        if (z != (null))
                        {
                            if (((j) == (0)) && (off_y != 0))
                            {
                                if ((z->ey) < (scan_y_top))
                                {
                                    z->ey = scan_y_top;
                                }
                            }
                            z->next = active;
                            active  = z;
                        }
                    }
                    ++e;
                }
                if ((active) != null)
                {
                    stbtt__fill_active_edges_new(scanline, scanline2 + 1, result->w, active, scan_y_top);
                }
                {
                    float sum = 0;
                    for (i = 0; (i) < (result->w); ++i)
                    {
                        float k = 0;
                        int   m = 0;
                        sum += scanline2[i];
                        k    = scanline[i] + sum;
                        k    = CRuntime.Fabs(k) * 255 + 0.5f;
                        m    = ((int)(k));
                        if ((m) > (255))
                        {
                            m = 255;
                        }
                        result->pixels[j * result->stride + i] = ((byte)(m));
                    }
                }
                step = &active;
                while ((*step) != null)
                {
                    stbtt__active_edge *z = *step;
                    z->fx += z->fdx;
                    step   = &((*step)->next);
                }
                ++y;
                ++j;
            }
            stbtt__hheap_cleanup(&hh, userdata);
            if (scanline != scanline_data)
            {
                CRuntime.Free(scanline);
            }
        }
Ejemplo n.º 2
0
        public static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample,
                                                         int off_x, int off_y, void *userdata)
        {
            var hh = new stbtt__hheap();
            stbtt__active_edge *active = null;
            var    y             = 0;
            var    j             = 0;
            var    i             = 0;
            var    scanline_data = stackalloc float[129];
            float *scanline;
            float *scanline2;

            if (result->w > 64)
            {
                scanline = (float *)CRuntime.malloc((ulong)((result->w * 2 + 1) * sizeof(float)));
            }
            else
            {
                scanline = scanline_data;
            }
            scanline2 = scanline + result->w;
            y         = off_y;
            e[n].y0   = (float)(off_y + result->h) + 1;
            while (j < result->h)
            {
                var scan_y_top    = y + 0.0f;
                var scan_y_bottom = y + 1.0f;
                var step          = &active;
                CRuntime.memset(scanline, 0, (ulong)(result->w * sizeof(float)));
                CRuntime.memset(scanline2, 0, (ulong)((result->w + 1) * sizeof(float)));
                while (*step != null)
                {
                    var z = *step;
                    if (z->ey <= scan_y_top)
                    {
                        *step = z->next;
                        z->direction = 0;
                        stbtt__hheap_free(&hh, z);
                    }
                    else
                    {
                        step = &(*step)->next;
                    }
                }

                while (e->y0 <= scan_y_bottom)
                {
                    if (e->y0 != e->y1)
                    {
                        var z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
                        if (z != null)
                        {
                            if (j == 0 && off_y != 0)
                            {
                                if (z->ey < scan_y_top)
                                {
                                    z->ey = scan_y_top;
                                }
                            }

                            z->next = active;
                            active  = z;
                        }
                    }

                    ++e;
                }

                if (active != null)
                {
                    stbtt__fill_active_edges_new(scanline, scanline2 + 1, result->w, active, scan_y_top);
                }
                {
                    float sum = 0;
                    for (i = 0; i < result->w; ++i)
                    {
                        float k = 0;
                        var   m = 0;
                        sum += scanline2[i];
                        k    = scanline[i] + sum;
                        k    = CRuntime.fabs(k) * 255 + 0.5f;
                        m    = (int)k;
                        if (m > 255)
                        {
                            m = 255;
                        }
                        result->pixels[j * result->stride + i] = (byte)m;
                    }
                }

                step = &active;
                while (*step != null)
                {
                    var z = *step;
                    z->fx += z->fdx;
                    step   = &(*step)->next;
                }

                ++y;
                ++j;
            }

            stbtt__hheap_cleanup(&hh, userdata);
            if (scanline != scanline_data)
            {
                CRuntime.free(scanline);
            }
        }