public static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n) { int i = 0; int j = 0; for (i = 1; (i) < (n); ++i) { stbtt__edge t = p[i]; stbtt__edge *a = &t; j = i; while ((j) > (0)) { stbtt__edge *b = &p[j - 1]; int c = a->y0 < b->y0 ? 1 : 0; if (c == 0) { break; } p[j] = p[j - 1]; --j; } if (i != j) { p[j] = t; } } }
public static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n) { var i = 0; var j = 0; for (i = 1; i < n; ++i) { var t = p[i]; var a = &t; j = i; while (j > 0) { var b = &p[j - 1]; var c = a->y0 < b->y0 ? 1 : 0; if (c == 0) { break; } p[j] = p[j - 1]; --j; } if (i != j) { p[j] = t; } } }
public static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n) { int i = 0; int j = 0; for (i = (int)(1); (i) < (n); ++i) { stbtt__edge t = (stbtt__edge)(p[i]); stbtt__edge *a = &t; j = (int)(i); while ((j) > (0)) { stbtt__edge *b = &p[j - 1]; int c = (int)(a->y0 < b->y0 ? 1 : 0); if (c == 0) { break; } p[j] = (stbtt__edge)(p[j - 1]); --j; } if (i != j) { p[j] = (stbtt__edge)(t); } } }
public static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) { stbtt__active_edge *z = (stbtt__active_edge *)(stbtt__hheap_alloc(hh, (ulong)(sizeof(stbtt__active_edge)), userdata)); float dxdy = (float)((e->x1 - e->x0) / (e->y1 - e->y0)); if (z == null) { return(z); } z->fdx = (float)(dxdy); z->fdy = (float)(dxdy != 0.0f ? (1.0f / dxdy) : 0.0f); z->fx = (float)(e->x0 + dxdy * (start_point - e->y0)); z->fx -= (float)(off_x); z->direction = (float)((e->invert) != 0 ? 1.0f : -1.0f); z->sy = (float)(e->y0); z->ey = (float)(e->y1); z->next = null; return(z); }
public static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) { var z = (stbtt__active_edge *)stbtt__hheap_alloc(hh, (ulong)sizeof(stbtt__active_edge), userdata); var dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); if (z == null) { return(z); } z->fdx = dxdy; z->fdy = dxdy != 0.0f ? 1.0f / dxdy : 0.0f; z->fx = e->x0 + dxdy * (start_point - e->y0); z->fx -= off_x; z->direction = e->invert != 0 ? 1.0f : -1.0f; z->sy = e->y0; z->ey = e->y1; z->next = null; return(z); }
public static void stbtt__sort_edges(stbtt__edge *p, int n) { stbtt__sort_edges_quicksort(p, n); stbtt__sort_edges_ins_sort(p, n); }
public static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n) { while ((n) > (12)) { stbtt__edge t = new stbtt__edge(); int c01 = 0; int c12 = 0; int c = 0; int m = 0; int i = 0; int j = 0; m = n >> 1; c01 = ((&p[0])->y0) < ((&p[m])->y0) ? 1 : 0; c12 = ((&p[m])->y0) < ((&p[n - 1])->y0) ? 1 : 0; if (c01 != c12) { int z = 0; c = ((&p[0])->y0) < ((&p[n - 1])->y0) ? 1 : 0; z = ((c) == (c12)) ? 0 : n - 1; t = p[z]; p[z] = p[m]; p[m] = t; } t = p[0]; p[0] = p[m]; p[m] = t; i = 1; j = n - 1; for (; ;) { for (; ; ++i) { if (!(((&p[i])->y0) < ((&p[0])->y0))) { break; } } for (; ; --j) { if (!(((&p[0])->y0) < ((&p[j])->y0))) { break; } } if ((i) >= (j)) { break; } t = p[i]; p[i] = p[j]; p[j] = t; ++i; --j; } if ((j) < (n - i)) { stbtt__sort_edges_quicksort(p, j); p = p + i; n = n - i; } else { stbtt__sort_edges_quicksort(p + i, n - i); n = j; } } }
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); } }
public static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n) { while (n > 12) { var t = new stbtt__edge(); var c01 = 0; var c12 = 0; var c = 0; var m = 0; var i = 0; var j = 0; m = n >> 1; c01 = (&p[0])->y0 < (&p[m])->y0 ? 1 : 0; c12 = (&p[m])->y0 < (&p[n - 1])->y0 ? 1 : 0; if (c01 != c12) { var z = 0; c = (&p[0])->y0 < (&p[n - 1])->y0 ? 1 : 0; z = c == c12 ? 0 : n - 1; t = p[z]; p[z] = p[m]; p[m] = t; } t = p[0]; p[0] = p[m]; p[m] = t; i = 1; j = n - 1; for (; ;) { for (; ; ++i) { if (!((&p[i])->y0 < (&p[0])->y0)) { break; } } for (; ; --j) { if (!((&p[0])->y0 < (&p[j])->y0)) { break; } } if (i >= j) { break; } t = p[i]; p[i] = p[j]; p[j] = t; ++i; --j; } if (j < n - i) { stbtt__sort_edges_quicksort(p, j); p = p + i; n = n - i; } else { stbtt__sort_edges_quicksort(p + i, n - i); n = j; } } }
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__sort_edges_quicksort(stbtt__edge *p, int n) { while ((n) > (12)) { stbtt__edge t = new stbtt__edge(); int c01 = 0; int c12 = 0; int c = 0; int m = 0; int i = 0; int j = 0; m = (int)(n >> 1); c01 = (int)(((&p[0])->y0) < ((&p[m])->y0) ? 1 : 0); c12 = (int)(((&p[m])->y0) < ((&p[n - 1])->y0) ? 1 : 0); if (c01 != c12) { int z = 0; c = (int)(((&p[0])->y0) < ((&p[n - 1])->y0) ? 1 : 0); z = (int)(((c) == (c12)) ? 0 : n - 1); t = (stbtt__edge)(p[z]); p[z] = (stbtt__edge)(p[m]); p[m] = (stbtt__edge)(t); } t = (stbtt__edge)(p[0]); p[0] = (stbtt__edge)(p[m]); p[m] = (stbtt__edge)(t); i = (int)(1); j = (int)(n - 1); for (; ;) { for (; ; ++i) { if (!(((&p[i])->y0) < ((&p[0])->y0))) { break; } } for (; ; --j) { if (!(((&p[0])->y0) < ((&p[j])->y0))) { break; } } if ((i) >= (j)) { break; } t = (stbtt__edge)(p[i]); p[i] = (stbtt__edge)(p[j]); p[j] = (stbtt__edge)(t); ++i; --j; } if ((j) < (n - i)) { stbtt__sort_edges_quicksort(p, (int)(j)); p = p + i; n = (int)(n - i); } else { stbtt__sort_edges_quicksort(p + i, (int)(n - i)); n = (int)(j); } } }
public static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n) { while ((n) > (12)) { stbtt__edge t = new stbtt__edge(); int c01 = 0; int c12 = 0; int c = 0; int m = 0; int i = 0; int j = 0; m = (int)(n >> 1); c01 = (int)(((&p[0])->y0) < ((&p[m])->y0) ? 1 : 0); c12 = (int)(((&p[m])->y0) < ((&p[n - 1])->y0) ? 1 : 0); if (c01 != c12) { int z = 0; c = (int)(((&p[0])->y0) < ((&p[n - 1])->y0) ? 1 : 0); z = (int)(((c) == (c12)) ? 0 : n - 1); t = (stbtt__edge)(p[z]); p[z] = (stbtt__edge)(p[m]); p[m] = (stbtt__edge)(t); } t = (stbtt__edge)(p[0]); p[0] = (stbtt__edge)(p[m]); p[m] = (stbtt__edge)(t); i = (int)(1); j = (int)(n - 1); for (; ;) { #pragma warning disable CS1717 // Assignment made to same variable for (i = (int)(i); ; ++i) { if (!(((&p[i])->y0) < ((&p[0])->y0))) { break; } } for (j = (int)(j); ; --j) { if (!(((&p[0])->y0) < ((&p[j])->y0))) { break; } } if ((i) >= (j)) { break; } t = (stbtt__edge)(p[i]); p[i] = (stbtt__edge)(p[j]); p[j] = (stbtt__edge)(t); ++i; --j; #pragma warning restore CS1717 // Assignment made to same variable } if ((j) < (n - i)) { stbtt__sort_edges_quicksort(p, (int)(j)); p = p + i; n = (int)(n - i); } else { stbtt__sort_edges_quicksort(p + i, (int)(n - i)); n = (int)(j); } } }