static void test_crbug131181(skiatest::Reporter*) { /* fX = 18.8943768, fY = 129.121277 }, { fX = 18.8937435, fY = 129.121689 }, { fX = 18.8950119, fY = 129.120422 }, { fX = 18.5030727, fY = 129.13121 */ uint32_t data[] = { 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27, 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197 }; SkPath path; moveToH(&path, &data[0]); cubicToH(&path, &data[2]); SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); SkPaint paint; paint.setAntiAlias(true); canvas->drawPath(path, paint); }
// we used to assert if the bounds of the device (clip) was larger than 32K // even when the path itself was smaller. We just draw and hope in the debug // version to not assert. static void test_giantaa(skiatest::Reporter* reporter) { const int W = 400; const int H = 400; SkAutoTUnref<SkCanvas> canvas(new_canvas(33000, 10)); canvas.get()->clear(SK_ColorTRANSPARENT); SkPaint paint; paint.setAntiAlias(true); SkPath path; path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); canvas.get()->drawPath(path, paint); }
static void test_bigcubic(skiatest::Reporter* reporter) { #ifdef SK_SCALAR_IS_FLOAT SkPath path; path.moveTo(64, 3); path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); SkPaint paint; paint.setAntiAlias(true); SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); canvas.get()->drawPath(path, paint); #endif }
static void test_bug533(skiatest::Reporter* reporter) { #ifdef SK_SCALAR_IS_FLOAT /* http://code.google.com/p/skia/issues/detail?id=533 This particular test/bug only applies to the float case, where the coordinates are very large. */ SkPath path; path.moveTo(64, 3); path.quadTo(-329936, -100000000, 1153, 330003); SkPaint paint; paint.setAntiAlias(true); SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); canvas.get()->drawPath(path, paint); #endif }
Canvas * detect_edges_canvas(Canvas * base, int num_threads) { Canvas * grayscaled_canv = grayscale_canvas(base, num_threads); const int w = base->w; const int h = base->h; Canvas * grad_canv = new_canvas(w, h); omp_set_num_threads((num_threads < 2) ? 1 : num_threads); int x; int y; #pragma omp parallel private(x, y) #pragma omp for collapse(2) schedule(dynamic, IMG_CHUNK) for(x = 1; x < w - 1; ++x) { for(y = 1; y < h - 1; ++y) { int i; int j; int gx = 0; for(i = -1; i < 2; ++i) { for(j = -1; j < 2; ++j) { gx += mattrix_x[i + 1][j + 1] * get_pixel(x + i, y + j, grayscaled_canv).r; } } int gy = 0; for(i = -1; i < 2; ++i) { for(j = -1; j < 2; ++j) { gy += mattrix_y[i + 1][j + 1] * get_pixel(x + i, y + j, grayscaled_canv).r; } } Byte grad = (Byte) sqrt(gx * gx + gy * gy); set_pixel(x, y, rgb(grad, grad, grad), grad_canv); } } release_canvas(grayscaled_canv); return grad_canv; }
Canvas * grayscale_canvas(Canvas * base, int num_threads) { const int w = base->w; const int h = base->h; Canvas * ret = new_canvas(w, h); omp_set_num_threads((num_threads < 2) ? 1 : num_threads); int x; int y; #pragma omp parallel private(x, y) #pragma omp for collapse(2) schedule(dynamic, IMG_CHUNK) for(x = 0; x < w; ++x) { for(y = 0; y < h; ++y) { const Color c = get_pixel(x, y, base); const Color gray = grayscale(c); set_pixel(x, y, gray, ret); } } return ret; }
// Need to exercise drawing an inverse-path whose bounds intersect the clip, // but whose edges do not (since its a quad which draws only in the bottom half // of its bounds). // In the debug build, we used to assert in this case, until it was fixed. // static void test_inversepathwithclip(skiatest::Reporter* reporter) { SkPath path; path.moveTo(0, SkIntToScalar(20)); path.quadTo(SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(20), SkIntToScalar(20)); path.toggleInverseFillType(); SkPaint paint; SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); canvas.get()->save(); canvas.get()->clipRect(SkRect::MakeWH(SkIntToScalar(19), SkIntToScalar(11))); paint.setAntiAlias(false); canvas.get()->drawPath(path, paint); paint.setAntiAlias(true); canvas.get()->drawPath(path, paint); canvas.get()->restore(); // Now do the test again, with the path flipped, so we only draw in the // top half of our bounds, and have the clip intersect our bounds at the // bottom. path.reset(); // preserves our filltype path.moveTo(0, SkIntToScalar(10)); path.quadTo(SkIntToScalar(10), SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10)); canvas.get()->clipRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(19), SkIntToScalar(19), SkIntToScalar(11))); paint.setAntiAlias(false); canvas.get()->drawPath(path, paint); paint.setAntiAlias(true); canvas.get()->drawPath(path, paint); }
int main(void) { Camera * camera = create_camera(); Canvas * canvas = new_canvas(CANVAS_W, CANVAS_H); int i; for(i = 0; i < MAX_SERPINSKY_PYRAMID_LEVEL; i++) { Scene * scene = new_scene(MAX_OBJECTS_NUMBER, MAX_LIGHT_SOURCES_NUMBER, BACKGROUND_COLOR); create_serpinsky_pyramid(scene, i); // Randomness causes unreproducible results // But in general - results are similar to Serpinsky pyramid //generate_random_spheres(scene, i * 400); prepare_scene(scene); printf("Number of polygons: %i. ", scene->last_object_index + 1); render_scene(scene, camera, canvas, THREADS_NUM); release_scene(scene); } release_canvas(canvas); release_camera(camera); return 0; }
Canvas * read_png(char * file_name) { unsigned char header[8]; // 8 is the maximum size that can be checked // open file and test for it being a png FILE *fp = fopen(file_name, "rb"); if (!fp) abort_("[read_png_file] File %s could not be opened for reading", file_name); fread(header, 1, 8, fp); if (png_sig_cmp(header, 0, 8)) abort_("[read_png_file] File %s is not recognized as a PNG file", file_name); // initialize stuff png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) abort_("[read_png_file] png_create_read_struct failed"); png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) abort_("[read_png_file] png_create_info_struct failed"); if (setjmp(png_jmpbuf(png_ptr))) abort_("[read_png_file] Error during init_io"); png_init_io(png_ptr, fp); png_set_sig_bytes(png_ptr, 8); png_read_info(png_ptr, info_ptr); int width = png_get_image_width(png_ptr, info_ptr); int height = png_get_image_height(png_ptr, info_ptr); png_set_interlace_handling(png_ptr); png_read_update_info(png_ptr, info_ptr); // read file if (setjmp(png_jmpbuf(png_ptr))) abort_("[read_png_file] Error during read_image"); png_bytep * row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height); int y; for (y = 0; y < height; y++) row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr)); png_read_image(png_ptr, row_pointers); Canvas * canvas = new_canvas(width, height); int x; for (y=0; y < canvas->h; y++) { png_byte * row = row_pointers[y]; for(x = 0; x < canvas->w; x++) { png_byte * ptr = &(row[x * 3]); set_pixel(x, y, rgb(ptr[0], ptr[1], ptr[2]), canvas); } } // cleanup heap allocation for (y=0; y < canvas->h; y++) free(row_pointers[y]); free(row_pointers); fclose(fp); return canvas; }
int main(void) { // Allocating scene Scene * scene = new_scene(MAX_OBJECTS_NUMBER, MAX_LIGHT_SOURCES_NUMBER, BACKGROUND_COLOR); // Allocating new sphere Float radius = 100; Point3d center = point3d(0, 0, 0); Color sphere_color = rgb(250, 30, 30); Material sphere_material = material(1, 5, 5, 10, 0, 10); Object3d * sphere = new_sphere(center, radius, sphere_color, sphere_material); // Adding sphere to the scene add_object(scene, sphere); // Allocating new triangle Object3d * triangle = new_triangle(point3d(-700, -700, -130), // vertex 1 point3d( 700, -700, -130), // vertex 2 point3d( 0, 400, -130), // vertex 3 rgb(100, 255, 30), // color material(1, 6, 0, 2, 0, 0) // surface params ); // Adding triangle to the scene add_object(scene, triangle); // Loading 3D model of cow from *.obj file // defining transformations and parameters of 3D model // TODO: must be refactored... SceneFaceHandlerParams load_params = new_scene_face_handler_params(scene, // scale: 40, // move dx, dy, dz: -150, -100, 30, // rotate around axises x, y, z: 0, 0, 0, // color rgb(200, 200, 50), // surface params material(2, 3, 0, 0, 0, 0) ); load_obj("./demo/models/cow.obj", // default handler which adding polygons of 3D model to scene: scene_face_handler, &load_params); // This function is requried (bulding k-d tree of entire scene) prepare_scene(scene); printf("\nNumber of polygons: %i\n", scene->last_object_index + 1); // Allocating new light source Color light_source_color = rgb(255, 255, 255); Point3d light_source_location = point3d(-300, 300, 300); LightSource3d * light_source = new_light_source(light_source_location, light_source_color); // Adding light source to the scene add_light_source(scene, light_source); // Adding fog Float density = 0.002; set_exponential_fog(scene, density); // Allocating camera // TODO: It's a pity, but quaternions are not implemented yet :( Point3d camera_location = point3d(0, 500, 0); Float focus = 320; Float x_angle = -1.57; Float y_angle = 0; Float z_angle = 3.14; Camera * camera = new_camera(camera_location, x_angle, y_angle, z_angle, focus); // Rotate camera if needed // rotate_camera(camera, d_x_angle, d_y_angle, d_z_angle); // Move camera if needed // move_camera(camera, vector3df(d_x, d_y, d_z)); // Alocate new canvas, to render scene on it Canvas * canvas = new_canvas(CANVAS_W, CANVAS_H); render_scene(scene, camera, canvas, THREADS_NUM); // Saving rendered image in PNG format write_png("example.png", canvas); release_canvas(canvas); release_scene(scene); release_camera(camera); return 0; }