void paint_cell(int row, int col, unsigned char color) { int pixel_row = row * PIXEL_SIZE; int pixel_col = col * PIXEL_SIZE; int drow, dcol; for (drow = 0; drow < PIXEL_SIZE; drow++) { for (dcol = 0; dcol < PIXEL_SIZE; dcol++) { paint_pixel(pixel_row + drow, pixel_col + dcol, color); } } }
void draw_window(SDL_Surface* screen) { pixel colour; colour.r = 125; colour.g = 25; colour.b = 125; if(SDL_MUSTLOCK(screen)){ SDL_UnlockSurface(screen); } for(int x = 0; x < screen->w; x++){ for(int y = 0; y < screen->h; y++){ paint_pixel(screen, x, y*screen->w, colour); } } SDL_UpdateRect(screen,0,0,0,0); return; }
static inline double paint_pixels(const unsigned total_width, const unsigned total_height, const unsigned img_width, const unsigned img_height, const unsigned start_x, const unsigned start_y, const unsigned lx, const unsigned rx, const unsigned uy, const unsigned ly, const unsigned iterations, JpegMap &img, JpegMap &img_mirror) { if (std::min(rx-lx, ly-uy) < 10) { double maxval = 0; for (int y=uy; y < ly; ++y) { for (int x=lx; x < rx; ++x) { const double val = paint_pixel(total_width, total_height, img_width, img_height, start_x, x, start_y, y, iterations, img, img_mirror); maxval = std::max(val, maxval); } } return maxval; } if (rx <= lx || ly <= uy) return 0; double maxdiff = 0; cmplx z; const cmplx pos = complex_coord(total_width, total_height, start_x, start_y); const int firstval = mandelbrot_iterations(pos, iterations, z); for (int y = uy+1; y < ly - 1; ++y) { // Left column const int val = paint_pixel(total_width, total_height, img_width, img_height, start_x, lx, start_y, y, iterations, img, img_mirror); // Right column const int val2 = paint_pixel(total_width, total_height, img_width, img_height, start_x, rx-1, start_y, y, iterations, img, img_mirror); maxdiff = std::max(maxdiff, std::fabs(val - firstval)); maxdiff = std::max(maxdiff, std::fabs(val2 - firstval)); } for (int x = lx; x < rx; ++x) { // Upper row const int val = paint_pixel(total_width, total_height, img_width, img_height, start_x, x, start_y, uy, iterations, img, img_mirror); // Lower row const int val2 = paint_pixel(total_width, total_height, img_width, img_height, start_x, x, start_y, ly-1, iterations, img, img_mirror); maxdiff = std::max(maxdiff, std::fabs(val - firstval)); maxdiff = std::max(maxdiff, std::fabs(val2 - firstval)); } if (maxdiff == 0) { const RgbColor col = rgb_mandelbrot(firstval, iterations, z); for (int y=uy; y < ly; ++y) { for (int x=lx; x < rx; ++x) { img.setPixel(x, y, col); img_mirror.setPixel(x, img_height - 1 - y, col); } } return firstval; } const unsigned mx = (rx + lx) / 2; const unsigned my = (ly + uy) / 2; int maxval = 0; int ret; // Upper left ret = paint_pixels(total_width, total_height, img_width, img_height, start_x, start_y, lx+1, mx, uy+1, my, iterations, img, img_mirror); maxval = std::max(ret, maxval); // Upper right ret = paint_pixels(total_width, total_height, img_width, img_height, start_x, start_y, mx, rx-1, uy+1, my, iterations, img, img_mirror); maxval = std::max(ret, maxval); // Lower left ret = paint_pixels(total_width, total_height, img_width, img_height, start_x, start_y, lx, mx, my, ly-1, iterations, img, img_mirror); maxval = std::max(ret, maxval); // Lower right ret = paint_pixels(total_width, total_height, img_width, img_height, start_x, start_y, mx, rx-1, my, ly-1, iterations, img, img_mirror); maxval = std::max(ret, maxval); return maxval; }
int compositor_process(weed_plant_t *inst, weed_timecode_t timecode) { int error; weed_plant_t **in_channels=NULL; int num_in_channels=0; weed_plant_t *out_channel=weed_get_plantptr_value(inst,"out_channels",&error); unsigned char *src; unsigned char *dst=weed_get_voidptr_value(out_channel,"pixel_data",&error),*dst2; int owidth=weed_get_int_value(out_channel,"width",&error),owidth3=owidth*3; int oheight=weed_get_int_value(out_channel,"height",&error); int in_width,in_height,out_width,out_height; int irowstride; int orowstride=weed_get_int_value(out_channel,"rowstrides",&error); //int palette=weed_get_int_value(out_channel,"current_palette",&error); weed_plant_t **in_params; int numscalex,numscaley,numoffsx,numoffsy,numalpha; int *bgcol; double *offsx,*offsy,*scalex,*scaley,*alpha; double myoffsx,myoffsy,myscalex,myscaley,myalpha; unsigned char *end; register int x,y,z; GdkPixbuf *in_pixbuf,*out_pixbuf; int up_interp=GDK_INTERP_HYPER; int down_interp=GDK_INTERP_BILINEAR; if (weed_plant_has_leaf(inst,"in_channels")) { num_in_channels=weed_leaf_num_elements(inst,"in_channels"); in_channels=weed_get_plantptr_array(inst,"in_channels",&error); } in_params=weed_get_plantptr_array(inst,"in_parameters",&error); numoffsx=weed_leaf_num_elements(in_params[0],"value"); offsx=weed_get_double_array(in_params[0],"value",&error); numoffsy=weed_leaf_num_elements(in_params[1],"value"); offsy=weed_get_double_array(in_params[1],"value",&error); numscalex=weed_leaf_num_elements(in_params[2],"value"); scalex=weed_get_double_array(in_params[2],"value",&error); numscaley=weed_leaf_num_elements(in_params[3],"value"); scaley=weed_get_double_array(in_params[3],"value",&error); numalpha=weed_leaf_num_elements(in_params[4],"value"); alpha=weed_get_double_array(in_params[4],"value",&error); bgcol=weed_get_int_array(in_params[5],"value",&error); // set out frame to bgcol end=dst+oheight*orowstride; for (dst2=dst; dst2<end; dst2+=orowstride) { for (x=0; x<owidth3; x+=3) { dst2[x]=bgcol[0]; dst2[x+1]=bgcol[1]; dst2[x+2]=bgcol[2]; } } weed_free(bgcol); // add overlays in reverse order for (z=num_in_channels-1; z>=0; z--) { // check if host disabled this channel : this is allowed as we have set "max_repeats" if (weed_plant_has_leaf(in_channels[z],"disabled")&&weed_get_boolean_value(in_channels[z],"disabled",&error)==WEED_TRUE) continue; if (z<numoffsx) myoffsx=(int)(offsx[z]*(double)owidth); else myoffsx=0; if (z<numoffsy) myoffsy=(int)(offsy[z]*(double)oheight); else myoffsy=0; if (z<numscalex) myscalex=scalex[z]; else myscalex=1.; if (z<numscaley) myscaley=scaley[z]; else myscaley=1.; if (z<numalpha) myalpha=alpha[z]; else myalpha=1.; out_width=(owidth*myscalex+.5); out_height=(oheight*myscaley+.5); if (out_width*out_height>0) { in_width=weed_get_int_value(in_channels[z],"width",&error); in_height=weed_get_int_value(in_channels[z],"height",&error); src=weed_get_voidptr_value(in_channels[z],"pixel_data",&error); irowstride=weed_get_int_value(in_channels[z],"rowstrides",&error); // scale image to new size in_pixbuf=pl_data_to_pixbuf(WEED_PALETTE_RGB24, in_width, in_height, irowstride, (guchar *)src); if (out_width>in_width||out_height>in_height) { out_pixbuf=gdk_pixbuf_scale_simple(in_pixbuf,out_width,out_height,up_interp); } else { out_pixbuf=gdk_pixbuf_scale_simple(in_pixbuf,out_width,out_height,down_interp); } g_object_unref(in_pixbuf); src=gdk_pixbuf_get_pixels(out_pixbuf); out_width=gdk_pixbuf_get_width(out_pixbuf); out_height=gdk_pixbuf_get_height(out_pixbuf); irowstride=gdk_pixbuf_get_rowstride(out_pixbuf); for (y=myoffsy; y<oheight&&y<myoffsy+out_height; y++) { for (x=myoffsx; x<owidth&&x<myoffsx+out_width; x++) { paint_pixel(dst,y*orowstride+x*3,src,(y-myoffsy)*irowstride+(x-myoffsx)*3,myalpha); } } g_object_unref(out_pixbuf); } } weed_free(offsx); weed_free(offsy); weed_free(scalex); weed_free(scaley); weed_free(alpha); if (num_in_channels>0) weed_free(in_channels); return WEED_NO_ERROR; }