} //end of the function GetMemory //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void *GetClearedMemory(unsigned long size) { void *ptr; ptr = GetMemory(size); Com_Memset(ptr, 0, size); return(ptr); } //end of the function GetClearedMemory
double generateNormalNumber(double seed) { double uniformSum = 0; for (unsigned i = 0; i < 12; ++i) { uniformSum += generateUniformNumber(seed); } double normalResult = uniformSum - 6; return(normalResult); // 6 is a magic number }
} //end of the function GetClearedMemory //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void *GetHunkMemory(unsigned long size) { void *ptr; unsigned long int *memid; ptr = botimport.HunkAlloc(size + sizeof(unsigned long int)); if (!ptr) { return(NULL); } memid = (unsigned long int *)ptr; *memid = HUNK_ID; return((unsigned long int *)((char *)ptr + sizeof(unsigned long int))); } //end of the function GetHunkMemory
//-------------------------------------------------------------------- public void generate(color_type* span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); do { base_type::interpolator().coordinates(&x, &y); span->v = *(value_type*) base_type::source().span(x >> image_subpixel_shift, y >> image_subpixel_shift, 1); span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
//-------------------------------------------------------------------- public void generate(color_type *span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); do { base_type::interpolator().coordinates(&x, &y); span->v = *(value_type *) base_type::source().span(x >> image_subpixel_shift, y >> image_subpixel_shift, 1); span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
//-------------------------------------------------------------------- public void generate(color_type *span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); calc_type fg; value_type *fg_ptr; do { int x_hr; int y_hr; base_type::interpolator().coordinates(&x_hr, &y_hr); x_hr -= base_type::filter_dx_int(); y_hr -= base_type::filter_dy_int(); int x_lr = x_hr >> image_subpixel_shift; int y_lr = y_hr >> image_subpixel_shift; fg = image_subpixel_scale * image_subpixel_scale / 2; x_hr &= image_subpixel_mask; y_hr &= image_subpixel_mask; fg_ptr = (value_type *)base_type::source().span(x_lr, y_lr, 2); fg += *fg_ptr * (image_subpixel_scale - x_hr) * (image_subpixel_scale - y_hr); fg_ptr = (value_type *)base_type::source().next_x(); fg += *fg_ptr * x_hr * (image_subpixel_scale - y_hr); fg_ptr = (value_type *)base_type::source().next_y(); fg += *fg_ptr * (image_subpixel_scale - x_hr) * y_hr; fg_ptr = (value_type *)base_type::source().next_x(); fg += *fg_ptr * x_hr * y_hr; span->v = value_type(fg >> (image_subpixel_shift * 2)); span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
//-------------------------------------------------------------------- public void generate(color_type* span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); int fg; value_type *fg_ptr; unsigned diameter = base_type::filter().diameter(); int start = base_type::filter().start(); int16* weight_array = base_type::filter().weight_array(); int x_count; int weight_y; do { base_type::interpolator().coordinates(&x, &y); x -= base_type::filter_dx_int(); y -= base_type::filter_dy_int(); int x_hr = x; int y_hr = y; int x_lr = x_hr >> image_subpixel_shift; int y_lr = y_hr >> image_subpixel_shift; fg = image_filter_scale / 2; int x_fract = x_hr & image_subpixel_mask; unsigned y_count = diameter; y_hr = image_subpixel_mask - (y_hr & image_subpixel_mask); fg_ptr = (value_type*)base_type::source().span(x_lr + start, y_lr + start, diameter); for(;;) { x_count = diameter; weight_y = weight_array[y_hr]; x_hr = image_subpixel_mask - x_fract; for(;;) { fg += *fg_ptr * ((weight_y * weight_array[x_hr] + image_filter_scale / 2) >> image_filter_shift); if(--x_count == 0) break; x_hr += image_subpixel_scale; fg_ptr = (value_type*)base_type::source().next_x(); } if(--y_count == 0) break; y_hr += image_subpixel_scale; fg_ptr = (value_type*)base_type::source().next_y(); } fg >>= image_filter_shift; if(fg < 0) fg = 0; if(fg > base_mask) fg = base_mask; span->v = (value_type)fg; span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
//-------------------------------------------------------------------- public void generate(color_type* span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); calc_type fg; value_type *fg_ptr; int16* weight_array = base_type::filter().weight_array() + ((base_type::filter().diameter()/2 - 1) << image_subpixel_shift); do { int x_hr; int y_hr; base_type::interpolator().coordinates(&x_hr, &y_hr); x_hr -= base_type::filter_dx_int(); y_hr -= base_type::filter_dy_int(); int x_lr = x_hr >> image_subpixel_shift; int y_lr = y_hr >> image_subpixel_shift; unsigned weight; fg = image_filter_scale / 2; x_hr &= image_subpixel_mask; y_hr &= image_subpixel_mask; fg_ptr = (value_type*)base_type::source().span(x_lr, y_lr, 2); weight = (weight_array[x_hr + image_subpixel_scale] * weight_array[y_hr + image_subpixel_scale] + image_filter_scale / 2) >> image_filter_shift; fg += weight * *fg_ptr; fg_ptr = (value_type*)base_type::source().next_x(); weight = (weight_array[x_hr] * weight_array[y_hr + image_subpixel_scale] + image_filter_scale / 2) >> image_filter_shift; fg += weight * *fg_ptr; fg_ptr = (value_type*)base_type::source().next_y(); weight = (weight_array[x_hr + image_subpixel_scale] * weight_array[y_hr] + image_filter_scale / 2) >> image_filter_shift; fg += weight * *fg_ptr; fg_ptr = (value_type*)base_type::source().next_x(); weight = (weight_array[x_hr] * weight_array[y_hr] + image_filter_scale / 2) >> image_filter_shift; fg += weight * *fg_ptr; fg >>= image_filter_shift; if(fg > base_mask) fg = base_mask; span->v = (value_type)fg; span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
//-------------------------------------------------------------------- public void generate(color_type* span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); calc_type fg; calc_type src_alpha; value_type back_v = m_back_color.v; value_type back_a = m_back_color.a; value_type *fg_ptr; int maxx = base_type::source().width() - 1; int maxy = base_type::source().height() - 1; do { int x_hr; int y_hr; base_type::interpolator().coordinates(&x_hr, &y_hr); x_hr -= base_type::filter_dx_int(); y_hr -= base_type::filter_dy_int(); int x_lr = x_hr >> image_subpixel_shift; int y_lr = y_hr >> image_subpixel_shift; if(x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { fg = image_subpixel_scale * image_subpixel_scale / 2; x_hr &= image_subpixel_mask; y_hr &= image_subpixel_mask; fg_ptr = (value_type*)base_type::source().row_ptr(y_lr) + x_lr; fg += *fg_ptr++ * (image_subpixel_scale - x_hr) * (image_subpixel_scale - y_hr); fg += *fg_ptr++ * (image_subpixel_scale - y_hr) * x_hr; ++y_lr; fg_ptr = (value_type*)base_type::source().row_ptr(y_lr) + x_lr; fg += *fg_ptr++ * (image_subpixel_scale - x_hr) * y_hr; fg += *fg_ptr++ * x_hr * y_hr; fg >>= image_subpixel_shift * 2; src_alpha = base_mask; } else { unsigned weight; if(x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { fg = back_v; src_alpha = back_a; } else { fg = src_alpha = image_subpixel_scale * image_subpixel_scale / 2; x_hr &= image_subpixel_mask; y_hr &= image_subpixel_mask; weight = (image_subpixel_scale - x_hr) * (image_subpixel_scale - y_hr); if(x_lr >= 0 && y_lr >= 0 && x_lr <= maxx && y_lr <= maxy) { fg += weight * *((value_type*)base_type::source().row_ptr(y_lr) + x_lr); src_alpha += weight * base_mask; } else { fg += back_v * weight; src_alpha += back_a * weight; } x_lr++; weight = x_hr * (image_subpixel_scale - y_hr); if(x_lr >= 0 && y_lr >= 0 && x_lr <= maxx && y_lr <= maxy) { fg += weight * *((value_type*)base_type::source().row_ptr(y_lr) + x_lr); src_alpha += weight * base_mask; } else { fg += back_v * weight; src_alpha += back_a * weight; } x_lr--; y_lr++; weight = (image_subpixel_scale - x_hr) * y_hr; if(x_lr >= 0 && y_lr >= 0 && x_lr <= maxx && y_lr <= maxy) { fg += weight * *((value_type*)base_type::source().row_ptr(y_lr) + x_lr); src_alpha += weight * base_mask; } else { fg += back_v * weight; src_alpha += back_a * weight; } x_lr++; weight = x_hr * y_hr; if(x_lr >= 0 && y_lr >= 0 && x_lr <= maxx && y_lr <= maxy) { fg += weight * *((value_type*)base_type::source().row_ptr(y_lr) + x_lr); src_alpha += weight * base_mask; } else { fg += back_v * weight; src_alpha += back_a * weight; } fg >>= image_subpixel_shift * 2; src_alpha >>= image_subpixel_shift * 2; } } span->v = (value_type)fg; span->a = (value_type)src_alpha; ++span; ++base_type::interpolator(); } while(--len); }
//-------------------------------------------------------------------- public void generate(color_type* span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); calc_type fg; value_type *fg_ptr; do { int x_hr; int y_hr; base_type::interpolator().coordinates(&x_hr, &y_hr); x_hr -= base_type::filter_dx_int(); y_hr -= base_type::filter_dy_int(); int x_lr = x_hr >> image_subpixel_shift; int y_lr = y_hr >> image_subpixel_shift; fg = image_subpixel_scale * image_subpixel_scale / 2; x_hr &= image_subpixel_mask; y_hr &= image_subpixel_mask; fg_ptr = (value_type*)base_type::source().span(x_lr, y_lr, 2); fg += *fg_ptr * (image_subpixel_scale - x_hr) * (image_subpixel_scale - y_hr); fg_ptr = (value_type*)base_type::source().next_x(); fg += *fg_ptr * x_hr * (image_subpixel_scale - y_hr); fg_ptr = (value_type*)base_type::source().next_y(); fg += *fg_ptr * (image_subpixel_scale - x_hr) * y_hr; fg_ptr = (value_type*)base_type::source().next_x(); fg += *fg_ptr * x_hr * y_hr; span->v = value_type(fg >> (image_subpixel_shift * 2)); span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
public DiskInfo(int index, string model, unsigned long size) { this.index = index; this.model = model; this.size = size; }
private virtual void g(unsigned n) { x = n as int; }
//-------------------------------------------------------------------- public void generate(color_type *span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); int fg; value_type *fg_ptr; unsigned diameter = base_type::filter().diameter(); int start = base_type::filter().start(); int16 * weight_array = base_type::filter().weight_array(); int x_count; int weight_y; do { base_type::interpolator().coordinates(&x, &y); x -= base_type::filter_dx_int(); y -= base_type::filter_dy_int(); int x_hr = x; int y_hr = y; int x_lr = x_hr >> image_subpixel_shift; int y_lr = y_hr >> image_subpixel_shift; fg = image_filter_scale / 2; int x_fract = x_hr & image_subpixel_mask; unsigned y_count = diameter; y_hr = image_subpixel_mask - (y_hr & image_subpixel_mask); fg_ptr = (value_type *)base_type::source().span(x_lr + start, y_lr + start, diameter); for (;;) { x_count = diameter; weight_y = weight_array[y_hr]; x_hr = image_subpixel_mask - x_fract; for (;;) { fg += *fg_ptr * ((weight_y * weight_array[x_hr] + image_filter_scale / 2) >> image_filter_shift); if (--x_count == 0) { break; } x_hr += image_subpixel_scale; fg_ptr = (value_type *)base_type::source().next_x(); } if (--y_count == 0) { break; } y_hr += image_subpixel_scale; fg_ptr = (value_type *)base_type::source().next_y(); } fg >>= image_filter_shift; if (fg < 0) { fg = 0; } if (fg > base_mask) { fg = base_mask; } span->v = (value_type)fg; span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
//-------------------------------------------------------------------- public void generate(color_type *span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); calc_type fg; value_type *fg_ptr; int16 * weight_array = base_type::filter().weight_array() + ((base_type::filter().diameter() / 2 - 1) << image_subpixel_shift); do { int x_hr; int y_hr; base_type::interpolator().coordinates(&x_hr, &y_hr); x_hr -= base_type::filter_dx_int(); y_hr -= base_type::filter_dy_int(); int x_lr = x_hr >> image_subpixel_shift; int y_lr = y_hr >> image_subpixel_shift; unsigned weight; fg = image_filter_scale / 2; x_hr &= image_subpixel_mask; y_hr &= image_subpixel_mask; fg_ptr = (value_type *)base_type::source().span(x_lr, y_lr, 2); weight = (weight_array[x_hr + image_subpixel_scale] * weight_array[y_hr + image_subpixel_scale] + image_filter_scale / 2) >> image_filter_shift; fg += weight * *fg_ptr; fg_ptr = (value_type *)base_type::source().next_x(); weight = (weight_array[x_hr] * weight_array[y_hr + image_subpixel_scale] + image_filter_scale / 2) >> image_filter_shift; fg += weight * *fg_ptr; fg_ptr = (value_type *)base_type::source().next_y(); weight = (weight_array[x_hr + image_subpixel_scale] * weight_array[y_hr] + image_filter_scale / 2) >> image_filter_shift; fg += weight * *fg_ptr; fg_ptr = (value_type *)base_type::source().next_x(); weight = (weight_array[x_hr] * weight_array[y_hr] + image_filter_scale / 2) >> image_filter_shift; fg += weight * *fg_ptr; fg >>= image_filter_shift; if (fg > base_mask) { fg = base_mask; } span->v = (value_type)fg; span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
//-------------------------------------------------------------------- public void generate(color_type *span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); calc_type fg; calc_type src_alpha; value_type back_v = m_back_color.v; value_type back_a = m_back_color.a; value_type *fg_ptr; int maxx = base_type::source().width() - 1; int maxy = base_type::source().height() - 1; do { int x_hr; int y_hr; base_type::interpolator().coordinates(&x_hr, &y_hr); x_hr -= base_type::filter_dx_int(); y_hr -= base_type::filter_dy_int(); int x_lr = x_hr >> image_subpixel_shift; int y_lr = y_hr >> image_subpixel_shift; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { fg = image_subpixel_scale * image_subpixel_scale / 2; x_hr &= image_subpixel_mask; y_hr &= image_subpixel_mask; fg_ptr = (value_type *)base_type::source().row_ptr(y_lr) + x_lr; fg += *fg_ptr++ *(image_subpixel_scale - x_hr) * (image_subpixel_scale - y_hr); fg += *fg_ptr++ *(image_subpixel_scale - y_hr) * x_hr; ++y_lr; fg_ptr = (value_type *)base_type::source().row_ptr(y_lr) + x_lr; fg += *fg_ptr++ *(image_subpixel_scale - x_hr) * y_hr; fg += *fg_ptr++ *x_hr * y_hr; fg >>= image_subpixel_shift * 2; src_alpha = base_mask; } else { unsigned weight; if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { fg = back_v; src_alpha = back_a; } else { fg = src_alpha = image_subpixel_scale * image_subpixel_scale / 2; x_hr &= image_subpixel_mask; y_hr &= image_subpixel_mask; weight = (image_subpixel_scale - x_hr) * (image_subpixel_scale - y_hr); if (x_lr >= 0 && y_lr >= 0 && x_lr <= maxx && y_lr <= maxy) { fg += weight * *((value_type *)base_type::source().row_ptr(y_lr) + x_lr); src_alpha += weight * base_mask; } else { fg += back_v * weight; src_alpha += back_a * weight; } x_lr++; weight = x_hr * (image_subpixel_scale - y_hr); if (x_lr >= 0 && y_lr >= 0 && x_lr <= maxx && y_lr <= maxy) { fg += weight * *((value_type *)base_type::source().row_ptr(y_lr) + x_lr); src_alpha += weight * base_mask; } else { fg += back_v * weight; src_alpha += back_a * weight; } x_lr--; y_lr++; weight = (image_subpixel_scale - x_hr) * y_hr; if (x_lr >= 0 && y_lr >= 0 && x_lr <= maxx && y_lr <= maxy) { fg += weight * *((value_type *)base_type::source().row_ptr(y_lr) + x_lr); src_alpha += weight * base_mask; } else { fg += back_v * weight; src_alpha += back_a * weight; } x_lr++; weight = x_hr * y_hr; if (x_lr >= 0 && y_lr >= 0 && x_lr <= maxx && y_lr <= maxy) { fg += weight * *((value_type *)base_type::source().row_ptr(y_lr) + x_lr); src_alpha += weight * base_mask; } else { fg += back_v * weight; src_alpha += back_a * weight; } fg >>= image_subpixel_shift * 2; src_alpha >>= image_subpixel_shift * 2; } } span->v = (value_type)fg; span->a = (value_type)src_alpha; ++span; ++base_type::interpolator(); } while(--len); }
/// <summary> /// Parse the given null terminated block of xml data. Passing in an encoding to this /// method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml /// to use that encoding, regardless of what TinyXml might otherwise try to detect. /// </summary> public override int Parse(string p, int index, TiXmlParsingData prevData /* = null*/, int encoding /* = TIXML_DEFAULT_ENCODING*/) { ClearError(); // Parse away, at the document level. Since a document // contains nothing but other tags, most of what happens // here is skipping white space. //if ( !p || !*p ) if (p == null || index < 0 || index >= p.Length) { SetError(ErrorType.TIXML_ERROR_DOCUMENT_EMPTY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN); return(0); } // Note that, for a document, this needs to come // before the while space skip, so that parsing // starts from the pointer we are given. location.Clear(); if (prevData != null) { location.row = prevData.cursor.row; location.col = prevData.cursor.col; } else { location.row = 0; location.col = 0; } TiXmlParsingData data = new TiXmlParsingData(p, index, TabSize(), location.row, location.col); location = data.Cursor(); #if UNUSED if (encoding == TiXmlEncoding.TIXML_ENCODING_UNKNOWN) { // Check for the Microsoft UTF-8 lead bytes. const unsigned char *pU = (const unsigned char *)p; if (*(pU + 0) && *(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) && *(pU + 1) == TIXML_UTF_LEAD_1 && *(pU + 2) && *(pU + 2) == TIXML_UTF_LEAD_2) { encoding = TIXML_ENCODING_UTF8; useMicrosoftBOM = true; } } #endif index = SkipWhiteSpace(p, index, encoding); //if ( !p ) if (index < 0) { SetError(ErrorType.TIXML_ERROR_DOCUMENT_EMPTY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN); return(-1); } while (index >= 0 && index < p.Length) { TiXmlNode node = Identify(p, index, encoding); if (node != null) { index = node.Parse(p, index, data, encoding); LinkEndChild(node); } else { break; } // Did we get encoding info? if (encoding == TiXmlEncoding.TIXML_ENCODING_UNKNOWN && node.ToDeclaration() != null) { TiXmlDeclaration dec = node.ToDeclaration(); string enc = dec.Encoding(); //assert( enc ); if (enc.Length == 0 /**enc == 0 */) { encoding = TiXmlEncoding.TIXML_ENCODING_UTF8; } else if (StringEqual(enc, 0, "UTF-8", true, TiXmlEncoding.TIXML_ENCODING_UNKNOWN)) { encoding = TiXmlEncoding.TIXML_ENCODING_UTF8; } else if (StringEqual(enc, 0, "UTF8", true, TiXmlEncoding.TIXML_ENCODING_UNKNOWN)) { encoding = TiXmlEncoding.TIXML_ENCODING_UTF8; // incorrect, but be nice } else { encoding = TiXmlEncoding.TIXML_ENCODING_LEGACY; } } index = SkipWhiteSpace(p, index, encoding); } // Was this empty? if (firstChild == null) { SetError(ErrorType.TIXML_ERROR_DOCUMENT_EMPTY, null, 0, null, encoding); return(INVALID_STRING_INDEX); } // All is well. return(index); }
/* ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking ** on the cache using a hash function. This is used for testing ** and debugging only. */ #if SQLITE_CHECK_PAGES /* ** Return a 32-bit hash of the page data for pPage. */ static u32 pager_datahash(int nByte, unsigned char pData){ u32 hash = 0; int i; for(i=0; i<nByte; i++){ hash = (hash*1039) + pData[i]; } return hash; }
//-------------------------------------------------------------------- public void generate(color_type* span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); long_type fg; int diameter = base_type::filter().diameter(); int filter_scale = diameter << image_subpixel_shift; int16* weight_array = base_type::filter().weight_array(); do { int rx; int ry; int rx_inv = image_subpixel_scale; int ry_inv = image_subpixel_scale; base_type::interpolator().coordinates(&x, &y); base_type::interpolator().local_scale(&rx, &ry); base_type::adjust_scale(&rx, &ry); rx_inv = image_subpixel_scale * image_subpixel_scale / rx; ry_inv = image_subpixel_scale * image_subpixel_scale / ry; int radius_x = (diameter * rx) >> 1; int radius_y = (diameter * ry) >> 1; int len_x_lr = (diameter * rx + image_subpixel_mask) >> image_subpixel_shift; x += base_type::filter_dx_int() - radius_x; y += base_type::filter_dy_int() - radius_y; fg = image_filter_scale / 2; int y_lr = y >> image_subpixel_shift; int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) * ry_inv) >> image_subpixel_shift; int total_weight = 0; int x_lr = x >> image_subpixel_shift; int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) * rx_inv) >> image_subpixel_shift; int x_hr2 = x_hr; value_type* fg_ptr = (value_type*)base_type::source().span(x_lr, y_lr, len_x_lr); for(;;) { int weight_y = weight_array[y_hr]; x_hr = x_hr2; for(;;) { int weight = (weight_y * weight_array[x_hr] + image_filter_scale / 2) >> downscale_shift; fg += *fg_ptr * weight; total_weight += weight; x_hr += rx_inv; if(x_hr >= filter_scale) break; fg_ptr = (value_type*)base_type::source().next_x(); } y_hr += ry_inv; if(y_hr >= filter_scale) break; fg_ptr = (value_type*)base_type::source().next_y(); } fg /= total_weight; if(fg < 0) fg = 0; if(fg > base_mask) fg = base_mask; span->v = (value_type)fg; span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
unsigned int getHash(unsigned int proxyId1, unsigned int proxyId2)
//template <typename T> //void store(const T * RESTRICT V); //template <typename T> //T delta(const T * RESTRICT V); //template <typename T> //void build_LE_A(); //template <typename T> //void build_LE_RHS(); /* calculate matrix */ void setup_matrix() { UInt32 iN = (UInt32)m_nets.size(); for (UInt32 k = 0; k < iN; k++) { m_terms[k].railstart = m_terms[k].count(); for (UInt32 i = 0; i < m_rails_temp[k].count(); i++) { this.m_terms[k].add(m_rails_temp[k].terms()[i], m_rails_temp[k].connected_net_idx()[i], false); } m_terms[k].set_pointers(); } foreach (terms_for_net_t rt in m_rails_temp) { rt.clear(); // no longer needed //plib::pfree(rt); // no longer needed } m_rails_temp.clear(); /* Sort in descending order by number of connected matrix voltages. * The idea is, that for Gauss-Seidel algo the first voltage computed * depends on the greatest number of previous voltages thus taking into * account the maximum amout of information. * * This actually improves performance on popeye slightly. Average * GS computations reduce from 2.509 to 2.370 * * Smallest to largest : 2.613 * Unsorted : 2.509 * Largest to smallest : 2.370 * * Sorting as a general matrix pre-conditioning is mentioned in * literature but I have found no articles about Gauss Seidel. * * For Gaussian Elimination however increasing order is better suited. * NOTE: Even better would be to sort on elements right of the matrix diagonal. * */ if (m_sort != eSortType.NOSORT) { int sort_order = (m_sort == eSortType.DESCENDING ? 1 : -1); for (UInt32 k = 0; k < iN - 1; k++) { for (UInt32 i = k + 1; i < iN; i++) { if (((int)(m_terms[k].railstart) - (int)(m_terms[i].railstart)) * sort_order < 0) { //std::swap(m_terms[i], m_terms[k]); var termsTemp = m_terms[i]; m_terms[i] = m_terms[k]; m_terms[k] = termsTemp; //std::swap(m_nets[i], m_nets[k]); var netsTemp = m_nets[i]; m_nets[i] = m_nets[k]; m_nets[k] = netsTemp; } } } foreach (var term in m_terms) { var other = term.connected_net_idx(); for (UInt32 i = 0; i < term.count(); i++) { if (other[i] != -1) { other[i] = get_net_idx(term.terms()[i].otherterm.net()); } } } } /* create a list of non zero elements. */ for (UInt32 k = 0; k < iN; k++) { terms_for_net_t t = m_terms[k]; /* pretty brutal */ var other = t.connected_net_idx(); t.nz.clear(); for (UInt32 i = 0; i < t.railstart; i++) { if (!t.nz.Contains((UInt32)other[i])) //if (!plib::container::contains(t->m_nz, static_cast<unsigned>(other[i]))) { t.nz.push_back((UInt32)other[i]); } } t.nz.push_back(k); // add diagonal /* and sort */ t.nz.Sort(); //std::sort(t.m_nz.begin(), t.m_nz.end()); } /* create a list of non zero elements right of the diagonal * These list anticipate the population of array elements by * Gaussian elimination. */ for (UInt32 k = 0; k < iN; k++) { terms_for_net_t t = m_terms[k]; /* pretty brutal */ var other = t.connected_net_idx(); if (k == 0) { t.nzrd.clear(); } else { t.nzrd = m_terms[k - 1].nzrd; for (var jIdx = 0; jIdx < t.nzrd.Count;) //for (var j = t.nzrd.begin(); j != t.nzrd.end(); ) { var j = t.nzrd[jIdx]; if (j < k + 1) { t.nzrd.erase(jIdx); } else { ++jIdx; } } } for (UInt32 i = 0; i < t.railstart; i++) { if (!t.nzrd.Contains((UInt32)other[i]) && other[i] >= (int)(k + 1)) //if (!plib::container::contains(t->m_nzrd, static_cast<unsigned>(other[i])) && other[i] >= static_cast<int>(k + 1)) { t.nzrd.push_back((UInt32)other[i]); } } /* and sort */ t.nzrd.Sort(); //std::sort(t.m_nzrd.begin(), t.m_nzrd.end()); } /* create a list of non zero elements below diagonal k * This should reduce cache misses ... */ bool [,] touched = new bool [iN, iN]; //bool **touched = plib::palloc_array<bool *>(iN); //for (UInt32 k = 0; k < iN; k++) // touched[k] = plib::palloc_array<bool>(iN); for (UInt32 k = 0; k < iN; k++) { for (UInt32 j = 0; j < iN; j++) { touched[k, j] = false; } for (UInt32 j = 0; j < m_terms[k].nz.size(); j++) { touched[k, m_terms[k].nz[j]] = true; } } m_ops = 0; for (UInt32 k = 0; k < iN; k++) { m_ops++; // 1/A(k,k) for (UInt32 row = k + 1; row < iN; row++) { if (touched[row, k]) { m_ops++; if (!m_terms[k].nzbd.Contains(row)) //if (!plib::container::contains(m_terms[k]->m_nzbd, row)) { m_terms[k].nzbd.push_back(row); } for (UInt32 col = k + 1; col < iN; col++) { if (touched[k, col]) { touched[row, col] = true; m_ops += 2; } } } } } log().verbose.op("Number of mults/adds for {0}: {1}", name(), m_ops); #if false if ((0)) { for (unsigned k = 0; k < iN; k++) { pstring line = plib::pfmt("{1:3}")(k); for (unsigned j = 0; j < m_terms[k]->m_nzrd.size(); j++) { line += plib::pfmt(" {1:3}")(m_terms[k]->m_nzrd[j]); } log().verbose("{1}", line); } } #endif /* * save states */ for (UInt32 k = 0; k < iN; k++) { string num = new plib.pfmt("{0}").op(k); state().save(this, m_terms[k].last_V, "lastV." + num); state().save(this, m_terms[k].DD_n_m_1, "m_DD_n_m_1." + num); state().save(this, m_terms[k].h_n_m_1, "m_h_n_m_1." + num); state().save(this, m_terms[k].go(), "GO" + num, m_terms[k].count()); state().save(this, m_terms[k].gt(), "GT" + num, m_terms[k].count()); state().save(this, m_terms[k].Idr(), "IDR" + num, m_terms[k].count()); } //for (UInt32 k = 0; k < iN; k++) // plib::pfree_array(touched[k]); //plib::pfree_array(touched); touched = null; }
//-------------------------------------------------------------------- public void generate(color_type *span, int x, int y, unsigned len) { base_type::interpolator().begin(x + base_type::filter_dx_dbl(), y + base_type::filter_dy_dbl(), len); long_type fg; int diameter = base_type::filter().diameter(); int filter_scale = diameter << image_subpixel_shift; int16 *weight_array = base_type::filter().weight_array(); do { int rx; int ry; int rx_inv = image_subpixel_scale; int ry_inv = image_subpixel_scale; base_type::interpolator().coordinates(&x, &y); base_type::interpolator().local_scale(&rx, &ry); base_type::adjust_scale(&rx, &ry); rx_inv = image_subpixel_scale * image_subpixel_scale / rx; ry_inv = image_subpixel_scale * image_subpixel_scale / ry; int radius_x = (diameter * rx) >> 1; int radius_y = (diameter * ry) >> 1; int len_x_lr = (diameter * rx + image_subpixel_mask) >> image_subpixel_shift; x += base_type::filter_dx_int() - radius_x; y += base_type::filter_dy_int() - radius_y; fg = image_filter_scale / 2; int y_lr = y >> image_subpixel_shift; int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) * ry_inv) >> image_subpixel_shift; int total_weight = 0; int x_lr = x >> image_subpixel_shift; int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) * rx_inv) >> image_subpixel_shift; int x_hr2 = x_hr; value_type *fg_ptr = (value_type *)base_type::source().span(x_lr, y_lr, len_x_lr); for (;;) { int weight_y = weight_array[y_hr]; x_hr = x_hr2; for (;;) { int weight = (weight_y * weight_array[x_hr] + image_filter_scale / 2) >> downscale_shift; fg += *fg_ptr * weight; total_weight += weight; x_hr += rx_inv; if (x_hr >= filter_scale) { break; } fg_ptr = (value_type *)base_type::source().next_x(); } y_hr += ry_inv; if (y_hr >= filter_scale) { break; } fg_ptr = (value_type *)base_type::source().next_y(); } fg /= total_weight; if (fg < 0) { fg = 0; } if (fg > base_mask) { fg = base_mask; } span->v = (value_type)fg; span->a = base_mask; ++span; ++base_type::interpolator(); } while(--len); }
void set(unsigned value) { data->nWeekDay = value; }