Copying Pixels


  int     copy_rect(Graphics *g, Point dp, Graphics *src, Rect sr);
  void    texture_rect(Graphics *g, Rect dr, Graphics *src, Rect sr);
  void    draw_image(Graphics *g, Rect dr, Image *img, Rect sr);
  Bitmap *image_to_bitmap(Window *win, Image *img);


The copy_rect operation copies pixels from the source rectangle sr in the source graphics object src, to the destination point dp in the destination graphics object g. There are some restrictions on this function:

For these reasons, it is best to think of bitmaps and windows as output devices only, with copying going from images to bitmaps to windows, but never in the other direction:

Valid drawing destinations.

The texture_rect function overlays the entire destination rectangle dr with copies of the source rectangle sr from the pixel source src, starting in the top-left point of dr and proceeding to the left and down. This produces a wall-paper effect.

The draw_image function specialises in drawing a scaled version of an image. It copies pixels from the source rectangle sr of the image img into the destination rectangle dr, scaling between the two rectangles as required. When drawing an image many times, it is sometimes more efficient to scale the image first then use copy_rect instead of draw_image, since the scaling is only performed once.

Drawing an image to a bitmap or window is implemented by creating a temporary bitmap, copying the image data into the bitmap, copying the bitmap to the window, then destroying the temporary bitmap. For this reason, when drawing an image many times, it is sometimes more efficient to create a bitmap from the image using image_to_bitmap, and then draw from that bitmap instead.