// Riermersma's formula static uint32_t rgb_diff(uint32_t x, uint32_t y) { int rm = (R(x)+R(y))/2; return 2*sqrd(R(x), R(y)) + 4*sqrd(G(x), G(y)) + 3*sqrd(B(x), B(y)) + rm*(sqrd(R(x), R(y))-sqrd(B(x), B(y)))/256; }
static void cmd_sd(void) { real sd, variance; int units; unsigned long qmask, m; int quantity; qmask = get_qlist(BIT(Q_DECLINATION)); if (!qmask) return; /* no quantities found - error already reported */ if (qmask == BIT(Q_DEFAULT)) { default_grade(pcs); return; } sd = read_numeric(fFalse, NULL); if (sd <= (real)0.0) { compile_error_skip(-/*Standard deviation must be positive*/48); return; } units = get_units(qmask, fFalse); if (units == UNITS_NULL) return; sd *= factor_tab[units]; variance = sqrd(sd); for (quantity = 0, m = BIT(quantity); m <= qmask; quantity++, m <<= 1) if (qmask & m) pcs->Var[quantity] = variance; }
void init_mandel(void) { mandel_surf = malloc(sizeof(Pixbuf)); mandel_surf->w = mandel_surf->h = 1024; mandel_surf->pitch = mandel_surf->w*sizeof(uint8_t); mandel_surf->bpp = 8; uint8_t *data = mandel_surf->data = malloc(mandel_surf->w * mandel_surf->h * sizeof(*data)); for(int y=0; y < mandel_surf->h; y++) { // TODO: speed this up (marching squares?) for(int x=0; x < mandel_surf->w; x++) { double complex z0 = x*2.0f/mandel_surf->w - 1.5f + (y*2.0f/mandel_surf->h - 1.0f)*I; double complex z = z0; // int i=0; while(cabs(z) < 2 && i < 1024) { int i=0; while(sqrd(cimag(z))+sqrd(creal(z)) < 4 && i < 128) { i++; z = z*z + z0; } //n + log2ln(R) – log2ln|z| float mu = (i + 1 - log2f(logf(cabs(z)))); data[y*mandel_surf->w + x] = 128*log2f(mu*(4.0f/128)+1); //data[y*mandel_surf->w + x] = (256*log2(i*32.0f/1024+1)/5); } } glPushAttrib(GL_TEXTURE_BIT); glGenTextures(1, &mandel_tex); glBindTexture(GL_TEXTURE_2D, mandel_tex); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, mandel_surf->w, mandel_surf->h, GL_LUMINANCE, GL_UNSIGNED_BYTE, mandel_surf->data); 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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPopAttrib(); }
static void default_grade(settings *s) { /* Values correspond to those in bcra5.svx */ s->Var[Q_POS] = (real)sqrd(0.05); s->Var[Q_LENGTH] = (real)sqrd(0.05); s->Var[Q_COUNT] = (real)sqrd(0.05); s->Var[Q_DX] = s->Var[Q_DY] = s->Var[Q_DZ] = (real)sqrd(0.05); s->Var[Q_BEARING] = (real)sqrd(rad(0.5)); s->Var[Q_GRADIENT] = (real)sqrd(rad(0.5)); s->Var[Q_BACKBEARING] = (real)sqrd(rad(0.5)); s->Var[Q_BACKGRADIENT] = (real)sqrd(rad(0.5)); /* SD of plumbed legs (0.25 degrees?) */ s->Var[Q_PLUMB] = (real)sqrd(rad(0.25)); /* SD of level legs (0.25 degrees?) */ s->Var[Q_LEVEL] = (real)sqrd(rad(0.25)); s->Var[Q_DEPTH] = (real)sqrd(0.05); }
// brightness formula static uint32_t rgb_diff(uint32_t x, uint32_t y) { return 2*sqrd(R(x), R(y)) + 3*sqrd(G(x), G(y)) + 1*sqrd(B(x), B(y)); }