Exemple #1
0
        public static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcount, int windings,
                                            float scale_x, float scale_y, float shift_x, float shift_y, int off_x, int off_y, int invert,
                                            void *userdata)
        {
            var          y_scale_inv = invert != 0 ? -scale_y : scale_y;
            stbtt__edge *e;
            var          n          = 0;
            var          i          = 0;
            var          j          = 0;
            var          k          = 0;
            var          m          = 0;
            var          vsubsample = 1;

            n = 0;
            for (i = 0; i < windings; ++i)
            {
                n += wcount[i];
            }

            e = (stbtt__edge *)CRuntime.malloc((ulong)(sizeof(stbtt__edge) * (n + 1)));
            if (e == null)
            {
                return;
            }
            n = 0;
            m = 0;
            for (i = 0; i < windings; ++i)
            {
                var p = pts + m;
                m += wcount[i];
                j  = wcount[i] - 1;
                for (k = 0; k < wcount[i]; j = k++)
                {
                    var a = k;
                    var b = j;
                    if (p[j].y == p[k].y)
                    {
                        continue;
                    }
                    e[n].invert = 0;
                    if (invert != 0 && p[j].y > p[k].y ||
                        invert == 0 && p[j].y < p[k].y)
                    {
                        e[n].invert = 1;
                        a           = j;
                        b           = k;
                    }

                    e[n].x0 = p[a].x * scale_x + shift_x;
                    e[n].y0 = (p[a].y * y_scale_inv + shift_y) * vsubsample;
                    e[n].x1 = p[b].x * scale_x + shift_x;
                    e[n].y1 = (p[b].y * y_scale_inv + shift_y) * vsubsample;
                    ++n;
                }
            }

            stbtt__sort_edges(e, n);
            stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, userdata);
            CRuntime.free(e);
        }
Exemple #2
0
        public static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcount, int windings, float scale_x, float scale_y, float shift_x, float shift_y, int off_x, int off_y, int invert, void *userdata)
        {
            float        y_scale_inv = (invert) != 0 ? -scale_y : scale_y;
            stbtt__edge *e;
            int          n          = 0;
            int          i          = 0;
            int          j          = 0;
            int          k          = 0;
            int          m          = 0;
            int          vsubsample = 1;

            n = 0;
            for (i = 0; (i) < (windings); ++i)
            {
                n += wcount[i];
            }
            e = (stbtt__edge *)(CRuntime.Malloc((ulong)(sizeof(stbtt__edge) * (n + 1))));
            if ((e) == (null))
            {
                return;
            }
            n = 0;
            m = 0;
            for (i = 0; (i) < (windings); ++i)
            {
                stbtt__point *p = pts + m;
                m += wcount[i];
                j  = wcount[i] - 1;
                for (k = 0; (k) < (wcount[i]); j = k++)
                {
                    int a = k;
                    int b = j;
                    if ((p[j].y) == (p[k].y))
                    {
                        continue;
                    }
                    e[n].invert = 0;
                    if ((((invert) != 0) && ((p[j].y) > (p[k].y))) || ((invert == 0) && ((p[j].y) < (p[k].y))))
                    {
                        e[n].invert = 1;
                        a           = j;
                        b           = k;
                    }
                    e[n].x0 = p[a].x * scale_x + shift_x;
                    e[n].y0 = (p[a].y * y_scale_inv + shift_y) * vsubsample;
                    e[n].x1 = p[b].x * scale_x + shift_x;
                    e[n].y1 = (p[b].y * y_scale_inv + shift_y) * vsubsample;
                    ++n;
                }
            }
            stbtt__sort_edges(e, n);
            stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, userdata);
            CRuntime.Free(e);
        }
        public static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcount, int windings, float scale_x, float scale_y, float shift_x, float shift_y, int off_x, int off_y, int invert, void *userdata)
        {
            float        y_scale_inv = (float)((invert) != 0 ? -scale_y : scale_y);
            stbtt__edge *e;
            int          n          = 0;
            int          i          = 0;
            int          j          = 0;
            int          k          = 0;
            int          m          = 0;
            int          vsubsample = (int)(1);

            n = (int)(0);
            for (i = (int)(0); (i) < (windings); ++i)
            {
                n += (int)(wcount[i]);
            }
            e = (stbtt__edge *)(CRuntime.malloc((ulong)(sizeof(stbtt__edge) * (n + 1))));
            if ((e) == (null))
            {
                return;
            }
            n = (int)(0);
            m = (int)(0);
            for (i = (int)(0); (i) < (windings); ++i)
            {
                stbtt__point *p = pts + m;
                m += (int)(wcount[i]);
                j  = (int)(wcount[i] - 1);
                for (k = (int)(0); (k) < (wcount[i]); j = (int)(k++))
                {
                    int a = (int)(k);
                    int b = (int)(j);
                    if ((p[j].y) == (p[k].y))
                    {
                        continue;
                    }
                    e[n].invert = (int)(0);
                    if ((((invert) != 0) && ((p[j].y) > (p[k].y))) || ((invert == 0) && ((p[j].y) < (p[k].y))))
                    {
                        e[n].invert = (int)(1);
                        a           = (int)(j);
                        b           = (int)(k);
                    }
                    e[n].x0 = (float)(p[a].x * scale_x + shift_x);
                    e[n].y0 = (float)((p[a].y * y_scale_inv + shift_y) * vsubsample);
                    e[n].x1 = (float)(p[b].x * scale_x + shift_x);
                    e[n].y1 = (float)((p[b].y * y_scale_inv + shift_y) * vsubsample);
                    ++n;
                }
            }
            stbtt__sort_edges(e, (int)(n));
            stbtt__rasterize_sorted_edges(result, e, (int)(n), (int)(vsubsample), (int)(off_x), (int)(off_y), userdata);
            CRuntime.free(e);
        }
Exemple #4
0
        public static void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)
        {
            float         scale           = (scale_x) > (scale_y) ? scale_y : scale_x;
            int           winding_count   = 0;
            int *         winding_lengths = (null);
            stbtt__point *windings        = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata);

            if ((windings) != null)
            {
                stbtt__rasterize(result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, userdata);
                CRuntime.Free(winding_lengths);
                CRuntime.Free(windings);
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
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);
            }
        }