void imagetest_write(void) { struct image *image; uint32_t i; struct rect rect; image = image_new(IMAGE_TYPE_8, 640, 480); image_putline(image, 20, 460, 620, 20, 60); image_putellipse(image, 320, 240, 300, 200, 64, 180); image_putcircle(image, 320, 240, 80, 64, 195); rect.x = 60; rect.y = 300; rect.w = 580; rect.h = 180; image_putrect(image, &rect, 80); for(i = 0; i < 256; i++) image_putpixel(image, 20 + i, 50, i); /* image_putstr(image, &image_font_6x10, 100, 40, 12, IMAGE_ALIGN_LEFT, "libchaos rocks!"); image_putstr(image, &image_font_6x10, 160, 80, 11, IMAGE_ALIGN_LEFT, "dschoint");*/ image_save_gif(image, "lala.gif"); image_delete(image); }
static Mask *ase_file_read_mask_chunk(FILE *f) { int c, u, v, byte; Mask *mask; // Read chunk data int x = fgetw(f); int y = fgetw(f); int w = fgetw(f); int h = fgetw(f); ase_file_read_padding(f, 8); std::string name = ase_file_read_string(f); mask = new Mask(); mask->setName(name.c_str()); mask->replace(x, y, w, h); // Read image data for (v=0; v<h; v++) for (u=0; u<(w+7)/8; u++) { byte = fgetc(f); for (c=0; c<8; c++) image_putpixel(mask->getBitmap(), u*8+c, v, byte & (1<<(7-c))); } return mask; }
void image_putpen(Image* image, Pen* pen, int x, int y, int fg_color, int bg_color) { Image* pen_image = pen->get_image(); int u, v, size = pen->get_size(); x -= size/2; y -= size/2; if (fg_color == bg_color) { image_rectfill(image, x, y, x+pen_image->w-1, y+pen_image->h-1, bg_color); } else { for (v=0; v<pen_image->h; v++) { for (u=0; u<pen_image->w; u++) { if (image_getpixel(pen_image, u, v)) image_putpixel(image, x+u, y+v, fg_color); else image_putpixel(image, x+u, y+v, bg_color); } } } }
static void pixel_for_image(int x, int y, Data *data) { image_putpixel(data->image, x, y, data->color); }
// clears the mask region in the current sprite with the specified background color void UndoTransaction::clearMask(int bgcolor) { Cel* cel = getCurrentCel(); if (!cel) return; Image* image = getCelImage(cel); if (!image) return; Mask* mask = m_document->getMask(); // If the mask is empty or is not visible then we have to clear the // entire image in the cel. if (!m_document->isMaskVisible()) { // If the layer is the background then we clear the image. if (m_sprite->getCurrentLayer()->is_background()) { if (isEnabled()) m_undoHistory->pushUndoer(new undoers::ImageArea(m_undoHistory->getObjects(), image, 0, 0, image->w, image->h)); // clear all image_clear(image, bgcolor); } // If the layer is transparent we can remove the cel (and its // associated image). else { removeCel(static_cast<LayerImage*>(m_sprite->getCurrentLayer()), cel); } } else { int offset_x = mask->getBounds().x-cel->getX(); int offset_y = mask->getBounds().y-cel->getY(); int u, v, putx, puty; int x1 = MAX(0, offset_x); int y1 = MAX(0, offset_y); int x2 = MIN(image->w-1, offset_x+mask->getBounds().w-1); int y2 = MIN(image->h-1, offset_y+mask->getBounds().h-1); // do nothing if (x1 > x2 || y1 > y2) return; if (isEnabled()) m_undoHistory->pushUndoer(new undoers::ImageArea(m_undoHistory->getObjects(), image, x1, y1, x2-x1+1, y2-y1+1)); // clear the masked zones for (v=0; v<mask->getBounds().h; v++) { div_t d = div(0, 8); uint8_t* address = ((uint8_t**)mask->getBitmap()->line)[v]+d.quot; for (u=0; u<mask->getBounds().w; u++) { if ((*address & (1<<d.rem))) { putx = u + offset_x; puty = v + offset_y; image_putpixel(image, putx, puty, bgcolor); } _image_bitmap_next_bit(d, address); } } } }