static int vibrance_slice16(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs) { VibranceContext *s = avctx->priv; AVFrame *frame = arg; const int depth = s->depth; const float max = (1 << depth) - 1; const float scale = 1.f / max; const float gc = s->lcoeffs[0]; const float bc = s->lcoeffs[1]; const float rc = s->lcoeffs[2]; const int width = frame->width; const int height = frame->height; const float intensity = s->intensity; const float alternate = s->alternate ? 1.f : -1.f; const float gintensity = intensity * s->balance[0]; const float bintensity = intensity * s->balance[1]; const float rintensity = intensity * s->balance[2]; const float sgintensity = alternate * FFSIGN(gintensity); const float sbintensity = alternate * FFSIGN(bintensity); const float srintensity = alternate * FFSIGN(rintensity); const int slice_start = (height * jobnr) / nb_jobs; const int slice_end = (height * (jobnr + 1)) / nb_jobs; const int glinesize = frame->linesize[0] / 2; const int blinesize = frame->linesize[1] / 2; const int rlinesize = frame->linesize[2] / 2; uint16_t *gptr = (uint16_t *)frame->data[0] + slice_start * glinesize; uint16_t *bptr = (uint16_t *)frame->data[1] + slice_start * blinesize; uint16_t *rptr = (uint16_t *)frame->data[2] + slice_start * rlinesize; for (int y = slice_start; y < slice_end; y++) { for (int x = 0; x < width; x++) { float g = gptr[x] * scale; float b = bptr[x] * scale; float r = rptr[x] * scale; float max_color = FFMAX3(r, g, b); float min_color = FFMIN3(r, g, b); float color_saturation = max_color - min_color; float luma = g * gc + r * rc + b * bc; const float cg = 1.f + gintensity * (1.f - sgintensity * color_saturation); const float cb = 1.f + bintensity * (1.f - sbintensity * color_saturation); const float cr = 1.f + rintensity * (1.f - srintensity * color_saturation); g = lerpf(luma, g, cg); b = lerpf(luma, b, cb); r = lerpf(luma, r, cr); gptr[x] = av_clip_uintp2_c(g * max, depth); bptr[x] = av_clip_uintp2_c(b * max, depth); rptr[x] = av_clip_uintp2_c(r * max, depth); } gptr += glinesize; bptr += blinesize; rptr += rlinesize; } return 0; }
float GameView::GetMonsterSpawnRate() const { float nightPercent = GetNightPercent(); float ratePercent = 1.f; if (nightPercent < .5f) { ratePercent = lerpf(.25f, 1.f, nightPercent * 2.f); } else { ratePercent = lerpf(1.f, .25f, (nightPercent * 2.f) - 1.f); } return 1.f / ((ratePercent) * (float)m_day * .5f); }
static float sminf(float a, float b) { float k = 0.1; float h = clampf(0.5+0.5*(b-a)/k, 0.0, 1.0); return lerpf(b, a, h) - k*h*(1.0-h); }
void GameView::UpdateCamera() { bool bAnooneAline = false; for (Player* p : m_players) { if (p->IsAlive()) { bAnooneAline = true; break; } } if (bAnooneAline) { // Fit players in view Vector2 minPlayer((float)m_pTilemap->getWidth(), (float)m_pTilemap->getHeight()); Vector2 maxPlayer(0.f); for (auto pPlayer : m_players) { minPlayer.x = onut::min(pPlayer->GetPosition().x, minPlayer.x); minPlayer.y = onut::min(pPlayer->GetPosition().y, minPlayer.y); maxPlayer.x = onut::max(pPlayer->GetPosition().x, maxPlayer.x); maxPlayer.y = onut::max(pPlayer->GetPosition().y, maxPlayer.y); } minPlayer.x -= 3; minPlayer.y -= 3; maxPlayer.x += 3; maxPlayer.y += 3; m_camera = (minPlayer + maxPlayer) * .5f; float playerViewHeight = maxPlayer.y - minPlayer.y; float zoomH = OScreenHf / playerViewHeight; if (zoomH > 64.f) zoomH = 64.f; float playerViewWidth = maxPlayer.x - minPlayer.x; float zoomW = OScreenWf / playerViewWidth; if (zoomW > 64.f) zoomW = 64.f; m_zoom = onut::min(zoomW, zoomH); } // Animate to target position m_cameraReal = Vector2::Lerp(m_cameraReal, m_camera, ODT * 1.5f); m_zoomReal = lerpf(m_zoomReal, m_zoom, ODT * 4.f); // Update camera based on the players position GetRootNode()->SetScale(Vector2(m_zoomReal)); GetRootNode()->SetPosition(-m_cameraReal * m_zoomReal + OScreenf * .5f); }
int main(int argc, char* argv[]) { if(argc != 4) { fprintf(stderr, "Usage: %s depthimage colorimage obj-file\n", argv[0]); exit(EXIT_FAILURE); } const char* depthfile = argv[1]; const char* colorfile = argv[2]; const char* objfile = argv[3]; uint8_t* img; uint32_t width, height; readpng(depthfile, &img, &width, &height); printf("expanding...\n"); float* imgf = expand8(img, width, height); free(img); printf("lerping...\n"); lerpf(imgf, width,height, 0.0f,241.0f, 1.0f,1.5f); #if 0 { printf("writing OBJ...\n"); /* generate the basename for the OBJ file by trying to find a "." and hacking off everything there and later. */ char* base_obj = calloc(strlen(objfile)+1, sizeof(char)); strcpy(base_obj, objfile); char* dot = strrchr(base_obj, '.'); if(dot) { *dot = '\0'; } write_objf(base_obj, colorfile, imgf, width, height); free(base_obj); } #endif { printf("writing TJF...\n"); /* generate the basename for the filename by trying to find a "." and hacking off everything there and later. */ char* base_tjf = calloc(strlen(objfile)+1, sizeof(char)); strcpy(base_tjf, objfile); char* dot = strrchr(base_tjf, '.'); if(dot) { *dot = '\0'; } write_tjff(16, base_tjf, colorfile, imgf, width, height); free(base_tjf); } return EXIT_SUCCESS; }
float wrap_lerpf(float a, float b, float u, float range_min, float range_max) { assert(range_max > range_min); const float range = range_max - range_min; float wrapped_a = a; float wrapped_b = b; if (fabsf(a - b) >= (range / 2.f)) { if (a > b) wrapped_a = wrap_range(a, range_min, range_max) - range; else wrapped_b = wrap_range(b, range_min, range_max) - range; } return wrap_range(lerpf(wrapped_a, wrapped_b, u), range_min, range_max); }
float LinearInterpolator::Interpolate(unsigned long left,unsigned long right) const { return lerpf(mValues[left],mValues[right],(mTime - mStates[left]) / (mStates[right] - mStates[left])); }
float lerp_clampf(float a, float b, float u) { return clampf(lerpf(a, b, u), a, b); }