static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpDrawable *drawable; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; run_mode = param[0].data.d_int32; INIT_I18N (); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; /* Get the specified drawable */ drawable = gimp_drawable_get (param[2].data.d_drawable); switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PIXELIZE_PROC, &pvals); /* First acquire information with a dialog */ if (! pixelize_dialog (drawable)) { gimp_drawable_detach (drawable); return; } break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are there! */ if ((! strcmp (name, PIXELIZE_PROC) && nparams != 4) || (! strcmp (name, PIXELIZE2_PROC) && nparams != 5)) { status = GIMP_PDB_CALLING_ERROR; } if (status == GIMP_PDB_SUCCESS) { pvals.pixelwidth = (gdouble) param[3].data.d_int32; if (nparams == 4) pvals.pixelheight = pvals.pixelwidth; else pvals.pixelheight = (gdouble) param[4].data.d_int32; } if ((status == GIMP_PDB_SUCCESS) && (pvals.pixelwidth <= 0 || pvals.pixelheight <= 0)) { status = GIMP_PDB_CALLING_ERROR; } break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PIXELIZE_PROC, &pvals); break; default: break; } if (status == GIMP_PDB_SUCCESS) { /* Make sure that the drawable is gray or RGB color */ if (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id)) { gimp_progress_init (_("Pixelizing")); /* set the tile cache size */ gimp_tile_cache_ntiles (TILE_CACHE_SIZE); /* run the pixelize effect */ pixelize (drawable, NULL); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PIXELIZE_PROC, &pvals, sizeof (PixelizeValues)); } else { /* g_message ("pixelize: cannot operate on indexed color images"); */ status = GIMP_PDB_EXECUTION_ERROR; } } values[0].data.d_status = status; gimp_drawable_detach (drawable); }
/*------------------------------------------------------------------------------ Main program. */ int main(int argc, char *argv[]) { int ifile, nfiles, npoly, npolys, i, res_max_temp; char scheme_temp; polygon **polys; polys=polys_global; // mtrace(); /* default output format */ fmt.out = keywords[POLYGON]; /* default is to renumber output polygons with old id numbers */ fmt.newid = 'o'; /* parse arguments */ parse_args(argc, argv); /* at least one input and output filename required as arguments */ if (argc - optind < 2) { if (optind > 1 || argc - optind == 1) { fprintf(stderr, "%s requires at least 2 arguments: polygon_infile and polygon_outfile\n", argv[0]); usage(); exit(1); } else { usage(); exit(0); } } msg("---------------- pixelize ----------------\n"); // snap angles scale(&axtol, axunit, 's'); scale(&btol, bunit, 's'); scale(&thtol, thunit, 's'); axunit = 's'; bunit = 's'; thunit = 's'; // msg("snap angles: axis %Lg%c latitude %Lg%c edge %Lg%c\n", axtol, axunit, btol, bunit, thtol, thunit); scale(&axtol, axunit, 'r'); scale(&btol, bunit, 'r'); scale(&thtol, thunit, 'r'); axunit = 'r'; bunit = 'r'; thunit = 'r'; /* tolerance angle for multiple intersections */ if (mtol != 0.) { scale(&mtol, munit, 's'); munit = 's'; msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit); scale(&mtol, munit, 'r'); munit = 'r'; } msg("pixelization scheme %c, maximum resolution %d\n", scheme, res_max); msg("maximum number of polygons allowed in each pixel: %d\n", polys_per_pixel); scheme_temp=scheme; res_max_temp=res_max; /* advise data format */ advise_fmt(&fmt); /* read polygons */ npoly = 0; nfiles = argc - 1 - optind; for (ifile = optind; ifile < optind + nfiles; ifile++) { npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly]); if (npolys == -1) exit(1); npoly += npolys; } if (nfiles >= 2) { msg("total of %d polygons read\n", npoly); } if (npoly == 0) { msg("STOP\n"); exit(0); } if(scheme!=scheme_temp || res_max!=res_max_temp){ msg("warning: pixelization information in input file is being discarded\n"); scheme=scheme_temp; res_max=res_max_temp; } /* pixelize polygons */ npolys = pixelize(npoly, polys, NPOLYSMAX - npoly, &polys[npoly]); if (npolys == -1) exit(1); pixelized=1; if(polys_per_pixel>0) res_max=-1; /* write polygons */ ifile = argc - 1; npolys = wrmask(argv[ifile], &fmt, npolys, &polys[npoly]); if (npolys == -1) exit(1); /* memmsg(); */ for(i=0;i<npoly+npolys;i++){ free_poly(polys[i]); } return(0); }
static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *roi, gint level) { GeglRectangle src_rect; GeglRectangle *whole_region; GeglProperties *o = GEGL_PROPERTIES (operation); GeglOperationAreaFilter *op_area; op_area = GEGL_OPERATION_AREA_FILTER (operation); whole_region = gegl_operation_source_get_bounding_box (operation, "input"); if (gegl_operation_use_opencl (operation)) if (cl_process (operation, input, output, roi)) return TRUE; if (o->size_x * o->size_y < SQR (ALLOC_THRESHOLD_SIZE)) { gfloat background_color[4]; gfloat *input_buf = g_new (gfloat, (CHUNK_SIZE + o->size_x * 2) * (CHUNK_SIZE + o->size_y * 2) * 4); gfloat *output_buf = g_new (gfloat, SQR (CHUNK_SIZE) * 4); gint i, j; gegl_color_get_pixel (o->background, babl_format("RaGaBaA float"), background_color); for (j = 0; (j-1) * CHUNK_SIZE < roi->height; j++) for (i = 0; (i-1) * CHUNK_SIZE < roi->width; i++) { GeglRectangle chunked_result; GeglRectangle chunked_sizes; chunked_result = *GEGL_RECTANGLE (roi->x + i * CHUNK_SIZE, roi->y + j * CHUNK_SIZE, CHUNK_SIZE, CHUNK_SIZE); gegl_rectangle_intersect (&chunked_result, &chunked_result, roi); if (chunked_result.width < 1 || chunked_result.height < 1) continue; src_rect = chunked_result; src_rect.x -= op_area->left; src_rect.y -= op_area->top; src_rect.width += op_area->left + op_area->right; src_rect.height += op_area->top + op_area->bottom; gegl_buffer_get (input, &src_rect, 1.0, babl_format ("RaGaBaA float"), input_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP); gegl_rectangle_copy (&chunked_sizes, &chunked_result); chunked_sizes.x = 0; chunked_sizes.y = 0; set_rectangle (output_buf, &chunked_sizes, &chunked_sizes, chunked_result.width, background_color, GEGL_PIXELIZE_NORM_INFINITY); pixelize (input_buf, output_buf, &chunked_result, &src_rect, whole_region, o); gegl_buffer_set (output, &chunked_result, 0, babl_format ("RaGaBaA float"), output_buf, GEGL_AUTO_ROWSTRIDE); } g_free (input_buf); g_free (output_buf); } else { gegl_buffer_set_color (output, roi, o->background); pixelize_noalloc (input, output, roi, whole_region, o); } return TRUE; }
void pixelize_5(Bitmap& bmp){ pixelize(bmp, 5); }