int image_draw_hline(image *i, uint32_t x, uint32_t y, uint32_t w, colour *c) { pixelref ref; int d; uint32_t n; if(c->format != i->format) { errno = EINVAL; return -1; } if(image_pixel(i, x, y, &ref) < 0) { return -1; } if(w > (i->vpwidth - x)) { w = i->vpwidth - x; } for(d = 0; d < i->planes; d++) { for(n = 0; n < w; n++) { ref.pixel[d][n] = c->p.values[d]; } } return 0; }
//Drawing void wind_draw(wind* w, image* img, float r, float g, float b, float a, float x0, float y0, float scale) { assert(bounded01(r) && bounded01(g) && bounded01(b) && bounded01(a)); for(unsigned i = 0; i < w->particles; i++) { //Translate, scale, and offset to to make truncation round properly. float x = (wind_x(w)[i] - x0) / scale + 0.5; float y = (wind_y(w)[i] - y0) / scale + 0.5; if(x < 0 || x >= img->width || y < 0 || y >= img->height) continue; float* rv = image_pixel(img, (unsigned)x, (unsigned)y, R); float* gv = image_pixel(img, (unsigned)x, (unsigned)y, G); float* bv = image_pixel(img, (unsigned)x, (unsigned)y, B); *rv = *rv * (1 - a) + a * r; *gv = *gv * (1 - a) + a * g; *bv = *bv * (1 - a) + a * b; } }
void wind_draw_roffset(wind* w, image* img, float r, float g, float b, float a, float x0, float y0, float scale, unsigned copies, float spread) { //assert(bounded01(r) && bounded01(g) && bounded01(b) && bounded01(a)); for(unsigned i = 0; i < w->particles; i++) { //Translate, scale, and offset to to make truncation round properly. float xf = (wind_x(w)[i] - x0) / scale + 0.5; float yf = (wind_y(w)[i] - y0) / scale + 0.5; for(unsigned j = 0; j < copies; j++) { vec2 s = symmetricBall(spread); unsigned x = (unsigned)(xf + s.x); unsigned y = (unsigned)(yf + s.y); if(x < 0 || x >= img->width || y < 0 || y >= img->height) continue; float* rv = image_pixel(img, (unsigned)x, (unsigned)y, R); float* gv = image_pixel(img, (unsigned)x, (unsigned)y, G); float* bv = image_pixel(img, (unsigned)x, (unsigned)y, B); *rv = *rv * (1 - a) + a * r; *gv = *gv * (1 - a) + a * g; *bv = *bv * (1 - a) + a * b; } } }
int write_image( const Image& image, const char *filename ) { if(std::string(filename).rfind(".png") == std::string::npos && std::string(filename).rfind(".PNG") == std::string::npos ) { printf("writing color image '%s'... failed, not a PNG image.\n", filename); return -1; } // flip de l'image : Y inverse entre GL et BMP Image flip= create_image(image.width, image.height, 4, make_color(0, 0, 0)); for(int y= 0; y < image.height; y++) for(int x= 0; x < image.width; x++) image_set_pixel(flip, x, image.height - y -1, image_pixel(image, x, y)); SDL_Surface *bmp= SDL_CreateRGBSurfaceFrom((void *) &flip.data.front(), image.width, image.height, 32, image.width * 4, #if 0 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF #else 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 #endif ); int code= IMG_SavePNG(bmp, filename); SDL_FreeSurface(bmp); release_image(flip); if(code < 0) printf("writing color image '%s'... failed\n%s\n", filename, SDL_GetError()); else printf("writing color image '%s'...\n", filename); return code; }
/* Copy up to w pixels from src up to (destx,desty)-(destx+w-1,desty) */ int image_draw_copyline(image *i, pixelref *src, uint32_t destx, uint32_t desty, uint32_t w) { pixelref dest; int c; if(destx > i->width || desty > i->height) { return 0; } if(w + destx > i->width) { w = i->width - destx; } if(image_pixel(i, destx, desty, &dest)) { return -1; } for(c = 0; c < i->planes; c++) { memcpy(dest.pixel[c], src->pixel[c], sizeof(pixel) * w); } return 0; }
static void egd_drv_output(ErlDrvData handle, char *buffer, int n) { egd_data* d = (egd_data*)handle; int command = 0; unsigned char error_code[4]; /* Error Control */ /* get command */ command = decode(&buffer); n -= 2; switch(command) { case IM_CREATE: image_create(d, buffer, n); break; case IM_PIXEL: image_pixel(d, buffer, n); break; case IM_LINE: image_line(d, buffer, n); break; case IM_RECTANGLE: image_rectangle(d, buffer, n); break; case IM_FILLEDRECTANGLE: image_filled_rectangle(d, buffer, n); break; case IM_POLYGON: image_polygon(d, buffer, n); break; case IM_FILLEDPOLYGON: image_filled_polygon(d, buffer, n); break; case IM_COLOR: image_color(d, buffer, n); break; case IM_ARC: image_arc(d, buffer, n); break; case IM_FILLEDARC: image_filled_arc(d, buffer, n); break; case IM_FILLEDELLIPSE: image_filled_ellipse(d, buffer, n); break; case IM_TEXT: image_text(d, buffer, n); break; case IM_TEXTUP: image_text_up(d, buffer, n); break; case IM_FONT_SIZE: image_font_size(d, buffer, n); break; case IM_FILL: image_fill(d, buffer, n); break; /* Resampling och Rotate */ case IM_RESAMPLE: image_resample(d, buffer, n); break; case IM_ROTATE: image_rotate(d, buffer, n); break; /* Fetching images */ case IM_GIF: image_gif(d,buffer,n); break; case IM_JPEG: image_jpeg(d,buffer,n); break; case IM_PNG: image_png(d,buffer,n); break; default: driver_output(d->port, (char *)encode((char *)error_code, 1), 4); break; } }