void WRATHDefaultTextAttributePacker:: pack_attribute(enum WRATHFormattedTextStream::corner_type ct, const glyph_data &in_glyph, const vec2 &normalized_glyph_coordinate_float, vecN<GLshort,2> normalized_glyph_coordinate_short, const std::vector<int> &custom_data_use, c_array<uint8_t> packing_destination, const PackerState&) const { c_array<character_attribute> attr; attr=packing_destination .sub_array(0, sizeof(character_attribute)) .reinterpret_pointer<character_attribute>(); ivec2 native_bl(in_glyph.m_glyph->texel_lower_left()); ivec2 native_sz(in_glyph.m_glyph->texel_size()); attr[0].position()=position_type(in_glyph.m_native_position[0].x(), in_glyph.m_native_position[0].y(), in_glyph.m_z_position, in_glyph.m_scale); attr[0].glyph_stretch()=glyph_stretch_type(in_glyph.m_horizontal_stretching, in_glyph.m_vertical_stretching); attr[0].glyph_size_and_bottom_left() =glyph_size_and_bottom_left_type(native_sz.x(), native_sz.y(), native_bl.x(), native_bl.y()); attr[0].glyph_normalized_coordinate()=normalized_glyph_coordinate_short; if(ct==WRATHFormattedTextStream::not_corner) { attr[0].color()=interpolate_color(in_glyph.m_color, normalized_glyph_coordinate_float); } else { attr[0].color()=in_glyph.m_color[ct]; } if(!custom_data_use.empty()) { c_array<character_attribute_with_custom<1> > attr_with; attr_with=packing_destination .sub_array(0, sizeof(character_attribute_with_custom<1>)) .reinterpret_pointer<character_attribute_with_custom<1> >(); WRATHassert(&attr_with[0].m_base==&attr[0]); for(int i=0, endi=custom_data_use.size(); i<endi; ++i) { attr_with[0].m_custom[i]=in_glyph.m_glyph->fetch_custom_float(custom_data_use[i]); } } }
static inline void updateTmp(GLContext *c, GLVertex *q, GLVertex *p0, GLVertex *p1, float t) { interpolate_color(c, q, p0, p1, t); if (c->texture_2d_enabled) { // NOTE: This could be implemented with operator overloading, // but i'm not 100% sure that we can completely disregard Z and W components so I'm leaving it like this for now. q->tex_coord.X = (p0->tex_coord.X + (p1->tex_coord.X - p0->tex_coord.X) * t); q->tex_coord.Y = (p0->tex_coord.Y + (p1->tex_coord.Y - p0->tex_coord.Y) * t); } q->clip_code = gl_clipcode(q->pc.X, q->pc.Y, q->pc.Z, q->pc.W); if (q->clip_code == 0) gl_transform_to_viewport(c, q); }
const struct rank * score_to_rank(int score) { static struct rank rank; struct score_rank_map *p; for (p = score_rank_map; p->score_limit; p++) { if (score < p->score_limit || p->score_limit == -1) { float t = (float)score/80000; if (t > 1.f) t = 1.f; rank.description = p->rank; interpolate_color(rank.color, 1.f - t); return &rank; } } assert(0); return NULL; }
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) { const uint32_t filters = piece->pipe->dsc.filters; dt_iop_highlights_data_t *data = (dt_iop_highlights_data_t *)piece->data; const float clip = data->clip * fminf(piece->pipe->dsc.processed_maximum[0], fminf(piece->pipe->dsc.processed_maximum[1], piece->pipe->dsc.processed_maximum[2])); // const int ch = piece->colors; if(!filters) { process_clip(piece, ivoid, ovoid, roi_in, roi_out, clip); for(int k=0;k<3;k++) piece->pipe->dsc.processed_maximum[k] = fminf(piece->pipe->dsc.processed_maximum[0], fminf(piece->pipe->dsc.processed_maximum[1], piece->pipe->dsc.processed_maximum[2])); return; } switch(data->mode) { case DT_IOP_HIGHLIGHTS_INPAINT: // a1ex's (magiclantern) idea of color inpainting: { const float clips[4] = { 0.987 * data->clip * piece->pipe->dsc.processed_maximum[0], 0.987 * data->clip * piece->pipe->dsc.processed_maximum[1], 0.987 * data->clip * piece->pipe->dsc.processed_maximum[2], clip }; if(filters == 9u) { const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) #endif for(int j = 0; j < roi_out->height; j++) { interpolate_color_xtrans(ivoid, ovoid, roi_in, roi_out, 0, 1, j, clips, xtrans, 0); interpolate_color_xtrans(ivoid, ovoid, roi_in, roi_out, 0, -1, j, clips, xtrans, 1); } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) #endif for(int i = 0; i < roi_out->width; i++) { interpolate_color_xtrans(ivoid, ovoid, roi_in, roi_out, 1, 1, i, clips, xtrans, 2); interpolate_color_xtrans(ivoid, ovoid, roi_in, roi_out, 1, -1, i, clips, xtrans, 3); } } else { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(data, piece) #endif for(int j = 0; j < roi_out->height; j++) { interpolate_color(ivoid, ovoid, roi_out, 0, 1, j, clips, filters, 0); interpolate_color(ivoid, ovoid, roi_out, 0, -1, j, clips, filters, 1); } // up/down directions #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(data, piece) #endif for(int i = 0; i < roi_out->width; i++) { interpolate_color(ivoid, ovoid, roi_out, 1, 1, i, clips, filters, 2); interpolate_color(ivoid, ovoid, roi_out, 1, -1, i, clips, filters, 3); } } break; } case DT_IOP_HIGHLIGHTS_LCH: if(filters == 9u) process_lch_xtrans(self, piece, ivoid, ovoid, roi_in, roi_out, clip); else process_lch_bayer(self, piece, ivoid, ovoid, roi_in, roi_out, clip); break; default: case DT_IOP_HIGHLIGHTS_CLIP: process_clip(piece, ivoid, ovoid, roi_in, roi_out, clip); break; } // update processed maximum const float m = fmaxf(fmaxf(piece->pipe->dsc.processed_maximum[0], piece->pipe->dsc.processed_maximum[1]), piece->pipe->dsc.processed_maximum[2]); for(int k = 0; k < 3; k++) piece->pipe->dsc.processed_maximum[k] = m; if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); }
static inline void interpolate(GLContext *c, GLVertex *q, GLVertex *p0, GLVertex *p1, float t) { q->pc = p0->pc + (p1->pc - p0->pc) * t; interpolate_color(c, q, p0, p1, t); }
/* ---------------------------------------------------------------------------- * Returns what the properties should be at the specified time. * These values are interpolated using the keyframes. */ bitmap_effect_props bitmap_effect::get_final_properties() { assert(!keyframes.empty()); if(keyframes.size() == 1) { return keyframes[0]; } else { //Find the previous and next keyframes. float prev_time = 0; float next_time = 0; bitmap_effect_props* prev_keyframe = &keyframes[0]; bitmap_effect_props* next_keyframe = NULL; for(auto k = keyframes.begin(); k != keyframes.end(); ++k) { if(k->first > cur_time) { next_keyframe = &k->second; next_time = k->first; break; } else { prev_keyframe = &k->second; prev_time = k->first; } } if(!next_keyframe) next_keyframe = prev_keyframe; bitmap_effect_props final_props; final_props.translation.x = interpolate_number( cur_time, prev_time, next_time, prev_keyframe->translation.x, next_keyframe->translation.x ); final_props.translation.y = interpolate_number( cur_time, prev_time, next_time, prev_keyframe->translation.y, next_keyframe->translation.y ); final_props.rotation = interpolate_number( cur_time, prev_time, next_time, prev_keyframe->rotation, next_keyframe->rotation ); final_props.scale.x = interpolate_number( cur_time, prev_time, next_time, prev_keyframe->scale.x, next_keyframe->scale.x ); final_props.scale.y = interpolate_number( cur_time, prev_time, next_time, prev_keyframe->scale.y, next_keyframe->scale.y ); final_props.tint_color = interpolate_color( cur_time, prev_time, next_time, prev_keyframe->tint_color, next_keyframe->tint_color ); final_props.glow_color = interpolate_color( cur_time, prev_time, next_time, prev_keyframe->glow_color, next_keyframe->glow_color ); return final_props; } }
/* ---------------------------------------------------------------------------- * Draws a treasure. */ void treasure::draw() { sprite* s_ptr = anim.get_cur_sprite(); if(!s_ptr) return; float draw_x, draw_y; float draw_w, draw_h, scale; get_sprite_center(this, s_ptr, &draw_x, &draw_y); get_sprite_dimensions(this, s_ptr, &draw_w, &draw_h, &scale); float radius = type->radius * scale; bool being_delivered = false; ALLEGRO_COLOR extra_color; if(fsm.cur_state->id == TREASURE_STATE_BEING_DELIVERED) { //If it's being delivered, do some changes to the scale and coloring. being_delivered = true; if(script_timer.get_ratio_left() >= 0.5) { //First half of the sucking in process = interpolated coloring. extra_color = interpolate_color( script_timer.get_ratio_left(), 0.5, 1.0, carrying_color_move, al_map_rgb(0, 0, 0) ); } else { //Second half of the sucking in process = interpolated scaling. extra_color = carrying_color_move; radius *= (script_timer.get_ratio_left() * 2.0); } } draw_sprite( s_ptr->bitmap, draw_x, draw_y, radius * 2.0, -1, angle, map_gray(get_sprite_brightness(this)) ); if(being_delivered) { int old_op, old_src, old_dst, old_aop, old_asrc, old_adst; al_get_separate_blender( &old_op, &old_src, &old_dst, &old_aop, &old_asrc, &old_adst ); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE); draw_sprite( s_ptr->bitmap, draw_x, draw_y, radius * 2.0, -1, angle, extra_color ); al_set_separate_blender( old_op, old_src, old_dst, old_aop, old_asrc, old_adst ); } }