void FPSCamera::Update( float _DeltaTime, float _TranslationSpeed, float _RotationSpeed, float _SpeedBoostWithShift ) { ////////////////////////////////////////////////////////////////////////// // Handle mouse manipulation // if ( gs_WindowInfos.Events.Mouse.dbuttons[0] > 0 ) { // Button down SetCapture( gs_WindowInfos.hWnd ); m_ButtonDownMouseX = gs_WindowInfos.Events.Mouse.x; m_ButtonDownMouseY = gs_WindowInfos.Events.Mouse.y; m_ButtonDownPosition = m_Position; m_ButtonDownTarget = m_Target; } else if ( gs_WindowInfos.Events.Mouse.dbuttons[0] < 0 ) { // Button up ReleaseCapture(); } if ( gs_WindowInfos.Events.Mouse.buttons[0] != 0 ) { int MouseDx = gs_WindowInfos.Events.Mouse.x - m_ButtonDownMouseX; int MouseDy = gs_WindowInfos.Events.Mouse.y - m_ButtonDownMouseY; float DAngleX = (_RotationSpeed * TWOPI) * MouseDx / RESX; float DAngleY = (_RotationSpeed * PI) * MouseDy / RESY; float3 At = m_ButtonDownTarget - m_ButtonDownPosition; float Distance2Target = At.Length(); At = At / Distance2Target; float Theta = asinf( At.y ); float Phi = atan2f( At.x, At.z ); Theta = CLAMP( Theta - DAngleY, -0.99f * HALFPI, +0.99f * HALFPI ); // Never completly up or down to avoid gimbal lock Phi -= DAngleX; float3 NewAt( sinf(Phi)*cosf(Theta), sinf(Theta), cosf(Phi)*cos(Theta) ); m_Target = m_Position + Distance2Target * NewAt; // Vector3 Euler = GetEuler( m_ButtonDownTransform ); // Matrix CamRotYMatrix = Matrix.RotationY( fAngleY + Euler.Y ); // Matrix CamRotXMatrix = Matrix.RotationX( fAngleX + Euler.X ); // Matrix CamRotZMatrix = Matrix.RotationZ( Euler.Z ); // // Matrix RotateMatrix = CamRotXMatrix * CamRotYMatrix * CamRotZMatrix; } float3 At = (m_Target - m_Position).Normalize(); float3 Right = At.Cross( m_Up ).Normalize(); float3 Up = Right.Cross( At ); ////////////////////////////////////////////////////////////////////////// // Handle keyboard manipulation // float Speed = _DeltaTime * _TranslationSpeed; if ( gs_WindowInfos.Events.Keyboard.State[KEY_LSHIFT] ) Speed *= _SpeedBoostWithShift; float3 Delta = float3::Zero; if ( gs_WindowInfos.pKeys['Q'] ) { // Strafe left Delta = Delta - Speed * Right; } if ( gs_WindowInfos.pKeys['D'] ) { // Strafe right Delta = Delta + Speed * Right; } if ( gs_WindowInfos.pKeys['Z'] ) { // Forward Delta = Delta + Speed * At; } if ( gs_WindowInfos.pKeys['S'] ) { // Backward Delta = Delta - Speed * At; } if ( gs_WindowInfos.pKeys[' '] ) { // Up Delta = Delta + Speed * Up; } if ( gs_WindowInfos.Events.Keyboard.State[KEY_LCONTROL] ) { // Down Delta = Delta - Speed * Up; } m_Position = m_Position + Delta; m_Target = m_Target + Delta; ////////////////////////////////////////////////////////////////////////// // Rebuild camera matrix m_Camera.LookAt( m_Position, m_Target, m_Up ); }
void pix_movement :: threshMessCallback(void *data, t_floatarg newmode) { GetMyClass(data)->threshold=CLAMP((float)255.*newmode); }
float CGUIControlGroupList::GetHeight() const { if (m_orientation == VERTICAL) return CLAMP(m_totalSize, m_minSize, m_height); return CGUIControlGroup::GetHeight(); }
void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { // FIXME: this returns nan!! dt_iop_colortransfer_data_t *data = (dt_iop_colortransfer_data_t *)piece->data; float *in = (float *)ivoid; float *out = (float *)ovoid; const int ch = piece->colors; if(data->flag == ACQUIRE) { if(piece->pipe->type == DT_DEV_PIXELPIPE_PREVIEW) { // only get stuff from the preview pipe, rest stays untouched. int hist[HISTN]; // get histogram of L capture_histogram(in, roi_in, hist); // invert histogram of L invert_histogram(hist, data->hist); // get n clusters kmeans(in, roi_in, data->n, data->mean, data->var); // notify gui that commit_params should let stuff flow back! data->flag = ACQUIRED; dt_iop_colortransfer_params_t *p = (dt_iop_colortransfer_params_t *)self->params; p->flag = ACQUIRE2; } memcpy(out, in, (size_t)sizeof(float) * ch * roi_out->width * roi_out->height); } else if(data->flag == APPLY) { // apply histogram of L and clustering of (a,b) int hist[HISTN]; capture_histogram(in, roi_in, hist); #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) shared(data, in, out, hist) #endif for(int k = 0; k < roi_out->height; k++) { size_t j = (size_t)ch * roi_out->width * k; for(int i = 0; i < roi_out->width; i++) { // L: match histogram out[j] = data->hist[hist[(int)CLAMP(HISTN * in[j] / 100.0, 0, HISTN - 1)]]; out[j] = CLAMP(out[j], 0, 100); j += ch; } } // cluster input buffer float(*const mean)[2] = malloc(2 * data->n * sizeof(float)); float(*const var)[2] = malloc(2 * data->n * sizeof(float)); kmeans(in, roi_in, data->n, mean, var); // get mapping from input clusters to target clusters int *const mapio = malloc(data->n * sizeof(int)); get_cluster_mapping(data->n, mean, data->mean, mapio); // for all pixels: find input cluster, transfer to mapped target cluster #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) shared(data, in, out) #endif for(int k = 0; k < roi_out->height; k++) { float weight[MAXN]; size_t j = (size_t)ch * roi_out->width * k; for(int i = 0; i < roi_out->width; i++) { const float L = in[j]; const float Lab[3] = { L, in[j + 1], in[j + 2] }; // a, b: subtract mean, scale nvar/var, add nmean #if 0 // single cluster, gives color banding const int ki = get_cluster(in + j, data->n, mean); out[j+1] = 100.0/out[j] * ((Lab[1] - mean[ki][0])*data->var[mapio[ki]][0]/var[ki][0] + data->mean[mapio[ki]][0]); out[j+2] = 100.0/out[j] * ((Lab[2] - mean[ki][1])*data->var[mapio[ki]][1]/var[ki][1] + data->mean[mapio[ki]][1]); #else // fuzzy weighting get_clusters(in + j, data->n, mean, weight); out[j + 1] = out[j + 2] = 0.0f; for(int c = 0; c < data->n; c++) { out[j + 1] += weight[c] * ((Lab[1] - mean[c][0]) * data->var[mapio[c]][0] / var[c][0] + data->mean[mapio[c]][0]); out[j + 2] += weight[c] * ((Lab[2] - mean[c][1]) * data->var[mapio[c]][1] / var[c][1] + data->mean[mapio[c]][1]); } #endif out[j + 3] = in[j + 3]; j += ch; } } free(mapio); free(var); free(mean); } else { memcpy(out, in, (size_t)sizeof(float) * ch * roi_out->width * roi_out->height); } }
static gboolean dt_iop_monochrome_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_monochrome_gui_data_t *g = (dt_iop_monochrome_gui_data_t *)self->gui_data; dt_iop_monochrome_params_t *p = (dt_iop_monochrome_params_t *)self->params; if(self->request_color_pick == DT_REQUEST_COLORPICK_MODULE) { p->a = self->picked_color[1]; p->b = self->picked_color[2]; float da = self->picked_color_max[1] - self->picked_color_min[1]; float db = self->picked_color_max[2] - self->picked_color_min[2]; p->size = CLAMP((da + db)/128.0, .5, 3.0); } gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->colorpicker), (self->request_color_pick == DT_REQUEST_COLORPICK_MODULE ? 1 : 0)); const int inset = DT_COLORCORRECTION_INSET; GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); int width = allocation.width, height = allocation.height; cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cr = cairo_create(cst); // clear bg cairo_set_source_rgb(cr, .2, .2, .2); cairo_paint(cr); cairo_translate(cr, inset, inset); cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); width -= 2 * inset; height -= 2 * inset; // clip region to inside: cairo_rectangle(cr, 0, 0, width, height); cairo_clip(cr); // flip y: cairo_translate(cr, 0, height); cairo_scale(cr, 1., -1.); const int cells = 8; for(int j = 0; j < cells; j++) for(int i = 0; i < cells; i++) { double rgb[3] = { 0.5, 0.5, 0.5 }; cmsCIELab Lab; Lab.L = 53.390011; Lab.a = Lab.b = 0; // grey // dt_iop_sRGB_to_Lab(rgb, Lab, 0, 0, 1.0, 1, 1); // get grey in Lab Lab.a = PANEL_WIDTH * (i / (cells - 1.0) - .5); Lab.b = PANEL_WIDTH * (j / (cells - 1.0) - .5); const float f = color_filter(Lab.a, Lab.b, p->a, p->b, 40 * 40 * p->size * p->size); Lab.L *= f * f; // exaggerate filter a little cmsDoTransform(g->xform, &Lab, rgb, 1); cairo_set_source_rgb(cr, rgb[0], rgb[1], rgb[2]); cairo_rectangle(cr, width * i / (float)cells, height * j / (float)cells, width / (float)cells - DT_PIXEL_APPLY_DPI(1), height / (float)cells - DT_PIXEL_APPLY_DPI(1)); cairo_fill(cr); } cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); cairo_set_source_rgb(cr, .7, .7, .7); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.0)); const float x = p->a * width / PANEL_WIDTH + width * .5f, y = p->b * height / PANEL_WIDTH + height * .5f; cairo_arc(cr, x, y, width * .22f * p->size, 0, 2.0 * M_PI); cairo_stroke(cr); cairo_destroy(cr); cairo_set_source_surface(crf, cst, 0, 0); cairo_paint(crf); cairo_surface_destroy(cst); return TRUE; }
template<typename Tin> static inline __host__ __device__ void _TDemoteClampZ(Tin &a, Ncv16u &out) {out = (Ncv16u)CLAMP(a, 0, USHRT_MAX);}
void vsx_widget_desktop::draw() { if (!init_run) return; // this is designed to be root, so set up things // Deal with movement around the desktop #define SGN(N) (N >= 0 ? 1 : -1) #define MAX(N, M) ((N) >= (M) ? (N) : (M)) #define MIN(N, M) ((N) <= (M) ? (N) : (M)) #define CLAMP(N, L, U) (MAX(MIN((N), (U)), (L))) //if (logo_time > animlen) { if (!interpolating) { double acc = 4, dec = 3, spd = global_key_speed; // interpolation falloff control float tt = dtime*interpolation_speed*global_interpolation_speed; if (tt > 1) { tt = 1; } if(zpd != 0.0) { double sgn = SGN(zpd); zps += dtime * acc * sgn * global_interpolation_speed; zps = CLAMP(zps, -1.2f, 1.2f); } if(zpd == 0.0) { double sgn = SGN(zps); zps -= dtime * dec * sgn * global_interpolation_speed; zps = MAX(zps * sgn, 0) * sgn; } zp += zps * fabs(zp - 1.1)* spd * dtime + zpp*(zp - 1.0f); zpp = zpp*(1-tt); if (zp > 100) {zp = 100; zps = 0;} if (zp < 1.2) {zp = 1.2; zps = 0;} if(xpd != 0.0) { double sgn = SGN(xpd); xps += dtime * acc * sgn * global_interpolation_speed; xps = CLAMP(xps, -1, 1); } if(xpd == 0.0) { double sgn = SGN(xps); xps -= dtime * dec * sgn * global_interpolation_speed; xps = MAX(xps * sgn, 0) * sgn; } xp += xps * fabs(zp - 1.1)* spd * dtime*0.6 + xpp*(zp-1.0f); xpp = xpp*(1-tt); if (xp > 10) {xp = 10; xps = 0;} if (xp < -10) {xp = -10; xps = 0;} if(ypd != 0.0) { double sgn = SGN(ypd); yps += dtime * acc * sgn * global_interpolation_speed; yps = CLAMP(yps, -1, 1); } if(ypd == 0.0) { double sgn = SGN(yps); yps -= dtime * dec * sgn * global_interpolation_speed; yps = MAX(yps * sgn, 0) * sgn; } yp += yps * fabs(zp - 1.1)* spd * dtime*0.6 + ypp*(zp-1.0f); ypp = ypp*(1-tt); if (yp > 10) {yp = 10; yps = 0;} if (yp < -10) {yp = -10; yps = 0;} // printf("xp: %f xps: %f xpd %f dt %f::",xp,xps,xpd,tt); } else { float tt = dtime*10.0f*global_interpolation_speed; if (tt > 1) { tt = 1; interpolating = false;} xp = xp*(1-tt)+camera_target.x*tt; yp = yp*(1-tt)+camera_target.y*tt; zp = zp*(1-tt)+camera_target.z*tt; if ( (round(xp*2000) == round(camera_target.x*2000)) && (round(yp*2000) == round(camera_target.y*2000)) && (round(zp*2000) == round(camera_target.z*2000)) ) interpolating = false; } glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45,screen_x/screen_y,0.001,120.0); gluLookAt(xp,yp,zp-1.1f,xp,yp,-1.1f,0.0,1.0,0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // PERFORMANCE_MODE_CHANGE // if (performance_mode) // glBlendFunc(GL_SRC_ALPHA, GL_ONE); //else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // //return; glEnable(GL_BLEND); //glClear(GL_COLOR_BUFFER_BIT); if (!performance_mode) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //glEnable(GL_LINE_SMOOTH); if (!performance_mode) { glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glColor4f(1,1,1,1); #ifndef VSXU_PLAYER if (!mtex.bind()) #endif glColor4f(skin_color[13].r,skin_color[13].g,skin_color[13].b,skin_color[13].a); //else glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(pos.x-size.x/2,pos.y-size.y/2,-10.0f); glTexCoord2f(0, 1); glVertex3f(pos.x-size.x/2,pos.y+size.y/2,-10.0f); glTexCoord2f(1, 1); glVertex3f(pos.x+size.x/2,pos.y+size.y/2,-10.0f); glTexCoord2f(1, 0); glVertex3f(pos.x+size.x/2,pos.y-size.y/2,-10.0f); glEnd(); #ifndef VSXU_PLAYER mtex._bind(); #endif } draw_children(); }
/** * Apply texture mapping to a span of fragments. */ void _swrast_texture_span( GLcontext *ctx, SWspan *span ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); GLfloat primary_rgba[MAX_WIDTH][4]; GLuint unit; ASSERT(span->end <= MAX_WIDTH); /* * Save copy of the incoming fragment colors (the GL_PRIMARY_COLOR) */ if (swrast->_TextureCombinePrimary) { GLuint i; for (i = 0; i < span->end; i++) { primary_rgba[i][RCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][RCOMP]); primary_rgba[i][GCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][GCOMP]); primary_rgba[i][BCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][BCOMP]); primary_rgba[i][ACOMP] = CHAN_TO_FLOAT(span->array->rgba[i][ACOMP]); } } /* First must sample all bump maps */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; if (texUnit->_ReallyEnabled && texUnit->_CurrentCombine->ModeRGB == GL_BUMP_ENVMAP_ATI) { const GLfloat (*texcoords)[4] = (const GLfloat (*)[4]) span->array->attribs[FRAG_ATTRIB_TEX0 + unit]; float4_array targetcoords = span->array->attribs[FRAG_ATTRIB_TEX0 + ctx->Texture.Unit[unit].BumpTarget - GL_TEXTURE0]; const struct gl_texture_object *curObj = texUnit->_Current; GLfloat *lambda = span->array->lambda[unit]; float4_array texels = get_texel_array(swrast, unit); GLuint i; GLfloat rotMatrix00 = ctx->Texture.Unit[unit].RotMatrix[0]; GLfloat rotMatrix01 = ctx->Texture.Unit[unit].RotMatrix[1]; GLfloat rotMatrix10 = ctx->Texture.Unit[unit].RotMatrix[2]; GLfloat rotMatrix11 = ctx->Texture.Unit[unit].RotMatrix[3]; /* adjust texture lod (lambda) */ if (span->arrayMask & SPAN_LAMBDA) { if (texUnit->LodBias + curObj->LodBias != 0.0F) { /* apply LOD bias, but don't clamp yet */ const GLfloat bias = CLAMP(texUnit->LodBias + curObj->LodBias, -ctx->Const.MaxTextureLodBias, ctx->Const.MaxTextureLodBias); GLuint i; for (i = 0; i < span->end; i++) { lambda[i] += bias; } } if (curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) { /* apply LOD clamping to lambda */ const GLfloat min = curObj->MinLod; const GLfloat max = curObj->MaxLod; GLuint i; for (i = 0; i < span->end; i++) { GLfloat l = lambda[i]; lambda[i] = CLAMP(l, min, max); } } } /* Sample the texture (span->end = number of fragments) */ swrast->TextureSample[unit]( ctx, texUnit->_Current, span->end, texcoords, lambda, texels ); /* manipulate the span values of the bump target not sure this can work correctly even ignoring the problem that channel is unsigned */ for (i = 0; i < span->end; i++) { targetcoords[i][0] += (texels[i][0] * rotMatrix00 + texels[i][1] * rotMatrix01) / targetcoords[i][3]; targetcoords[i][1] += (texels[i][0] * rotMatrix10 + texels[i][1] * rotMatrix11) / targetcoords[i][3]; } } } /* * Must do all texture sampling before combining in order to * accomodate GL_ARB_texture_env_crossbar. */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; if (texUnit->_ReallyEnabled && texUnit->_CurrentCombine->ModeRGB != GL_BUMP_ENVMAP_ATI) { const GLfloat (*texcoords)[4] = (const GLfloat (*)[4]) span->array->attribs[FRAG_ATTRIB_TEX0 + unit]; const struct gl_texture_object *curObj = texUnit->_Current; GLfloat *lambda = span->array->lambda[unit]; float4_array texels = get_texel_array(swrast, unit); /* adjust texture lod (lambda) */ if (span->arrayMask & SPAN_LAMBDA) { if (texUnit->LodBias + curObj->LodBias != 0.0F) { /* apply LOD bias, but don't clamp yet */ const GLfloat bias = CLAMP(texUnit->LodBias + curObj->LodBias, -ctx->Const.MaxTextureLodBias, ctx->Const.MaxTextureLodBias); GLuint i; for (i = 0; i < span->end; i++) { lambda[i] += bias; } } if (curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) { /* apply LOD clamping to lambda */ const GLfloat min = curObj->MinLod; const GLfloat max = curObj->MaxLod; GLuint i; for (i = 0; i < span->end; i++) { GLfloat l = lambda[i]; lambda[i] = CLAMP(l, min, max); } } } /* Sample the texture (span->end = number of fragments) */ swrast->TextureSample[unit]( ctx, texUnit->_Current, span->end, texcoords, lambda, texels ); /* GL_SGI_texture_color_table */ if (texUnit->ColorTableEnabled) { _mesa_lookup_rgba_float(&texUnit->ColorTable, span->end, texels); } /* GL_EXT_texture_swizzle */ if (curObj->_Swizzle != SWIZZLE_NOOP) { swizzle_texels(curObj->_Swizzle, span->end, texels); } } } /* * OK, now apply the texture (aka texture combine/blend). * We modify the span->color.rgba values. */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { if (ctx->Texture.Unit[unit]._ReallyEnabled) { texture_combine( ctx, unit, span->end, primary_rgba, swrast->TexelBuffer, span->array->rgba ); } } }
/** * Do texture application for: * GL_EXT_texture_env_combine * GL_ARB_texture_env_combine * GL_EXT_texture_env_dot3 * GL_ARB_texture_env_dot3 * GL_ATI_texture_env_combine3 * GL_NV_texture_env_combine4 * conventional GL texture env modes * * \param ctx rendering context * \param unit the texture combiner unit * \param n number of fragments to process (span width) * \param primary_rgba incoming fragment color array * \param texelBuffer pointer to texel colors for all texture units * * \param rgba incoming/result fragment colors */ static void texture_combine( GLcontext *ctx, GLuint unit, GLuint n, const float4_array primary_rgba, const GLfloat *texelBuffer, GLchan (*rgbaChan)[4] ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); const struct gl_texture_unit *textureUnit = &(ctx->Texture.Unit[unit]); const struct gl_tex_env_combine_state *combine = textureUnit->_CurrentCombine; float4_array argRGB[MAX_COMBINER_TERMS]; float4_array argA[MAX_COMBINER_TERMS]; const GLfloat scaleRGB = (GLfloat) (1 << combine->ScaleShiftRGB); const GLfloat scaleA = (GLfloat) (1 << combine->ScaleShiftA); const GLuint numArgsRGB = combine->_NumArgsRGB; const GLuint numArgsA = combine->_NumArgsA; GLfloat ccolor[MAX_COMBINER_TERMS][MAX_WIDTH][4]; /* temp color buffers */ GLfloat rgba[MAX_WIDTH][4]; GLuint i, term; for (i = 0; i < n; i++) { rgba[i][RCOMP] = CHAN_TO_FLOAT(rgbaChan[i][RCOMP]); rgba[i][GCOMP] = CHAN_TO_FLOAT(rgbaChan[i][GCOMP]); rgba[i][BCOMP] = CHAN_TO_FLOAT(rgbaChan[i][BCOMP]); rgba[i][ACOMP] = CHAN_TO_FLOAT(rgbaChan[i][ACOMP]); } /* printf("modeRGB 0x%x modeA 0x%x srcRGB1 0x%x srcA1 0x%x srcRGB2 0x%x srcA2 0x%x\n", combine->ModeRGB, combine->ModeA, combine->SourceRGB[0], combine->SourceA[0], combine->SourceRGB[1], combine->SourceA[1]); */ /* * Do operand setup for up to 4 operands. Loop over the terms. */ for (term = 0; term < numArgsRGB; term++) { const GLenum srcRGB = combine->SourceRGB[term]; const GLenum operandRGB = combine->OperandRGB[term]; switch (srcRGB) { case GL_TEXTURE: argRGB[term] = get_texel_array(swrast, unit); break; case GL_PRIMARY_COLOR: argRGB[term] = primary_rgba; break; case GL_PREVIOUS: argRGB[term] = rgba; break; case GL_CONSTANT: { float4_array c = ccolor[term]; GLfloat red = textureUnit->EnvColor[0]; GLfloat green = textureUnit->EnvColor[1]; GLfloat blue = textureUnit->EnvColor[2]; GLfloat alpha = textureUnit->EnvColor[3]; for (i = 0; i < n; i++) { ASSIGN_4V(c[i], red, green, blue, alpha); } argRGB[term] = ccolor[term]; } break; /* GL_ATI_texture_env_combine3 allows GL_ZERO & GL_ONE as sources. */ case GL_ZERO: { float4_array c = ccolor[term]; for (i = 0; i < n; i++) { ASSIGN_4V(c[i], 0.0F, 0.0F, 0.0F, 0.0F); } argRGB[term] = ccolor[term]; } break; case GL_ONE: { float4_array c = ccolor[term]; for (i = 0; i < n; i++) { ASSIGN_4V(c[i], 1.0F, 1.0F, 1.0F, 1.0F); } argRGB[term] = ccolor[term]; } break; default: /* ARB_texture_env_crossbar source */ { const GLuint srcUnit = srcRGB - GL_TEXTURE0; ASSERT(srcUnit < ctx->Const.MaxTextureUnits); if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled) return; argRGB[term] = get_texel_array(swrast, srcUnit); } } if (operandRGB != GL_SRC_COLOR) { float4_array src = argRGB[term]; float4_array dst = ccolor[term]; /* point to new arg[term] storage */ argRGB[term] = ccolor[term]; switch (operandRGB) { case GL_ONE_MINUS_SRC_COLOR: for (i = 0; i < n; i++) { dst[i][RCOMP] = 1.0F - src[i][RCOMP]; dst[i][GCOMP] = 1.0F - src[i][GCOMP]; dst[i][BCOMP] = 1.0F - src[i][BCOMP]; } break; case GL_SRC_ALPHA: for (i = 0; i < n; i++) { dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = src[i][ACOMP]; } break; case GL_ONE_MINUS_SRC_ALPHA: for (i = 0; i < n; i++) { dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = 1.0F - src[i][ACOMP]; } break; default: _mesa_problem(ctx, "Bad operandRGB"); } } } /* * Set up the argA[term] pointers */ for (term = 0; term < numArgsA; term++) { const GLenum srcA = combine->SourceA[term]; const GLenum operandA = combine->OperandA[term]; switch (srcA) { case GL_TEXTURE: argA[term] = get_texel_array(swrast, unit); break; case GL_PRIMARY_COLOR: argA[term] = primary_rgba; break; case GL_PREVIOUS: argA[term] = rgba; break; case GL_CONSTANT: { float4_array c = ccolor[term]; GLfloat alpha = textureUnit->EnvColor[3]; for (i = 0; i < n; i++) c[i][ACOMP] = alpha; argA[term] = ccolor[term]; } break; /* GL_ATI_texture_env_combine3 allows GL_ZERO & GL_ONE as sources. */ case GL_ZERO: { float4_array c = ccolor[term]; for (i = 0; i < n; i++) c[i][ACOMP] = 0.0F; argA[term] = ccolor[term]; } break; case GL_ONE: { float4_array c = ccolor[term]; for (i = 0; i < n; i++) c[i][ACOMP] = 1.0F; argA[term] = ccolor[term]; } break; default: /* ARB_texture_env_crossbar source */ { const GLuint srcUnit = srcA - GL_TEXTURE0; ASSERT(srcUnit < ctx->Const.MaxTextureUnits); if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled) return; argA[term] = get_texel_array(swrast, srcUnit); } } if (operandA == GL_ONE_MINUS_SRC_ALPHA) { float4_array src = argA[term]; float4_array dst = ccolor[term]; argA[term] = ccolor[term]; for (i = 0; i < n; i++) { dst[i][ACOMP] = 1.0F - src[i][ACOMP]; } } } /* RGB channel combine */ { float4_array arg0 = argRGB[0]; float4_array arg1 = argRGB[1]; float4_array arg2 = argRGB[2]; float4_array arg3 = argRGB[3]; switch (combine->ModeRGB) { case GL_REPLACE: for (i = 0; i < n; i++) { rgba[i][RCOMP] = arg0[i][RCOMP] * scaleRGB; rgba[i][GCOMP] = arg0[i][GCOMP] * scaleRGB; rgba[i][BCOMP] = arg0[i][BCOMP] * scaleRGB; } break; case GL_MODULATE: for (i = 0; i < n; i++) { rgba[i][RCOMP] = arg0[i][RCOMP] * arg1[i][RCOMP] * scaleRGB; rgba[i][GCOMP] = arg0[i][GCOMP] * arg1[i][GCOMP] * scaleRGB; rgba[i][BCOMP] = arg0[i][BCOMP] * arg1[i][BCOMP] * scaleRGB; } break; case GL_ADD: if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) */ for (i = 0; i < n; i++) { rgba[i][RCOMP] = (arg0[i][RCOMP] * arg1[i][RCOMP] + arg2[i][RCOMP] * arg3[i][RCOMP]) * scaleRGB; rgba[i][GCOMP] = (arg0[i][GCOMP] * arg1[i][GCOMP] + arg2[i][GCOMP] * arg3[i][GCOMP]) * scaleRGB; rgba[i][BCOMP] = (arg0[i][BCOMP] * arg1[i][BCOMP] + arg2[i][BCOMP] * arg3[i][BCOMP]) * scaleRGB; } } else { /* 2-term addition */ for (i = 0; i < n; i++) { rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP]) * scaleRGB; rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP]) * scaleRGB; rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP]) * scaleRGB; } } break; case GL_ADD_SIGNED: if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) - 0.5 */ for (i = 0; i < n; i++) { rgba[i][RCOMP] = (arg0[i][RCOMP] * arg1[i][RCOMP] + arg2[i][RCOMP] * arg3[i][RCOMP] - 0.5) * scaleRGB; rgba[i][GCOMP] = (arg0[i][GCOMP] * arg1[i][GCOMP] + arg2[i][GCOMP] * arg3[i][GCOMP] - 0.5) * scaleRGB; rgba[i][BCOMP] = (arg0[i][BCOMP] * arg1[i][BCOMP] + arg2[i][BCOMP] * arg3[i][BCOMP] - 0.5) * scaleRGB; } } else { for (i = 0; i < n; i++) { rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP] - 0.5) * scaleRGB; rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP] - 0.5) * scaleRGB; rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP] - 0.5) * scaleRGB; } } break; case GL_INTERPOLATE: for (i = 0; i < n; i++) { rgba[i][RCOMP] = (arg0[i][RCOMP] * arg2[i][RCOMP] + arg1[i][RCOMP] * (1.0F - arg2[i][RCOMP])) * scaleRGB; rgba[i][GCOMP] = (arg0[i][GCOMP] * arg2[i][GCOMP] + arg1[i][GCOMP] * (1.0F - arg2[i][GCOMP])) * scaleRGB; rgba[i][BCOMP] = (arg0[i][BCOMP] * arg2[i][BCOMP] + arg1[i][BCOMP] * (1.0F - arg2[i][BCOMP])) * scaleRGB; } break; case GL_SUBTRACT: for (i = 0; i < n; i++) { rgba[i][RCOMP] = (arg0[i][RCOMP] - arg1[i][RCOMP]) * scaleRGB; rgba[i][GCOMP] = (arg0[i][GCOMP] - arg1[i][GCOMP]) * scaleRGB; rgba[i][BCOMP] = (arg0[i][BCOMP] - arg1[i][BCOMP]) * scaleRGB; } break; case GL_DOT3_RGB_EXT: case GL_DOT3_RGBA_EXT: /* Do not scale the result by 1 2 or 4 */ for (i = 0; i < n; i++) { GLfloat dot = ((arg0[i][RCOMP] - 0.5F) * (arg1[i][RCOMP] - 0.5F) + (arg0[i][GCOMP] - 0.5F) * (arg1[i][GCOMP] - 0.5F) + (arg0[i][BCOMP] - 0.5F) * (arg1[i][BCOMP] - 0.5F)) * 4.0F; dot = CLAMP(dot, 0.0F, 1.0F); rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = dot; } break; case GL_DOT3_RGB: case GL_DOT3_RGBA: /* DO scale the result by 1 2 or 4 */ for (i = 0; i < n; i++) { GLfloat dot = ((arg0[i][RCOMP] - 0.5F) * (arg1[i][RCOMP] - 0.5F) + (arg0[i][GCOMP] - 0.5F) * (arg1[i][GCOMP] - 0.5F) + (arg0[i][BCOMP] - 0.5F) * (arg1[i][BCOMP] - 0.5F)) * 4.0F * scaleRGB; dot = CLAMP(dot, 0.0, 1.0F); rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = dot; } break; case GL_MODULATE_ADD_ATI: for (i = 0; i < n; i++) { rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) + arg1[i][RCOMP]) * scaleRGB; rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) + arg1[i][GCOMP]) * scaleRGB; rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) + arg1[i][BCOMP]) * scaleRGB; } break; case GL_MODULATE_SIGNED_ADD_ATI: for (i = 0; i < n; i++) { rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) + arg1[i][RCOMP] - 0.5) * scaleRGB; rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) + arg1[i][GCOMP] - 0.5) * scaleRGB; rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) + arg1[i][BCOMP] - 0.5) * scaleRGB; } break; case GL_MODULATE_SUBTRACT_ATI: for (i = 0; i < n; i++) { rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) - arg1[i][RCOMP]) * scaleRGB; rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) - arg1[i][GCOMP]) * scaleRGB; rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) - arg1[i][BCOMP]) * scaleRGB; } break; case GL_BUMP_ENVMAP_ATI: /* this produces a fixed rgba color, and the coord calc is done elsewhere */ for (i = 0; i < n; i++) { /* rgba result is 0,0,0,1 */ rgba[i][RCOMP] = 0.0; rgba[i][GCOMP] = 0.0; rgba[i][BCOMP] = 0.0; rgba[i][ACOMP] = 1.0; } return; /* no alpha processing */ default: _mesa_problem(ctx, "invalid combine mode"); } } /* Alpha channel combine */ { float4_array arg0 = argA[0]; float4_array arg1 = argA[1]; float4_array arg2 = argA[2]; float4_array arg3 = argA[3]; switch (combine->ModeA) { case GL_REPLACE: for (i = 0; i < n; i++) { rgba[i][ACOMP] = arg0[i][ACOMP] * scaleA; } break; case GL_MODULATE: for (i = 0; i < n; i++) { rgba[i][ACOMP] = arg0[i][ACOMP] * arg1[i][ACOMP] * scaleA; } break; case GL_ADD: if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) */ for (i = 0; i < n; i++) { rgba[i][ACOMP] = (arg0[i][ACOMP] * arg1[i][ACOMP] + arg2[i][ACOMP] * arg3[i][ACOMP]) * scaleA; } } else { /* two-term add */ for (i = 0; i < n; i++) { rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP]) * scaleA; } } break; case GL_ADD_SIGNED: if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) - 0.5 */ for (i = 0; i < n; i++) { rgba[i][ACOMP] = (arg0[i][ACOMP] * arg1[i][ACOMP] + arg2[i][ACOMP] * arg3[i][ACOMP] - 0.5) * scaleA; } } else { /* a + b - 0.5 */ for (i = 0; i < n; i++) { rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP] - 0.5F) * scaleA; } } break; case GL_INTERPOLATE: for (i = 0; i < n; i++) { rgba[i][ACOMP] = (arg0[i][ACOMP] * arg2[i][ACOMP] + arg1[i][ACOMP] * (1.0F - arg2[i][ACOMP])) * scaleA; } break; case GL_SUBTRACT: for (i = 0; i < n; i++) { rgba[i][ACOMP] = (arg0[i][ACOMP] - arg1[i][ACOMP]) * scaleA; } break; case GL_MODULATE_ADD_ATI: for (i = 0; i < n; i++) { rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) + arg1[i][ACOMP]) * scaleA; } break; case GL_MODULATE_SIGNED_ADD_ATI: for (i = 0; i < n; i++) { rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) + arg1[i][ACOMP] - 0.5F) * scaleA; } break; case GL_MODULATE_SUBTRACT_ATI: for (i = 0; i < n; i++) { rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) - arg1[i][ACOMP]) * scaleA; } break; default: _mesa_problem(ctx, "invalid combine mode"); } } /* Fix the alpha component for GL_DOT3_RGBA_EXT/ARB combining. * This is kind of a kludge. It would have been better if the spec * were written such that the GL_COMBINE_ALPHA value could be set to * GL_DOT3. */ if (combine->ModeRGB == GL_DOT3_RGBA_EXT || combine->ModeRGB == GL_DOT3_RGBA) { for (i = 0; i < n; i++) { rgba[i][ACOMP] = rgba[i][RCOMP]; } } for (i = 0; i < n; i++) { UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][RCOMP], rgba[i][RCOMP]); UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][GCOMP], rgba[i][GCOMP]); UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][BCOMP], rgba[i][BCOMP]); UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][ACOMP], rgba[i][ACOMP]); } }
static void wave (guchar *src, guchar *dst, gint width, gint height, gint bypp, gboolean has_alpha, gdouble cen_x, gdouble cen_y, gdouble amplitude, gdouble wavelength, gdouble phase, gboolean smear, gboolean reflective, gboolean verbose) { glong rowsiz; guchar *p; guchar *dest; gint x1, y1, x2, y2; gint x, y; gint prog_interval = 0; gint x1_in, y1_in, x2_in, y2_in; gdouble xhsiz, yhsiz; /* Half size of selection */ gdouble radius, radius2; /* Radius and radius^2 */ gdouble amnt, d; gdouble needx, needy; gdouble dx, dy; gdouble xscale, yscale; gint xi, yi; guchar *values[4]; guchar zeroes[4] = { 0, 0, 0, 0 }; phase = phase * G_PI / 180.0; rowsiz = width * bypp; if (verbose) { gimp_progress_init (_("Waving")); prog_interval = height / 10; } x1 = y1 = 0; x2 = width; y2 = height; /* Compute wave radii (semiaxes) */ xhsiz = (double) (x2 - x1) / 2.0; yhsiz = (double) (y2 - y1) / 2.0; /* These are the necessary scaling factors to turn the wave ellipse into a large circle */ if (xhsiz < yhsiz) { xscale = yhsiz / xhsiz; yscale = 1.0; } else if (xhsiz > yhsiz) { xscale = 1.0; yscale = xhsiz / yhsiz; } else { xscale = 1.0; yscale = 1.0; } radius = MAX (xhsiz, yhsiz); radius2 = radius * radius; /* Wave the image! */ dst += y1 * rowsiz + x1 * bypp; wavelength *= 2; for (y = y1; y < y2; y++) { dest = dst; if (verbose && (y % prog_interval == 0)) gimp_progress_update ((double) y / (double) height); for (x = x1; x < x2; x++) { /* Distance from current point to wave center, scaled */ dx = (x - cen_x) * xscale; dy = (y - cen_y) * yscale; /* Distance^2 to center of *circle* (our scaled ellipse) */ d = sqrt (dx * dx + dy * dy); /* Use the formula described above. */ /* Calculate waved point and scale again to ellipsify */ /* * Reflective waves are strange - the effect is much * more like a mirror which is in the shape of * the wave than anything else. */ if (reflective) { amnt = amplitude * fabs (sin (((d / wavelength) * (2.0 * G_PI) + phase))); needx = (amnt * dx) / xscale + cen_x; needy = (amnt * dy) / yscale + cen_y; } else { amnt = amplitude * sin (((d / wavelength) * (2.0 * G_PI) + phase)); needx = (amnt + dx) / xscale + cen_x; needy = (amnt + dy) / yscale + cen_y; } /* Calculations complete; now copy the proper pixel */ if (smear) { xi = CLAMP (needx, 0, width - 2); yi = CLAMP (needy, 0, height - 2); } else { xi = needx; yi = needy; } p = src + rowsiz * yi + xi * bypp; x1_in = WITHIN (0, xi, width - 1); y1_in = WITHIN (0, yi, height - 1); x2_in = WITHIN (0, xi + 1, width - 1); y2_in = WITHIN (0, yi + 1, height - 1); if (x1_in && y1_in) values[0] = p; else values[0] = zeroes; if (x2_in && y1_in) values[1] = p + bypp; else values[1] = zeroes; if (x1_in && y2_in) values[2] = p + rowsiz; else values[2] = zeroes; if (x2_in && y2_in) values[3] = p + bypp + rowsiz; else values[3] = zeroes; gimp_bilinear_pixels_8 (dest, needx, needy, bypp, has_alpha, values); dest += bypp; } dst += rowsiz; } if (verbose) gimp_progress_update (1.0); }
void DespeckleOperation::executePixel(float output[4], int x, int y, void * /*data*/) { float w = 0.0f; float color_org[4]; float color_mid[4]; float color_mid_ok[4]; float in1[4]; int x1 = x - 1; int x2 = x; int x3 = x + 1; int y1 = y - 1; int y2 = y; int y3 = y + 1; CLAMP(x1, 0, getWidth() - 1); CLAMP(x2, 0, getWidth() - 1); CLAMP(x3, 0, getWidth() - 1); CLAMP(y1, 0, getHeight() - 1); CLAMP(y2, 0, getHeight() - 1); CLAMP(y3, 0, getHeight() - 1); float value[4]; this->m_inputValueOperation->read(value, x2, y2, NULL); // const float mval = 1.0f - value[0]; this->m_inputOperation->read(color_org, x2, y2, NULL); #define TOT_DIV_ONE 1.0f #define TOT_DIV_CNR (float)M_SQRT1_2 #define WTOT (TOT_DIV_ONE * 4 + TOT_DIV_CNR * 4) #define COLOR_ADD(fac) \ { \ madd_v4_v4fl(color_mid, in1, fac); \ if (color_diff(in1, color_org, this->m_threshold)) { \ w += fac; \ madd_v4_v4fl(color_mid_ok, in1, fac); \ } \ } zero_v4(color_mid); zero_v4(color_mid_ok); this->m_inputOperation->read(in1, x1, y1, NULL); COLOR_ADD(TOT_DIV_CNR) this->m_inputOperation->read(in1, x2, y1, NULL); COLOR_ADD(TOT_DIV_ONE) this->m_inputOperation->read(in1, x3, y1, NULL); COLOR_ADD(TOT_DIV_CNR) this->m_inputOperation->read(in1, x1, y2, NULL); COLOR_ADD(TOT_DIV_ONE) #if 0 this->m_inputOperation->read(in2, x2, y2, NULL); madd_v4_v4fl(color_mid, in2, this->m_filter[4]); #endif this->m_inputOperation->read(in1, x3, y2, NULL); COLOR_ADD(TOT_DIV_ONE) this->m_inputOperation->read(in1, x1, y3, NULL); COLOR_ADD(TOT_DIV_CNR) this->m_inputOperation->read(in1, x2, y3, NULL); COLOR_ADD(TOT_DIV_ONE) this->m_inputOperation->read(in1, x3, y3, NULL); COLOR_ADD(TOT_DIV_CNR) mul_v4_fl(color_mid, 1.0f / (4.0f + (4.0f * (float)M_SQRT1_2))); // mul_v4_fl(color_mid, 1.0f / w); if ((w != 0.0f) && ((w / WTOT) > (this->m_threshold_neighbor)) && color_diff(color_mid, color_org, this->m_threshold)) { mul_v4_fl(color_mid_ok, 1.0f / w); interp_v4_v4v4(output, color_org, color_mid_ok, value[0]); } else { copy_v4_v4(output, color_org); } }
/* Evaluate spline IK for a given bone */ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *ob, bPoseChannel *pchan, int index, float ctime) { bSplineIKConstraint *ikData = tree->ikData; float poseHead[3], poseTail[3], poseMat[4][4]; float splineVec[3], scaleFac, radius = 1.0f; /* firstly, calculate the bone matrix the standard way, since this is needed for roll control */ BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1); copy_v3_v3(poseHead, pchan->pose_head); copy_v3_v3(poseTail, pchan->pose_tail); /* step 1: determine the positions for the endpoints of the bone */ { float vec[4], dir[3], rad; float tailBlendFac = 1.0f; /* determine if the bone should still be affected by SplineIK */ if (tree->points[index + 1] >= 1.0f) { /* spline doesn't affect the bone anymore, so done... */ pchan->flag |= POSE_DONE; return; } else if ((tree->points[index] >= 1.0f) && (tree->points[index + 1] < 1.0f)) { /* blending factor depends on the amount of the bone still left on the chain */ tailBlendFac = (1.0f - tree->points[index + 1]) / (tree->points[index] - tree->points[index + 1]); } /* tail endpoint */ if (where_on_path(ikData->tar, tree->points[index], vec, dir, NULL, &rad, NULL)) { /* apply curve's object-mode transforms to the position * unless the option to allow curve to be positioned elsewhere is activated (i.e. no root) */ if ((ikData->flag & CONSTRAINT_SPLINEIK_NO_ROOT) == 0) mul_m4_v3(ikData->tar->obmat, vec); /* convert the position to pose-space, then store it */ mul_m4_v3(ob->imat, vec); interp_v3_v3v3(poseTail, pchan->pose_tail, vec, tailBlendFac); /* set the new radius */ radius = rad; } /* head endpoint */ if (where_on_path(ikData->tar, tree->points[index + 1], vec, dir, NULL, &rad, NULL)) { /* apply curve's object-mode transforms to the position * unless the option to allow curve to be positioned elsewhere is activated (i.e. no root) */ if ((ikData->flag & CONSTRAINT_SPLINEIK_NO_ROOT) == 0) mul_m4_v3(ikData->tar->obmat, vec); /* store the position, and convert it to pose space */ mul_m4_v3(ob->imat, vec); copy_v3_v3(poseHead, vec); /* set the new radius (it should be the average value) */ radius = (radius + rad) / 2; } } /* step 2: determine the implied transform from these endpoints * - splineVec: the vector direction that the spline applies on the bone * - scaleFac: the factor that the bone length is scaled by to get the desired amount */ sub_v3_v3v3(splineVec, poseTail, poseHead); scaleFac = len_v3(splineVec) / pchan->bone->length; /* step 3: compute the shortest rotation needed to map from the bone rotation to the current axis * - this uses the same method as is used for the Damped Track Constraint (see the code there for details) */ { float dmat[3][3], rmat[3][3], tmat[3][3]; float raxis[3], rangle; /* compute the raw rotation matrix from the bone's current matrix by extracting only the * orientation-relevant axes, and normalizing them */ copy_v3_v3(rmat[0], pchan->pose_mat[0]); copy_v3_v3(rmat[1], pchan->pose_mat[1]); copy_v3_v3(rmat[2], pchan->pose_mat[2]); normalize_m3(rmat); /* also, normalize the orientation imposed by the bone, now that we've extracted the scale factor */ normalize_v3(splineVec); /* calculate smallest axis-angle rotation necessary for getting from the * current orientation of the bone, to the spline-imposed direction */ cross_v3_v3v3(raxis, rmat[1], splineVec); rangle = dot_v3v3(rmat[1], splineVec); CLAMP(rangle, -1.0f, 1.0f); rangle = acosf(rangle); /* multiply the magnitude of the angle by the influence of the constraint to * control the influence of the SplineIK effect */ rangle *= tree->con->enforce; /* construct rotation matrix from the axis-angle rotation found above * - this call takes care to make sure that the axis provided is a unit vector first */ axis_angle_to_mat3(dmat, raxis, rangle); /* combine these rotations so that the y-axis of the bone is now aligned as the spline dictates, * while still maintaining roll control from the existing bone animation */ mul_m3_m3m3(tmat, dmat, rmat); /* m1, m3, m2 */ normalize_m3(tmat); /* attempt to reduce shearing, though I doubt this'll really help too much now... */ copy_m4_m3(poseMat, tmat); } /* step 4: set the scaling factors for the axes */ { /* only multiply the y-axis by the scaling factor to get nice volume-preservation */ mul_v3_fl(poseMat[1], scaleFac); /* set the scaling factors of the x and z axes from... */ switch (ikData->xzScaleMode) { case CONSTRAINT_SPLINEIK_XZS_ORIGINAL: { /* original scales get used */ float scale; /* x-axis scale */ scale = len_v3(pchan->pose_mat[0]); mul_v3_fl(poseMat[0], scale); /* z-axis scale */ scale = len_v3(pchan->pose_mat[2]); mul_v3_fl(poseMat[2], scale); break; } case CONSTRAINT_SPLINEIK_XZS_INVERSE: { /* old 'volume preservation' method using the inverse scale */ float scale; /* calculate volume preservation factor which is * basically the inverse of the y-scaling factor */ if (fabsf(scaleFac) != 0.0f) { scale = 1.0f / fabsf(scaleFac); /* we need to clamp this within sensible values */ /* NOTE: these should be fine for now, but should get sanitised in future */ CLAMP(scale, 0.0001f, 100000.0f); } else scale = 1.0f; /* apply the scaling */ mul_v3_fl(poseMat[0], scale); mul_v3_fl(poseMat[2], scale); break; } case CONSTRAINT_SPLINEIK_XZS_VOLUMETRIC: { /* improved volume preservation based on the Stretch To constraint */ float final_scale; /* as the basis for volume preservation, we use the inverse scale factor... */ if (fabsf(scaleFac) != 0.0f) { /* NOTE: The method here is taken wholesale from the Stretch To constraint */ float bulge = powf(1.0f / fabsf(scaleFac), ikData->bulge); if (bulge > 1.0f) { if (ikData->flag & CONSTRAINT_SPLINEIK_USE_BULGE_MAX) { float bulge_max = max_ff(ikData->bulge_max, 1.0f); float hard = min_ff(bulge, bulge_max); float range = bulge_max - 1.0f; float scale = (range > 0.0f) ? 1.0f / range : 0.0f; float soft = 1.0f + range * atanf((bulge - 1.0f) * scale) / (float)M_PI_2; bulge = interpf(soft, hard, ikData->bulge_smooth); } } if (bulge < 1.0f) { if (ikData->flag & CONSTRAINT_SPLINEIK_USE_BULGE_MIN) { float bulge_min = CLAMPIS(ikData->bulge_min, 0.0f, 1.0f); float hard = max_ff(bulge, bulge_min); float range = 1.0f - bulge_min; float scale = (range > 0.0f) ? 1.0f / range : 0.0f; float soft = 1.0f - range * atanf((1.0f - bulge) * scale) / (float)M_PI_2; bulge = interpf(soft, hard, ikData->bulge_smooth); } } /* compute scale factor for xz axes from this value */ final_scale = sqrtf(bulge); } else { /* no scaling, so scale factor is simple */ final_scale = 1.0f; } /* apply the scaling (assuming normalised scale) */ mul_v3_fl(poseMat[0], final_scale); mul_v3_fl(poseMat[2], final_scale); break; } } /* finally, multiply the x and z scaling by the radius of the curve too, * to allow automatic scales to get tweaked still */ if ((ikData->flag & CONSTRAINT_SPLINEIK_NO_CURVERAD) == 0) { mul_v3_fl(poseMat[0], radius); mul_v3_fl(poseMat[2], radius); } } /* step 5: set the location of the bone in the matrix */ if (ikData->flag & CONSTRAINT_SPLINEIK_NO_ROOT) { /* when the 'no-root' option is affected, the chain can retain * the shape but be moved elsewhere */ copy_v3_v3(poseHead, pchan->pose_head); } else if (tree->con->enforce < 1.0f) { /* when the influence is too low * - blend the positions for the 'root' bone * - stick to the parent for any other */ if (pchan->parent) { copy_v3_v3(poseHead, pchan->pose_head); } else { /* FIXME: this introduces popping artifacts when we reach 0.0 */ interp_v3_v3v3(poseHead, pchan->pose_head, poseHead, tree->con->enforce); } } copy_v3_v3(poseMat[3], poseHead); /* finally, store the new transform */ copy_m4_m4(pchan->pose_mat, poseMat); copy_v3_v3(pchan->pose_head, poseHead); /* recalculate tail, as it's now outdated after the head gets adjusted above! */ BKE_pose_where_is_bone_tail(pchan); /* done! */ pchan->flag |= POSE_DONE; }
/** * Render a horizontal span of quads */ static void flush_spans(struct setup_context *setup) { const int step = MAX_QUADS; const int xleft0 = setup->span.left[0]; const int xleft1 = setup->span.left[1]; const int xright0 = setup->span.right[0]; const int xright1 = setup->span.right[1]; struct quad_stage *pipe = setup->softpipe->quad.first; const int minleft = block_x(MIN2(xleft0, xleft1)); const int maxright = MAX2(xright0, xright1); int x; /* process quads in horizontal chunks of 16 */ for (x = minleft; x < maxright; x += step) { unsigned skip_left0 = CLAMP(xleft0 - x, 0, step); unsigned skip_left1 = CLAMP(xleft1 - x, 0, step); unsigned skip_right0 = CLAMP(x + step - xright0, 0, step); unsigned skip_right1 = CLAMP(x + step - xright1, 0, step); unsigned lx = x; unsigned q = 0; unsigned skipmask_left0 = (1U << skip_left0) - 1U; unsigned skipmask_left1 = (1U << skip_left1) - 1U; /* These calculations fail when step == 32 and skip_right == 0. */ unsigned skipmask_right0 = ~0U << (unsigned)(step - skip_right0); unsigned skipmask_right1 = ~0U << (unsigned)(step - skip_right1); unsigned mask0 = ~skipmask_left0 & ~skipmask_right0; unsigned mask1 = ~skipmask_left1 & ~skipmask_right1; if (mask0 | mask1) { do { unsigned quadmask = (mask0 & 3) | ((mask1 & 3) << 2); if (quadmask) { setup->quad[q].input.x0 = lx; setup->quad[q].input.y0 = setup->span.y; setup->quad[q].input.facing = setup->facing; setup->quad[q].inout.mask = quadmask; setup->quad_ptrs[q] = &setup->quad[q]; q++; } mask0 >>= 2; mask1 >>= 2; lx += 2; } while (mask0 | mask1); pipe->run( pipe, setup->quad_ptrs, q ); } } setup->span.y = 0; setup->span.right[0] = 0; setup->span.right[1] = 0; setup->span.left[0] = 1000000; /* greater than right[0] */ setup->span.left[1] = 1000000; /* greater than right[1] */ }
static DerivedMesh *doOcean(ModifierData *md, Object *ob, DerivedMesh *derivedData, int UNUSED(useRenderParams)) { OceanModifierData *omd = (OceanModifierData *) md; DerivedMesh *dm = NULL; OceanResult ocr; MVert *mverts; int cfra; int i, j; /* use cached & inverted value for speed * expanded this would read... * * (axis / (omd->size * omd->spatial_size)) + 0.5f) */ #define OCEAN_CO(_size_co_inv, _v) ((_v * _size_co_inv) + 0.5f) const float size_co_inv = 1.0f / (omd->size * omd->spatial_size); /* can happen in when size is small, avoid bad array lookups later and quit now */ if (!finite(size_co_inv)) { return derivedData; } /* update modifier */ if (omd->refresh & MOD_OCEAN_REFRESH_ADD) { omd->ocean = BKE_ocean_add(); } if (omd->refresh & MOD_OCEAN_REFRESH_RESET) { init_ocean_modifier(omd); } if (omd->refresh & MOD_OCEAN_REFRESH_CLEAR_CACHE) { clear_cache_data(omd); } omd->refresh = 0; /* do ocean simulation */ if (omd->cached == true) { if (!omd->oceancache) { init_cache_data(ob, omd); } BKE_ocean_simulate_cache(omd->oceancache, md->scene->r.cfra); } else { simulate_ocean_modifier(omd); } if (omd->geometry_mode == MOD_OCEAN_GEOM_GENERATE) { dm = generate_ocean_geometry(omd); DM_ensure_normals(dm); } else if (omd->geometry_mode == MOD_OCEAN_GEOM_DISPLACE) { dm = CDDM_copy(derivedData); } cfra = md->scene->r.cfra; CLAMP(cfra, omd->bakestart, omd->bakeend); cfra -= omd->bakestart; /* shift to 0 based */ mverts = dm->getVertArray(dm); /* add vcols before displacement - allows lookup based on position */ if (omd->flag & MOD_OCEAN_GENERATE_FOAM) { if (CustomData_number_of_layers(&dm->loopData, CD_MLOOPCOL) < MAX_MCOL) { const int num_polys = dm->getNumPolys(dm); const int num_loops = dm->getNumLoops(dm); MLoop *mloops = dm->getLoopArray(dm); MLoopCol *mloopcols = CustomData_add_layer_named( &dm->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, num_loops, omd->foamlayername); if (mloopcols) { /* unlikely to fail */ MPoly *mpolys = dm->getPolyArray(dm); MPoly *mp; for (i = 0, mp = mpolys; i < num_polys; i++, mp++) { MLoop *ml = &mloops[mp->loopstart]; MLoopCol *mlcol = &mloopcols[mp->loopstart]; for (j = mp->totloop; j--; ml++, mlcol++) { const float *vco = mverts[ml->v].co; const float u = OCEAN_CO(size_co_inv, vco[0]); const float v = OCEAN_CO(size_co_inv, vco[1]); float foam; if (omd->oceancache && omd->cached == true) { BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v); foam = ocr.foam; CLAMP(foam, 0.0f, 1.0f); } else { BKE_ocean_eval_uv(omd->ocean, &ocr, u, v); foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage); } mlcol->r = mlcol->g = mlcol->b = (char)(foam * 255); /* This needs to be set (render engine uses) */ mlcol->a = 255; } } } } } /* displace the geometry */ /* Note: tried to parallelized that one and previous foam loop, but gives 20% slower results... odd. */ { const int num_verts = dm->getNumVerts(dm); for (i = 0; i < num_verts; i++) { float *vco = mverts[i].co; const float u = OCEAN_CO(size_co_inv, vco[0]); const float v = OCEAN_CO(size_co_inv, vco[1]); if (omd->oceancache && omd->cached == true) { BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v); } else { BKE_ocean_eval_uv(omd->ocean, &ocr, u, v); } vco[2] += ocr.disp[1]; if (omd->chop_amount > 0.0f) { vco[0] += ocr.disp[0]; vco[1] += ocr.disp[2]; } } } #undef OCEAN_CO return dm; }
static void tilt_sanitize_args(TiltArgs *args) { args->dx = CLAMP(args->dx, -100, 100); args->dy = CLAMP(args->dy, -100, 100); }
static enum pipe_error sf_unit_create_from_key(struct brw_context *brw, struct brw_sf_unit_key *key, struct brw_winsys_reloc *reloc, struct brw_winsys_buffer **bo_out) { struct brw_sf_unit_state sf; enum pipe_error ret; int chipset_max_threads; memset(&sf, 0, sizeof(sf)); sf.thread0.grf_reg_count = align(key->total_grf, 16) / 16 - 1; /* reloc */ sf.thread0.kernel_start_pointer = 0; sf.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; sf.thread3.dispatch_grf_start_reg = 3; if (brw->gen == 5) sf.thread3.urb_entry_read_offset = 3; else sf.thread3.urb_entry_read_offset = 1; sf.thread3.urb_entry_read_length = key->urb_entry_read_length; sf.thread4.nr_urb_entries = key->nr_urb_entries; sf.thread4.urb_entry_allocation_size = key->sfsize - 1; /* Each SF thread produces 1 PUE, and there can be up to 24(Pre-IGDNG) or * 48(IGDNG) threads */ if (brw->gen == 5) chipset_max_threads = 48; else chipset_max_threads = 24; sf.thread4.max_threads = MIN2(chipset_max_threads, key->nr_urb_entries) - 1; if (BRW_DEBUG & DEBUG_SINGLE_THREAD) sf.thread4.max_threads = 0; if (BRW_DEBUG & DEBUG_STATS) sf.thread4.stats_enable = 1; /* CACHE_NEW_SF_VP */ /* reloc */ sf.sf5.sf_viewport_state_offset = 0; sf.sf5.viewport_transform = 1; if (key->scissor) sf.sf6.scissor = 1; if (key->front_ccw) sf.sf5.front_winding = BRW_FRONTWINDING_CCW; else sf.sf5.front_winding = BRW_FRONTWINDING_CW; switch (key->cull_face) { case PIPE_FACE_FRONT: sf.sf6.cull_mode = BRW_CULLMODE_FRONT; break; case PIPE_FACE_BACK: sf.sf6.cull_mode = BRW_CULLMODE_BACK; break; case PIPE_FACE_FRONT_AND_BACK: sf.sf6.cull_mode = BRW_CULLMODE_BOTH; break; case PIPE_FACE_NONE: sf.sf6.cull_mode = BRW_CULLMODE_NONE; break; default: assert(0); sf.sf6.cull_mode = BRW_CULLMODE_NONE; break; } /* _NEW_LINE */ /* XXX use ctx->Const.Min/MaxLineWidth here */ sf.sf6.line_width = CLAMP(key->line_width, 1.0, 5.0) * (1<<1); sf.sf6.line_endcap_aa_region_width = 1; if (key->line_smooth) sf.sf6.aa_enable = 1; else if (sf.sf6.line_width <= 0x2) sf.sf6.line_width = 0; /* XXX: gl_rasterization_rules? something else? */ sf.sf6.point_rast_rule = BRW_RASTRULE_UPPER_RIGHT; sf.sf6.point_rast_rule = BRW_RASTRULE_LOWER_RIGHT; sf.sf6.point_rast_rule = 1; /* XXX clamp max depends on AA vs. non-AA */ /* _NEW_POINT */ sf.sf7.sprite_point = key->point_sprite; sf.sf7.point_size = CLAMP(rint(key->point_size), 1, 255) * (1<<3); sf.sf7.use_point_size_state = !key->point_attenuated; sf.sf7.aa_line_distance_mode = 0; /* might be BRW_NEW_PRIMITIVE if we have to adjust pv for polygons: */ if (!key->flatshade_first) { sf.sf7.trifan_pv = 2; sf.sf7.linestrip_pv = 1; sf.sf7.tristrip_pv = 2; } else { sf.sf7.trifan_pv = 1; sf.sf7.linestrip_pv = 0; sf.sf7.tristrip_pv = 0; } sf.sf7.line_last_pixel_enable = key->line_last_pixel_enable; /* Set bias for OpenGL rasterization rules: */ if (key->gl_rasterization_rules) { sf.sf6.dest_org_vbias = 0x8; sf.sf6.dest_org_hbias = 0x8; } else { sf.sf6.dest_org_vbias = 0x0; sf.sf6.dest_org_hbias = 0x0; } ret = brw_upload_cache(&brw->cache, BRW_SF_UNIT, key, sizeof(*key), reloc, 2, &sf, sizeof(sf), NULL, NULL, bo_out); if (ret) return ret; return PIPE_OK; }
void VR_ShowCrosshair () { vec3_t forward, up, right; vec3_t start, end, impact; float size; if( (sv_player && (int)(sv_player->v.weapon) == IT_AXE) ) return; // setup gl glDisable (GL_DEPTH_TEST); glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); GL_PolygonOffset (OFFSET_SHOWTRIS); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable (GL_TEXTURE_2D); glDisable (GL_CULL_FACE); // calc the line and draw VectorCopy (cl.viewent.origin, start); start[2] -= cl.viewheight - 10; AngleVectors (cl.aimangles, forward, right, up); size = CLAMP (1.0, vr_crosshair_size.value, 5.0); switch((int) vr_crosshair.value) { default: case VR_CROSSHAIR_POINT: if (vr_crosshair_depth.value <= 0) { // trace to first wall VectorMA (start, 4096, forward, end); TraceLine (start, end, impact); } else { // fix crosshair to specific depth VectorMA (start, vr_crosshair_depth.value * meters_to_units, forward, impact); } glEnable(GL_POINT_SMOOTH); glColor4f (1, 0, 0, 0.5); glPointSize( size * glwidth / 1280.0f ); glBegin(GL_POINTS); glVertex3f (impact[0], impact[1], impact[2]); glEnd(); glDisable(GL_POINT_SMOOTH); break; case VR_CROSSHAIR_LINE: // trace to first entity VectorMA (start, 4096, forward, end); TraceLineToEntity (start, end, impact, sv_player); glColor4f (1, 0, 0, 0.4); glLineWidth( size * glwidth / (1280.0f) ); glBegin (GL_LINES); glVertex3f (start[0], start[1], start[2]); glVertex3f (impact[0], impact[1], impact[2]); glEnd (); break; } // cleanup gl glColor3f (1,1,1); glEnable (GL_TEXTURE_2D); glEnable (GL_CULL_FACE); glDisable(GL_BLEND); glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); GL_PolygonOffset (OFFSET_NONE); glEnable (GL_DEPTH_TEST); }
void OptionHandler::reloadSettings() { // gather options... QSettings config; config.beginGroup("/baghira/Style"); //we need that first to make sure we use some proper settings ;) customButtonColor = QColor(config.readNumEntry("Design_ButtonColor",(int)qApp->palette().active().button().rgb())); // design handling: // first try file: QString tmpString; FILE *file = NULL; wmDesign = 5; for (int i = 0; i < 8; i++) custCols[i] = -1; if (qstrcmp( qApp->argv() [ 0 ], "ksplash" ) == 0) { style_ = Panther; _toolbuttonStyle = Panther; _buttonStyle = Panther; tabStyle_ = Clever; bgStipple = false; inactiveButtonColor = Background; } else { // first try for a tmp file from bab starter int tmpFile = 0; tmpString = QDir::homeDirPath() + "/.baghira/.bab/" + qApp->argv() [ 0 ]; file = fopen(tmpString.latin1(), "r"); if( file == NULL ) { tmpFile = 1; tmpString = QDir::homeDirPath() + "/.baghira/" + qApp->argv() [ 0 ]; file = fopen(tmpString.latin1(), "r"); if( file == NULL ) { tmpFile = 2; tmpString = QDir::homeDirPath() + "/.baghira/.bab/.style"; file = fopen(tmpString.latin1(), "r"); } } if (file != NULL) { style_ = _buttonStyle = _toolbuttonStyle = Panther; int i3 = inactiveButtonColor = -1; tabStyle_ = (tabStyle)-1; fscanf(file,"%u\n%u\n%u\n%u\n%u\n%u\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n",&style_, &wmDesign, &_buttonStyle, &_toolbuttonStyle, &tabStyle_, &i3, &custCols[0], &custCols[1], &custCols[2], &custCols[3], &custCols[4], &custCols[5], &custCols[6], &custCols[7], &inactiveButtonColor); fclose(file); if (_toolbuttonStyle < 0 || _toolbuttonStyle >= NUMSTYLES) _toolbuttonStyle = (Style)config.readNumEntry( "Special_ToolbuttonStyle", style_); if (_buttonStyle < 0 || _buttonStyle >= NUMSTYLES) _buttonStyle = (Style)config.readNumEntry( "Special_ButtonStyle", style_); if (tabStyle_ < 0 || tabStyle_ > 2) tabStyle_ = (tabStyle) config.readNumEntry( (style_ == Brushed)?"Design_TabStyleBrushed":"Design_TabStyleAqua", Clever); if (inactiveButtonColor < 0 || inactiveButtonColor > 3) inactiveButtonColor = config.readNumEntry( "Design_InactiveButtonStyle", Background); if (style_ == Brushed) bgStipple = TRUE; else if (i3 == 0) bgStipple = FALSE; else bgStipple = config.readBoolEntry( "Design_StippleBackground", true ); // inactive Button if (tmpFile == 0) remove(tmpString.latin1()); // remove TEMPORARY file else if (tmpFile == 2) { tmpString = QDir::homeDirPath() + "/.baghira/.bab/.deco"; if ((file = fopen(tmpString.latin1(), "r")) != NULL) { fscanf(file,"%u\n%u\n",&i3, &wmDesign); fclose(file); } } } else { style_ = (Style)config.readNumEntry( "Design_Default", Panther ); _toolbuttonStyle = (Style)config.readNumEntry( "Special_ToolbuttonStyle", style_); _buttonStyle = (Style)config.readNumEntry( "Special_ButtonStyle", style_); tabStyle_ = (tabStyle) config.readNumEntry( (style_ == Brushed)?"Design_TabStyleBrushed":"Design_TabStyleAqua", Clever); bgStipple = (style_ == Brushed) ? true : config.readBoolEntry( "Design_StippleBackground", true ); inactiveButtonColor = config.readNumEntry( "Design_InactiveButtonStyle", Background); } } contrast = 0; if (wmDesign > 4) wmDesign = style_; if (style_ == Jaguar) contrast = 4; else if (style_ == Brushed) { tintBrush = config.readBoolEntry( "Colors_TintBrushedMetal", false ); if (tintBrush) brushTint.setRgb( config.readNumEntry( "Colors_BrushTint", ( int ) bgColor().rgb())); } // menu stuff glossyMenus_ = config.readBoolEntry( "Menu_Glossy", true ); menuBackground = config.readNumEntry( "Menu_Background", Standard); menuOpacity = config.readNumEntry( "Menu_Opacity", 70); int menuColorStyle = config.readNumEntry( "Menu_ColorStyle", 0); menuColorButton = (menuColorStyle == 1); useCustomMenuColor = (menuColorStyle == 2); shadowText = config.readBoolEntry( "Menu_ShadowText", false); if (useCustomMenuColor){ color = QColor( config.readNumEntry( "Menu_Color1", 0 ) ); color2 = QColor( config.readNumEntry( "Menu_Color2", 0 ) ); colorHigh = QColor( config.readNumEntry( "Menu_ColorHighlight", 0 ) ); fgColor = QColor( config.readNumEntry( "Menu_TextColor", 0 ) ); fgColorHigh = QColor( config.readNumEntry( "Menu_TextColorHighlight", 0 ) ); } else if (menuColorButton){ color = customButtonColor; color2 = customButtonColor.dark(130); } else { color = qApp->palette().active().background(); color2 = qApp->palette().active().background().dark(130); } drawMenuStripe_ = config.readBoolEntry("Menu_DrawMenuStripe", false); if (drawMenuStripe_) menuStripeColor_ = QColor(config.readNumEntry("Menu_StripeColor"),(int)Qt::white.rgb()); // color stuff // widgets customWidgetColor = config.readBoolEntry( "Colors_UseCustomColors", false); if ( customWidgetColor ) { customColors[ CustomRadioOn ].setRgb( config.readNumEntry( "Colors_RadioOn", ( int ) buttonColor().rgb() ) ); customColors[ CustomRadioOff ].setRgb( config.readNumEntry( "Colors_RadioOff", ( int ) bgColor().rgb() ) ); customColors[ CustomCBOn ].setRgb( config.readNumEntry( "Colors_CheckOn", ( int ) buttonColor().rgb() ) ); customColors[ CustomCBOff ].setRgb( config.readNumEntry( "Colors_CheckOff", ( int ) bgColor().rgb() ) ); customColors[ CustomTabOn ].setRgb( config.readNumEntry( "Colors_TabActive", ( int ) buttonColor().rgb() ) ); customColors[ CustomTabOff ].setRgb( config.readNumEntry( "Colors_TabInactive", ( int ) bgColor().rgb() ) ); customColors[ CustomSBSlider ].setRgb( config.readNumEntry( "Colors_Slider", ( int ) bgColor().rgb() ) ); customColors[ CustomSBSliderHover ].setRgb( config.readNumEntry( "Colors_SliderHovered", ( int ) buttonColor().rgb() ) ); customColors[ CustomSBSliderPressed ].setRgb( config.readNumEntry( "Colors_SliderPressed", ( int ) buttonColor().dark(110).rgb() ) ); customColors[ CustomSBGroove ].setRgb( config.readNumEntry( "Colors_SliderGroove", ( int ) bgColor().rgb() ) ); } if (inactiveButtonColor == Custom) customInactiveButtonColor = QColor( config.readNumEntry( "Design_InactiveButtonColor", (int) bgColor().rgb())); contrast += config.readNumEntry( "Design_StippleContrast", 3); bevelHighlights_ = config.readBoolEntry( "Design_BevelAsHighlight", true); //shadows groupboxshadow = (style_ == Brushed) ? false : config.readBoolEntry( "Design_ShadowGroupBoxes", true ); shadowDarkness = config.readNumEntry( "Design_GroupBoxeShadowDarkness", 6); //ListViews expanderStyle = config.readNumEntry( "Special_ExpanderStyle", Apple); useCustomExpanderColor = config.readBoolEntry( "Special_CustomExpanderColor", false); if (useCustomExpanderColor) expanderColor = QColor( config.readNumEntry( "Special_ExpanderColor", (int) qApp->palette().active().text().rgb())); drawDotlines = config.readBoolEntry( "Special_DrawTreeLines", true); if (drawDotlines){ dotlineStyle = config.readNumEntry( "Special_TreelineStyle", Line); dotlineColor = QColor( config.readNumEntry( "Special_TreelineColor", (int) qApp->palette().active().mid().rgb())); } //slider squeezesbslider = config.readBoolEntry( "Special_SqueezeSlider", false ); shadowsbslider = config.readBoolEntry( "Special_ShadowSlider", false ); animateSlider = config.readBoolEntry( "Special_AnimateSlider", true ); // toolbar int utb = config.readNumEntry( "Special_UnhoveredToolButtons", 2 ); tbFrame = (utb == 2) || ((style_ == Brushed) && (utb == 1)) || ((style_ != Brushed) && (utb == 0)); // tweaks centerTabs = config.readBoolEntry( "Design_CenterTabs", true); smoothListViewHeaders = (style_ == Milk) ? true : !config.readBoolEntry( "Special_UseFlatLVH", false); smootherLVH = config.readBoolEntry( "Special_RoundTaskbuttons", false); icyButtons = config.readNumEntry( "Design_ButtonStyle", 0) == 0; progressBar = config.readNumEntry( "Special_ProgressStyle", baghira); removeKickerBevel = config.readBoolEntry( "Special_RemoveKickerBevel", false); animateButton = config.readBoolEntry( "Design_AnimateButtons", true); animateProgress = config.readBoolEntry( "Design_AnimateProgress", true); drawProgressLabel = config.readBoolEntry( "Special_ShowProgressValue", false); config.endGroup(); config.beginGroup("/baghira/Deco"); titleButtonColor_[0] = QColor((unsigned int)config.readNumEntry( "CloseButtonColor", QColor(200,85,70).rgb())); titleButtonColor_[1] = QColor((unsigned int)config.readNumEntry( "MinButtonColor", QColor(230,155,40).rgb())); titleButtonColor_[2] = QColor((unsigned int)config.readNumEntry( "MaxButtonColor", QColor(121,180,54).rgb())); if (style_ == Jaguar) { titleColor_[0] = QColor((unsigned int)config.readNumEntry( "inactiveColor1_1", QColor(204,214,230).rgb())); titleColor_[1] = QColor((unsigned int)config.readNumEntry( "inactiveColor2_1", QColor(194,196,211).rgb())); } else if (style_ != Brushed) { titleColor_[0] = QColor((unsigned int)config.readNumEntry( "activeColor1_2", QColor(238,238,238).rgb())); titleColor_[1] = QColor((unsigned int)config.readNumEntry( "activeColor2_2", QColor(205,202,205).rgb())); } if (style_ == Tiger) { int r,g,b; aDecoColor1_ = QColor((unsigned int)config.readNumEntry( "activeColor2_4", (unsigned int) QColor(205,202,205).rgb())); aDecoColor2_ = QColor((unsigned int)config.readNumEntry( "activeColor1_4", (unsigned int) QColor(238,238,238).rgb())); r = (int)CLAMP(aDecoColor1_.red() * pow((double)aDecoColor1_.red() / (double)aDecoColor2_.red(),2.0),0,255); g = (int)CLAMP(aDecoColor1_.green() * pow((double)aDecoColor1_.green() / (double)aDecoColor2_.green(),2.0),0,255); b = (int)CLAMP(aDecoColor1_.blue() * pow((double)aDecoColor1_.blue() / (double)aDecoColor2_.blue(),2.0),0,255); aDecoColor2_.setRgb(r,g,b); } else { aDecoColor1_ = Qt::black; aDecoColor2_ = Qt::black; } config.endGroup(); // Option gathered }
template<typename Tin> static inline __host__ __device__ void _TDemoteClampNN(Tin &a, Ncv32u &out) {out = (Ncv32u)CLAMP(a+0.5f, 0, UINT_MAX);}
void commit_params (dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) { dt_iop_profilegamma_params_t *p = (dt_iop_profilegamma_params_t *)p1; dt_iop_profilegamma_data_t *d = (dt_iop_profilegamma_data_t *)piece->data; const float linear = p->linear; const float gamma = p->gamma; d->linear = p->linear; d->gamma = p->gamma; float a, b, c, g; if(gamma == 1.0) { #ifdef _OPENMP #pragma omp parallel for default(none) shared(d) schedule(static) #endif for(int k=0; k<0x10000; k++) d->table[k] = 1.0*k/0x10000; } else { if(linear == 0.0) { #ifdef _OPENMP #pragma omp parallel for default(none) shared(d) schedule(static) #endif for(int k=0; k<0x10000; k++) d->table[k] = powf(1.00*k/0x10000, gamma); } else { if(linear<1.0) { g = gamma*(1.0-linear)/(1.0-gamma*linear); a = 1.0/(1.0+linear*(g-1)); b = linear*(g-1)*a; c = powf(a*linear+b, g)/linear; } else { a = b = g = 0.0; c = 1.0; } #ifdef _OPENMP #pragma omp parallel for default(none) shared(d,a,b,c,g) schedule(static) #endif for(int k=0; k<0x10000; k++) { float tmp; if (k<0x10000*linear) tmp = c*k/0x10000; else tmp = powf(a*k/0x10000+b, g); d->table[k] = tmp; } } } // now the extrapolation stuff: const float x[4] = {0.7f, 0.8f, 0.9f, 1.0f}; const float y[4] = {d->table[CLAMP((int)(x[0]*0x10000ul), 0, 0xffff)], d->table[CLAMP((int)(x[1]*0x10000ul), 0, 0xffff)], d->table[CLAMP((int)(x[2]*0x10000ul), 0, 0xffff)], d->table[CLAMP((int)(x[3]*0x10000ul), 0, 0xffff)] }; dt_iop_estimate_exp(x, y, 4, d->unbounded_coeffs); }
/** * gimp_session_info_apply_geometry: * @info: * @screen: * @current_monitor: * * Apply the geometry stored in the session info object to the * associated widget. **/ void gimp_session_info_apply_geometry (GimpSessionInfo *info, GdkScreen *screen, gint current_monitor, gboolean apply_stored_monitor) { GdkRectangle rect; GdkRectangle work_rect; gchar geom[32]; gint monitor; gint width; gint height; g_return_if_fail (GIMP_IS_SESSION_INFO (info)); g_return_if_fail (GTK_IS_WINDOW (info->p->widget)); g_return_if_fail (GDK_IS_SCREEN (screen)); monitor = current_monitor; if (apply_stored_monitor) { gint n_monitors; n_monitors = gdk_screen_get_n_monitors (screen); if (info->p->monitor != DEFAULT_MONITOR && info->p->monitor < n_monitors) { monitor = info->p->monitor; } else { monitor = gdk_screen_get_primary_monitor (screen); } } gdk_screen_get_monitor_geometry (screen, monitor, &rect); gdk_screen_get_monitor_workarea (screen, monitor, &work_rect); info->p->x += rect.x; info->p->y += rect.y; if (gimp_session_info_get_remember_size (info) && info->p->width > 0 && info->p->height > 0) { width = info->p->width; height = info->p->height; } else { GtkRequisition requisition; gtk_widget_size_request (info->p->widget, &requisition); width = requisition.width; height = requisition.height; } info->p->x = CLAMP (info->p->x, work_rect.x, work_rect.x + work_rect.width - width); info->p->y = CLAMP (info->p->y, work_rect.y, work_rect.y + work_rect.height - height); if (info->p->right_align && info->p->bottom_align) { g_strlcpy (geom, "-0-0", sizeof (geom)); } else if (info->p->right_align) { g_snprintf (geom, sizeof (geom), "-0%+d", info->p->y); } else if (info->p->bottom_align) { g_snprintf (geom, sizeof (geom), "%+d-0", info->p->x); } else { g_snprintf (geom, sizeof (geom), "%+d%+d", info->p->x, info->p->y); } gtk_window_parse_geometry (GTK_WINDOW (info->p->widget), geom); if (gimp_session_info_get_remember_size (info) && info->p->width > 0 && info->p->height > 0) { gtk_window_set_default_size (GTK_WINDOW (info->p->widget), info->p->width, info->p->height); } /* Window managers and windowing systems suck. They have their own * ideas about WM standards and when it's appropriate to honor * user/application-set window positions and when not. Therefore, * use brute force and "manually" position dialogs whenever they * are shown. This is important especially for transient dialogs, * because window managers behave even "smarter" then... */ if (GTK_IS_DIALOG (info->p->widget)) g_signal_connect (info->p->widget, "show", G_CALLBACK (gimp_session_info_dialog_show), info); }
Ref<Texture> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, const Size2 p_size) const { Ref<Curve> curve_ref = p_from; ERR_FAIL_COND_V(curve_ref.is_null(), Ref<Texture>()); Curve &curve = **curve_ref; // FIXME: Should be ported to use p_size as done in b2633a97 int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); thumbnail_size *= EDSCALE; Ref<Image> img_ref; img_ref.instance(); Image &im = **img_ref; im.create(thumbnail_size, thumbnail_size / 2, 0, Image::FORMAT_RGBA8); im.lock(); Color bg_color(0.1, 0.1, 0.1, 1.0); for (int i = 0; i < thumbnail_size; i++) { for (int j = 0; j < thumbnail_size / 2; j++) { im.set_pixel(i, j, bg_color); } } Color line_color(0.8, 0.8, 0.8, 1.0); float range_y = curve.get_max_value() - curve.get_min_value(); int prev_y = 0; for (int x = 0; x < im.get_width(); ++x) { float t = static_cast<float>(x) / im.get_width(); float v = (curve.interpolate_baked(t) - curve.get_min_value()) / range_y; int y = CLAMP(im.get_height() - v * im.get_height(), 0, im.get_height()); // Plot point if (y >= 0 && y < im.get_height()) { im.set_pixel(x, y, line_color); } // Plot vertical line to fix discontinuity (not 100% correct but enough for a preview) if (x != 0 && Math::abs(y - prev_y) > 1) { int y0, y1; if (y < prev_y) { y0 = y; y1 = prev_y; } else { y0 = prev_y; y1 = y; } for (int ly = y0; ly < y1; ++ly) { im.set_pixel(x, ly, line_color); } } prev_y = y; } im.unlock(); Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); ptex->create_from_image(img_ref, 0); return ptex; }
ReducedImage* rcm_reduce_image (GimpDrawable *drawable, GimpDrawable *mask, gint LongerSize, gint Slctn) { guint32 image; GimpPixelRgn srcPR, srcMask; ReducedImage *temp; guchar *tempRGB, *src_row, *tempmask, *src_mask_row; gint i, j, x1, x2, y1, y2; gint RH, RW, width, height, bytes; gboolean NoSelectionMade; gint offx, offy; gdouble *tempHSV, H, S, V; bytes = drawable->bpp; temp = g_new0 (ReducedImage, 1); /* get bounds of image or selection */ gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); if (((x2-x1) != drawable->width) || ((y2-y1) != drawable->height)) NoSelectionMade = FALSE; else NoSelectionMade = TRUE; switch (Slctn) { case ENTIRE_IMAGE: x1 = 0; x2 = drawable->width; y1 = 0; y2 = drawable->height; break; case SELECTION_IN_CONTEXT: x1 = MAX (0, x1 - (x2-x1) / 2.0); x2 = MIN (drawable->width, x2 + (x2-x1) / 2.0); y1 = MAX (0, y1 - (y2-y1) / 2.0); y2 = MIN (drawable->height, y2 + (y2-y1) / 2.0); break; default: break; /* take selection dimensions */ } /* clamp to image size since this is the size of the mask */ gimp_drawable_offsets (drawable->drawable_id, &offx, &offy); image = gimp_item_get_image (drawable->drawable_id); x1 = CLAMP (x1, - offx, gimp_image_width (image) - offx); x2 = CLAMP (x2, - offx, gimp_image_width (image) - offx); y1 = CLAMP (y1, - offy, gimp_image_height (image) - offy); y2 = CLAMP (y2, - offy, gimp_image_height (image) - offy); /* calculate size of preview */ width = x2 - x1; height = y2 - y1; if (width < 1 || height < 1) return temp; if (width > height) { RW = LongerSize; RH = (float) height * (float) LongerSize / (float) width; } else { RH = LongerSize; RW = (float)width * (float) LongerSize / (float) height; } /* allocate memory */ tempRGB = g_new (guchar, RW * RH * bytes); tempHSV = g_new (gdouble, RW * RH * bytes); tempmask = g_new (guchar, RW * RH); gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&srcMask, mask, x1 + offx, y1 + offy, width, height, FALSE, FALSE); src_row = g_new (guchar, width * bytes); src_mask_row = g_new (guchar, width * bytes); /* reduce image */ for (i = 0; i < RH; i++) { gint whichcol, whichrow; whichrow = (float)i * (float)height / (float)RH; gimp_pixel_rgn_get_row (&srcPR, src_row, x1, y1 + whichrow, width); gimp_pixel_rgn_get_row (&srcMask, src_mask_row, x1 + offx, y1 + offy + whichrow, width); for (j = 0; j < RW; j++) { whichcol = (float)j * (float)width / (float)RW; if (NoSelectionMade) tempmask[i*RW+j] = 255; else tempmask[i*RW+j] = src_mask_row[whichcol]; gimp_rgb_to_hsv4 (&src_row[whichcol*bytes], &H, &S, &V); tempRGB[i*RW*bytes+j*bytes+0] = src_row[whichcol*bytes+0]; tempRGB[i*RW*bytes+j*bytes+1] = src_row[whichcol*bytes+1]; tempRGB[i*RW*bytes+j*bytes+2] = src_row[whichcol*bytes+2]; tempHSV[i*RW*bytes+j*bytes+0] = H; tempHSV[i*RW*bytes+j*bytes+1] = S; tempHSV[i*RW*bytes+j*bytes+2] = V; if (bytes == 4) tempRGB[i*RW*bytes+j*bytes+3] = src_row[whichcol*bytes+3]; } } /* return values */ temp->width = RW; temp->height = RH; temp->rgb = tempRGB; temp->hsv = tempHSV; temp->mask = tempmask; return temp; }
HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Material *ma, const float vec[3], const float vec1[3], const float *orco, const float *uvco, float hasize, float vectsize, int seed, const float pa_co[3]) { HaloRen *har; MTex *mtex; float tin, tr, tg, tb, ta; float xn, yn, zn, texvec[3], hoco[4], hoco1[4], in[3], tex[3], out[3]; int i, hasrgb; if (hasize==0.0f) return NULL; projectverto(vec, re->winmat, hoco); if (hoco[3]==0.0f) return NULL; if (vec1) { projectverto(vec1, re->winmat, hoco1); if (hoco1[3]==0.0f) return NULL; } har= RE_findOrAddHalo(obr, obr->tothalo++); copy_v3_v3(har->co, vec); har->hasize= hasize; /* actual projectvert is done in function project_renderdata() because of parts/border/pano */ /* we do it here for sorting of halos */ zn= hoco[3]; har->xs= 0.5f*re->winx*(hoco[0]/zn); har->ys= 0.5f*re->winy*(hoco[1]/zn); har->zs= 0x7FFFFF*(hoco[2]/zn); har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); /* halovect */ if (vec1) { har->type |= HA_VECT; xn= har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]); yn= har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]); if (xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0; else zn= atan2(yn, xn); har->sin= sin(zn); har->cos= cos(zn); zn= len_v3v3(vec1, vec)*0.5f; har->hasize= vectsize*zn + (1.0f-vectsize)*hasize; sub_v3_v3v3(har->no, vec, vec1); normalize_v3(har->no); } if (ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA; har->alfa= ma->alpha; har->r= ma->r; har->g= ma->g; har->b= ma->b; har->add= (255.0f*ma->add); har->mat= ma; har->hard= ma->har; har->seed= seed % 256; if (ma->mode & MA_STAR) har->starpoints= ma->starc; if (ma->mode & MA_HALO_LINES) har->linec= ma->linec; if (ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc; if (ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec; if ((ma->mode & MA_HALOTEX) && ma->mtex[0]) har->tex= 1; for (i=0; i<MAX_MTEX; i++) if (ma->mtex[i] && (ma->septex & (1<<i))==0) { mtex= ma->mtex[i]; copy_v3_v3(texvec, vec); if (mtex->texco & TEXCO_NORM) { ; } else if (mtex->texco & TEXCO_OBJECT) { if (mtex->object) mul_m4_v3(mtex->object->imat_ren, texvec); } else if (mtex->texco & TEXCO_GLOB) { copy_v3_v3(texvec, vec); } else if (mtex->texco & TEXCO_UV && uvco) { int uv_index=CustomData_get_named_layer_index(&dm->faceData, CD_MTFACE, mtex->uvname); if (uv_index<0) uv_index=CustomData_get_active_layer_index(&dm->faceData, CD_MTFACE); uv_index-=CustomData_get_layer_index(&dm->faceData, CD_MTFACE); texvec[0]=2.0f*uvco[2*uv_index]-1.0f; texvec[1]=2.0f*uvco[2*uv_index+1]-1.0f; texvec[2]=0.0f; } else if (mtex->texco & TEXCO_PARTICLE) { /* particle coordinates in range [0, 1] */ texvec[0] = 2.f * pa_co[0] - 1.f; texvec[1] = 2.f * pa_co[1] - 1.f; texvec[2] = pa_co[2]; } else if (orco) { copy_v3_v3(texvec, orco); } hasrgb = externtex(mtex, texvec, &tin, &tr, &tg, &tb, &ta, 0); //yn= tin*mtex->colfac; //zn= tin*mtex->alphafac; if (mtex->mapto & MAP_COL) { tex[0]=tr; tex[1]=tg; tex[2]=tb; out[0]=har->r; out[1]=har->g; out[2]=har->b; texture_rgb_blend(in, tex, out, tin, mtex->colfac, mtex->blendtype); // zn= 1.0-yn; //har->r= (yn*tr+ zn*ma->r); //har->g= (yn*tg+ zn*ma->g); //har->b= (yn*tb+ zn*ma->b); har->r= in[0]; har->g= in[1]; har->b= in[2]; } /* alpha returned, so let's use it instead of intensity */ if (hasrgb) tin = ta; if (mtex->mapto & MAP_ALPHA) har->alfa = texture_value_blend(mtex->def_var, har->alfa, tin, mtex->alphafac, mtex->blendtype); if (mtex->mapto & MAP_HAR) har->hard = 1.0f+126.0f*texture_value_blend(mtex->def_var, ((float)har->hard)/127.0f, tin, mtex->hardfac, mtex->blendtype); if (mtex->mapto & MAP_RAYMIRR) har->hasize = 100.0f*texture_value_blend(mtex->def_var, har->hasize/100.0f, tin, mtex->raymirrfac, mtex->blendtype); if (mtex->mapto & MAP_TRANSLU) { float add = texture_value_blend(mtex->def_var, (float)har->add/255.0f, tin, mtex->translfac, mtex->blendtype); CLAMP(add, 0.f, 1.f); har->add = 255.0f*add; } /* now what on earth is this good for?? */ //if (mtex->texco & 16) { // har->alfa= tin; //} } return har; }
static void convert_sampler(struct st_context *st, struct pipe_sampler_state *sampler, GLuint texUnit) { struct gl_texture_object *texobj; struct gl_context *ctx = st->ctx; struct gl_sampler_object *msamp; texobj = ctx->Texture.Unit[texUnit]._Current; if (!texobj) { texobj = _mesa_get_fallback_texture(ctx, TEXTURE_2D_INDEX); } msamp = _mesa_get_samplerobj(ctx, texUnit); memset(sampler, 0, sizeof(*sampler)); sampler->wrap_s = gl_wrap_xlate(msamp->WrapS); sampler->wrap_t = gl_wrap_xlate(msamp->WrapT); sampler->wrap_r = gl_wrap_xlate(msamp->WrapR); sampler->min_img_filter = gl_filter_to_img_filter(msamp->MinFilter); sampler->min_mip_filter = gl_filter_to_mip_filter(msamp->MinFilter); sampler->mag_img_filter = gl_filter_to_img_filter(msamp->MagFilter); if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB) sampler->normalized_coords = 1; sampler->lod_bias = ctx->Texture.Unit[texUnit].LodBias + msamp->LodBias; sampler->min_lod = CLAMP(msamp->MinLod, 0.0f, (GLfloat) texobj->MaxLevel - texobj->BaseLevel); sampler->max_lod = MIN2((GLfloat) texobj->MaxLevel - texobj->BaseLevel, msamp->MaxLod); if (sampler->max_lod < sampler->min_lod) { /* The GL spec doesn't seem to specify what to do in this case. * Swap the values. */ float tmp = sampler->max_lod; sampler->max_lod = sampler->min_lod; sampler->min_lod = tmp; assert(sampler->min_lod <= sampler->max_lod); } if (msamp->BorderColor.ui[0] || msamp->BorderColor.ui[1] || msamp->BorderColor.ui[2] || msamp->BorderColor.ui[3]) { struct gl_texture_image *teximg; teximg = texobj->Image[0][texobj->BaseLevel]; st_translate_color(msamp->BorderColor.f, teximg ? teximg->_BaseFormat : GL_RGBA, sampler->border_color.f); } sampler->max_anisotropy = (msamp->MaxAnisotropy == 1.0 ? 0 : (GLuint) msamp->MaxAnisotropy); /* only care about ARB_shadow, not SGI shadow */ if (msamp->CompareMode == GL_COMPARE_R_TO_TEXTURE) { sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE; sampler->compare_func = st_compare_func_to_pipe(msamp->CompareFunc); } sampler->seamless_cube_map = ctx->Texture.CubeMapSeamless || msamp->CubeMapSeamless; }
void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, const float col[4], int x1, int y1, int x2, int y2) { int i, j; float a; /* alpha */ float ai; /* alpha inverted */ float aich; /* alpha, inverted, ai/255.0 - Convert char to float at the same time */ if ((!rect && !rectf) || (!col) || col[3]==0.0f) return; /* sanity checks for coords */ CLAMP(x1, 0, width); CLAMP(x2, 0, width); CLAMP(y1, 0, height); CLAMP(y2, 0, height); if (x1>x2) SWAP(int,x1,x2); if (y1>y2) SWAP(int,y1,y2); if (x1==x2 || y1==y2) return; a = col[3]; ai = 1-a; aich = ai/255.0f; if (rect) { unsigned char *pixel; unsigned char chr=0, chg=0, chb=0; float fr=0, fg=0, fb=0; const int alphaint= FTOCHAR(a); if (a == 1.0f) { chr = FTOCHAR(col[0]); chg = FTOCHAR(col[1]); chb = FTOCHAR(col[2]); } else { fr = col[0]*a; fg = col[1]*a; fb = col[2]*a; } for (j = 0; j < y2-y1; j++) { for (i = 0; i < x2-x1; i++) { pixel = rect + 4 * (((y1 + j) * width) + (x1 + i)); if (pixel >= rect && pixel < rect+ (4 * (width * height))) { if (a == 1.0f) { pixel[0] = chr; pixel[1] = chg; pixel[2] = chb; pixel[3] = 255; } else { int alphatest; pixel[0] = (char)((fr + ((float)pixel[0]*aich))*255.0f); pixel[1] = (char)((fg + ((float)pixel[1]*aich))*255.0f); pixel[2] = (char)((fb + ((float)pixel[2]*aich))*255.0f); pixel[3] = (char)((alphatest= ((int)pixel[3] + alphaint)) < 255 ? alphatest : 255); } } } } } if (rectf) { float *pixel; for (j = 0; j < y2-y1; j++) { for (i = 0; i < x2-x1; i++) { pixel = rectf + 4 * (((y1 + j) * width) + (x1 + i)); if (a == 1.0f) { pixel[0] = col[0]; pixel[1] = col[1]; pixel[2] = col[2]; pixel[3] = 1.0f; } else { float alphatest; pixel[0] = (col[0]*a) + (pixel[0]*ai); pixel[1] = (col[1]*a) + (pixel[1]*ai); pixel[2] = (col[2]*a) + (pixel[2]*ai); pixel[3] = (alphatest= (pixel[3] + a)) < 1.0f ? alphatest : 1.0f; } } } } }
float CGUIControlGroupList::GetWidth() const { if (m_orientation == HORIZONTAL) return CLAMP(m_totalSize, m_minSize, m_width); return CGUIControlGroup::GetWidth(); }
float BKE_brush_sample_masktex( const Scene *scene, Brush *br, const float point[2], const int thread, struct ImagePool *pool) { UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; MTex *mtex = &br->mask_mtex; float rgba[4], intensity; if (!mtex->tex) { return 1.0f; } if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) { float rotation = -mtex->rot; float point_2d[2] = {point[0], point[1]}; float x, y; float co[3]; x = point_2d[0] - br->mask_stencil_pos[0]; y = point_2d[1] - br->mask_stencil_pos[1]; if (rotation > 0.001f || rotation < -0.001f) { const float angle = atan2f(y, x) + rotation; const float flen = sqrtf(x * x + y * y); x = flen * cosf(angle); y = flen * sinf(angle); } if (fabsf(x) > br->mask_stencil_dimension[0] || fabsf(y) > br->mask_stencil_dimension[1]) { zero_v4(rgba); return 0.0f; } x /= (br->mask_stencil_dimension[0]); y /= (br->mask_stencil_dimension[1]); co[0] = x; co[1] = y; co[2] = 0.0f; externtex( mtex, co, &intensity, rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false); } else { float rotation = -mtex->rot; float point_2d[2] = {point[0], point[1]}; float x = 0.0f, y = 0.0f; /* Quite warnings */ float invradius = 1.0f; /* Quite warnings */ float co[3]; if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) { /* keep coordinates relative to mouse */ rotation += ups->brush_rotation_sec; x = point_2d[0] - ups->mask_tex_mouse[0]; y = point_2d[1] - ups->mask_tex_mouse[1]; /* use pressure adjusted size for fixed mode */ invradius = 1.0f / ups->pixel_radius; } else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) { /* leave the coordinates relative to the screen */ /* use unadjusted size for tiled mode */ invradius = 1.0f / BKE_brush_size_get(scene, br); x = point_2d[0]; y = point_2d[1]; } else if (mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM) { rotation += ups->brush_rotation_sec; /* these contain a random coordinate */ x = point_2d[0] - ups->mask_tex_mouse[0]; y = point_2d[1] - ups->mask_tex_mouse[1]; invradius = 1.0f / ups->pixel_radius; } x *= invradius; y *= invradius; /* it is probably worth optimizing for those cases where * the texture is not rotated by skipping the calls to * atan2, sqrtf, sin, and cos. */ if (rotation > 0.001f || rotation < -0.001f) { const float angle = atan2f(y, x) + rotation; const float flen = sqrtf(x * x + y * y); x = flen * cosf(angle); y = flen * sinf(angle); } co[0] = x; co[1] = y; co[2] = 0.0f; externtex( mtex, co, &intensity, rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false); } CLAMP(intensity, 0.0f, 1.0f); switch (br->mask_pressure) { case BRUSH_MASK_PRESSURE_CUTOFF: intensity = ((1.0f - intensity) < ups->size_pressure_value) ? 1.0f : 0.0f; break; case BRUSH_MASK_PRESSURE_RAMP: intensity = ups->size_pressure_value + intensity * (1.0f - ups->size_pressure_value); break; default: break; } return intensity; }
static void rna_GameFloatProperty_value_set(PointerRNA *ptr, float value) { bProperty *prop= (bProperty*)(ptr->data); CLAMP(value, -10000.0f, 10000.0f); *(float*)(&prop->data)= value; }
//---------------------------------------------------- void CRocketLauncher::UpdateTPLaser(float frameTime) { m_lastUpdate -= frameTime; bool allowUpdate = true; if(m_lastUpdate<=0.0f) m_lastUpdate = m_Timeout; else allowUpdate = false; const CCamera& camera = gEnv->pRenderer->GetCamera(); //If character not visible, laser is not correctly updated if(CActor* pOwner = GetOwnerActor()) { ICharacterInstance* pCharacter = pOwner->GetEntity()->GetCharacter(0); if(pCharacter && !pCharacter->IsCharacterVisible()) return; } Vec3 offset(-0.06f,0.28f,0.115f); //To match scope position in TP LAW model Vec3 pos = GetEntity()->GetWorldTM().TransformPoint(offset); Vec3 dir = GetEntity()->GetWorldRotation().GetColumn1(); Vec3 hitPos(0,0,0); float laserLength = 0.0f; if(allowUpdate) { IPhysicalEntity* pSkipEntity = NULL; if(GetOwner()) pSkipEntity = GetOwner()->GetPhysics(); const float range = m_LaserRangeTP; // Use the same flags as the AI system uses for visibility. const int objects = ent_terrain|ent_static|ent_rigid|ent_sleeping_rigid|ent_independent; //ent_living; const int flags = (geom_colltype_ray << rwi_colltype_bit) | rwi_colltype_any | (10 & rwi_pierceability_mask) | (geom_colltype14 << rwi_colltype_bit); ray_hit hit; if (gEnv->pPhysicalWorld->RayWorldIntersection(pos, dir*range, objects, flags, &hit, 1, &pSkipEntity, pSkipEntity ? 1 : 0)) { laserLength = hit.dist; m_lastLaserHitPt = hit.pt; m_lastLaserHitSolid = true; } else { m_lastLaserHitSolid = false; m_lastLaserHitPt = pos + dir * range; laserLength = range + 0.1f; } // Hit near plane if (dir.Dot(camera.GetViewdir()) < 0.0f) { Plane nearPlane; nearPlane.SetPlane(camera.GetViewdir(), camera.GetPosition()); nearPlane.d -= camera.GetNearPlane()+0.15f; Ray ray(pos, dir); Vec3 out; m_lastLaserHitViewPlane = false; if (Intersect::Ray_Plane(ray, nearPlane, out)) { float dist = Distance::Point_Point(pos, out); if (dist < laserLength) { laserLength = dist; m_lastLaserHitPt = out; m_lastLaserHitSolid = true; m_lastLaserHitViewPlane = true; } } } hitPos = m_lastLaserHitPt; } else { laserLength = Distance::Point_Point(m_lastLaserHitPt, pos); hitPos = pos + dir * laserLength; } if (m_smoothLaserLength < 0.0f) m_smoothLaserLength = laserLength; else { if (laserLength < m_smoothLaserLength) m_smoothLaserLength = laserLength; else m_smoothLaserLength += (laserLength - m_smoothLaserLength) * min(1.0f, 10.0f * frameTime); } const float assetLength = 2.0f; m_smoothLaserLength = CLAMP(m_smoothLaserLength,0.01f,m_LaserRangeTP); float scale = m_smoothLaserLength / assetLength; // Scale the laser based on the distance. Matrix34 scl; scl.SetIdentity(); scl.SetScale(Vec3(1,scale,1)); scl.SetTranslation(offset); GetEntity()->SetSlotLocalTM( eIGS_Aux1, scl); if (m_dotEffectSlot >= 0) { if (m_lastLaserHitSolid) { Matrix34 dotMatrix = Matrix34::CreateTranslationMat(Vec3(0,m_smoothLaserLength,0)); dotMatrix.AddTranslation(offset); if(m_lastLaserHitViewPlane) dotMatrix.Scale(Vec3(0.2f,0.2f,0.2f)); GetEntity()->SetSlotLocalTM(m_dotEffectSlot,dotMatrix); } else { Matrix34 scaleMatrix; scaleMatrix.SetIdentity(); scaleMatrix.SetScale(Vec3(0.001f,0.001f,0.001f)); GetEntity()->SetSlotLocalTM(m_dotEffectSlot, scaleMatrix); } } }