void *str2ptr_set(struct str2ptr *map, char *key, void *value) { unsigned int hash = _hash(key), index = _get_index(map, key, hash); void *old = NULL; if(index <= map->mask) { old = map->pair[index].value; map->pair[index].value = value; } else if(map->fill == map->mask + 1) { struct str2ptr new_map; unsigned int size = (map->mask + 1) << 2; memset(&new_map, 0, sizeof(new_map)); new_map.mask = size - 1; new_map.pair = (struct str2ptr_pair *)calloc(size, sizeof(*new_map.pair)); for(index = 0; index < map->mask + 1; ++index) { _insert(&new_map, map->pair[index].key, map->pair[index].hash, map->pair[index].value); } _insert(&new_map, key, hash, value); free(map->pair); *map = new_map; } else { _insert(map, key, hash, value); } return old; }
void CyclingAgenda::add(const Derivation& i) { /// \todo Make sure we don't insert duplicate elements _qs.at(_get_index(i)).add(i); while (this->size() > MAX_AGENDA_SIZE) this->remove_worst(); }
NRPixBlock *FilterSlot::get(int slot_nr) { int index = _get_index(slot_nr); assert(index >= 0); /* If we didn't have the specified image, but we could create it * from the other information we have, let's do that */ if (_slot[index] == NULL && (slot_nr == NR_FILTER_SOURCEALPHA || slot_nr == NR_FILTER_BACKGROUNDIMAGE || slot_nr == NR_FILTER_BACKGROUNDALPHA || slot_nr == NR_FILTER_FILLPAINT || slot_nr == NR_FILTER_STROKEPAINT)) { /* If needed, fetch background */ if (slot_nr == NR_FILTER_BACKGROUNDIMAGE) { NRPixBlock *pb; pb = nr_arena_item_get_background(_arena_item); if (pb) { pb->empty = false; this->set(NR_FILTER_BACKGROUNDIMAGE, pb); } else { NRPixBlock *source = this->get(NR_FILTER_SOURCEGRAPHIC); pb = new NRPixBlock(); if (!pb) return NULL; // Allocation failed nr_pixblock_setup_fast(pb, source->mode, source->area.x0, source->area.y0, source->area.x1, source->area.y1, true); if (pb->size != NR_PIXBLOCK_SIZE_TINY && pb->data.px == NULL) { // allocation failed delete pb; return NULL; } pb->empty = FALSE; this->set(NR_FILTER_BACKGROUNDIMAGE, pb); } } else if (slot_nr == NR_FILTER_SOURCEALPHA) { /* If only a alpha channel is needed, strip it from full image */ NRPixBlock *src = get(NR_FILTER_SOURCEGRAPHIC); NRPixBlock *sa = filter_get_alpha(src); set(NR_FILTER_SOURCEALPHA, sa); } else if (slot_nr == NR_FILTER_BACKGROUNDALPHA) { NRPixBlock *src = get(NR_FILTER_BACKGROUNDIMAGE); NRPixBlock *ba = filter_get_alpha(src); set(NR_FILTER_BACKGROUNDALPHA, ba); } else if (slot_nr == NR_FILTER_FILLPAINT) { /* When a paint is needed, fetch it from arena item */ // TODO } else if (slot_nr == NR_FILTER_STROKEPAINT) { // TODO } } if (_slot[index]) { _slot[index]->empty = false; } assert(slot_nr == NR_FILTER_SLOT_NOT_SET ||_slot_number[index] == slot_nr); return _slot[index]; }
void *str2ptr_del(struct str2ptr *map, char *key) { unsigned int hash = _hash(key), index = _get_index(map, key, hash); void *result = NULL; if(index <= map->mask) { result = map->pair[index].value; free((char *)map->pair[index].key); memset(map->pair + index, 0, sizeof(*map->pair)); } return result; }
int luaC_array__newindex(lua_State *L) { struct Array *A = lunum_checkarray1(L, 1); const int m = _get_index(L, A); const enum ArrayType T = A->dtype; void *val = lunum_tovalue(L, T); memcpy((char*)A->data + array_sizeof(T)*m, val, array_sizeof(T)); free(val); return 0; }
static int luaC_array__newindex(lua_State *L) { Array *A = lunum_checkarray1(L, 1); int success; const size_t m = _get_index(L, A, &success); if (success) { const ArrayType T = A->dtype; ArrayAllNum val; lunum_tovalue(L, T, &val); memcpy((char*)A->data + array_sizeof(T)*m, &val, array_sizeof(T)); } return 0; }
int gcseg_solve_n8(const float *pcap, int width, int height, int stride, const char *trimap, int tmstep, uchar *alpha, int astep, uchar a0, uchar a1, float seedEng) { int flow=0; if(trimap) { int *index=new int[width*height]; int np=_get_index(trimap,width,height,tmstep,index,width); flow=_solve_maxflow_mn8(pcap,width,height,stride,trimap,tmstep,seedEng, index,width,np,alpha,astep,-1,a0,a1); delete[]index; } else flow=_solve_maxflow_n8(pcap,width,height,stride,alpha,astep,-1,a0,a1); return flow; }
int gcseg_solve_n8(const uchar *prob, int width, int height, int pstep, const float *ecap, int estride, const char *trimap, int tmstep, uchar *alpha, int astep, uchar a0, uchar a1, float seedEng) { int flow=0; if(trimap) { int *index=new int[width*height]; int np=_get_index(trimap,width,height,tmstep,index,width); flow=_solve_maxflow_pmn8(prob,width,height,pstep, ecap,estride, trimap, tmstep, seedEng, index,width,np,alpha,astep,-1,a0,a1); delete[]index; } else { assert(prob); flow=_solve_maxflow_pn8(prob,width,height,pstep, ecap, estride, alpha,astep,-1,a0,a1); } return flow; }
static int luaC_array__index(lua_State *L) { Array *A = lunum_checkarray1(L, 1); // Figure out what is the format of the input index. If it's a number or a // table of numbers, then pass it along to _get_index. If it's an array of bools, // then use it as a mask. // --------------------------------------------------------------------------- if (lunum_hasmetatable(L, 2, "array")) { Array *M = lunum_checkarray1(L, 2); if (M->dtype != ARRAY_TYPE_BOOL) { return luaL_error(L, "index array must be of type bool"); } Array B = array_new_from_mask(A, M); lunum_pusharray1(L, &B); return 1; } /* try to index into array */ int success; const size_t m = _get_index(L, A, &success); if (success) { _push_value(L, A->dtype, (char*)A->data + array_sizeof(A->dtype)*m); return 1; } /* check metatable */ lua_getmetatable(L, 1); lua_pushvalue(L, 2); if (lua_gettable(L, -2) != LUA_TNIL) { return 1; } return 0; }
int luaC_array__index(lua_State *L) { struct Array *A = lunum_checkarray1(L, 1); // Figure out what is the format of the input index. If it's a number or a // table of numbers, then pass it along to _get_index. If it's a table of // tables or numbers, then assume it's a slice. If it's an array of bools, // then use it as a mask. // --------------------------------------------------------------------------- if (lunum_hasmetatable(L, 2, "array")) { struct Array *M = lunum_checkarray1(L, 2); if (M->dtype != ARRAY_TYPE_BOOL) { luaL_error(L, "index array must be of type bool"); } struct Array B = array_new_from_mask(A, M); lunum_pusharray1(L, &B); return 1; } else if (lua_type(L, 2) == LUA_TTABLE || lua_type(L, 2) == LUA_TSTRING) { lua_getglobal(L, "lunum"); lua_getfield(L, -1, "__build_slice"); lua_remove(L, -2); lua_pushvalue(L, 1); lua_pushvalue(L, 2); lua_call(L, 2, 1); return 1; } const int m = _get_index(L, A); _push_value(L, A->dtype, (char*)A->data + array_sizeof(A->dtype)*m); return 1; }
avl_node< __Key, __Value, __Compare >* operator->() const { return _get_index(); }
void FilterSlot::set(int slot_nr, NRPixBlock *pb) { /* Unnamed slot is for saving filter primitive results, when parameter * 'result' is not set. Only the filter immediately after this one * can access unnamed results, so we don't have to worry about overwriting * previous results in filter chain. On the other hand, we may not * overwrite any other image with this one, because they might be * accessed later on. */ int index = ((slot_nr != NR_FILTER_SLOT_NOT_SET) ? _get_index(slot_nr) : _get_index(NR_FILTER_UNNAMED_SLOT)); assert(index >= 0); // Unnamed slot is only for Inkscape::Filters::FilterSlot internal use. assert(slot_nr != NR_FILTER_UNNAMED_SLOT); assert(slot_nr == NR_FILTER_SLOT_NOT_SET ||_slot_number[index] == slot_nr); if (slot_nr == NR_FILTER_SOURCEGRAPHIC || slot_nr == NR_FILTER_BACKGROUNDIMAGE) { Geom::Matrix trans = units.get_matrix_display2pb(); if (fabs(trans[1]) > 1e-6 || fabs(trans[2]) > 1e-6) { NRPixBlock *trans_pb = new NRPixBlock; int x0 = pb->area.x0; int y0 = pb->area.y0; int x1 = pb->area.x1; int y1 = pb->area.y1; int min_x = _min4(trans[0] * x0 + trans[2] * y0 + trans[4], trans[0] * x0 + trans[2] * y1 + trans[4], trans[0] * x1 + trans[2] * y0 + trans[4], trans[0] * x1 + trans[2] * y1 + trans[4]); int max_x = _max4(trans[0] * x0 + trans[2] * y0 + trans[4], trans[0] * x0 + trans[2] * y1 + trans[4], trans[0] * x1 + trans[2] * y0 + trans[4], trans[0] * x1 + trans[2] * y1 + trans[4]); int min_y = _min4(trans[1] * x0 + trans[3] * y0 + trans[5], trans[1] * x0 + trans[3] * y1 + trans[5], trans[1] * x1 + trans[3] * y0 + trans[5], trans[1] * x1 + trans[3] * y1 + trans[5]); int max_y = _max4(trans[1] * x0 + trans[3] * y0 + trans[5], trans[1] * x0 + trans[3] * y1 + trans[5], trans[1] * x1 + trans[3] * y0 + trans[5], trans[1] * x1 + trans[3] * y1 + trans[5]); nr_pixblock_setup_fast(trans_pb, pb->mode, min_x, min_y, max_x, max_y, true); if (trans_pb->size != NR_PIXBLOCK_SIZE_TINY && trans_pb->data.px == NULL) { /* TODO: this gets hit occasionally. Worst case scenario: * images are exported in horizontal stripes. One stripe * is not too high, but can get thousands of pixels wide. * Rotate this 45 degrees -> _huge_ image */ g_warning("Memory allocation failed in Inkscape::Filters::FilterSlot::set (transform)"); return; } if (filterquality == FILTER_QUALITY_BEST) { NR::transform_bicubic(trans_pb, pb, trans); } else { NR::transform_nearest(trans_pb, pb, trans); } nr_pixblock_release(pb); delete pb; pb = trans_pb; } else if (fabs(trans[0] - 1) > 1e-6 || fabs(trans[3] - 1) > 1e-6) { NRPixBlock *trans_pb = new NRPixBlock; int x0 = pb->area.x0; int y0 = pb->area.y0; int x1 = pb->area.x1; int y1 = pb->area.y1; int min_x = _min2(trans[0] * x0 + trans[4], trans[0] * x1 + trans[4]); int max_x = _max2(trans[0] * x0 + trans[4], trans[0] * x1 + trans[4]); int min_y = _min2(trans[3] * y0 + trans[5], trans[3] * y1 + trans[5]); int max_y = _max2(trans[3] * y0 + trans[5], trans[3] * y1 + trans[5]); nr_pixblock_setup_fast(trans_pb, pb->mode, min_x, min_y, max_x, max_y, true); if (trans_pb->size != NR_PIXBLOCK_SIZE_TINY && trans_pb->data.px == NULL) { g_warning("Memory allocation failed in Inkscape::Filters::FilterSlot::set (scaling)"); return; } NR::scale_bicubic(trans_pb, pb); nr_pixblock_release(pb); delete pb; pb = trans_pb; } } if(_slot[index]) { nr_pixblock_release(_slot[index]); delete _slot[index]; } _slot[index] = pb; _last_out = index; }
void *str2ptr_get(struct str2ptr *map, char *key) { unsigned int hash = _hash(key), index = _get_index(map, key, hash); return (index <= map->mask) ? map->pair[index].value : NULL; }
//! @brief Get an element by const reference given a D-tuple index. const T& at(int *index) const { int II = _get_index(index); return data[II]; }
//! @brief Get an element by reference given a D-tuple index. T& at(int *index) { int II = _get_index(index); return data[II]; }