ArtSVP * nr_art_svp_from_svl (NRSVL * svl) { ArtSVP * asvp; NRSVL * s; int n_segs, sn; if (!svl) { asvp = (ArtSVP *)art_alloc (sizeof (ArtSVP)); asvp->n_segs = 0; return asvp; } n_segs = 0; for (s = svl; s != NULL; s = s->next) n_segs++; asvp = (ArtSVP *)art_alloc (sizeof (ArtSVP) + (n_segs - 1) * sizeof (ArtSVPSeg)); asvp->n_segs = n_segs; sn = 0; for (s = svl; s != NULL; s = s->next) { ArtSVPSeg * aseg; NRVertex * v; int n_points, pn; aseg = &asvp->segs[sn]; n_points = 0; for (v = s->vertex; v != NULL; v = v->next) n_points++; aseg->n_points = n_points; aseg->dir = (s->wind == -1); aseg->points = art_new (ArtPoint, n_points); pn = 0; for (v = s->vertex; v != NULL; v = v->next) { aseg->points[pn].x = NR_COORD_TO_ART (v->x); aseg->points[pn].y = NR_COORD_TO_ART (v->y); pn++; } aseg->bbox.x0 = NR_COORD_TO_ART (s->bbox.x0); aseg->bbox.y0 = NR_COORD_TO_ART (s->bbox.y0); aseg->bbox.x1 = NR_COORD_TO_ART (s->bbox.x1); aseg->bbox.y1 = NR_COORD_TO_ART (s->bbox.y1); sn++; } return asvp; }
/** * art_svp_merge: Merge the segments of two svp's. * @svp1: One svp to merge. * @svp2: The other svp to merge. * * Merges the segments of two SVP's into a new one. The resulting * #ArtSVP data structure will share the segments of the argument * svp's, so it is probably a good idea to free it shallowly, * especially if the arguments will be freed with art_svp_free(). * * Return value: The merged #ArtSVP. **/ static ArtSVP * art_svp_merge (const ArtSVP *svp1, const ArtSVP *svp2) { ArtSVP *svp_new; int ix; int ix1, ix2; svp_new = (ArtSVP *)art_alloc (sizeof(ArtSVP) + (svp1->n_segs + svp2->n_segs - 1) * sizeof(ArtSVPSeg)); ix1 = 0; ix2 = 0; for (ix = 0; ix < svp1->n_segs + svp2->n_segs; ix++) { if (ix1 < svp1->n_segs && (ix2 == svp2->n_segs || art_svp_seg_compare (&svp1->segs[ix1], &svp2->segs[ix2]) < 1)) svp_new->segs[ix] = svp1->segs[ix1++]; else svp_new->segs[ix] = svp2->segs[ix2++]; } svp_new->n_segs = ix; return svp_new; }
/** * art_alphagamma_new: Create a new #ArtAlphaGamma. * @gamma: Gamma value. * * Create a new #ArtAlphaGamma for a specific value of @gamma. When * correctly implemented (which is generally not the case in libart), * alpha compositing with an alphagamma parameter is equivalent to * applying the gamma transformation to source images, doing the alpha * compositing (in linear intensity space), then applying the inverse * gamma transformation, bringing it back to a gamma-adjusted * intensity space. * * Return value: The newly created #ArtAlphaGamma. **/ ArtAlphaGamma * art_alphagamma_new (double gamma) { int tablesize; ArtAlphaGamma *alphagamma; int i; int *table; art_u8 *invtable; double s, r_gamma; tablesize = ceil (gamma * 8); if (tablesize < 10) tablesize = 10; alphagamma = (ArtAlphaGamma *)art_alloc (sizeof(ArtAlphaGamma) + ((1 << tablesize) - 1) * sizeof(art_u8)); alphagamma->gamma = gamma; alphagamma->invtable_size = tablesize; table = alphagamma->table; for (i = 0; i < 256; i++) table[i] = (int)floor (((1 << tablesize) - 1) * pow (i * (1.0 / 255), gamma) + 0.5); invtable = alphagamma->invtable; s = 1.0 / ((1 << tablesize) - 1); r_gamma = 1.0 / gamma; for (i = 0; i < 1 << tablesize; i++) invtable[i] = (int)floor (255 * pow (i * s, r_gamma) + 0.5); return alphagamma; }
static MateComponent_Canvas_ArtUTA * impl_MateComponent_Canvas_Component_update (PortableServer_Servant servant, const MateComponent_Canvas_State *state, const MateComponent_Canvas_affine aff, const MateComponent_Canvas_SVP *clip_path, CORBA_long flags, CORBA_double *x1, CORBA_double *y1, CORBA_double *x2, CORBA_double *y2, CORBA_Environment *ev) { Gcc *gcc = GCC (matecomponent_object_from_servant (servant)); MateCanvasItem *item = MATE_CANVAS_ITEM (gcc->priv->item); double affine [6]; int i; ArtSVP *svp = NULL; MateComponent_Canvas_ArtUTA *cuta; MateCanvasItemClass *gci_class = g_type_class_ref ( mate_canvas_item_get_type ()); restore_state (item, state); for (i = 0; i < 6; i++) affine [i] = aff [i]; if (clip_path->_length > 0) { svp = art_alloc (sizeof (ArtSVP) + (clip_path->_length * sizeof (ArtSVPSeg))); if (svp == NULL) goto fail; svp->n_segs = clip_path->_length; for (i = 0; svp->n_segs; i++) { gboolean ok; ok = CORBA_SVP_Segment_to_SVPSeg (&clip_path->_buffer [i], &svp->segs [i]); if (!ok) { int j; for (j = 0; j < i; j++) { free_seg (&svp->segs [j]); art_free (svp); goto fail; } } } } invoke_update (item, (double *)aff, svp, flags); if (svp){ for (i = 0; i < svp->n_segs; i++) free_seg (&svp->segs [i]); art_free (svp); } fail: if (getenv ("CC_DEBUG")) printf ("%g %g %g %g\n", item->x1, item->x2, item->y1, item->y2); *x1 = item->x1; *x2 = item->x2; *y1 = item->y1; *y2 = item->y2; cuta = CORBA_UTA (item->canvas->redraw_area); if (cuta == NULL) { CORBA_exception_set_system (ev, ex_CORBA_NO_MEMORY, CORBA_COMPLETED_NO); return NULL; } /* * Now, mark our canvas as fully up to date */ /* Clears flags for root item. */ (* gci_class->update) (item->canvas->root, affine, svp, flags); if (item->canvas->redraw_area) { art_uta_free (item->canvas->redraw_area); item->canvas->redraw_area = NULL; } item->canvas->need_redraw = FALSE; return cuta; }
//! //! //! //! @param[in] req //! @param[in] prev_art //! //! @return A pointer to a newly created artifact //! artifact *convert_requirements(imager_request * req, artifact * prev_art) { char *id = NULL; char *sig = NULL; char *i = NULL; char *o = NULL; s64 size_bytes = 0; char sig_buf[MAX_ARTIFACT_SIG] = ""; char id_buf[EUCA_MAX_PATH] = ""; char prev_id_buf[EUCA_MAX_PATH] = ""; artifact *this_art = NULL; convert_params *state = NULL; assert(req); assert(req->internal); prev_art = skip_sentinels(prev_art); state = ((convert_params *) req->internal); // _validate should have enforced that assert(strlen(state->in) > 0 || prev_art != NULL); // calculate output size by assuming it will be the same as input size if (state->remote && state->in_type == VMDK) { // remote input size_bytes = vmdk_get_size(state->remote); } else { // local input if (prev_art) { size_bytes = prev_art->size_bytes; } else if (strcmp(state->in, "-") == 0) { // standard input size_bytes = 0; } else { size_bytes = file_size(state->in); } } if (size_bytes < 0) { LOGINFO("failed to locate required input '%s'\n", state->in); return NULL; } if (prev_art) { id = prev_art->id; sig = prev_art->sig; } else { // covert intput files into blobstore IDs by replacing slashes with hyphens i = state->in; o = prev_id_buf; do { if (*i == '/') { if (i != state->in) *o++ = '-'; } else *o++ = *i; } while (*i++ && ((o - prev_id_buf) < sizeof(prev_id_buf))); id = prev_id_buf; sig = ""; //! @TODO calculate proper sig for the file } if (state->out) { id = state->out; // specified ID trumps generated one } else { snprintf(id_buf, sizeof(id_buf), "%s.%s", id, (state->out_type == VMDK) ? "vmdk" : "disk"); // append dest type id = id_buf; } // append new info to the signature snprintf(sig_buf, sizeof(sig_buf), "%s\n\nconverted from=%s to=%s size=%ld\n", sig, state->in, (state->out==NULL)?("(next stage)"):(state->out), size_bytes); sig = sig_buf; this_art = art_alloc(id, sig, size_bytes, !state->remote, // do not cache remote conversions TRUE, // must be a file FALSE, // should not be hollow convert_creator, NULL); // not using the VBR if (this_art == NULL) err("out of memory"); this_art->internal = ((void *)state); this_art->id_is_path = (state->out != NULL); art_add_dep(this_art, prev_art); return this_art; }
GdkPixBuf *image_load(FILE *f) { int w,h,i,j; art_u8 *pixels=NULL, *dptr; unsigned char *lines[4], /* Used to expand rows, via rec_outbuf_height, from the header file: "* Usually rec_outbuf_height will be 1 or 2, at most 4." */ **lptr; struct jpeg_decompress_struct cinfo; struct iojpeg_JPEG_error_mgr jerr; GdkPixBuf *pixbuf; /* setup error handler */ cinfo.err = jpeg_std_error(&(jerr.pub)); jerr.pub.error_exit = g_JPEGFatalErrorHandler; if (sigsetjmp(jerr.setjmp_buffer, 1)) { /* Whoops there was a jpeg error */ if (pixels != NULL) art_free(pixels); jpeg_destroy_decompress(&cinfo); return NULL; } /* load header, setup */ jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo, f); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); cinfo.do_fancy_upsampling = FALSE; cinfo.do_block_smoothing = FALSE; w = cinfo.output_width; h = cinfo.output_height; g_print("w: %d h: %d\n", w, h); pixels = art_alloc(h * w * 3); if (pixels == NULL) { jpeg_destroy_decompress(&cinfo); return NULL; } dptr = pixels; /* decompress all the lines, a few at a time */ while (cinfo.output_scanline < cinfo.output_height) { lptr = lines; for (i=0;i<cinfo.rec_outbuf_height;i++) { *lptr++=dptr; dptr+=w*3; } jpeg_read_scanlines(&cinfo, lines, cinfo.rec_outbuf_height); if (cinfo.output_components==1) { /* expand grey->colour */ /* expand from the end of the memory down, so we can use the same buffer */ for (i=cinfo.rec_outbuf_height-1;i>=0;i--) { unsigned char *from, *to; from = lines[i]+w-1; to = lines[i]+w*3-3; for (j=w-1;j>=0;j--) { to[0] = from[0]; to[1] = from[0]; to[2] = from[0]; to-=3; from--; } } } } jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); /* finish off, create the pixbuf */ pixbuf = gdk_pixbuf_new (art_pixbuf_new_rgb (pixels, w, h, (w * 3)), NULL); if (!pixbuf) art_free (pixels); return pixbuf; }