def draw!(x,y,image)

        draw_height = image.height
        draw_width = image.width

        if y+image.height > self.height
          draw_height = self.height - y
        end

        if x+image.width > self.width
          draw_width = self.width - x
        end

        dest_pixel_data = self.pixel_data
        orig_pixel_data = image.pixel_data

        (0..draw_height-1).each do |y_orig|
          y_dest = y_orig + y

          origpointer = y_orig*image.width*3
          destpointer = (y_dest*width+x)*3

          (0..draw_width-1).each do |x_orig|
            color = orig_pixel_data[origpointer..origpointer+2]

              alpha = image.alpha_data[y_orig*image.width+x_orig].ord

                if alpha < 255
                  if alpha > 0
                    dest_pixel_data[destpointer] =
                      (( orig_pixel_data[origpointer].ord*(alpha) + dest_pixel_data[destpointer].ord*(255-alpha) ) / 255).chr
                      origpointer = origpointer + 1
                      destpointer = destpointer + 1

                    dest_pixel_data[destpointer] =
                      (( orig_pixel_data[origpointer].ord*(alpha) + dest_pixel_data[destpointer].ord*(255-alpha) ) / 255).chr
                      origpointer = origpointer + 1
                      destpointer = destpointer + 1

                    dest_pixel_data[destpointer] =
                      (( orig_pixel_data[origpointer].ord*(alpha) + dest_pixel_data[destpointer].ord*(255-alpha) ) / 255).chr
                      origpointer = origpointer + 1
                      destpointer = destpointer + 1

                  else
                    destpointer = destpointer + 3
                    origpointer = origpointer + 3
                  end
                else
                  dest_pixel_data[destpointer..destpointer+2] = color
                  destpointer = destpointer + 3
                  origpointer = origpointer + 3
                end
          end
        end
    end
def draw!(x,y,image)

        draw_height = image.height
        draw_width = image.width

        if y+image.height > self.height
          draw_height = self.height - y
        end

        if x+image.width > self.width
          draw_width = self.width - x
        end

        dest_pixel_data = self.pixel_data
        orig_pixel_data = image.pixel_data

        (0..draw_height-1).each do |y_orig|
          y_dest = y_orig + y

          origpointer = y_orig*image.width*3
          destpointer = (y_dest*width+x)*3

          (0..draw_width-1).each do |x_orig|
            color = orig_pixel_data[origpointer..origpointer+2]

              alpha = image.alpha_data[y_orig*image.width+x_orig].ord

                if alpha < 255
                  if alpha > 0
                    dest_pixel_data[destpointer] =
                      (( orig_pixel_data[origpointer].ord*(alpha) + dest_pixel_data[destpointer].ord*(255-alpha) ) / 255).chr
                      origpointer = origpointer + 1
                      destpointer = destpointer + 1

                    dest_pixel_data[destpointer] =
                      (( orig_pixel_data[origpointer].ord*(alpha) + dest_pixel_data[destpointer].ord*(255-alpha) ) / 255).chr
                      origpointer = origpointer + 1
                      destpointer = destpointer + 1

                    dest_pixel_data[destpointer] =
                      (( orig_pixel_data[origpointer].ord*(alpha) + dest_pixel_data[destpointer].ord*(255-alpha) ) / 255).chr
                      origpointer = origpointer + 1
                      destpointer = destpointer + 1

                  else
                    destpointer = destpointer + 3
                    origpointer = origpointer + 3
                  end
                else
                  dest_pixel_data[destpointer..destpointer+2] = color
                  destpointer = destpointer + 3
                  origpointer = origpointer + 3
                end
          end
        end
    end
Draw a given image to the given x and y coordinates (matching left-upper corner of the drawn image)
 when drawing, the method use the alpha channel of the origin image to properly implement
 alpha drawing (transparency)

 Examples:

   image.draw!(0,0,other_image)