void HatDescSearch( // search in a grid around the current landmark double& x, // io: (in: old position of landmark, out: new position) double& y, // io: const HatFit hatfit) // in: func to estimate descriptor match { // If HAT_SEARCH_RESOL is 2, force x,y positions to be divisible // by 2 to increase cache hit rate. This increases the mean hit rate // from about 67% to 88% and barely affects landmark accuracy. int ix = HAT_SEARCH_RESOL == 2? round2(x): cvRound(x); int iy = HAT_SEARCH_RESOL == 2? round2(y): cvRound(y); double fit_best = -FLT_MAX; int xoffset_best = 0, yoffset_best = 0; // in pixels for (int yoffset = -HAT_MAX_OFFSET; yoffset <= HAT_MAX_OFFSET; yoffset += HAT_SEARCH_RESOL) { for (int xoffset = -HAT_MAX_OFFSET; xoffset <= HAT_MAX_OFFSET; xoffset += HAT_SEARCH_RESOL) { const double fit = GetHatFit(ix + xoffset, iy + yoffset, hatfit); if (fit > fit_best) { fit_best = fit; xoffset_best = xoffset; yoffset_best = yoffset; } } } x += xoffset_best; y += yoffset_best; }
bool CFeatureExtraction::GetGaborResponse(CvMat * pGaborMat) { float* pMatPos; int idx = 0; printf("\nCFeatureExtraction::GetGaborResponse in\n"); // Convert our image to grayscale (Gabor doesn't care about colors! I hope?) IplImage *pGrayImg = cvCreateImage(cvSize(m_pSrcImg->width,m_pSrcImg->height), IPL_DEPTH_32F, 1); cvCvtColor(m_pSrcImgFloat,pGrayImg,CV_BGR2GRAY); // The output image IplImage *reimg = cvCreateImage(cvSize(pGrayImg->width,pGrayImg->height), IPL_DEPTH_32F, 1); double freq = 0.4; int freq_steps = 4; int ori_count = 6; double ori_space = PI/ori_count; int i,j; for (i=0;i<freq_steps;i++) { double bw = (2 * freq) / 3; double sx = round2(0.5 / PI / pow(bw,2)); double sy = round2(0.5 * log(2.0) / pow(PI,2.0) / pow(freq,2.0) / (pow(tan(ori_space / 2),2.0))); for (j=0;j<ori_count;j++) { double ori = j*ori_space; GetGaborResponse(pGrayImg, reimg, ori, freq, sx, sy); // This being a test and all, display the image // displayImage(title, reimg); //char filename[255]; //sprintf(filename, "gabor%02d.bmp", idx+1); //cvSaveImage(filename,reimg); // Concat the new vector to the result matrix int k; pMatPos = (float *) pGaborMat->data.fl; float * pResData = (float *) reimg->imageData; for (k=0;k<reimg->width*reimg->height;k++) { pMatPos[idx] = (float) pResData[0]; pMatPos += 24; pResData++; } idx++; } freq /= 2; } // Release cvReleaseImage(&reimg); cvReleaseImage(&pGrayImg); printf("CFeatureExtraction::GetGaborResponse out\n"); return true; }
/* * Initialize globals that cannot be handled statically. */ void initglob(void) { /* * Round hash table sizes to next power of two, and set masks for hashing. */ lchsize = round2(lchsize); cmask = lchsize - 1; fhsize = round2(fhsize); fmask = fhsize - 1; ghsize = round2(ghsize); gmask = ghsize - 1; ihsize = round2(ihsize); imask = ihsize - 1; lhsize = round2(lhsize); lmask = lhsize - 1; }
static void send_conf (struct device_s *dev) { int y1, y2, x1, x2; size_t size = 100; DBG(100,"Sending configuration packet on device %s\n",dev->devname); y1 = (int) round2 ((dev->optionw[Y1_OFFSET] / ((double) MAX_Y_S)) * MAX_Y_H); y2 = (int) round2 ((dev->optionw[Y2_OFFSET] / ((double) MAX_Y_S)) * MAX_Y_H); x1 = (int) round2 ((dev->optionw[X1_OFFSET] / ((double) MAX_X_S)) * MAX_X_H); x2 = (int) round2 ((dev->optionw[X2_OFFSET] / ((double) MAX_X_S)) * MAX_X_H); DBG(100,"\t x1: %d, x2: %d, y1: %d, y2: %d\n",x1, x2, y1, y2); DBG(100,"\t brightness: %d, contrast: %d\n", dev->optionw[BRIGH_OFFSET], dev->optionw[CONTR_OFFSET]); DBG(100,"\t resolution: %d\n",dev->optionw[RES_OFFSET]); dev->conf_data[0] = htonl (0x15); dev->conf_data[1] = htonl (dev->optionw[BRIGH_OFFSET]); dev->conf_data[2] = htonl (dev->optionw[CONTR_OFFSET]); dev->conf_data[3] = htonl (dev->optionw[RES_OFFSET]); dev->conf_data[4] = htonl (0x1); dev->conf_data[5] = htonl (0x1); dev->conf_data[6] = htonl (0x1); dev->conf_data[7] = htonl (0x1); dev->conf_data[8] = 0; dev->conf_data[9] = 0; dev->conf_data[10] = htonl (0x8); dev->conf_data[11] = 0; dev->conf_data[12] = 0; dev->conf_data[13] = 0; dev->conf_data[14] = 0; dev->conf_data[16] = htonl (y1); dev->conf_data[17] = htonl (x1); dev->conf_data[18] = htonl (y2); dev->conf_data[19] = htonl (x2); dev->conf_data[20] = 0; dev->conf_data[21] = 0; dev->conf_data[22] = htonl (0x491); dev->conf_data[23] = htonl (0x352); if (dev->optionw[COLOR_OFFSET] == RGB) { dev->conf_data[15] = htonl (0x2); dev->conf_data[24] = htonl (0x1); DBG(100,"\t Scanning in RGB format\n"); } else { dev->conf_data[15] = htonl (0x6); dev->conf_data[24] = htonl (0x0); DBG(100,"\t Scanning in Grayscale format\n"); } sanei_usb_write_bulk (dev->dn, (unsigned char *) dev->conf_data, &size); }
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[]) { int p = (int)mxGetScalar(in[0]); int q = (int)mxGetScalar(in[1]); int p2 = (int)mxGetScalar(in[2]); int q2 = (int)mxGetScalar(in[3]); //int Lp = (int)mxGetScalar(in[4]); //int Lq = (int)mxGetScalar(in[5]); int Lp=round2((double)p/p2); int Lq=round2((double)q/q2); out[0] = mxCreateDoubleMatrix(p,q,mxREAL); double*classes=mxGetPr(out[0]); constraint_classes(classes,p,q,p2,q2,Lp,Lq); }
static int sm_get_memspeed (char *name, int table_num) { if(Platform.RAM.Type) return round2( Platform.RAM.Frequency / 500000, 2); else return 667; }
void dumpStaticTableData(const UInt8 * tableBuffer, int maxStructureSize, int structureCount, int tableLength) { int index = 0; printf("\n\t#define STATIC_SMBIOS_SM_MAX_STRUCTURE_SIZE\t%d\n", maxStructureSize); printf("\n\t#define STATIC_SMBIOS_DMI_STRUCTURE_COUNT\t%d\n", structureCount); printf("\n"); printf("\t#define STATIC_SMBIOS_DATA \\\n"); printf("\t/* SMBIOS data (0x%04x / %d bytes) converted with smbios2struct2 into little endian format. */ \\\n", tableLength, tableLength); printf("\t/* 0x0000 */\t"); UInt16 length = round2(tableLength, 4); UInt32 * newTableData = malloc(tableLength); bcopy((UInt32 *)tableBuffer, newTableData, tableLength); do { printf("0x%08x", (unsigned int)newTableData[index++]); if ((index * 4) <= length) { printf(", "); if ((index % 8) == 0) { printf("\\\n\t/* 0x%04x */\t", (index * 4)); } } } while((index * 4) <= length); printf("\n"); free(newTableData); }
void rlwe_kex_compute_key_bob(const uint32_t b[1024], const uint32_t s[1024], uint64_t c[16], uint64_t k[16], FFT_CTX *ctx) { uint32_t v[1024]; uint32_t eprimeprime[1024]; RAND_CTX rand_ctx; if (!RAND_CTX_init(&rand_ctx)) { fprintf(stderr, "Randomness allocation error."); return; } #if CONSTANT_TIME sample_ct(eprimeprime, &rand_ctx); #else sample(eprimeprime, &rand_ctx); #endif key_gen(v, b, s, eprimeprime, ctx); #if CONSTANT_TIME crossround2_ct(c, v, &rand_ctx`); round2_ct(k, v); #else crossround2(c, v, &rand_ctx); round2(k, v); #endif memset((char *) v, 0, 1024 * sizeof(uint32_t)); memset((char *) eprimeprime, 0, 1024 * sizeof(uint32_t)); RAND_CTX_cleanup(&rand_ctx); }
int quantize(float *B,float **cb,int nt,int ny,int nx,int dim,float thresh) { int it,i,offset,N; float *A,*weight,avgweight; int ny2,nx2,ei; unsigned char *P; int debug=0; ei = nt*ny*nx; printf ("color quantization\n"); offset=2; ny2 = ny+2*offset; nx2 = nx+2*offset; weight=(float *)calloc(ei,sizeof(float)); A=(float *)calloc(ny2*nx2*dim,sizeof(float)); avgweight = 0; for (it=0;it<nt;it++) { extendboundfloat(B+it*ny*nx*dim,A,ny,nx,offset,dim); avgweight += pga(B+it*ny*nx*dim,A,ny,nx,offset,weight+it*ny*nx,dim); } avgweight /= nt; free(A); for (i=0;i<ei;i++) weight[i] = exp(-weight[i]); P=(unsigned char *)calloc(ei,sizeof(unsigned char)); N=MAX(round2(2*avgweight),round2(17*sqrt(dim/3.0))); if (N>256) N=256; N=greedy(B,ei,dim,N,cb,0.05,P,weight); /* These codes are for testing direct VQ */ /* weight=(float *)calloc(ei,sizeof(float)); for (i=0;i<ei;i++) weight[i] = 1; P=(unsigned char *)calloc(ei,sizeof(unsigned char)); N=20; greedy(B,ei,dim,N,cb,0.05,P,weight); */ N=mergecb(B,cb,P,ei,N,thresh,dim); gla(B,ei,dim,N,cb,0.03,P,weight); if (debug) printf("N=%d \n",N); free(weight); free(P); return N; }
int main(int argc, char **argv) { if (argc != 2) { printf("usage: %s filename\n", argv[0]); return 1; } if (round1(argv[1]) || round2(argv[1])) return 1; return 0; }
static void md5_process_block(md5_ctx_t *p, uint32 *block) { uint32 orig[4]; memcpy(orig, p->d, sizeof(orig)); round1(p->d, block); round2(p->d, block); round3(p->d, block); round4(p->d, block); p->d[0] += orig[0]; p->d[1] += orig[1]; p->d[2] += orig[2]; p->d[3] += orig[3]; }
int round_tensor_dimension(int dim, bool periodic, int padding) { if (periodic) return dim; const int tmp = 2*dim-1; if (tmp == 1) return 1; switch (padding) { case PADDING_DISABLE: return tmp; case PADDING_ROUND_2: return round2(tmp); case PADDING_ROUND_4: return round4(tmp); case PADDING_ROUND_8: return round8(tmp); case PADDING_ROUND_POT: return round_pot(tmp); case PADDING_SMALL_PRIME_FACTORS: return round_small_prime_factors(tmp+1); default: throw std::runtime_error("Invalid padding strategy"); } }
int main(int argc, char **argv) { int a_origin_size; int i, max; signal(SIGCHLD, sigchld_handler); signal(SIGTERM, clean); signal(SIGQUIT, clean); if(argc == 1) { printf("введите количество элементов в массиве: "); fflush(stdout); } scanf("%d", &a_origin_size); if(a_origin_size <= 0) { exit(0); } a_size = round2(a_origin_size); sn_init(); for(i = max = 0; i < a_origin_size; i++) { scanf("%d", array + i); max = MAX(array[i], max); } for(; i < a_size; array[i++] = max); if(a_origin_size > 1) { build_schedule(); //print_schedule(); run(); } for(i = 0; i < a_origin_size; printf("%d ", array[i++])); printf("\n"); clean(0); return 0; }
static void TraceShape( // write an image file showing current shape on the image const Shape& shape, // in: current search shape const Image& pyrimg, // in: image scaled to this pyramid level int ilev, // in: pyramid level (0 is full size) int iter, // in: model iteration (-1 if start shape) const char* suffix) // in { #if TRACE_IMAGES // will be 0 unless debugging (defined in stasm.h) static int index; // number images so they appear in order in the directory // start at index 30 because lower indices have already used for facedet etc. if (strcmp(suffix, "start") == 0) index = 30; Image img; // pyrimg rescaled back to full size image (after rescaling by eyemouth) const double RESOLUTION = 2; // 1 for no extra resolution, 2 for double resolution const double rescale = RESOLUTION / GetPyrScale(ilev); cv::resize(pyrimg, img, cv::Size(), rescale, rescale, cv::INTER_NEAREST); CImage cimg; cvtColor(img, cimg, CV_GRAY2BGR); // color image DesaturateImg(cimg); Shape shape1(RoundMat(shape)); shape1 += .4; // put shape points in center of rescaled pixels shape1 *= rescale; DrawShape(cimg, shape1, C_YELLOW, false, 1); char path[SLEN]; if (iter < 0) // start shape? sprintf(path, "%s_%2.2d_%s.bmp", Base(imgpath_g), index, suffix); else sprintf(path, "%s_%2.2d_lev%d_iter%d_%s.bmp", Base(imgpath_g), index, ilev, iter, suffix); ImgPrintf(cimg, 10 * RESOLUTION, 20 * RESOLUTION, C_YELLOW, 2, path); if (iter >= 0) { // draw 1D patch boundary at one point (patch is drawn // horizontal, not rotated to shape boundary as it should be) // [Thanks to Satish Lokkoju for RoundMat fix] Shape shape2(RoundMat(shape)); int ipoint = 0; int proflen = 9; // TASM_1D_PROFLEN int x1 = cvRound(shape2(ipoint, IX)) - proflen / 2; int x2 = x1 + proflen; int y1 = cvRound(shape2(ipoint, IY)); int y2 = y1 + 1; rectangle(cimg, cv::Point(cvRound(rescale * x1), cvRound(rescale * y1)), cv::Point(cvRound(rescale * x2), cvRound(rescale * y2)), CV_RGB(255,0,0), 1); // draw 2D patch boundary at one point if (ilev <= HAT_START_LEV) // we use HATs only at upper pyr levs { // get position of left eye pupil by first converting to a shape17 ipoint = 0; // assume we can't get position of left eye pupil Shape newshape(Shape17OrEmpty(shape2)); if (newshape.rows) // successfully converted to a shape17? ipoint = L17_LPupil; else newshape = shape2; #define round2(x) 2 * cvRound((x) / 2) int patchwidth = HAT_PATCH_WIDTH + round2(ilev * HAT_PATCH_WIDTH_ADJ); x1 = cvRound(newshape(ipoint, IX)) - patchwidth / 2; x2 = x1 + patchwidth; y1 = cvRound(newshape(ipoint, IY)) - patchwidth / 2; y2 = y1 + patchwidth; rectangle(cimg, cv::Point(cvRound(rescale * x1), cvRound(rescale * y1)), cv::Point(cvRound(rescale * x2), cvRound(rescale * y2)), CV_RGB(255,0,0), 1); } } lprintf("%s\n", path); if (!cv::imwrite(path, cimg)) Err("Cannot write %s", path); index++; #endif // TRACE_IMAGES }
/* * CAST-256 Decryption */ void CAST_256::decrypt_n(const byte in[], byte out[], size_t blocks) const { for(size_t i = 0; i != blocks; ++i) { u32bit A = load_be<u32bit>(in, 0); u32bit B = load_be<u32bit>(in, 1); u32bit C = load_be<u32bit>(in, 2); u32bit D = load_be<u32bit>(in, 3); round1(C, D, MK[44], RK[44]); round2(B, C, MK[45], RK[45]); round3(A, B, MK[46], RK[46]); round1(D, A, MK[47], RK[47]); round1(C, D, MK[40], RK[40]); round2(B, C, MK[41], RK[41]); round3(A, B, MK[42], RK[42]); round1(D, A, MK[43], RK[43]); round1(C, D, MK[36], RK[36]); round2(B, C, MK[37], RK[37]); round3(A, B, MK[38], RK[38]); round1(D, A, MK[39], RK[39]); round1(C, D, MK[32], RK[32]); round2(B, C, MK[33], RK[33]); round3(A, B, MK[34], RK[34]); round1(D, A, MK[35], RK[35]); round1(C, D, MK[28], RK[28]); round2(B, C, MK[29], RK[29]); round3(A, B, MK[30], RK[30]); round1(D, A, MK[31], RK[31]); round1(C, D, MK[24], RK[24]); round2(B, C, MK[25], RK[25]); round3(A, B, MK[26], RK[26]); round1(D, A, MK[27], RK[27]); round1(D, A, MK[23], RK[23]); round3(A, B, MK[22], RK[22]); round2(B, C, MK[21], RK[21]); round1(C, D, MK[20], RK[20]); round1(D, A, MK[19], RK[19]); round3(A, B, MK[18], RK[18]); round2(B, C, MK[17], RK[17]); round1(C, D, MK[16], RK[16]); round1(D, A, MK[15], RK[15]); round3(A, B, MK[14], RK[14]); round2(B, C, MK[13], RK[13]); round1(C, D, MK[12], RK[12]); round1(D, A, MK[11], RK[11]); round3(A, B, MK[10], RK[10]); round2(B, C, MK[ 9], RK[ 9]); round1(C, D, MK[ 8], RK[ 8]); round1(D, A, MK[ 7], RK[ 7]); round3(A, B, MK[ 6], RK[ 6]); round2(B, C, MK[ 5], RK[ 5]); round1(C, D, MK[ 4], RK[ 4]); round1(D, A, MK[ 3], RK[ 3]); round3(A, B, MK[ 2], RK[ 2]); round2(B, C, MK[ 1], RK[ 1]); round1(C, D, MK[ 0], RK[ 0]); store_be(out, A, B, C, D); in += BLOCK_SIZE; out += BLOCK_SIZE; } }
/* * CAST-256 Key Schedule */ void CAST_256::key_schedule(const byte key[], size_t length) { static const u32bit KEY_MASK[192] = { 0x5A827999, 0xC95C653A, 0x383650DB, 0xA7103C7C, 0x15EA281D, 0x84C413BE, 0xF39DFF5F, 0x6277EB00, 0xD151D6A1, 0x402BC242, 0xAF05ADE3, 0x1DDF9984, 0x8CB98525, 0xFB9370C6, 0x6A6D5C67, 0xD9474808, 0x482133A9, 0xB6FB1F4A, 0x25D50AEB, 0x94AEF68C, 0x0388E22D, 0x7262CDCE, 0xE13CB96F, 0x5016A510, 0xBEF090B1, 0x2DCA7C52, 0x9CA467F3, 0x0B7E5394, 0x7A583F35, 0xE9322AD6, 0x580C1677, 0xC6E60218, 0x35BFEDB9, 0xA499D95A, 0x1373C4FB, 0x824DB09C, 0xF1279C3D, 0x600187DE, 0xCEDB737F, 0x3DB55F20, 0xAC8F4AC1, 0x1B693662, 0x8A432203, 0xF91D0DA4, 0x67F6F945, 0xD6D0E4E6, 0x45AAD087, 0xB484BC28, 0x235EA7C9, 0x9238936A, 0x01127F0B, 0x6FEC6AAC, 0xDEC6564D, 0x4DA041EE, 0xBC7A2D8F, 0x2B541930, 0x9A2E04D1, 0x0907F072, 0x77E1DC13, 0xE6BBC7B4, 0x5595B355, 0xC46F9EF6, 0x33498A97, 0xA2237638, 0x10FD61D9, 0x7FD74D7A, 0xEEB1391B, 0x5D8B24BC, 0xCC65105D, 0x3B3EFBFE, 0xAA18E79F, 0x18F2D340, 0x87CCBEE1, 0xF6A6AA82, 0x65809623, 0xD45A81C4, 0x43346D65, 0xB20E5906, 0x20E844A7, 0x8FC23048, 0xFE9C1BE9, 0x6D76078A, 0xDC4FF32B, 0x4B29DECC, 0xBA03CA6D, 0x28DDB60E, 0x97B7A1AF, 0x06918D50, 0x756B78F1, 0xE4456492, 0x531F5033, 0xC1F93BD4, 0x30D32775, 0x9FAD1316, 0x0E86FEB7, 0x7D60EA58, 0xEC3AD5F9, 0x5B14C19A, 0xC9EEAD3B, 0x38C898DC, 0xA7A2847D, 0x167C701E, 0x85565BBF, 0xF4304760, 0x630A3301, 0xD1E41EA2, 0x40BE0A43, 0xAF97F5E4, 0x1E71E185, 0x8D4BCD26, 0xFC25B8C7, 0x6AFFA468, 0xD9D99009, 0x48B37BAA, 0xB78D674B, 0x266752EC, 0x95413E8D, 0x041B2A2E, 0x72F515CF, 0xE1CF0170, 0x50A8ED11, 0xBF82D8B2, 0x2E5CC453, 0x9D36AFF4, 0x0C109B95, 0x7AEA8736, 0xE9C472D7, 0x589E5E78, 0xC7784A19, 0x365235BA, 0xA52C215B, 0x14060CFC, 0x82DFF89D, 0xF1B9E43E, 0x6093CFDF, 0xCF6DBB80, 0x3E47A721, 0xAD2192C2, 0x1BFB7E63, 0x8AD56A04, 0xF9AF55A5, 0x68894146, 0xD7632CE7, 0x463D1888, 0xB5170429, 0x23F0EFCA, 0x92CADB6B, 0x01A4C70C, 0x707EB2AD, 0xDF589E4E, 0x4E3289EF, 0xBD0C7590, 0x2BE66131, 0x9AC04CD2, 0x099A3873, 0x78742414, 0xE74E0FB5, 0x5627FB56, 0xC501E6F7, 0x33DBD298, 0xA2B5BE39, 0x118FA9DA, 0x8069957B, 0xEF43811C, 0x5E1D6CBD, 0xCCF7585E, 0x3BD143FF, 0xAAAB2FA0, 0x19851B41, 0x885F06E2, 0xF738F283, 0x6612DE24, 0xD4ECC9C5, 0x43C6B566, 0xB2A0A107, 0x217A8CA8, 0x90547849, 0xFF2E63EA, 0x6E084F8B, 0xDCE23B2C, 0x4BBC26CD, 0xBA96126E, 0x296FFE0F, 0x9849E9B0, 0x0723D551, 0x75FDC0F2, 0xE4D7AC93, 0x53B19834, 0xC28B83D5, 0x31656F76, 0xA03F5B17, 0x0F1946B8 }; static const byte KEY_ROT[32] = { 0x13, 0x04, 0x15, 0x06, 0x17, 0x08, 0x19, 0x0A, 0x1B, 0x0C, 0x1D, 0x0E, 0x1F, 0x10, 0x01, 0x12, 0x03, 0x14, 0x05, 0x16, 0x07, 0x18, 0x09, 0x1A, 0x0B, 0x1C, 0x0D, 0x1E, 0x0F, 0x00, 0x11, 0x02 }; MK.resize(48); RK.resize(48); secure_vector<u32bit> K(8); for(size_t i = 0; i != length; ++i) K[i/4] = (K[i/4] << 8) + key[i]; u32bit A = K[0], B = K[1], C = K[2], D = K[3], E = K[4], F = K[5], G = K[6], H = K[7]; for(size_t i = 0; i != 48; i += 4) { round1(G, H, KEY_MASK[4*i+ 0], KEY_ROT[(4*i+ 0) % 32]); round2(F, G, KEY_MASK[4*i+ 1], KEY_ROT[(4*i+ 1) % 32]); round3(E, F, KEY_MASK[4*i+ 2], KEY_ROT[(4*i+ 2) % 32]); round1(D, E, KEY_MASK[4*i+ 3], KEY_ROT[(4*i+ 3) % 32]); round2(C, D, KEY_MASK[4*i+ 4], KEY_ROT[(4*i+ 4) % 32]); round3(B, C, KEY_MASK[4*i+ 5], KEY_ROT[(4*i+ 5) % 32]); round1(A, B, KEY_MASK[4*i+ 6], KEY_ROT[(4*i+ 6) % 32]); round2(H, A, KEY_MASK[4*i+ 7], KEY_ROT[(4*i+ 7) % 32]); round1(G, H, KEY_MASK[4*i+ 8], KEY_ROT[(4*i+ 8) % 32]); round2(F, G, KEY_MASK[4*i+ 9], KEY_ROT[(4*i+ 9) % 32]); round3(E, F, KEY_MASK[4*i+10], KEY_ROT[(4*i+10) % 32]); round1(D, E, KEY_MASK[4*i+11], KEY_ROT[(4*i+11) % 32]); round2(C, D, KEY_MASK[4*i+12], KEY_ROT[(4*i+12) % 32]); round3(B, C, KEY_MASK[4*i+13], KEY_ROT[(4*i+13) % 32]); round1(A, B, KEY_MASK[4*i+14], KEY_ROT[(4*i+14) % 32]); round2(H, A, KEY_MASK[4*i+15], KEY_ROT[(4*i+15) % 32]); RK[i ] = (A % 32); RK[i+1] = (C % 32); RK[i+2] = (E % 32); RK[i+3] = (G % 32); MK[i ] = H; MK[i+1] = F; MK[i+2] = D; MK[i+3] = B; } }
static int PatchWidth( // patchwidth at the given pyramid level int ilev) // in: pyramid level (0 is full size) { return HAT_PATCH_WIDTH + round2(ilev * HAT_PATCH_WIDTH_ADJ); }
int main(int argc, char *argv[]) { // Instanciations variables int i,j; int TailleIn, TailleOut; FILE* fichierMatIn = NULL; FILE* fichierMatOut = NULL; int** MatIn = NULL; int** MatOut = NULL; float zoom; /* --------On gère la matrice en entrée-----------*/ // On lit le fichier en entrée pour récuperer la taille de notre matrice a transformer if(argc > 1) { fichierMatIn = fopen(argv[1], "r"); if(fichierMatIn != NULL) fscanf(fichierMatIn, "%i\n", &TailleIn); else { printf("Mauvais fichier d'entrée"); return -1; } } else { printf("Aucun fichier en entrée"); return -1; } // On instancie une matrice qui peut le contenir MatIn = malloc(sizeof(int*)*TailleIn); for(i=0; i<TailleIn; i++) MatIn[i] = malloc(sizeof(int)*TailleIn); // On remplit la matrice for(i=0; i<TailleIn*TailleIn; i++) fscanf(fichierMatIn, "%i\t", &MatIn[(int)(i/TailleIn)][i % TailleIn]); /* On ouvre le fichier de sortie */ if (argc > 3) { fichierMatOut = fopen(argv[3], "w+"); if (fichierMatOut == NULL) { printf("Mauvais fichier de sortie"); return -1; } } /* ---------On crée la matrice de sortie -----------*/ // On récupere sa taille if(argc > 2) { TailleOut = atoi(argv[2]); } // On instancie une matrice pour la contenir MatOut = malloc(sizeof(int*)*TailleOut); for(i=0; i<TailleOut; i++) { MatOut[i] = malloc(sizeof(int)*TailleOut); } /* --------- On retrouve le facteur de zoom ou étirement ---------------*/ zoom = (float)(TailleOut-1) / (TailleIn-1); printf("TailleOut = %i\tTailleIn = %i\t zoom = %f\n\n", TailleOut, TailleIn, zoom); /* -------- On implémente l'algorithme -------------- */ // for (i=0; i<TailleOut; i++) { for (j=0; j<TailleOut; j++) { if ( (int)(i/zoom) == i/zoom ) /* On est entre deux valeurs justes horizontales */ { /* On est sur une valeur juste */ if ( (int)(j/zoom) == j/zoom ) MatOut[i][j] = round2(MatIn[(int)(i/zoom)][(int)(j/zoom)] * zoom); else if ( (int)(j/zoom) +1 < TailleIn ) MatOut[i][j] = round2( ( MatIn[(int)(i/zoom)][(int)(j/zoom)] + ( MatIn[(int)(i/zoom)][(int)(j/zoom)+1] - MatIn[(int)(i/zoom)][(int)(j/zoom)] )*(j/zoom - (int)(j/zoom)) )*zoom ); } else if ( (int)(j/zoom) == j/zoom && (int)(i/zoom) +1 < TailleIn ) /* On est entre deux valeurs justes verticales */ { MatOut[i][j] = round2( ( MatIn[(int)(i/zoom)][(int)(j/zoom)] + ( MatIn[(int)(i/zoom)+1][(int)(j/zoom)] - MatIn[(int)(i/zoom)][(int)(j/zoom)] )*(i/zoom - (int)(i/zoom) ) )*zoom ); } else if ( (int)(j/zoom) +1 < TailleIn && (int)(i/zoom) +1 < TailleIn ) /* On est entre quatres valeurs justes */ { float d1, d2, d3, d4, dNorm; d1 = sqrt( ((int)(i/zoom) - i/zoom)*((int)(i/zoom) - i/zoom) + ((int)(j/zoom) - j/zoom)*((int)(j/zoom) - j/zoom) ); d2 = sqrt( ((int)(i/zoom) - i/zoom + 1)*((int)(i/zoom) - i/zoom + 1) + ((int)(j/zoom) - j/zoom)*((int)(j/zoom) - j/zoom) ); d3 = sqrt( ((int)(i/zoom) - i/zoom)*((int)(i/zoom) - i/zoom) + ((int)(j/zoom) - j/zoom + 1)*((int)(j/zoom) - j/zoom + 1) ); d4 = sqrt( ((int)(i/zoom) - i/zoom + 1)*((int)(i/zoom) - i/zoom + 1) + ((int)(j/zoom) - j/zoom + 1)*((int)(j/zoom) - j/zoom + 1) ); dNorm = 4*dM - d1 - d2 - d3 - d4; MatOut[i][j] = round2(( ( (dM - d1)*MatIn[(int)(i/zoom)][(int)(j/zoom)] + (dM - d2)*MatIn[(int)(i/zoom) + 1][(int)(j/zoom)] + (dM - d3)*MatIn[(int)(i/zoom)][(int)(j/zoom) +1] + (dM - d4)*MatIn[(int)(i/zoom) + 1][(int)(j/zoom) +1])/dNorm)*zoom); } //if (i == TailleOut -1 || j == TailleOut -1) else printf("i = %i\tj = %i\t(int)(j/zoom) = %i\tj/zoom = %f\t(int)(i/zoom) = %i\ti/zoom = %f\t\tMatOut[%i][%i] = %i\n",i , j, (int)(j/zoom), j/zoom, (int)(i/zoom), i/zoom, i, j, MatOut[i][j]); } } /* -------- On écrit dans le fichier de sortie ---------*/ fprintf(fichierMatOut, "%i\n", TailleOut); for(i=0; i<TailleOut; i++) { for(j=0; j<TailleOut; j++) { fprintf(fichierMatOut, "%i\t", MatOut[i][j]); } //fprintf(fichierMatOut, "\n"); } return 0; }
int main(int argc, char * argv[]) { char dirspec[128]; int filedesc = 0; struct stat my_sb; if (argc == 2) { uid_t real_uid = getuid(); uid_t euid = geteuid(); #if DEBUG printf("UID: %u EUID: %u\n", real_uid, euid); #endif // Under sudo, getuid and geteuid return 0. if (real_uid != 0 || euid != 0) { printf("Error: Not root. Use sudo ./smbios2struct4 [filename without extension]\n"); exit (-1); } } mach_port_t masterPort; io_service_t service = MACH_PORT_NULL; CFDataRef dataRef; UInt16 maxStructureSize, structureCount = 0; UInt16 tableLength = 0, droppedTables = 0; UInt16 newTableLength = 0; IOMasterPort(MACH_PORT_NULL, &masterPort); //================================================================================== io_registry_entry_t efi = IORegistryEntryFromPath(kIOMasterPortDefault, kIODeviceTreePlane ":/efi"); if (efi == IO_OBJECT_NULL) { #if DEBUG printf("FAILURE: Unable to locate EFI registry entry.\n"); #endif exit(-1); } else { #if DEBUG printf("OK\n"); #endif dataRef = (CFDataRef) IORegistryEntryCreateCFProperty(efi, CFSTR("device-properties"), kCFAllocatorDefault, kNilOptions); if (dataRef) { UInt32 * deviceProperties = (UInt32 *) CFDataGetBytePtr(dataRef); UInt16 devicePropertiesBytes = (int) CFDataGetLength(dataRef); #if DEBUG printf("Property 'device-properties' %d bytes found.", numBytes); #endif if ((argc == 2) && (devicePropertiesBytes)) // Write to file? { // Sanity check for required directory. if (stat("/Extra", &my_sb) != 0) { mkdir("/Extra", (S_IRWXU | S_IRWXG | S_IRWXO)); } // Sanity check for required directory. if (stat("/Extra/EFI", &my_sb) != 0) { mkdir("/Extra/EFI", (S_IRWXU | S_IRWXG | S_IRWXO)); } sprintf (dirspec, "/Extra/EFI/%s.bin", argv[1]); filedesc = open(dirspec, O_WRONLY|O_CREAT|O_TRUNC, 0644); if (filedesc == -1) { printf("Error: Unable to open file!\n"); } else { int status = write(filedesc, deviceProperties, devicePropertiesBytes); if (status != devicePropertiesBytes) { printf("status %d, saved %d bytes\n", status, devicePropertiesBytes); } else { printf("%d bytes written to: %s\n", devicePropertiesBytes, dirspec); } } close (filedesc); } } #if DEBUG else { printf("FAILURE: Unable to locate ':/efi/device-properties'\n"); } #endif } //================================================================================== service = IOServiceGetMatchingService(masterPort, IOServiceMatching("AppleSMBIOS")); if (service) { #if DEBUG printf("\nAppleSMBIOS found\n"); #endif dataRef = (CFDataRef) IORegistryEntryCreateCFProperty(service, CFSTR("SMBIOS-EPS"), kCFAllocatorDefault, kNilOptions); if (dataRef) { // We could use isA_CFData(dataRef) {} here, but that would force us to include // another file, which in my opinion would be overkill (dataRef should always be there). #if DEBUG printf("Have SMBIOS-EPS dataRef\n\n"); #endif struct SMBEntryPoint * eps = (struct SMBEntryPoint *) CFDataGetBytePtr(dataRef); tableLength = eps->dmi.tableLength; /* shadowTableData = malloc(tableLength); bzero(shadowTableData, tableLength); bcopy((void *)(unsigned int)eps->dmi.tableAddress, shadowTableData, tableLength); */ #if DEBUG // _SM_ eps->anchor[4] = 0; // Prevent garbage output. printf("eps.anchor : %s\n", eps->anchor); printf("eps.checksum : 0x02%x\n", eps->checksum); printf("eps.entryPointLength : 0x%x\n", eps->entryPointLength); printf("eps.majorVersion : 0x%02x\n", eps->majorVersion); printf("eps.minorVersion : 0x%02x\n", eps->minorVersion); #endif maxStructureSize = eps->maxStructureSize; #if DEBUG printf("eps.maxStructureSize : 0x%04x\n", maxStructureSize); printf("eps.entryPointRevision: 0x%02x\n", eps->entryPointRevision); printf("eps.formattedArea : %s\n\n", eps->formattedArea); // _DMI_ eps->dmi.anchor[5] = 0; // Prevent garbage output. printf("eps.dmi.anchor : %s\n", eps->dmi.anchor); printf("eps.dmi.checksum : 0x%02x\n", eps->dmi.checksum); printf("eps.dmi.tableLength : 0x%04x\n", tableLength); // eps->dmi.tableLength); printf("eps.dmi.tableAddress : 0x%08x\n", (unsigned int)eps->dmi.tableAddress); #endif structureCount = eps->dmi.structureCount; #if DEBUG printf("eps.dmi.structureCount: 0x%04x\n", structureCount); printf("eps.dmi.bcdRevision : 0x%x\n", eps->dmi.bcdRevision); #endif // Done with dataRef / release it. CFRelease(dataRef); } #if DEBUG printf("\n"); #endif dataRef = (CFDataRef) IORegistryEntryCreateCFProperty(service, CFSTR("SMBIOS"), kCFAllocatorDefault, kNilOptions); if (dataRef) { // We could use isA_CFData(dataRef) {} here, but that would force us to include another // header file, which in my opinion would be overkill as dataRef should always be there. #if DEBUG printf("Have SMBIOS dataRef\n"); #endif UInt32 * tableData = (UInt32 *) CFDataGetBytePtr(dataRef); #if VERBOSE UInt16 numBytes = (int) CFDataGetLength(dataRef); printf("\nNumber of bytes: %d (Original SMBIOS table)\n", numBytes); #endif SMBStructHeader * header; const UInt8 * tablePtr = (const UInt8 *) tableData; const UInt8 * tableEndPtr = tablePtr + tableLength; const UInt8 * tableStructureStart = 0; const UInt8 * droppedTableStructureStart = 0; const UInt8 * tableBuffer = malloc(tableLength); // int index = 0; int maxStructureSize = 0; int newStructureCount = 0; int structureLength = 0; SMBWord newHandle = 0; bzero((void *)tableBuffer, sizeof(tableBuffer)); while (structureCount-- && (tableEndPtr > tablePtr + sizeof(SMBStructHeader))) { droppedTableStructureStart = tableStructureStart = 0; header = (SMBStructHeader *) tablePtr; if (header->length > tableEndPtr - tablePtr) { break; } switch (header->type) { case kSMBTypeBIOSInformation: // Type 0 case kSMBTypeSystemInformation: // Type 1 case kSMBTypeBaseBoard: // Type 2 case kSMBTypeProcessorInformation: // Type 4 // case kSMBTypeMemoryModule: // Type 6 // case kSMBTypeSystemSlot: // Type 9 case kSMBTypePhysicalMemoryArray: // Type 16 case kSMBTypeMemoryDevice: // Type 17 case kSMBTypeEndOfTable: // Type 127 case kSMBTypeFirmwareVolume: // Type 128 case kSMBTypeMemorySPD: // Type 130 case kSMBTypeOemProcessorType: // Type 131 case kSMBTypeOemProcessorBusSpeed: // Type 132 newStructureCount++; tableStructureStart = tablePtr; header->handle = newHandle++; // printf("type: %d, handle: %d\n", header->type, header->handle); break; default: droppedTables++; droppedTableStructureStart = tablePtr; } VERBOSE_DUMP("Table: %3d %37s @%p Formatted area: %2d bytes ", header->type, tableDescriptions[header->type], tablePtr, header->length); // Skip the formatted area of the structure. tablePtr += header->length; // Skip the unformatted structure area at the end (strings). for (; tableEndPtr > tablePtr + sizeof(SMBStructHeader); tablePtr++) { // Look for a terminating double NULL. if (tablePtr[0] == 0 && tablePtr[1] == 0) { tablePtr += 2; break; } } if (tableStructureStart) { structureLength = tablePtr - tableStructureStart; VERBOSE_DUMP("Structure length: %3d bytes.\n", structureLength); bcopy((void *)tableStructureStart, (void *)tableBuffer + newTableLength, structureLength); newTableLength += structureLength; // Taking care of eps->maxStructureSize if (maxStructureSize < structureLength) { maxStructureSize = structureLength; } } else if (droppedTableStructureStart) { structureLength = tablePtr - droppedTableStructureStart; VERBOSE_DUMP("Structure length: %3d bytes (dropped).\n", structureLength); } } VERBOSE_DUMP("\nDropped tables: %2d.\n", droppedTables); if (argc == 2) // Write to file? { // Sanity check for required directory. if (stat("/Extra/SMBIOS", &my_sb) != 0) { mkdir("/Extra/SMBIOS", (S_IRWXU | S_IRWXG | S_IRWXO)); } sprintf (dirspec, "/Extra/SMBIOS/%s.bin", argv[1]); filedesc = open(dirspec, O_WRONLY|O_CREAT|O_TRUNC, 0644); if (filedesc == -1) { printf("Error: Unable to open file!\n"); } else { newTableLength = round2((newTableLength + 2), 4); VERBOSE_DUMP("newTableLength: %d\n", newTableLength); int status = write(filedesc, tableBuffer, newTableLength); if (status != newTableLength) { printf("status %d, saved %d bytes\n", status, newTableLength); } else { printf("%d bytes written to: %s\n", newTableLength, dirspec); } } close (filedesc); } else { dumpStaticTableData(tableBuffer, maxStructureSize, newStructureCount, newTableLength); } free((void *)tableBuffer); // Done with dataRef / release it. CFRelease(dataRef); } // Done with the service / release it. IOObjectRelease(service); } exit(0); }
int do_nebula_report (dbref enactor) { static char buffer[BUFFER_LEN], nbuff[20]; double px = sdb[n].coords.x / PARSEC; double py = sdb[n].coords.y / PARSEC; double pz = sdb[n].coords.z / PARSEC; double cx[2], cy[2], cz[2]; double dx, dy, dz; register int x, y, z; register int i = 0; aspace_borders *nebula; double range; cx[0] = ceil(px / 100.0) * 100.0; cx[1] = floor(px / 100.0) * 100.0; cy[0] = ceil(py / 100.0) * 100.0; cy[1] = floor(py / 100.0) * 100.0; cz[0] = ceil(pz / 100.0) * 100.0; cz[1] = floor(pz / 100.0) * 100.0; if (error_on_console(enactor)) { return 0; } else if (!sdb[n].sensor.lrs_exist) { notify(enactor, ansi_red(tprintf("%s has no long-range sensors.", Name(sdb[n].object)))); } else if (!sdb[n].sensor.lrs_active) { notify(enactor, ansi_red("Long-range sensors are inactive.")); } else { snprintf(buffer, sizeof(buffer), "%s%s--[%sNebula Report%s]--------------------------------------------------------------%s\n%sNebulae Bearing Range Core Vis Core Coordinates%s\n%s-------------------- ------- ------- -------- ---------------------------------%s\n", ANSI_HILITE, ANSI_BLUE, ANSI_YELLOW, ANSI_BLUE, ANSI_NORMAL, ANSI_CYAN, ANSI_WHITE, ANSI_BLUE, ANSI_WHITE); if (aspace_config.nebula >= 1 && im_count(nebula_map) > 0) { for (i = 1; i <= im_count(nebula_map); i++) { nebula = im_find(nebula_map, i); if (!nebula) continue; range = xyz2range(sdb[n].coords.x, sdb[n].coords.y, sdb[n].coords.z, nebula->x, nebula->y, nebula->z) / PARSEC; if (fabs(range - nebula->radius) >= 150.0) continue; strncat(buffer, tprintf("%-20.20s %3d %-3d %-7.7s %7.3f%% %10.3f %10.3f %10.3f\n", nebula->name, (int) round2(xy2bearing((nebula->x - sdb[n].coords.x), (nebula->y - sdb[n].coords.y))), (int) round2(xyz2elevation((nebula->x - sdb[n].coords.x), (nebula->y - sdb[n].coords.y), (nebula->z - sdb[n].coords.z))), unparse_range(xyz2range(sdb[n].coords.x, sdb[n].coords.y, sdb[n].coords.z, nebula->x, nebula->y, nebula->z)), xyz2vis(nebula->x, nebula->y, nebula->z) * 100.0, nebula->x / PARSEC, nebula->y / PARSEC, nebula->z / PARSEC), sizeof(buffer) - 1); } } if (aspace_config.nebula <= 1) { for (z = 0; z < 2; ++z) { for (y = 0; y < 2; ++y) { for (x = 0; x < 2; ++x) { snprintf(nbuff, sizeof(nbuff), "Nebula %d-%d-%d", round2(fabs(cx[x] / 100.0)), round2(fabs(cy[y] / 100.0)), round2(fabs(cz[z] / 100.0))); dx = cx[x] * PARSEC; dy = cy[y] * PARSEC; dz = cz[z] * PARSEC; strncat(buffer, tprintf("%-20.20s %3d %-3d %-7.7s %7.3f%% %10.3f %10.3f %10.3f\n", nbuff, (int) round2(xy2bearing((dx - sdb[n].coords.x), (dy - sdb[n].coords.y))), (int) round2(xyz2elevation((dx - sdb[n].coords.x), (dy - sdb[n].coords.y), (dz - sdb[n].coords.z))), unparse_range(xyz2range(sdb[n].coords.x, sdb[n].coords.y, sdb[n].coords.z, dx, dy, dz)), xyz2vis(dx, dy, dz) * 100.0, cx[x] - sdb[n].coords.xo / PARSEC, cy[y] - sdb[n].coords.yo / PARSEC, cz[z] - sdb[n].coords.zo / PARSEC), sizeof(buffer) - 1); } } } } strncat(buffer, format_l_line(), sizeof(buffer) - 1); strncat(buffer, format_Course(n), sizeof(buffer) - 1); strncat(buffer, format_Speed(n), sizeof(buffer) - 1); strncat(buffer, "\n", sizeof(buffer) - 1); strncat(buffer, format_Location(n), sizeof(buffer) - 1); strncat(buffer, format_Velocity(n), sizeof(buffer) - 1); strncat(buffer, "\n", sizeof(buffer) - 1); strncat(buffer, format_l_end(), sizeof(buffer) - 1); notify(enactor, buffer); return 1; } return 0; }
static void update_img_size (struct device_s *dev) { int dx, dy; /* Only update the width when not scanning, * otherwise the scanner give us the correct width */ if (dev->status == STATUS_SCANNING) { dev->height = -1; return; } dx = dev->optionw[X2_OFFSET] - dev->optionw[X1_OFFSET]; dy = dev->optionw[Y2_OFFSET] - dev->optionw[Y1_OFFSET]; switch (dev->optionw[RES_OFFSET]) { case 75: dev->width = round2 ((dx / ((double) MAX_X_S)) * 640); dev->height = round2 ((dy / ((double) MAX_Y_S)) * 880); break; case 100: dev->width = round2 ((dx / ((double) MAX_X_S)) * 848); dev->height = round2 ((dy / ((double) MAX_Y_S)) * 1180); break; case 150: dev->width = round2 ((dx / ((double) MAX_X_S)) * 1264); dev->height = round2 ((dy / ((double) MAX_Y_S)) * 1775); break; case 200: dev->width = round2 ((dx / ((double) MAX_X_S)) * 1696); dev->height = round2 ((dy / ((double) MAX_Y_S)) * 2351); break; case 300: dev->width = round2 ((dx / ((double) MAX_X_S)) * 2528); dev->height = round2 ((dy / ((double) MAX_Y_S)) * 3510); break; case 600: dev->width = round2 ((dx / ((double) MAX_X_S)) * 5088); dev->height = round2 ((dy / ((double) MAX_Y_S)) * 7020); break; case 1200: dev->width = round2 ((dx / ((double) MAX_X_S)) * 10208); dev->height = round2 ((dy / ((double) MAX_Y_S)) * 14025); break; } DBG(2,"New image size: %dx%d\n",dev->width, dev->height); }
int gla(float *A,int nvec,int ndim,int N,float **codebook,float t,unsigned char *P, float *weight) { int iv,in,i,j,jn,codeword_exist=0,k,l; float *totalw,d1,d2,rate,lastmse,mse,*centroid,*d; totalw=(float *)calloc(N,sizeof(float)); d=(float *)calloc(ndim,sizeof(float)); for (i=0;i<5;i++) { /* get the new partition and total distortion using NN */ mse=0.0; j=0; for (iv=0;iv<nvec;iv++) { for (k=0;k<ndim;k++) d[k] = A[j++]-codebook[0][k]; d1=0; for (k=0;k<ndim;k++) d1 += sqr(d[k]); P[iv]=0; for (in=1;in<N;in++) { d2=0; l=j-ndim; for (k=0;k<ndim;k++) { d2+=sqr(A[l]-codebook[in][k]); l++; if (d2>=d1) break; } if (d2<d1) { d1=d2; P[iv]= (unsigned char) in; } } mse+=d1; } /* get the new codebook using centroid */ for (in=0;in<N;in++) { totalw[in]=0.0; for (k=0;k<ndim;k++) codebook[in][k]=0; } j = 0; for (iv=0;iv<nvec;iv++) { for (k=0;k<ndim;k++) codebook[P[iv]][k] += weight[iv]*A[j++]; totalw[P[iv]]+=weight[iv]; } for (in=0;in<N;in++) { if (totalw[in]>0.0) { for (k=0;k<ndim;k++) codebook[in][k] /= totalw[in]; } else { /* assign a training vector not in the codebook as code vector */ codeword_exist=1; iv= round2 ( ((float) rand()) *(nvec-1)/RAND_MAX); while (codeword_exist<=2 && codeword_exist>0) { j = iv*ndim; for (k=0;k<ndim;k++) codebook[in][k] = A[j++]; for (jn=0;jn<N;jn++) { if (jn!=in) { for (k=0;k<ndim;k++) d[k]=codebook[jn][k]-codebook[in][k]; d1=0; for (k=0;k<ndim;k++) d1 += sqr(d[k]); if (d1==0) break; } } if (jn==N) codeword_exist=0; else { iv = round2( ((float) rand()) *(nvec-1)/RAND_MAX); codeword_exist++; } } } } if (i>0) { rate=(lastmse-mse)/lastmse; if (rate<t) break; } lastmse=mse; } for (in=0;in<N;in++) { totalw[in]=0.0; for (k=0;k<ndim;k++) codebook[in][k]=0; } j = 0; for (iv=0;iv<nvec;iv++) { for (k=0;k<ndim;k++) codebook[P[iv]][k] += A[j++]; totalw[P[iv]]+=1.0; } for (in=0;in<N;in++) { if (totalw[in]>0) { for (k=0;k<ndim;k++) codebook[in][k] /= totalw[in]; } } free(d); free(totalw); return codeword_exist; }
GLDepthRenderTarget::GLDepthRenderTarget(int w, int h, int l):GLRenderTarget() { GLuint shadowMapTexture=0; GLuint rboId=0; width = w; height = h; if(!gl_ext_framebuffer.integer) return; if(!GLEW_ARB_texture_non_power_of_two) { width = round2(width); height = round2(height); texS = w/(float)width; texT = h/(float)height; } glGenTextures(1, &shadowMapTexture); if(l && gl_ext_texture_array.integer) { Console_Printf(" Generate DEPTH ARRAY FBO %dx%dx%d. ", w, h, l); glBindTexture(GL_TEXTURE_2D_ARRAY, shadowMapTexture); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, width, height, l, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glBindTexture(GL_TEXTURE_2D_ARRAY, 0); glGenFramebuffersEXT(1, &fboId); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId); glGenRenderbuffersEXT(1, &rboId); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height); // attach a renderbuffer to depth attachment point glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId); // attach a texture to FBO depth attachment point // Big: actually we set the target when we go to use it //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D/*_ARRAY*/, shadowMapTexture, 0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); } else if(l==0 && GLEW_ARB_depth_texture) { Console_Printf(" Generate DEPTH FBO %dx%d. ", w, h); glBindTexture(GL_TEXTURE_2D, shadowMapTexture); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); //glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE ); //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE ); glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glBindTexture(GL_TEXTURE_2D, 0); glGenFramebuffersEXT(1, &fboId); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId); glGenRenderbuffersEXT(1, &rboId); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height); // attach a renderbuffer to depth attachment point glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId); // attach a texture to FBO depth attachment point // Big: actually we set the target when we go to use it //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadowMapTexture, 0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); } #ifdef DEBUG GLSL_catchLastError("GLDepthRenderTarget::GLDepthRenderTarget"); #endif GL_CheckFBOStatus(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //now create a pass for when we go to use this thing passCount = 1; passes[0] = new GLMaterialPass(this); passes[0]->texmaps[0] = shadowMapTexture; passes[0]->texmap_num = 1; if(l && gl_ext_texture_array.integer) { passes[0]->multitexture = true; passes[0]->arrayTexture = true; } }
GLRenderTarget::GLRenderTarget(int w, int h, bool depth):GLMaterial() { GLuint texId=0, texDepthId=0; texS = texT = 1.0f; fboId = 0; width = w; height = h; if(!gl_ext_framebuffer.integer || !GL_VersionAtLeast(2,1)) { width = MIN(width, (unsigned int)Vid_GetScreenW()); height = MIN(height, (unsigned int)Vid_GetScreenH()); } if(!GLEW_ARB_texture_non_power_of_two) { width = round2(width); height = round2(height); texS = w/(float)width; texT = h/(float)height; } glGenTextures(1, &texId); glBindTexture(GL_TEXTURE_2D, texId); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); if(vid_multisample.integer && gl_arb_texture_multisample.integer) { glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, vid_multisample.integer, GL_BGRA, width, height, GL_TRUE); } else { glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } glBindTexture(GL_TEXTURE_2D, 0); if(gl_ext_framebuffer.integer && GL_VersionAtLeast(2,1)) { if(depth) { glGenTextures(1, &texDepthId); glBindTexture(GL_TEXTURE_2D, texDepthId); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); GL_GenerateFBOWithDepth(texId, texDepthId, &fboId, w, h); } else { GL_GenerateFBO(texId, &fboId, w, h); } } else { width=height=0; texS = texT = 1.0f; } #ifdef DEBUG GLSL_catchLastError("GLRenderTarget::GLRenderTarget"); #endif //now create a pass for when we go to use this thing passCount = 1; passes[0] = new GLMaterialPass(this); passes[0]->texmaps[0] = texId; passes[0]->texmap_num = 1; if(depth) { passes[0]->texmaps[1] = texDepthId; passes[0]->texmap_num = 2; } }
static SANE_Status setvalue (SANE_Handle h, SANE_Int option, void *value, SANE_Int * info) { struct device_s *dev = (struct device_s *) h; SANE_Status status = SANE_STATUS_GOOD; int s_unit; int s_unit_2; if (option == 0) return SANE_STATUS_UNSUPPORTED; status = sanei_constrain_value (&(dev->optiond[option]), value, info); if (status != SANE_STATUS_GOOD) return status; if (info) *info |= SANE_INFO_RELOAD_PARAMS; switch (option) { case X1_OFFSET: dev->optionw[option] = *((SANE_Word *) value); s_unit = (int) round2 ((dev->optionw[option] / ((double) MAX_X_S)) * MAX_X_H); s_unit_2 = (int) round2 ((dev->optionw[X2_OFFSET] / ((double) MAX_X_S)) * MAX_X_H); if (abs (s_unit_2 - s_unit) < MIN_SCAN_ZONE) s_unit = s_unit_2 - MIN_SCAN_ZONE; dev->optionw[option] = round2 ((s_unit / ((double) MAX_X_H)) * MAX_X_S); if (info) *info |= SANE_INFO_INEXACT; break; case X2_OFFSET: /* X units */ /* convert into "scanner" unit, then back into mm */ dev->optionw[option] = *((SANE_Word *) value); s_unit = (int) round2 ((dev->optionw[option] / ((double) MAX_X_S)) * MAX_X_H); s_unit_2 = (int) round2 ((dev->optionw[X1_OFFSET] / ((double) MAX_X_S)) * MAX_X_H); if (abs (s_unit_2 - s_unit) < MIN_SCAN_ZONE) s_unit = s_unit_2 + MIN_SCAN_ZONE; dev->optionw[option] = round2 ((s_unit / ((double) MAX_X_H)) * MAX_X_S); if (info) *info |= SANE_INFO_INEXACT; break; case Y1_OFFSET: /* Y units */ dev->optionw[option] = *((SANE_Word *) value); s_unit = (int) round2 ((dev->optionw[option] / ((double) MAX_Y_S)) * MAX_Y_H); s_unit_2 = (int) round2 ((dev->optionw[Y2_OFFSET] / ((double) MAX_Y_S)) * MAX_Y_H); if (abs (s_unit_2 - s_unit) < MIN_SCAN_ZONE) s_unit = s_unit_2 - MIN_SCAN_ZONE; dev->optionw[option] = round2 ((s_unit / ((double) MAX_Y_H)) * MAX_Y_S); if (info) *info |= SANE_INFO_INEXACT; break; case Y2_OFFSET: /* Y units */ dev->optionw[option] = *((SANE_Word *) value); s_unit = (int) round2 ((dev->optionw[option] / ((double) MAX_Y_S)) * MAX_Y_H); s_unit_2 = (int) round2 ((dev->optionw[Y1_OFFSET] / ((double) MAX_Y_S)) * MAX_Y_H); if (abs (s_unit_2 - s_unit) < MIN_SCAN_ZONE) s_unit = s_unit_2 + MIN_SCAN_ZONE; dev->optionw[option] = round2 ((s_unit / ((double) MAX_Y_H)) * MAX_Y_S); if (info) *info |= SANE_INFO_INEXACT; break; case COLOR_OFFSET: if (!strcmp ((char *) value, mode_list[0])) dev->optionw[option] = GRAY; /* Gray */ else if (!strcmp ((char *) value, mode_list[1])) dev->optionw[option] = RGB; /* RGB */ else return SANE_STATUS_INVAL; break; default: dev->optionw[option] = *((SANE_Word *) value); } return SANE_STATUS_GOOD; }
GLint GLAPIENTRY gluBuild2DMipmaps(GLenum target, GLint components, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data) { GLint w, h, maxsize; void *image, *newimage; GLint neww, newh, level, bpp; int error; GLboolean done; GLint retval = 0; GLint unpackrowlength, unpackalignment, unpackskiprows, unpackskippixels; GLint packrowlength, packalignment, packskiprows, packskippixels; if (width < 1 || height < 1) return GLU_INVALID_VALUE; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize); w = round2(width); if (w > maxsize) { w = maxsize; } h = round2(height); if (h > maxsize) { h = maxsize; } bpp = bytes_per_pixel(format, type); if (bpp == 0) { /* probably a bad format or type enum */ return GLU_INVALID_ENUM; } /* Get current glPixelStore values */ glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpackrowlength); glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpackalignment); glGetIntegerv(GL_UNPACK_SKIP_ROWS, &unpackskiprows); glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &unpackskippixels); glGetIntegerv(GL_PACK_ROW_LENGTH, &packrowlength); glGetIntegerv(GL_PACK_ALIGNMENT, &packalignment); glGetIntegerv(GL_PACK_SKIP_ROWS, &packskiprows); glGetIntegerv(GL_PACK_SKIP_PIXELS, &packskippixels); /* set pixel packing */ glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_SKIP_ROWS, 0); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); done = GL_FALSE; if (w != width || h != height) { /* must rescale image to get "top" mipmap texture image */ image = malloc((w + 4) * h * bpp); if (!image) { return GLU_OUT_OF_MEMORY; } error = gluScaleImage(format, width, height, type, data, w, h, type, image); if (error) { retval = error; done = GL_TRUE; } } else { image = (void *) data; } level = 0; while (!done) { if (image != data) { /* set pixel unpacking */ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); } glTexImage2D(target, level, components, w, h, 0, format, type, image); if (w == 1 && h == 1) break; neww = (w < 2) ? 1 : w / 2; newh = (h < 2) ? 1 : h / 2; newimage = malloc((neww + 4) * newh * bpp); if (!newimage) { return GLU_OUT_OF_MEMORY; } error = gluScaleImage(format, w, h, type, image, neww, newh, type, newimage); if (error) { retval = error; done = GL_TRUE; } if (image != data) { free(image); } image = newimage; w = neww; h = newh; level++; } if (image != data) { free(image); } /* Restore original glPixelStore state */ glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackrowlength); glPixelStorei(GL_UNPACK_ALIGNMENT, unpackalignment); glPixelStorei(GL_UNPACK_SKIP_ROWS, unpackskiprows); glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackskippixels); glPixelStorei(GL_PACK_ROW_LENGTH, packrowlength); glPixelStorei(GL_PACK_ALIGNMENT, packalignment); glPixelStorei(GL_PACK_SKIP_ROWS, packskiprows); glPixelStorei(GL_PACK_SKIP_PIXELS, packskippixels); return retval; }
/* * CAST-256 Encryption */ void CAST_256::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { for(size_t i = 0; i != blocks; ++i) { uint32_t A = load_be<uint32_t>(in, 0); uint32_t B = load_be<uint32_t>(in, 1); uint32_t C = load_be<uint32_t>(in, 2); uint32_t D = load_be<uint32_t>(in, 3); round1(C, D, m_MK[ 0], m_RK[ 0]); round2(B, C, m_MK[ 1], m_RK[ 1]); round3(A, B, m_MK[ 2], m_RK[ 2]); round1(D, A, m_MK[ 3], m_RK[ 3]); round1(C, D, m_MK[ 4], m_RK[ 4]); round2(B, C, m_MK[ 5], m_RK[ 5]); round3(A, B, m_MK[ 6], m_RK[ 6]); round1(D, A, m_MK[ 7], m_RK[ 7]); round1(C, D, m_MK[ 8], m_RK[ 8]); round2(B, C, m_MK[ 9], m_RK[ 9]); round3(A, B, m_MK[10], m_RK[10]); round1(D, A, m_MK[11], m_RK[11]); round1(C, D, m_MK[12], m_RK[12]); round2(B, C, m_MK[13], m_RK[13]); round3(A, B, m_MK[14], m_RK[14]); round1(D, A, m_MK[15], m_RK[15]); round1(C, D, m_MK[16], m_RK[16]); round2(B, C, m_MK[17], m_RK[17]); round3(A, B, m_MK[18], m_RK[18]); round1(D, A, m_MK[19], m_RK[19]); round1(C, D, m_MK[20], m_RK[20]); round2(B, C, m_MK[21], m_RK[21]); round3(A, B, m_MK[22], m_RK[22]); round1(D, A, m_MK[23], m_RK[23]); round1(D, A, m_MK[27], m_RK[27]); round3(A, B, m_MK[26], m_RK[26]); round2(B, C, m_MK[25], m_RK[25]); round1(C, D, m_MK[24], m_RK[24]); round1(D, A, m_MK[31], m_RK[31]); round3(A, B, m_MK[30], m_RK[30]); round2(B, C, m_MK[29], m_RK[29]); round1(C, D, m_MK[28], m_RK[28]); round1(D, A, m_MK[35], m_RK[35]); round3(A, B, m_MK[34], m_RK[34]); round2(B, C, m_MK[33], m_RK[33]); round1(C, D, m_MK[32], m_RK[32]); round1(D, A, m_MK[39], m_RK[39]); round3(A, B, m_MK[38], m_RK[38]); round2(B, C, m_MK[37], m_RK[37]); round1(C, D, m_MK[36], m_RK[36]); round1(D, A, m_MK[43], m_RK[43]); round3(A, B, m_MK[42], m_RK[42]); round2(B, C, m_MK[41], m_RK[41]); round1(C, D, m_MK[40], m_RK[40]); round1(D, A, m_MK[47], m_RK[47]); round3(A, B, m_MK[46], m_RK[46]); round2(B, C, m_MK[45], m_RK[45]); round1(C, D, m_MK[44], m_RK[44]); store_be(out, A, B, C, D); in += BLOCK_SIZE; out += BLOCK_SIZE; } }
GLint gluBuild2DMipmaps( GLenum target, GLint components, GLint width, GLint height, GLenum format, GLenum type, const void *data ) { GLint w, h, maxsize; void *image, *newimage; GLint neww, newh, level, bpp; int error; glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxsize ); w = round2( width ); if (w>maxsize) { w = maxsize; } h = round2( height ); if (h>maxsize) { h = maxsize; } bpp = bytes_per_pixel( format, type ); if (bpp==0) { /* probably a bad format or type enum */ return GLU_INVALID_ENUM; } if (w!=width || h!=height) { /* must rescale image to get "top" mipmap texture image */ image = malloc( (w+4) * h * bpp ); if (!image) { return GLU_OUT_OF_MEMORY; } error = gluScaleImage( format, width, height, type, data, w, h, type, image ); if (error) { return error; } } else { image = (void *) data; } level = 0; while (1) { glTexImage2D( target, level, components, w, h, 0, format, type, image ); if (w==1 && h==1) break; neww = (w<2) ? 1 : w/2; newh = (h<2) ? 1 : h/2; newimage = malloc( (neww+4) * newh * bpp ); if (!newimage) { return GLU_OUT_OF_MEMORY; } error = gluScaleImage( format, w, h, type, image, neww, newh, type, newimage ); if (error) { return error; } if (image!=data) { free( image ); } image = newimage; w = neww; h = newh; level++; } if (image!=data) { free( image ); } return 0; }
void dreieck(void) { double a; // Seitenlänge von Seite a double alpha_deg; // Winkel in Grad double b; double beta_deg; double c; double gamma_deg = 90; int a_floor, b_floor, c_floor; int a_ceil, b_ceil, c_ceil; int a_round, b_round, c_round; // Error Var int err; // Dialogeröffnung strich(50,'-'); printf ("Rechtwinkliges Dreieck\n"); strich(50,'-'); // Seite/Winkel einlesen do { int i = 0; char side[100]; printf("Bitte Laenge Seite a eingeben: "); // scanf("%lf", &a); fgets(side, 100, stdin); // check for alpha err = 0; while (side[i] != '\0') { if (isalpha(side[i])) err = 1; i += 1; } a = strtod(side, NULL); if (err == 1) printf("No Chars !!!\n"); else if (a <= 0) printf("Beachte: a > 0 !!!\n"); } while (err == 1 || a <= 0); do { int i = 0; char angel[100]; printf("Bitte Winkel Alpha in Grad eingeben: "); // scanf("%lf", &alpha_deg); fgets(angel, 100, stdin); // check for alpha err = 0; while (angel[i] != '\0') { if (isalpha(angel[i])) err = 1; i += 1; } alpha_deg = strtod(angel, NULL); if (err == 1) printf("No Chars !!!\n"); else if (alpha_deg >= 90 || alpha_deg <= 0) printf("Beachte: 0 < Winkel < 90 !!!\n"); } while (err == 1 || alpha_deg >= 90 || alpha_deg <= 0); // Berechnung aller Seiten und Winkel b = a / tan(deg2rad(alpha_deg)); c = a / sin(deg2rad(alpha_deg)); beta_deg = 90 - alpha_deg; // speichern aller Ergebnisse in einer neuen Variablen // abrunden aller Seiten auf die nächste ganze Zahl a_floor = floor(a); b_floor = floor(b); c_floor = floor(c); // aufrunden aller Seiten auf die nächste ganze Zahl a_ceil = ceil(a); b_ceil = ceil(b); c_ceil = ceil(c); // (korrektes) runden aller Seiten auf die nächste ganze Zahl a_round = round2(a); b_round = round2(b); c_round = round2(c); // Ausgabe aller Seiten und Winkel printf(" 2 NK-Stellen gerundet abgerundet aufgerundet\n"); strich(57,'-'); printf("a %10.2f %10d %10d %10d\n", a, a_round, a_floor, a_ceil); printf("b %10.2f %10d %10d %10d\n", b, b_round, b_floor, b_ceil); printf("c %10.2f %10d %10d %10d\n", c, c_round, c_floor, c_ceil); printf("Alpha (Grad) %6.2f\n", alpha_deg); printf("Beta (Grad) %6.2f\n", beta_deg); printf("Gamma (Grad) %6.2f\n", gamma_deg); printf("Alpha (rad) %7.3f\n", deg2rad(alpha_deg)); printf("Beta (rad) %7.3f\n", deg2rad(beta_deg)); printf("Gamma (rad) %7.3f\n", deg2rad(gamma_deg)); }