bool pdf_plot_path(const float *p, unsigned int n, colour fill, float width, colour c, const float transform[6]) { unsigned int i; bool empty_path; #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "."); #endif if (n == 0) return true; if (c == NS_TRANSPARENT && fill == NS_TRANSPARENT) return true; if (p[0] != PLOTTER_PATH_MOVE) return false; apply_clip_and_mode(false, fill, c, width, DashPattern_eNone); empty_path = true; for (i = 0 ; i < n ; ) { if (p[i] == PLOTTER_PATH_MOVE) { HPDF_Page_MoveTo(pdf_page, transform_x(transform, p[i+1], p[i+2]), transform_y(transform, p[i+1], p[i+2])); i+= 3; } else if (p[i] == PLOTTER_PATH_CLOSE) { if (!empty_path) HPDF_Page_ClosePath(pdf_page); i++; } else if (p[i] == PLOTTER_PATH_LINE) { HPDF_Page_LineTo(pdf_page, transform_x(transform, p[i+1], p[i+2]), transform_y(transform, p[i+1], p[i+2])); i+=3; empty_path = false; } else if (p[i] == PLOTTER_PATH_BEZIER) { HPDF_Page_CurveTo(pdf_page, transform_x(transform, p[i+1], p[i+2]), transform_y(transform, p[i+1], p[i+2]), transform_x(transform, p[i+3], p[i+4]), transform_y(transform, p[i+3], p[i+4]), transform_x(transform, p[i+5], p[i+6]), transform_y(transform, p[i+5], p[i+6])); i += 7; empty_path = false; } else { NSLOG(netsurf, INFO, "bad path command %f", p[i]); return false; } } if (empty_path) { HPDF_Page_EndPath(pdf_page); return true; } if (fill != NS_TRANSPARENT) { if (c != NS_TRANSPARENT) HPDF_Page_FillStroke(pdf_page); else HPDF_Page_Fill(pdf_page); } else HPDF_Page_Stroke(pdf_page); return true; }
void VectorView::on_display() { set_ortho_projection(); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_1D); glPolygonMode(GL_FRONT_AND_BACK, pmode ? GL_LINE : GL_FILL); // initial grid point and grid step double gt = gs; if (hexa) gt *= sqrt(3.0)/2.0; double max_length = 0.0; // transform all vertices vec.lock_data(); int i; int nv = vec.get_num_vertices(); double4* vert = vec.get_vertices(); double2* tvert = new double2[nv]; for (i = 0; i < nv; i++) { tvert[i][0] = transform_x(vert[i][0]); tvert[i][1] = transform_y(vert[i][1]); // find max length of vectors double length = sqr(vert[i][2]) + sqr(vert[i][3]); if (length > max_length) max_length = length; } max_length = sqrt(max_length); // value range double min = range_min, max = range_max; if (range_auto) { min = vec.get_min_value(); max = vec.get_max_value(); } double irange = 1.0 / (max - min); // special case: constant solution if (fabs(min - max) < 1e-8) { irange = 1.0; min -= 0.5; } // draw all triangles int3* xtris = vec.get_triangles(); if (mode != 1) glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id); glBegin(GL_TRIANGLES); glColor3f(0.95f, 0.95f, 0.95f); for (i = 0; i < vec.get_num_triangles(); i++) { double mag = sqrt(sqr(vert[xtris[i][0]][2]) + sqr(vert[xtris[i][0]][3])); glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0); glVertex2d(tvert[xtris[i][0]][0], tvert[xtris[i][0]][1]); mag = sqrt(sqr(vert[xtris[i][1]][2]) + sqr(vert[xtris[i][1]][3])); glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0); glVertex2d(tvert[xtris[i][1]][0], tvert[xtris[i][1]][1]); mag = sqrt(sqr(vert[xtris[i][2]][2]) + sqr(vert[xtris[i][2]][3])); glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0); glVertex2d(tvert[xtris[i][2]][0], tvert[xtris[i][2]][1]); } glEnd(); glDisable(GL_TEXTURE_1D); // draw all edges /*if (mode == 0) glColor3f(0.3, 0.3, 0.3); else*/ glColor3f(0.5, 0.5, 0.5); glBegin(GL_LINES); int3* edges = vec.get_edges(); for (i = 0; i < vec.get_num_edges(); i++) { if (lines || edges[i][2] != 0) { glVertex2d(tvert[edges[i][0]][0], tvert[edges[i][0]][1]); glVertex2d(tvert[edges[i][1]][0], tvert[edges[i][1]][1]); } } glEnd(); // draw dashed edges if (lines) { glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0xCCCC); glBegin(GL_LINES); int2* dashes = vec.get_dashes(); for (i = 0; i < vec.get_num_dashes(); i++) { glVertex2d(tvert[dashes[i][0]][0], tvert[dashes[i][0]][1]); glVertex2d(tvert[dashes[i][1]][0], tvert[dashes[i][1]][1]); } glEnd(); glDisable(GL_LINE_STIPPLE); } // draw arrows if (mode != 2) { for (i = 0; i < vec.get_num_triangles(); i++) { double miny = 1e100; int idx, k, l1, l2, r2, r1, s; double lry, x; double mr, ml, lx, rx, xval, yval; double wh = output_height + gt, ww = output_width + gs; if ((tvert[xtris[i][0]][0] < -gs) && (tvert[xtris[i][1]][0] < -gs) && (tvert[xtris[i][2]][0] < -gs)) continue; if ((tvert[xtris[i][0]][0] > ww) && (tvert[xtris[i][1]][0] > ww) && (tvert[xtris[i][2]][0] > ww)) continue; if ((tvert[xtris[i][0]][1] < -gt) && (tvert[xtris[i][1]][1] < -gt) && (tvert[xtris[i][2]][1] < -gt)) continue; if ((tvert[xtris[i][0]][1] > wh) && (tvert[xtris[i][1]][1] > wh) && (tvert[xtris[i][2]][1] > wh)) continue; // find vertex with min y-coordinate for (k = 0; k < 3; k++) if (tvert[xtris[i][k]][1] < miny) miny = tvert[xtris[i][idx = k]][1]; l1 = r1 = xtris[i][idx]; l2 = xtris[i][n_vert(idx)]; r2 = xtris[i][p_vert(idx)]; // plane of x and y values on triangle double a[2], b[2], c[2], d[2]; for (int n = 0; n < 2; n++) { a[n] = (tvert[l1][1] - tvert[l2][1])*(vert[r1][2 +n] - vert[r2][2+n]) - (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][1] - tvert[r2][1]); b[n] = (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][0] - tvert[r2][0]) - (tvert[l1][0] - tvert[l2][0])*(vert[r1][2+n] - vert[r2][2+n]); c[n] = (tvert[l1][0] - tvert[l2][0])*(tvert[r1][1] - tvert[r2][1]) - (tvert[l1][1] - tvert[l2][1])*(tvert[r1][0] - tvert[r2][0]); d[n] = -a[n] * tvert[l1][0] - b[n] * tvert[l1][1] - c[n] * vert[l1][2+n]; a[n] /= c[n]; b[n] /= c[n]; d[n] /= c[n]; } s = (int) ceil((tvert[l1][1] - gy)/gt); // first step lry = gy + s*gt; bool shift = hexa && (s & 1); // if there are two points with min y-coordinate, switch to the next segment if ((tvert[l1][1] == tvert[l2][1]) || (tvert[r1][1] == tvert[r2][1])) if (tvert[l1][1] == tvert[l2][1]) {l1 = l2; l2 = r2;} else if (tvert[r1][1] == tvert[r2][1]) {r1 = r2; r2 = l2;} // slope of the left and right segment ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]); mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]); // x-coordinates of the endpoints of the first line lx = tvert[l1][0] + ml * (lry - (tvert[l1][1])); rx = tvert[r1][0] + mr * (lry - (tvert[r1][1])); if (lry < -gt) { k = (int) floor(-lry/gt); lry += gt * k; lx += k * ml * gt; rx += k * mr * gt; } // while we are in triangle while (((lry < tvert[l2][1]) || (lry < tvert[r2][1])) && (lry < wh)) { // while we are in the segment while (((lry <= tvert[l2][1]) && (lry <= tvert[r2][1])) && (lry < wh)) { double gz = gx; if (shift) gz -= 0.5*gs; s = (int) ceil((lx - gz)/gs); x = gz + s*gs; if (hexa) shift = !shift; if (x < -gs) { k = (int) floor(-x/gs); x += gs * k; } // go along the line while ((x < rx) && (x < ww)) { // plot the arrow xval = -a[0]*x - b[0]*lry - d[0]; yval = -a[1]*x - b[1]*lry - d[1]; plot_arrow(x, lry, xval, yval, max, min, gs); x += gs; } // move to the next line lx += ml*gt; rx += mr*gt; lry += gt; } // change segment if (lry >= tvert[l2][1]) { l1 = l2; l2 = r2; ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]); lx = tvert[l1][0] + ml * (lry - (tvert[l1][1])); } else { r1 = r2; r2 = l2; mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]); rx = tvert[r1][0] + mr * (lry - (tvert[r1][1])); } } } } delete [] tvert; vec.unlock_data(); }
enum piglit_result test_format(int format_index) { const struct format *format = &formats[format_index]; GLuint tex, bo; bool is_rg = (format->channels == R || format->channels == RG); bool is_arb = (format->channels == I || format->channels == L || format->channels == LA || format->channels == A); bool is_rgb32 = (format->channels == RGB); bool pass = true; int data_components, num_samples; int i; bool returns_float = (format->norm || format->type == GL_FLOAT || format->type == GL_HALF_FLOAT); bool returns_int = (!format->norm && (format->type == GL_BYTE || format->type == GL_SHORT || format->type == GL_INT)); bool returns_uint = (!format->norm && (format->type == GL_UNSIGNED_BYTE || format->type == GL_UNSIGNED_SHORT || format->type == GL_UNSIGNED_INT)); struct program *prog; if (returns_float) prog = &prog_f; else if (returns_int) prog = &prog_i; else prog = &prog_u; glUseProgram(prog->prog); if (test_arb != is_arb) return PIGLIT_SKIP; if (is_rgb32 && !test_rgb32) return PIGLIT_SKIP; /* These didn't exist in the extension before being promoted to * GL 3.1. */ if (is_rg && piglit_get_gl_version() < 31) return PIGLIT_SKIP; printf("Testing %s\n", piglit_get_gl_enum_name(format->format)); glGenBuffers(1, &bo); glBindBuffer(GL_TEXTURE_BUFFER, bo); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_BUFFER, tex); glTexBuffer(GL_TEXTURE_BUFFER, format->format, bo); switch (format->type) { case GL_BYTE: case GL_UNSIGNED_BYTE: glBufferData(GL_TEXTURE_BUFFER, sizeof(uint8_data), uint8_data, GL_STATIC_READ); data_components = ARRAY_SIZE(uint8_data); break; case GL_SHORT: case GL_UNSIGNED_SHORT: glBufferData(GL_TEXTURE_BUFFER, sizeof(uint16_data), uint16_data, GL_STATIC_READ); data_components = ARRAY_SIZE(uint16_data); break; case GL_INT: case GL_UNSIGNED_INT: glBufferData(GL_TEXTURE_BUFFER, sizeof(uint32_data), uint32_data, GL_STATIC_READ); data_components = ARRAY_SIZE(uint32_data); break; case GL_FLOAT: glBufferData(GL_TEXTURE_BUFFER, sizeof(float_data), float_data, GL_STATIC_READ); data_components = ARRAY_SIZE(float_data); break; case GL_HALF_FLOAT: { unsigned short hf_data[ARRAY_SIZE(float_data)]; for (i = 0; i < ARRAY_SIZE(float_data); i++) { hf_data[i] = piglit_half_from_float(float_data[i]); } glBufferData(GL_TEXTURE_BUFFER, sizeof(hf_data), hf_data, GL_STATIC_READ); data_components = ARRAY_SIZE(float_data); break; } default: printf("line %d, bad type: %s\n", __LINE__, piglit_get_gl_enum_name(format->type)); return PIGLIT_SKIP; } num_samples = data_components / format->components; for (i = 0; i < num_samples; i++) { float x1 = 5 + i * 10; float x2 = 10 + i * 10; float y1 = piglit_height - (5 + y_index * 10); float y2 = piglit_height - (10 + y_index * 10); GLfloat verts[8] = { transform_x(x1), transform_y(y1), transform_x(x2), transform_y(y1), transform_x(x2), transform_y(y2), transform_x(x1), transform_y(y2), }; float expected_f[4]; uint32_t expected_i[4]; const float green[4] = {0, 1, 0, 0}; if (returns_float) { if (!get_expected_f(format, i, expected_f)) return PIGLIT_SKIP; glUniform4fv(prog->expected_location, 1, expected_f); } else { if (!get_expected_i(format, i, expected_i)) return PIGLIT_SKIP; if (returns_uint) { glUniform4uiv(prog->expected_location, 1, expected_i); } else { glUniform4iv(prog->expected_location, 1, (int *)expected_i); } } glUniform1i(prog->pos_location, i); glBufferData(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_STREAM_DRAW); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); if (pass && !piglit_probe_rect_rgba(x1, y2, x2 - x1, y1 - y2, green)) { if (returns_int) { printf(" Texel: %d %d %d %d\n", expected_i[0], expected_i[1], expected_i[2], expected_i[3]); } else if (returns_uint) { printf(" Texel: %u %u %u %u\n", expected_i[0], expected_i[1], expected_i[2], expected_i[3]); } else { printf(" Texel: %f %f %f %f\n", expected_f[0], expected_f[1], expected_f[2], expected_f[3]); } pass = false; } } glDeleteBuffers(1, &bo); glDeleteTextures(1, &tex); glUseProgram(0); y_index++; piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, "%s", piglit_get_gl_enum_name(format->format)); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
void OrderView::on_display() { set_ortho_projection(); glDisable(GL_TEXTURE_1D); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); // transform all vertices ord.lock_data(); int i, nv = ord.get_num_vertices(); double3* vert = ord.get_vertices(); double2* tvert = malloc_with_check<double2>(nv); for (i = 0; i < nv; i++) { tvert[i][0] = transform_x(vert[i][0]); tvert[i][1] = transform_y(vert[i][1]); } // draw all triangles int3* tris = ord.get_triangles(); glBegin(GL_TRIANGLES); for (i = 0; i < ord.get_num_triangles(); i++) { const float* color = order_colors[(int)vert[tris[i][0]][2]]; glColor3f(color[0], color[1], color[2]); glVertex2d(tvert[tris[i][0]][0], tvert[tris[i][0]][1]); glVertex2d(tvert[tris[i][1]][0], tvert[tris[i][1]][1]); glVertex2d(tvert[tris[i][2]][0], tvert[tris[i][2]][1]); } glEnd(); // draw all edges if (pal_type == 0) glColor3f(0.4f, 0.4f, 0.4f); else if (pal_type == 1) glColor3f(1.0f, 1.0f, 1.0f); else glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_LINES); int2* edges = ord.get_edges(); for (i = 0; i < ord.get_num_edges(); i++) { glVertex2d(tvert[edges[i][0]][0], tvert[edges[i][0]][1]); glVertex2d(tvert[edges[i][1]][0], tvert[edges[i][1]][1]); } glEnd(); // draw labels if (b_orders) { int* lvert; char** ltext; double2* lbox; int nl = ord.get_labels(lvert, ltext, lbox); for (i = 0; i < nl; i++) if (lbox[i][0] * scale > get_text_width(ltext[i]) && lbox[i][1] * scale > 13) { //color = get_palette_color((vert[lvert[i]][2] - 1) / 9.0); const float* color = order_colors[(int)vert[lvert[i]][2]]; if ((color[0] * 0.39f + color[1] * 0.50f + color[2] * 0.11f) > 0.5f) glColor3f(0, 0, 0); else glColor3f(1, 1, 1); draw_text(tvert[lvert[i]][0], tvert[lvert[i]][1], ltext[i], 0); } } free_with_check(tvert); ord.unlock_data(); }