示例#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)
        {
            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);
            }
        }
        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             = (int)(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         = (int)(off_y);
            e[n].y0   = (float)((float)(off_y + result->h) + 1);
            while ((j) < (result->h))
            {
                float scan_y_top          = (float)(y + 0.0f);
                float scan_y_bottom       = (float)(y + 1.0f);
                stbtt__active_edge **step = &active;
                CRuntime.memset(scanline, (int)(0), (ulong)(result->w * sizeof(float)));
                CRuntime.memset(scanline2, (int)(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 = (float)(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, (int)(off_x), (float)(scan_y_top), userdata);
                        if (z != (null))
                        {
                            if (((j) == (0)) && (off_y != 0))
                            {
                                if ((z->ey) < (scan_y_top))
                                {
                                    z->ey = (float)(scan_y_top);
                                }
                            }
                            z->next = active;
                            active  = z;
                        }
                    }
                    ++e;
                }
                if ((active) != null)
                {
                    stbtt__fill_active_edges_new(scanline, scanline2 + 1, (int)(result->w), active, (float)(scan_y_top));
                }
                {
                    float sum = (float)(0);
                    for (i = (int)(0); (i) < (result->w); ++i)
                    {
                        float k = 0;
                        int   m = 0;
                        sum += (float)(scanline2[i]);
                        k    = (float)(scanline[i] + sum);
                        k    = (float)((float)(CRuntime.fabs((double)(k))) * 255 + 0.5f);
                        m    = ((int)(k));
                        if ((m) > (255))
                        {
                            m = (int)(255);
                        }
                        result->pixels[j * result->stride + i] = ((byte)(m));
                    }
                }
                step = &active;
                while ((*step) != null)
                {
                    stbtt__active_edge *z = *step;
                    z->fx += (float)(z->fdx);
                    step   = &((*step)->next);
                }
                ++y;
                ++j;
            }
            stbtt__hheap_cleanup(&hh, userdata);
            if (scanline != scanline_data)
            {
                CRuntime.free(scanline);
            }
        }