void f0r_update(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe) { assert(instance); three_point_balance_instance_t* inst = (three_point_balance_instance_t*)instance; unsigned char* dst = (unsigned char*)outframe; const unsigned char* src = (unsigned char*)inframe; int mapRed[256]; int mapGreen[256]; int mapBlue[256]; double redPoints[6] = {inst->blackColor.r, 0, inst->grayColor.r, 0.5, inst->whiteColor.r, 1}; double greenPoints[6] = {inst->blackColor.g, 0, inst->grayColor.g, 0.5, inst->whiteColor.g, 1}; double bluePoints[6] = {inst->blackColor.b, 0, inst->grayColor.b, 0.5, inst->whiteColor.b, 1}; double *redCoeffs = calcParabolaCoeffs(redPoints); double *greenCoeffs = calcParabolaCoeffs(greenPoints); double *blueCoeffs = calcParabolaCoeffs(bluePoints); //building map for values from 0 to 255 for(int i = 0; i < 256; i++) { double w = parabola(i / 255., redCoeffs); mapRed[i] = CLAMP(w, 0, 1) * 255; w = parabola(i / 255., greenCoeffs); mapGreen[i] = CLAMP(w, 0, 1) * 255; w = parabola(i / 255., blueCoeffs); mapBlue[i] = CLAMP(w, 0, 1) * 255; } free(redCoeffs); free(greenCoeffs); free(blueCoeffs); for(int j = 0; j < inst->width; j++) { int copyPixel = inst->splitPreview && ((inst->srcPosition && j < inst->width / 2) || (!inst->srcPosition && j >= inst->width / 2)); for(int i = 0; i < inst->height; i++) { int offset = (i * inst->width + j) * 4; if (copyPixel) { dst[offset] = src[offset]; offset++; dst[offset] = src[offset]; offset++; dst[offset] = src[offset]; offset++; } else { dst[offset] = mapRed[src[offset]]; offset++; dst[offset] = mapGreen[src[offset]]; offset++; dst[offset] = mapBlue[src[offset]]; offset++; } dst[offset] = src[offset]; // copy alpha offset++; } } }
void parabola(double a, const point2d &begin, const point2d &end){ glVertex2d(begin[0], begin[1]); point2d delta = end-begin; if(norm1(delta) <= 1.0/pointsize) return; point2d midpoint(2); midpoint[0] = begin[0]+delta[0]/2; midpoint[1] = a*square(midpoint[0]); parabola(a, begin, midpoint); parabola(a, midpoint, end); }
double area(double x1,double y1,double x2,double y2,double x3, double y3) { double pa,pb,pc,la,lb,r; parabola(x1,y1,x2,y2,&pa,&pb,&pc); line(x2,y2,x3,y3,&la,&lb); r = area_parabola(pa,pb,pc,x2,x3) - area_line(la,lb,x2,x3); return r<0?-r:r; }
void Shearer::animate(QPainter *painter,SelectedItem *item,qreal percent) { // Have to translate the entire coordinate system back to zero, so that the shear takes place // around the origin. Otherwise, the image will be pulled too far away, the further it is from // the origin. QPointF pos = item->mapToScene(item->rect().x(),item->rect().y()); painter->translate(item->rect().width()/2 + pos.x(),item->rect().height()/2 + pos.y()); qreal shearVal = 0; if ( percent <= 0.5 ) { // Pulling top left corner up and out, bottom right corner down and out. shearVal = parabola(percent); } else { // Negative shear - pulling the other way. shearVal = -(parabola(percent-0.5)); } painter->shear(shearVal,shearVal); // Now that we've done the shear, translate back again. painter->translate(-item->rect().width()/2 - pos.x(),-item->rect().height()/2 - pos.y()); int imageSize = item->current()->selectedImageSize(); draw(painter,item,imageSize,imageSize); }
void paratraverse(int r) { cleardevice(); std::vector<Point2D> list; parabola(getmaxx()/2, getmaxy(), 16, list, true); std::sort(list.begin(), list.end(), compPoint2D); setcolor(WHITE); float theta = 0; for (auto i = list.begin(); i != list.end(); i+=10, theta+=10) { Point2D t(*i); if (t.y > getmaxy() - r) t.y = t.y - r; else if(i - list.begin() > list.size()/2) t = Point2D(t.x - r, t.y); else t = Point2D(t.x + r, t.y); wheel(t, r, theta); parabola(getmaxx()/2, getmaxy(), 16, list); setcolor(BLACK); delay(100); wheel(t, r, theta); setcolor(WHITE); } getch(); }