component* textinput_create(const text_settings *tconf, const char *text, const char *initialvalue) { component *c = widget_create(); textinput *tb = malloc(sizeof(textinput)); memset(tb, 0, sizeof(textinput)); tb->text = strdup(text); memcpy(&tb->tconf, tconf, sizeof(text_settings)); tb->pos = &tb->pos_; // Background for field int tsize = text_char_width(&tb->tconf); image img; image_create(&img, 15*tsize+2, tsize+3); image_clear(&img, COLOR_MENU_BG); image_rect(&img, 0, 0, 15*tsize+1, tsize+2, COLOR_MENU_BORDER); surface_create_from_image(&tb->sur, &img); image_free(&img); // Copy over the initial value memcpy(tb->buf, initialvalue, strlen(initialvalue)+1); // Widget stuff widget_set_obj(c, tb); widget_set_render_cb(c, textinput_render); widget_set_event_cb(c, textinput_event); widget_set_tick_cb(c, textinput_tick); widget_set_free_cb(c, textinput_free); return c; }
int main(int argc, char **argv) { image *i; FILE *f; (void) argc; (void) argv; colourmap_init(); i = image_create(PF_YCBCR, 1920, 1080); if(!i) { fprintf(stderr, "%s: failed to allocate image\n", argv[0]); exit(255); } image_clear(i, &black); testcard_ebu100(i); f = fopen("test.yuv16", "wb"); image_export_ycc444_16_planar(i, f); fclose(f); f = fopen("test.yuv8", "wb"); image_export_ycc444_8_planar(i, f); fclose(f); image_export_tiff_ycc444_16(i, "test.ycc444-16.tiff"); image_export_tiff_ycc444_8(i, "test.ycc444-8.tiff"); return 0; }
int generate_blacklevel(image *i) { uint32_t size, midx, midy, y, x, n; /* Patches are squares 13.35% of the height */ size = i->vpheight / 7.5; /* Find the centre */ midx = i->vpwidth / 2; midy = i->vpheight / 2; /* Fill with black */ if(image_clear(i, &black)) { return -1; } n = 1; for(y = midy - size * 2; y < midy + size * 2; y += size) { for(x = midx - size * 2; x < midx + size * 2; x += size) { if(n % 2) { if(image_draw_fillrect(i, x, y, size, size, &sub_black)) { return -1; } } n++; } n++; } return 0; }
/** * Returns a new layer (flat_layer) with all "layer" rendered frame by * frame from "frmin" to "frmax" (inclusive). "layer" can be a set of * layers, so the routine flattens all children to an unique output * layer. * * @param dst_sprite The sprite where to put the new flattened layer. * @param src_layer Generally a set of layers to be flattened. */ LayerImage* layer_new_flatten_copy(Sprite* dst_sprite, const Layer* src_layer, int x, int y, int w, int h, int frmin, int frmax) { UniquePtr<LayerImage> flatLayer(new LayerImage(dst_sprite)); for (int frame=frmin; frame<=frmax; frame++) { // Does this frame have cels to render? if (has_cels(src_layer, frame)) { // Create a new image Image* image = image_new(flatLayer->getSprite()->getImgType(), w, h); try { // Create the new cel for the output layer (add the image to stock too). Cel* cel = new Cel(frame, flatLayer->getSprite()->getStock()->addImage(image)); cel->setPosition(x, y); // Clear the image and render this frame. image_clear(image, 0); layer_render(src_layer, image, -x, -y, frame); flatLayer->addCel(cel); } catch (...) { delete image; throw; } } } return flatLayer.release(); }
int image_init(image *img, jpeg_header *header) { int hmax; int vmax; int i; memset(img, 0, sizeof(image)); img->width = header->width; img->height = header->height; img->nplanes = header->ncomps; hmax = 0; vmax = 0; for (i = 0; i < img->nplanes; i++) { jpeg_component *comp; comp = &header->comp[i]; hmax = OD_MAXI(hmax, comp->hsamp); vmax = OD_MAXI(vmax, comp->vsamp); } for (i = 0; i < img->nplanes; i++) { jpeg_component *comp; image_plane *plane; comp = &header->comp[i]; plane = &img->plane[i]; plane->width = comp->hblocks << 3; plane->height = comp->vblocks << 3; /* TODO support 16-bit images */ plane->xstride = 1; plane->ystride = plane->xstride*plane->width; plane->xdec = OD_ILOG(hmax) - OD_ILOG(comp->hsamp); plane->ydec = OD_ILOG(vmax) - OD_ILOG(comp->vsamp); plane->data = od_aligned_malloc(plane->ystride*plane->height, IMAGE_ALIGN); if (plane->data == NULL) { image_clear(img); return EXIT_FAILURE; } plane->coef = od_aligned_malloc(plane->width*plane->height*sizeof(short), IMAGE_ALIGN); if (plane->coef == NULL) { image_clear(img); return EXIT_FAILURE; } } img->pixels = od_aligned_malloc(img->width*img->height*3, IMAGE_ALIGN); if (img->pixels == NULL) { image_clear(img); return EXIT_FAILURE; } return EXIT_SUCCESS; }
Image* image_crop(const Image* image, int x, int y, int w, int h, int bgcolor) { if (w < 1) throw std::invalid_argument("image_crop: Width is less than 1"); if (h < 1) throw std::invalid_argument("image_crop: Height is less than 1"); Image* trim = Image::create(image->getPixelFormat(), w, h); trim->mask_color = image->mask_color; image_clear(trim, bgcolor); image_copy(trim, image, -x, -y); return trim; }
static void image_unload_internal(mess_image *image, int is_final_unload) { /* is there an actual image loaded? */ if (!is_loaded(image)) return; /* call the unload function */ if (image->dev->unload) image->dev->unload(image); image_clear(image); image_clear_error(image); osd_image_load_status_changed(image, is_final_unload); }
void menu_background_create(texture *tex, int w, int h) { image img; image_create(&img, w, h); image_clear(&img, COLOR_MENU_BG); for(int x = 7; x < w; x += 8) { image_line(&img, x, 0, x, h-1, COLOR_MENU_LINE); } for(int y = 7; y < h; y += 8) { image_line(&img, 0, y, w-1, y, COLOR_MENU_LINE); } image_rect(&img, 0, 0, w-1, h-1, COLOR_MENU_BORDER); texture_create_from_img(tex, &img); image_free(&img); }
int Sprite::getPixel(int x, int y, FrameNumber frame) const { int color = 0; if ((x >= 0) && (y >= 0) && (x < m_width) && (y < m_height)) { Image* image = Image::create(m_format, 1, 1); image_clear(image, (m_format == IMAGE_INDEXED ? getTransparentColor(): 0)); render(image, -x, -y, frame); color = image_getpixel(image, 0, 0); image_free(image); } return color; }
// the *other* style menu background void menu_background2_create(texture *tex, int w, int h) { image img; image_create(&img, w, h); image_clear(&img, COLOR_MENU_BG); for(int x = 5; x < w; x += 5) { image_line(&img, x, 0, x, h-1, COLOR_MENU_LINE2); } for(int y = 4; y < h; y += 5) { image_line(&img, 0, y, w-1, y, COLOR_MENU_LINE2); } image_rect(&img, 1, 1, w-2, h-2, COLOR_MENU_BORDER2); image_rect(&img, 0, 0, w-2, h-2, COLOR_MENU_BORDER1); texture_create_from_img(tex, &img); image_free(&img); }
/* creates the background */ image_t* create_background() { image_t* img = image_create(VIDEO_SCREEN_W, VIDEO_SCREEN_H); font_t *fnt = font_create("disclaimer"); v2d_t camera = v2d_new(VIDEO_SCREEN_W/2, VIDEO_SCREEN_H/2); image_clear(video_get_backbuffer(), image_rgb(0,0,0)); font_set_width(fnt, VIDEO_SCREEN_W - 6); font_set_text(fnt, "%s", text); font_set_position(fnt, v2d_new(3,3)); font_render(fnt, camera); image_blit(video_get_backbuffer(), img, 0, 0, 0, 0, image_width(img), image_height(img)); font_destroy(fnt); return img; }
Image* NewImageFromMask(const DocumentLocation& location) { const Sprite* srcSprite = location.sprite(); const Mask* srcMask = location.document()->getMask(); const Image* srcBitmap = srcMask->getBitmap(); const gfx::Rect& srcBounds = srcMask->getBounds(); const uint8_t* address; int x, y, u, v, getx, gety; Image *dst; const Image *src = location.image(&x, &y); div_t d; ASSERT(srcSprite); ASSERT(srcMask); ASSERT(srcBitmap); ASSERT(src); dst = Image::create(srcSprite->getPixelFormat(), srcBounds.w, srcBounds.h); if (!dst) return NULL; // Clear the new image image_clear(dst, 0); // Copy the masked zones for (v=0; v<srcBounds.h; v++) { d = div(0, 8); address = ((const uint8_t**)srcBitmap->line)[v]+d.quot; for (u=0; u<srcBounds.w; u++) { if ((*address & (1<<d.rem))) { getx = u+srcBounds.x-x; gety = v+srcBounds.y-y; if ((getx >= 0) && (getx < src->w) && (gety >= 0) && (gety < src->h)) dst->putpixel(u, v, src->getpixel(getx, gety)); } _image_bitmap_next_bit(d, address); } } return dst; }
Document* Document::createBasicDocument(PixelFormat format, int width, int height, int ncolors) { // Create the sprite. UniquePtr<Sprite> sprite(new Sprite(format, width, height, ncolors)); sprite->setTotalFrames(FrameNumber(1)); // Create the main image. int indexInStock; { UniquePtr<Image> image(Image::create(format, width, height)); // Clear the image with mask color. image_clear(image, 0); // Add image in the sprite's stock. indexInStock = sprite->getStock()->addImage(image); image.release(); // Release the image because it is in the sprite's stock. } // Create the first transparent layer. { UniquePtr<LayerImage> layer(new LayerImage(sprite)); layer->setName("Layer 1"); // Create the cel. { UniquePtr<Cel> cel(new Cel(FrameNumber(0), indexInStock)); cel->setPosition(0, 0); // Add the cel in the layer. layer->addCel(cel); cel.release(); // Release the cel because it is in the layer } // Add the layer in the sprite. sprite->getFolder()->addLayer(layer.release()); // Release the layer because it's owned by the sprite } // Create the document with the new sprite. UniquePtr<Document> document(new Document(sprite)); sprite.release(); // Release the sprite because it is in the document. document->setFilename("Sprite"); return document.release(); // Release the document (it does not throw) returning the raw pointer }
void progressbar_create_block(progress_bar *bar) { float prog = bar->percentage / 100.0f; int w = bar->w * prog; if(w > 0) { image tmp; image_create(&tmp, w, bar->h); image_clear(&tmp, bar->int_bg_color); image_rect_bevel(&tmp, 0, 0, w - 1, bar->h-1, bar->int_topleft_color, bar->int_bottomright_color, bar->int_bottomright_color, bar->int_topleft_color); texture_create(&bar->block); texture_init_from_img(&bar->block, &tmp); image_free(&tmp); } }
char *ascii_read() { FILE *jpeg = webcam_read(); image_t *original = image_read(jpeg), *resized = image_new(opt_width, opt_height); fclose(jpeg); image_clear(resized); image_resize(original, resized); char *ascii = image_print(resized); image_destroy(original); image_destroy(resized); return ascii; }
int generate_ebu3325_5_blue(image *i) { uint32_t size; /* Patches are squares 13.35% of the height */ size = i->vpheight / 7.5; /* Fill with black */ if(image_clear(i, &black)) { return -1; } /* Place the centre square */ if(image_draw_fillrect(i, (i->vpwidth - size) / 2, (i->vpheight - size) / 2, size, size, &ebu_blue)) { return -1; } return 0; }
Image* NewImageFromMask(const Document* srcDocument) { const Sprite* srcSprite = srcDocument->getSprite(); const Mask* srcMask = srcDocument->getMask(); const uint8_t* address; int x, y, u, v, getx, gety; Image *dst; const Image *src = srcSprite->getCurrentImage(&x, &y); div_t d; ASSERT(srcSprite); ASSERT(srcMask); ASSERT(srcMask->bitmap); ASSERT(src); dst = image_new(srcSprite->getImgType(), srcMask->w, srcMask->h); if (!dst) return NULL; // Clear the new image image_clear(dst, 0); // Copy the masked zones for (v=0; v<srcMask->h; v++) { d = div(0, 8); address = ((const uint8_t**)srcMask->bitmap->line)[v]+d.quot; for (u=0; u<srcMask->w; u++) { if ((*address & (1<<d.rem))) { getx = u+srcMask->x-x; gety = v+srcMask->y-y; if ((getx >= 0) && (getx < src->w) && (gety >= 0) && (gety < src->h)) dst->putpixel(u, v, src->getpixel(getx, gety)); } _image_bitmap_next_bit(d, address); } } return dst; }
void Document::prepareExtraCel(int x, int y, int w, int h, int opacity) { ASSERT(getSprite() != NULL); if (!m_extraCel) m_extraCel = new Cel(FrameNumber(0), 0); // Ignored fields for this cell (frame, and image index) m_extraCel->setPosition(x, y); m_extraCel->setOpacity(opacity); if (!m_extraImage || m_extraImage->getPixelFormat() != getSprite()->getPixelFormat() || m_extraImage->w != w || m_extraImage->h != h) { delete m_extraImage; // image m_extraImage = Image::create(getSprite()->getPixelFormat(), w, h); image_clear(m_extraImage, m_extraImage->mask_color = 0); } }
void progressbar_create(progress_bar *bar, unsigned int x, unsigned int y, unsigned int w, unsigned int h, color border_topleft_color, color border_bottomright_color, color bg_color, color int_topleft_color, color int_bottomright_color, color int_bg_color, int orientation) { bar->x = x; bar->y = y; bar->w = w; bar->h = h; bar->orientation = orientation; bar->percentage = 100; bar->int_topleft_color = int_topleft_color; bar->int_bottomright_color = int_bottomright_color; bar->int_bg_color = int_bg_color; texture_create(&bar->block); texture_create(&bar->background); // Background, image tmp; image_create(&tmp, w, h); image_clear(&tmp, bg_color); image_rect_bevel(&tmp, 0, 0, w-1, h-1, border_topleft_color, border_bottomright_color, border_bottomright_color, border_topleft_color); texture_init_from_img(&bar->background, &tmp); image_free(&tmp); // Bar progressbar_create_block(bar); }
int generate_ebu3325_5(image *i) { uint32_t size, frame; colour *col; /* Determine the colour from the frame index */ frame = i->frame % 15; col = ebu_shades[frame]; /* Patches are squares 13.35% of the height */ size = i->vpheight / 7.5; /* Fill with black */ if(image_clear(i, &black)) { return -1; } /* Place the centre square */ if(image_draw_fillrect(i, (i->vpwidth - size) / 2, (i->vpheight - size) / 2, size, size, col)) { return -1; } return 0; }
void vgClearImage(VGImage image, VGint x, VGint y, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct vg_image *img; if (image == VG_INVALID_HANDLE) { vg_set_error(ctx, VG_BAD_HANDLE_ERROR); return; } if (width <= 0 || height <= 0) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } img = (struct vg_image*)image; if (x + width < 0 || y + height < 0) return; image_clear(img, x, y, width, height); }
static void image_dealloc (zbarImage *self) { image_clear(self); ((PyObject*)self)->ob_type->tp_free((PyObject*)self); }
ExpandCelCanvas::ExpandCelCanvas(Document* document, Sprite* sprite, Layer* layer, TiledMode tiledMode) : m_document(document) , m_sprite(sprite) , m_layer(layer) , m_cel(NULL) , m_celImage(NULL) , m_celCreated(false) , m_closed(false) , m_committed(false) { if (m_layer->is_image()) { m_cel = static_cast<LayerImage*>(layer)->getCel(m_sprite->getCurrentFrame()); if (m_cel) m_celImage = m_sprite->getStock()->getImage(m_cel->getImage()); } // If there is no Cel if (m_cel == NULL) { // Create the image m_celImage = Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight()); image_clear(m_celImage, sprite->getTransparentColor()); // create the cel m_cel = new Cel(m_sprite->getCurrentFrame(), 0); static_cast<LayerImage*>(m_layer)->addCel(m_cel); m_celCreated = true; } m_originalCelX = m_cel->getX(); m_originalCelY = m_cel->getY(); // region to draw int x1, y1, x2, y2; if (tiledMode == TILED_NONE) { // non-tiled x1 = MIN(m_cel->getX(), 0); y1 = MIN(m_cel->getY(), 0); x2 = MAX(m_cel->getX()+m_celImage->w, m_sprite->getWidth()); y2 = MAX(m_cel->getY()+m_celImage->h, m_sprite->getHeight()); } else { // tiled x1 = 0; y1 = 0; x2 = m_sprite->getWidth(); y2 = m_sprite->getHeight(); } // create two copies of the image region which we'll modify with the tool m_srcImage = image_crop(m_celImage, x1-m_cel->getX(), y1-m_cel->getY(), x2-x1, y2-y1, m_sprite->getTransparentColor()); m_dstImage = Image::createCopy(m_srcImage); // We have to adjust the cel position to match the m_dstImage // position (the new m_dstImage will be used in RenderEngine to // draw this cel). m_cel->setPosition(x1, y1); }
void onImport() { // The user don't select a sheet yet. if (!m_document) { Alert::show("Import Sprite Sheet<<Select a sprite first.||&Close"); return; } // The list of frames imported from the sheet std::vector<Image*> animation; try { Sprite* sprite = m_document->getSprite(); FrameNumber currentFrame = m_context->getActiveLocation().frame(); // As first step, we cut each tile and add them into "animation" list. for (int y=m_rect.y; y<sprite->getHeight(); y += m_rect.h) { for (int x=m_rect.x; x<sprite->getWidth(); x += m_rect.w) { base::UniquePtr<Image> resultImage(Image::create(sprite->getPixelFormat(), m_rect.w, m_rect.h)); // Clear the image with mask color. image_clear(resultImage, 0); // Render the portion of sheet. sprite->render(resultImage, -x, -y, currentFrame); animation.push_back(resultImage); resultImage.release(); } } if (animation.size() == 0) { Alert::show("Import Sprite Sheet" "<<The specified rectangle does not create any tile." "<<Select a rectangle inside the sprite region." "||&OK"); return; } // The following steps modify the sprite, so we wrap all // operations in a undo-transaction. ContextWriter writer(m_context); UndoTransaction undoTransaction(writer.context(), "Import Sprite Sheet", undo::ModifyDocument); DocumentApi api = m_document->getApi(); // Add the layer in the sprite. LayerImage* resultLayer = api.newLayer(sprite); // Add all frames+cels to the new layer for (size_t i=0; i<animation.size(); ++i) { int indexInStock; // Add the image into the sprite's stock indexInStock = api.addImageInStock(sprite, animation[i]); animation[i] = NULL; // Create the cel. base::UniquePtr<Cel> resultCel(new Cel(FrameNumber(i), indexInStock)); // Add the cel in the layer. api.addCel(resultLayer, resultCel); resultCel.release(); } // Copy the list of layers (because we will modify it in the iteration). LayerList layers = sprite->getFolder()->getLayersList(); // Remove all other layers for (LayerIterator it=layers.begin(), end=layers.end(); it!=end; ++it) { if (*it != resultLayer) api.removeLayer(*it); } // Change the number of frames api.setTotalFrames(sprite, FrameNumber(animation.size())); // Set the size of the sprite to the tile size. api.setSpriteSize(sprite, m_rect.w, m_rect.h); undoTransaction.commit(); } catch (...) { for (size_t i=0; i<animation.size(); ++i) delete animation[i]; throw; } update_screen_for_document(m_document); closeWindow(NULL); }
static int image_load_internal(mess_image *image, const char *path, int is_create, int create_format, option_resolution *create_args) { image_error_t err; const char *software_path; char *software_path_list = NULL; const void *buffer; const game_driver *gamedrv; UINT32 open_plan[4]; int i; /* sanity checks */ assert_always(image, "image_load(): image is NULL"); assert_always(path, "image_load(): path is NULL"); /* we are now loading */ image->is_loading = 1; /* first unload the image */ image_unload(image); /* record the filename */ image->err = set_image_filename(image, path, NULL); if (image->err) goto done; /* tell the OSD layer that this is changing */ osd_image_load_status_changed(image, 0); /* do we need to reset the CPU? */ if ((timer_get_time() > 0) && image->dev->reset_on_load) mame_schedule_soft_reset(Machine); /* determine open plan */ determine_open_plan(image, is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !image->file && open_plan[i]; i++) { software_path = software_path_list; do { gamedrv = Machine->gamedrv; while(!is_loaded(image) && gamedrv) { /* open the file */ image->err = load_image_by_path(image, software_path, gamedrv, open_plan[i], path); if (image->err && (image->err != IMAGE_ERROR_FILENOTFOUND)) goto done; /* move on to the next driver */ gamedrv = mess_next_compatible_driver(gamedrv); } /* move on to the next entry in the software path; if we can */ if (software_path) software_path += strlen(software_path) + 1; } while(!is_loaded(image) && software_path && *software_path); } /* did we fail to find the file? */ if (!is_loaded(image)) { image->err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* if applicable, call device verify */ if (image->dev->imgverify && !image_has_been_created(image)) { /* access the memory */ buffer = image_ptr(image); if (!buffer) { image->err = IMAGE_ERROR_OUTOFMEMORY; goto done; } /* verify the file */ err = image->dev->imgverify(buffer, (size_t) image->length); if (err) { image->err = IMAGE_ERROR_INVALIDIMAGE; goto done; } } /* call device load or create */ if (image_has_been_created(image) && image->dev->create) { err = image->dev->create(image, create_format, create_args); if (err) { if (!image->err) image->err = IMAGE_ERROR_UNSPECIFIED; goto done; } } else if (image->dev->load) { /* using device load */ err = image->dev->load(image); if (err) { if (!image->err) image->err = IMAGE_ERROR_UNSPECIFIED; goto done; } } /* success! */ done: if (software_path_list) free(software_path_list); if (image->err) image_clear(image); image->is_loading = 1; return image->err ? INIT_FAIL : INIT_PASS; }
/** * Shows the "New Sprite" dialog. */ void NewFileCommand::onExecute(Context* context) { JWidget width, height, radio1, radio2, radio3, colors, ok, bg_box; int imgtype, w, h, bg, ncolors; char buf[1024]; Color bg_table[] = { Color::fromMask(), Color::fromRgb(0, 0, 0), Color::fromRgb(255, 255, 255), Color::fromRgb(255, 0, 255), app_get_colorbar()->getBgColor() }; // Load the window widget FramePtr window(load_widget("new_sprite.xml", "new_sprite")); get_widgets(window, "width", &width, "height", &height, "radio1", &radio1, "radio2", &radio2, "radio3", &radio3, "colors", &colors, "ok_button", &ok, "bg_box", &bg_box, NULL); // Default values: Indexed, 320x240, Background color imgtype = get_config_int("NewSprite", "Type", IMAGE_INDEXED); imgtype = MID(IMAGE_RGB, imgtype, IMAGE_INDEXED); w = get_config_int("NewSprite", "Width", 320); h = get_config_int("NewSprite", "Height", 240); bg = get_config_int("NewSprite", "Background", 4); // Default = Background color ncolors = get_config_int("NewSprite", "Colors", 256); width->setTextf("%d", MAX(1, w)); height->setTextf("%d", MAX(1, h)); colors->setTextf("%d", MID(2, ncolors, 256)); // Select image-type switch (imgtype) { case IMAGE_RGB: radio1->setSelected(true); break; case IMAGE_GRAYSCALE: radio2->setSelected(true); break; case IMAGE_INDEXED: radio3->setSelected(true); break; } // Select background color jlistbox_select_index(bg_box, bg); // Open the window window->open_window_fg(); if (window->get_killer() == ok) { bool ok = false; // Get the options if (radio1->isSelected()) imgtype = IMAGE_RGB; else if (radio2->isSelected()) imgtype = IMAGE_GRAYSCALE; else if (radio3->isSelected()) imgtype = IMAGE_INDEXED; w = width->getTextInt(); h = height->getTextInt(); ncolors = colors->getTextInt(); bg = jlistbox_get_selected_index(bg_box); w = MID(1, w, 9999); h = MID(1, h, 9999); ncolors = MID(2, ncolors, 256); // Select the color Color color = Color::fromMask(); if (bg >= 0 && bg <= 4) { color = bg_table[bg]; ok = true; } if (ok) { // Save the configuration set_config_int("NewSprite", "Type", imgtype); set_config_int("NewSprite", "Width", w); set_config_int("NewSprite", "Height", h); set_config_int("NewSprite", "Background", bg); // Create the new sprite ASSERT(imgtype == IMAGE_RGB || imgtype == IMAGE_GRAYSCALE || imgtype == IMAGE_INDEXED); ASSERT(w >= 1 && w <= 9999); ASSERT(h >= 1 && h <= 9999); UniquePtr<Document> document( Document::createBasicDocument(imgtype, w, h, (imgtype == IMAGE_INDEXED ? ncolors: 256))); Sprite* sprite(document->getSprite()); get_default_palette()->copyColorsTo(sprite->getCurrentPalette()); usprintf(buf, "Sprite-%04d", ++_sprite_counter); document->setFilename(buf); // If the background color isn't transparent, we have to // convert the `Layer 1' in a `Background' if (color.getType() != Color::MaskType) { Sprite* sprite = document->getSprite(); ASSERT(sprite->getCurrentLayer() && sprite->getCurrentLayer()->is_image()); static_cast<LayerImage*>(sprite->getCurrentLayer())->configureAsBackground(); image_clear(sprite->getCurrentImage(), color_utils::color_for_image(color, imgtype)); } // Show the sprite to the user context->addDocument(document); // Release the document as it is already owned by the context. // And put the document in a reliable editor. set_document_in_more_reliable_editor(document.release()); } } }
static int lualock_lua_image_clear(lua_State *L) { image_t *image = luaL_checkudata(L, 1, "lualock.image"); image_clear(image); return 0; }
void copy_cel(ContextWriter& writer) { Document* document = writer.document(); Sprite* sprite = writer.sprite(); UndoTransaction undo(writer.context(), "Move Cel", undo::ModifyDocument); Cel *src_cel, *dst_cel; ASSERT(src_layer != NULL); ASSERT(dst_layer != NULL); ASSERT(src_frame >= 0 && src_frame < sprite->getTotalFrames()); ASSERT(dst_frame >= 0 && dst_frame < sprite->getTotalFrames()); src_cel = static_cast<LayerImage*>(src_layer)->getCel(src_frame); dst_cel = static_cast<LayerImage*>(dst_layer)->getCel(dst_frame); // Remove the 'dst_cel' (if it exists) because it must be replaced // with 'src_cel' if ((dst_cel != NULL) && (!dst_layer->isBackground() || src_cel != NULL)) remove_cel(sprite, undo, static_cast<LayerImage*>(dst_layer), dst_cel); // Move the cel in the same layer. if (src_cel != NULL) { Image *src_image = sprite->getStock()->getImage(src_cel->getImage()); Image *dst_image; int image_index; int dst_cel_x; int dst_cel_y; int dst_cel_opacity; // If we are moving a cel from a transparent layer to the // background layer, we have to clear the background of the image. if (!src_layer->isBackground() && dst_layer->isBackground()) { dst_image = image_crop(src_image, -src_cel->getX(), -src_cel->getY(), sprite->getWidth(), sprite->getHeight(), 0); image_clear(dst_image, app_get_color_to_clear_layer(dst_layer)); image_merge(dst_image, src_image, src_cel->getX(), src_cel->getY(), 255, BLEND_MODE_NORMAL); dst_cel_x = 0; dst_cel_y = 0; dst_cel_opacity = 255; } else { dst_image = Image::createCopy(src_image); dst_cel_x = src_cel->getX(); dst_cel_y = src_cel->getY(); dst_cel_opacity = src_cel->getOpacity(); } // Add the image in the stock image_index = sprite->getStock()->addImage(dst_image); if (undo.isEnabled()) undo.pushUndoer(new undoers::AddImage(undo.getObjects(), sprite->getStock(), image_index)); // Create the new cel dst_cel = new Cel(dst_frame, image_index); dst_cel->setPosition(dst_cel_x, dst_cel_y); dst_cel->setOpacity(dst_cel_opacity); if (undo.isEnabled()) undo.pushUndoer(new undoers::AddCel(undo.getObjects(), dst_layer, dst_cel)); static_cast<LayerImage*>(dst_layer)->addCel(dst_cel); } undo.commit(); document->notifyCelCopied(src_layer, src_frame, dst_layer, dst_frame); set_frame_to_handle(NULL, FrameNumber(0), NULL, FrameNumber(0)); }
void move_cel(ContextWriter& writer) { Document* document = writer.document(); Sprite* sprite = writer.sprite(); Cel *src_cel, *dst_cel; ASSERT(src_layer != NULL); ASSERT(dst_layer != NULL); ASSERT(src_frame >= 0 && src_frame < sprite->getTotalFrames()); ASSERT(dst_frame >= 0 && dst_frame < sprite->getTotalFrames()); if (src_layer->isBackground()) { copy_cel(writer); return; } src_cel = static_cast<LayerImage*>(src_layer)->getCel(src_frame); dst_cel = static_cast<LayerImage*>(dst_layer)->getCel(dst_frame); UndoTransaction undo(writer.context(), "Move Cel", undo::ModifyDocument); /* remove the 'dst_cel' (if it exists) because it must be replaced with 'src_cel' */ if ((dst_cel != NULL) && (!dst_layer->isBackground() || src_cel != NULL)) remove_cel(sprite, undo, static_cast<LayerImage*>(dst_layer), dst_cel); /* move the cel in the same layer */ if (src_cel != NULL) { if (src_layer == dst_layer) { if (undo.isEnabled()) undo.pushUndoer(new undoers::SetCelFrame(undo.getObjects(), src_cel)); src_cel->setFrame(dst_frame); } /* move the cel in different layers */ else { if (undo.isEnabled()) undo.pushUndoer(new undoers::RemoveCel(undo.getObjects(), src_layer, src_cel)); static_cast<LayerImage*>(src_layer)->removeCel(src_cel); src_cel->setFrame(dst_frame); /* if we are moving a cel from a transparent layer to the background layer, we have to clear the background of the image */ if (!src_layer->isBackground() && dst_layer->isBackground()) { Image *src_image = sprite->getStock()->getImage(src_cel->getImage()); Image *dst_image = image_crop(src_image, -src_cel->getX(), -src_cel->getY(), sprite->getWidth(), sprite->getHeight(), 0); if (undo.isEnabled()) { undo.pushUndoer(new undoers::ReplaceImage(undo.getObjects(), sprite->getStock(), src_cel->getImage())); undo.pushUndoer(new undoers::SetCelPosition(undo.getObjects(), src_cel)); undo.pushUndoer(new undoers::SetCelOpacity(undo.getObjects(), src_cel)); } image_clear(dst_image, app_get_color_to_clear_layer(dst_layer)); image_merge(dst_image, src_image, src_cel->getX(), src_cel->getY(), 255, BLEND_MODE_NORMAL); src_cel->setPosition(0, 0); src_cel->setOpacity(255); sprite->getStock()->replaceImage(src_cel->getImage(), dst_image); image_free(src_image); } if (undo.isEnabled()) undo.pushUndoer(new undoers::AddCel(undo.getObjects(), dst_layer, src_cel)); static_cast<LayerImage*>(dst_layer)->addCel(src_cel); } } undo.commit(); document->notifyCelMoved(src_layer, src_frame, dst_layer, dst_frame); set_frame_to_handle(NULL, FrameNumber(0), NULL, FrameNumber(0)); }
bool FliFormat::onSave(FileOp* fop) { Sprite* sprite = fop->document->getSprite(); unsigned char cmap[768]; unsigned char omap[768]; s_fli_header fli_header; int c, times; Image *bmp, *old; Palette *pal; /* prepare fli header */ fli_header.filesize = 0; fli_header.frames = 0; fli_header.width = sprite->getWidth(); fli_header.height = sprite->getHeight(); if ((fli_header.width == 320) && (fli_header.height == 200)) fli_header.magic = HEADER_FLI; else fli_header.magic = HEADER_FLC; fli_header.depth = 8; fli_header.flags = 3; fli_header.speed = get_time_precision(sprite); fli_header.created = 0; fli_header.updated = 0; fli_header.aspect_x = 1; fli_header.aspect_y = 1; fli_header.oframe1 = fli_header.oframe2 = 0; /* open the file to write in binary mode */ FileHandle f(fop->filename.c_str(), "wb"); fseek(f, 128, SEEK_SET); /* create the bitmaps */ bmp = Image::create(IMAGE_INDEXED, sprite->getWidth(), sprite->getHeight()); old = Image::create(IMAGE_INDEXED, sprite->getWidth(), sprite->getHeight()); if ((!bmp) || (!old)) { fop_error(fop, "Not enough memory for temporary bitmaps.\n"); if (bmp) image_free(bmp); if (old) image_free(old); return false; } /* write frame by frame */ for (FrameNumber frpos(0); frpos < sprite->getTotalFrames(); ++frpos) { /* get color map */ pal = sprite->getPalette(frpos); for (c=0; c<256; c++) { cmap[3*c ] = _rgba_getr(pal->getEntry(c)); cmap[3*c+1] = _rgba_getg(pal->getEntry(c)); cmap[3*c+2] = _rgba_getb(pal->getEntry(c)); } /* render the frame in the bitmap */ image_clear(bmp, 0); layer_render(sprite->getFolder(), bmp, 0, 0, frpos); /* how many times this frame should be written to get the same time that it has in the sprite */ times = sprite->getFrameDuration(frpos) / fli_header.speed; for (c=0; c<times; c++) { /* write this frame */ if (frpos == 0 && c == 0) fli_write_frame(f, &fli_header, NULL, NULL, (unsigned char *)bmp->dat, cmap, W_ALL); else fli_write_frame(f, &fli_header, (unsigned char *)old->dat, omap, (unsigned char *)bmp->dat, cmap, W_ALL); /* update the old image and color-map to the new ones to compare later */ image_copy(old, bmp, 0, 0); memcpy(omap, cmap, 768); } /* update progress */ fop_progress(fop, (float)(frpos.next()) / (float)(sprite->getTotalFrames())); } /* write the header and close the file */ fli_write_header(f, &fli_header); /* destroy the bitmaps */ image_free(bmp); image_free(old); return true; }