diff --git a/src/app/app_menus.cpp b/src/app/app_menus.cpp index 52eac793c..04d1659c8 100644 --- a/src/app/app_menus.cpp +++ b/src/app/app_menus.cpp @@ -65,7 +65,7 @@ AppMenus::AppMenus() void AppMenus::reload() { XmlDocumentRef doc(GuiXml::instance()->doc()); - TiXmlHandle handle(doc); + TiXmlHandle handle(doc.get()); const char* path = GuiXml::instance()->filename(); //////////////////////////////////////// diff --git a/src/app/cmd/add_frame.cpp b/src/app/cmd/add_frame.cpp index 2c1bea8f4..51d7c6633 100644 --- a/src/app/cmd/add_frame.cpp +++ b/src/app/cmd/add_frame.cpp @@ -45,7 +45,7 @@ void AddFrame::onExecute() LayerImage* bglayer = sprite->backgroundLayer(); if (bglayer) { ImageRef bgimage(Image::create(sprite->pixelFormat(), sprite->width(), sprite->height())); - clear_image(bgimage, doc->bgColor(bglayer)); + clear_image(bgimage.get(), doc->bgColor(bglayer)); Cel* cel = new Cel(m_newFrame, bgimage); m_addCel.reset(new cmd::AddCel(bglayer, cel)); m_addCel->execute(context()); diff --git a/src/app/cmd/background_from_layer.cpp b/src/app/cmd/background_from_layer.cpp index ac0dfc0eb..72ae2d808 100644 --- a/src/app/cmd/background_from_layer.cpp +++ b/src/app/cmd/background_from_layer.cpp @@ -57,8 +57,8 @@ void BackgroundFromLayer::onExecute() Image* cel_image = cel->image(); ASSERT(cel_image); - clear_image(bg_image, bgcolor); - render::composite_image(bg_image, cel_image, + clear_image(bg_image.get(), bgcolor); + render::composite_image(bg_image.get(), cel_image, cel->x(), cel->y(), MID(0, cel->opacity(), 255), static_cast(layer)->getBlendMode()); @@ -69,11 +69,11 @@ void BackgroundFromLayer::onExecute() // same size of cel-image and bg-image if (bg_image->width() == cel_image->width() && bg_image->height() == cel_image->height()) { - executeAndAdd(new CopyRect(cel_image, bg_image, + executeAndAdd(new CopyRect(cel_image, bg_image.get(), gfx::Clip(0, 0, cel_image->bounds()))); } else { - ImageRef bg_image2(Image::createCopy(bg_image)); + ImageRef bg_image2(Image::createCopy(bg_image.get())); executeAndAdd(new cmd::ReplaceImage(sprite, cel->imageRef(), bg_image2)); } } @@ -84,7 +84,7 @@ void BackgroundFromLayer::onExecute() if (!cel) { ImageRef cel_image(Image::create(sprite->pixelFormat(), sprite->width(), sprite->height())); - clear_image(cel_image, bgcolor); + clear_image(cel_image.get(), bgcolor); // Create the new cel and add it to the new background layer cel = new Cel(frame, cel_image); diff --git a/src/app/cmd/clear_image.cpp b/src/app/cmd/clear_image.cpp index c45ce2b40..b9c6ddaf6 100644 --- a/src/app/cmd/clear_image.cpp +++ b/src/app/cmd/clear_image.cpp @@ -35,8 +35,8 @@ void ClearImage::onExecute() void ClearImage::onUndo() { - copy_image(image(), m_copy); - m_copy.reset(nullptr); + copy_image(image(), m_copy.get()); + m_copy.reset(); } } // namespace cmd diff --git a/src/app/cmd/clear_mask.cpp b/src/app/cmd/clear_mask.cpp index a0b892919..f5f5fdc7b 100644 --- a/src/app/cmd/clear_mask.cpp +++ b/src/app/cmd/clear_mask.cpp @@ -113,7 +113,7 @@ void ClearMask::clear() void ClearMask::restore() { - copy_image(m_dstImage->image(), m_copy, m_offsetX, m_offsetY); + copy_image(m_dstImage->image(), m_copy.get(), m_offsetX, m_offsetY); } } // namespace cmd diff --git a/src/app/cmd/copy_cel.cpp b/src/app/cmd/copy_cel.cpp index dba78899d..697c79161 100644 --- a/src/app/cmd/copy_cel.cpp +++ b/src/app/cmd/copy_cel.cpp @@ -95,10 +95,10 @@ void CopyCel::onExecute() int blend = (srcLayer->isBackground() ? BLEND_MODE_COPY: BLEND_MODE_NORMAL); - ImageRef tmp(Image::createCopy(dstImage)); - render::composite_image(tmp, srcImage, + ImageRef tmp(Image::createCopy(dstImage.get())); + render::composite_image(tmp.get(), srcImage, srcCel->x(), srcCel->y(), 255, blend); - executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds()))); + executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds()))); } } // For transparent layers diff --git a/src/app/cmd/deselect_mask.cpp b/src/app/cmd/deselect_mask.cpp index eb5089f6e..bed893258 100644 --- a/src/app/cmd/deselect_mask.cpp +++ b/src/app/cmd/deselect_mask.cpp @@ -37,7 +37,7 @@ void DeselectMask::onUndo() doc->setMask(m_oldMask); doc->setMaskVisible(true); - m_oldMask.reset(nullptr); + m_oldMask.reset(); } size_t DeselectMask::onMemSize() const diff --git a/src/app/cmd/flatten_layers.cpp b/src/app/cmd/flatten_layers.cpp index 194b552d8..1c94b9003 100644 --- a/src/app/cmd/flatten_layers.cpp +++ b/src/app/cmd/flatten_layers.cpp @@ -57,8 +57,8 @@ void FlattenLayers::onExecute() // Copy all frames to the background. for (frame_t frame(0); frametotalFrames(); ++frame) { // Clear the image and render this frame. - clear_image(image, bgcolor); - render.renderSprite(image, sprite, frame); + clear_image(image.get(), bgcolor); + render.renderSprite(image.get(), sprite, frame); // TODO Keep cel links when possible @@ -71,11 +71,11 @@ void FlattenLayers::onExecute() cel_image = cel->imageRef(); ASSERT(cel_image); - executeAndAdd(new cmd::CopyRect(cel_image, image, + executeAndAdd(new cmd::CopyRect(cel_image.get(), image.get(), gfx::Clip(0, 0, image->bounds()))); } else { - cel_image.reset(Image::createCopy(image)); + cel_image.reset(Image::createCopy(image.get())); cel = new Cel(frame, cel_image); background->addCel(cel); } diff --git a/src/app/cmd/move_cel.cpp b/src/app/cmd/move_cel.cpp index 5d3a4f91d..ac6b2436d 100644 --- a/src/app/cmd/move_cel.cpp +++ b/src/app/cmd/move_cel.cpp @@ -98,10 +98,10 @@ void MoveCel::onExecute() int blend = (srcLayer->isBackground() ? BLEND_MODE_COPY: BLEND_MODE_NORMAL); - ImageRef tmp(Image::createCopy(dstImage)); - render::composite_image(tmp, srcImage, + ImageRef tmp(Image::createCopy(dstImage.get())); + render::composite_image(tmp.get(), srcImage, srcCel->x(), srcCel->y(), 255, blend); - executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds()))); + executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds()))); } executeAndAdd(new cmd::ClearCel(srcCel)); } diff --git a/src/app/cmd/replace_image.cpp b/src/app/cmd/replace_image.cpp index 44b7159d5..350809284 100644 --- a/src/app/cmd/replace_image.cpp +++ b/src/app/cmd/replace_image.cpp @@ -37,10 +37,10 @@ void ReplaceImage::onExecute() // modify/re-add this same image ID ImageRef oldImage = sprite()->getImageRef(m_oldImageId); ASSERT(oldImage); - m_copy.reset(Image::createCopy(oldImage)); + m_copy.reset(Image::createCopy(oldImage.get())); sprite()->replaceImage(m_oldImageId, m_newImage); - m_newImage.reset(nullptr); + m_newImage.reset(); } void ReplaceImage::onUndo() @@ -51,7 +51,7 @@ void ReplaceImage::onUndo() m_copy->setId(m_oldImageId); sprite()->replaceImage(m_newImageId, m_copy); - m_copy.reset(Image::createCopy(newImage)); + m_copy.reset(Image::createCopy(newImage.get())); } void ReplaceImage::onRedo() @@ -62,7 +62,7 @@ void ReplaceImage::onRedo() m_copy->setId(m_newImageId); sprite()->replaceImage(m_oldImageId, m_copy); - m_copy.reset(Image::createCopy(oldImage)); + m_copy.reset(Image::createCopy(oldImage.get())); } } // namespace cmd diff --git a/src/app/cmd/reselect_mask.cpp b/src/app/cmd/reselect_mask.cpp index 223c29d95..761ab8f15 100644 --- a/src/app/cmd/reselect_mask.cpp +++ b/src/app/cmd/reselect_mask.cpp @@ -29,7 +29,7 @@ void ReselectMask::onExecute() if (m_oldMask) { doc->setMask(m_oldMask); - m_oldMask.reset(nullptr); + m_oldMask.reset(); } doc->setMaskVisible(true); diff --git a/src/app/cmd/set_cel_data.cpp b/src/app/cmd/set_cel_data.cpp index 7c24aaa60..f281a5655 100644 --- a/src/app/cmd/set_cel_data.cpp +++ b/src/app/cmd/set_cel_data.cpp @@ -39,7 +39,7 @@ void SetCelData::onExecute() createCopy(); cel->setDataRef(m_newData); - m_newData.reset(nullptr); + m_newData.reset(); } void SetCelData::onUndo() @@ -52,7 +52,7 @@ void SetCelData::onUndo() m_dataCopy->image()->setId(m_oldImageId); cel->setDataRef(m_dataCopy); - m_dataCopy.reset(nullptr); + m_dataCopy.reset(); } else { CelDataRef oldData = cel->sprite()->getCelDataRef(m_oldDataId); diff --git a/src/app/commands/cmd_import_sprite_sheet.cpp b/src/app/commands/cmd_import_sprite_sheet.cpp index 5dd88d0ae..92fbae537 100644 --- a/src/app/commands/cmd_import_sprite_sheet.cpp +++ b/src/app/commands/cmd_import_sprite_sheet.cpp @@ -267,7 +267,7 @@ retry:; Image::create(sprite->pixelFormat(), frameBounds.w, frameBounds.h)); // Render the portion of sheet. - render.renderSprite(resultImage, sprite, currentFrame, + render.renderSprite(resultImage.get(), sprite, currentFrame, gfx::Clip(0, 0, x, y, frameBounds.w, frameBounds.h)); animation.push_back(resultImage); diff --git a/src/app/commands/cmd_merge_down_layer.cpp b/src/app/commands/cmd_merge_down_layer.cpp index 6a154f517..47eca62be 100644 --- a/src/app/commands/cmd_merge_down_layer.cpp +++ b/src/app/commands/cmd_merge_down_layer.cpp @@ -94,7 +94,7 @@ void MergeDownLayerCommand::onExecute(Context* context) // With source image? if (src_image) { // No destination image - if (dst_image == NULL) { // Only a transparent layer can have a null cel + if (!dst_image) { // Only a transparent layer can have a null cel // Copy this cel to the destination layer... // Creating a copy of the image @@ -122,13 +122,14 @@ void MergeDownLayerCommand::onExecute(Context* context) doc::color_t bgcolor = app_get_color_to_clear_layer(dst_layer); - ImageRef new_image(doc::crop_image(dst_image, + ImageRef new_image(doc::crop_image( + dst_image.get(), bounds.x-dst_cel->x(), bounds.y-dst_cel->y(), bounds.w, bounds.h, bgcolor)); // Merge src_image in new_image - render::composite_image(new_image, src_image, + render::composite_image(new_image.get(), src_image, src_cel->x()-bounds.x, src_cel->y()-bounds.y, src_cel->opacity(), diff --git a/src/app/commands/cmd_rotate.cpp b/src/app/commands/cmd_rotate.cpp index 3b1d42db2..26324f7b6 100644 --- a/src/app/commands/cmd_rotate.cpp +++ b/src/app/commands/cmd_rotate.cpp @@ -111,7 +111,7 @@ protected: ImageRef new_image(Image::create(image->pixelFormat(), m_angle == 180 ? image->width(): image->height(), m_angle == 180 ? image->height(): image->width())); - doc::rotate_image(image, new_image, m_angle); + doc::rotate_image(image, new_image.get(), m_angle); api.replaceImage(m_sprite, cel->imageRef(), new_image); } diff --git a/src/app/commands/cmd_sprite_size.cpp b/src/app/commands/cmd_sprite_size.cpp index fdecf57e2..abaec5730 100644 --- a/src/app/commands/cmd_sprite_size.cpp +++ b/src/app/commands/cmd_sprite_size.cpp @@ -95,7 +95,7 @@ protected: ImageRef new_image(Image::create(image->pixelFormat(), MAX(1, w), MAX(1, h))); doc::algorithm::fixup_image_transparent_colors(image); - doc::algorithm::resize_image(image, new_image, + doc::algorithm::resize_image(image, new_image.get(), m_resize_method, m_sprite->palette(cel->frame()), m_sprite->rgbMap(cel->frame())); @@ -125,7 +125,7 @@ protected: gfx::Rect( scale_x(m_document->mask()->bounds().x-1), scale_y(m_document->mask()->bounds().y-1), MAX(1, w), MAX(1, h))); - algorithm::resize_image(old_bitmap, new_mask->bitmap(), + algorithm::resize_image(old_bitmap.get(), new_mask->bitmap(), m_resize_method, m_sprite->palette(0), // Ignored m_sprite->rgbMap(0)); // Ignored diff --git a/src/app/commands/filters/cmd_convolution_matrix.cpp b/src/app/commands/filters/cmd_convolution_matrix.cpp index 6fcbc6966..fa092d090 100644 --- a/src/app/commands/filters/cmd_convolution_matrix.cpp +++ b/src/app/commands/filters/cmd_convolution_matrix.cpp @@ -181,14 +181,14 @@ void ConvolutionMatrixCommand::onExecute(Context* context) ConvolutionMatrixFilter filter; filter.setTiledMode(docPref.tiled.mode()); - if (matrix != 0) + if (matrix) filter.setMatrix(matrix); FilterManagerImpl filterMgr(context, &filter); ConvolutionMatrixWindow window(filter, filterMgr, m_stock); if (window.doModal()) { - if (filter.getMatrix() != NULL) + if (filter.getMatrix()) set_config_string(ConfigSection, "Selected", filter.getMatrix()->getName()); } } diff --git a/src/app/commands/filters/convolution_matrix_stock.cpp b/src/app/commands/filters/convolution_matrix_stock.cpp index 5134ca69b..69a690418 100644 --- a/src/app/commands/filters/convolution_matrix_stock.cpp +++ b/src/app/commands/filters/convolution_matrix_stock.cpp @@ -68,7 +68,8 @@ void ConvolutionMatrixStock::reloadStock() while (rf.next()) { // Open matrices stock file - base::FileHandle f = base::open_file(rf.filename(), "r"); + base::FileHandle handle(base::open_file(rf.filename(), "r")); + FILE* f = handle.get(); if (!f) continue; diff --git a/src/app/commands/filters/filter_worker.cpp b/src/app/commands/filters/filter_worker.cpp index 729a0706d..b7bfac340 100644 --- a/src/app/commands/filters/filter_worker.cpp +++ b/src/app/commands/filters/filter_worker.cpp @@ -91,7 +91,7 @@ FilterWorker::FilterWorker(FilterManagerImpl* filterMgr) FilterWorker::~FilterWorker() { - if (m_alertWindow != NULL) + if (m_alertWindow) m_alertWindow->closeWindow(NULL); delete m_progressBar; diff --git a/src/app/document_range_tests.cpp b/src/app/document_range_tests.cpp index 414aadd12..528ad98e4 100644 --- a/src/app/document_range_tests.cpp +++ b/src/app/document_range_tests.cpp @@ -115,8 +115,8 @@ public: layer->addCel(cel); } - clear_image(image, black); - put_pixel(image, i, j, white); + clear_image(image.get(), black); + put_pixel(image.get(), i, j, white); } } } diff --git a/src/app/file/ase_format.cpp b/src/app/file/ase_format.cpp index c0e12a5e7..2087cfdb6 100644 --- a/src/app/file/ase_format.cpp +++ b/src/app/file/ase_format.cpp @@ -150,7 +150,8 @@ FileFormat* CreateAseFormat() bool AseFormat::onLoad(FileOp* fop) { - FileHandle f(open_file_with_exception(fop->filename, "rb")); + FileHandle handle(open_file_with_exception(fop->filename, "rb")); + FILE* f = handle.get(); ASE_Header header; if (!ase_file_read_header(f, &header)) { @@ -295,7 +296,8 @@ bool AseFormat::onLoad(FileOp* fop) bool AseFormat::onSave(FileOp* fop) { Sprite* sprite = fop->document->sprite(); - FileHandle f(open_file_with_exception(fop->filename, "wb")); + FileHandle handle(open_file_with_exception(fop->filename, "wb")); + FILE* f = handle.get(); // Write the header ASE_Header header; @@ -1037,15 +1039,15 @@ static Cel* ase_file_read_cel_chunk(FILE* f, Sprite* sprite, frame_t frame, switch (image->pixelFormat()) { case IMAGE_RGB: - read_raw_image(f, image, fop, header); + read_raw_image(f, image.get(), fop, header); break; case IMAGE_GRAYSCALE: - read_raw_image(f, image, fop, header); + read_raw_image(f, image.get(), fop, header); break; case IMAGE_INDEXED: - read_raw_image(f, image, fop, header); + read_raw_image(f, image.get(), fop, header); break; } @@ -1096,15 +1098,15 @@ static Cel* ase_file_read_cel_chunk(FILE* f, Sprite* sprite, frame_t frame, switch (image->pixelFormat()) { case IMAGE_RGB: - read_compressed_image(f, image, chunk_end, fop, header); + read_compressed_image(f, image.get(), chunk_end, fop, header); break; case IMAGE_GRAYSCALE: - read_compressed_image(f, image, chunk_end, fop, header); + read_compressed_image(f, image.get(), chunk_end, fop, header); break; case IMAGE_INDEXED: - read_compressed_image(f, image, chunk_end, fop, header); + read_compressed_image(f, image.get(), chunk_end, fop, header); break; } } diff --git a/src/app/file/bmp_format.cpp b/src/app/file/bmp_format.cpp index c216e0058..3f6da0239 100644 --- a/src/app/file/bmp_format.cpp +++ b/src/app/file/bmp_format.cpp @@ -602,7 +602,8 @@ bool BmpFormat::onLoad(FileOp *fop) PixelFormat pixelFormat; int format; - FileHandle f(open_file_with_exception(fop->filename, "rb")); + FileHandle handle(open_file_with_exception(fop->filename, "rb")); + FILE* f = handle.get(); if (read_bmfileheader(f, &fileheader) != 0) return false; @@ -692,7 +693,7 @@ bool BmpFormat::onLoad(FileOp *fop) } // Setup the file-data. - if (fop->seq.format_options == NULL) { + if (!fop->seq.format_options) { base::SharedPtr bmp_options(new BmpOptions()); bmp_options->format = format; @@ -711,7 +712,7 @@ bool BmpFormat::onLoad(FileOp *fop) #ifdef ENABLE_SAVE bool BmpFormat::onSave(FileOp *fop) { - Image *image = fop->seq.image; + Image* image = fop->seq.image.get(); int bfSize; int biSizeImage; int bpp = (image->pixelFormat() == IMAGE_RGB) ? 24 : 8; @@ -729,7 +730,8 @@ bool BmpFormat::onSave(FileOp *fop) bfSize = 54 + biSizeImage; /* header + image data */ } - FileHandle f(open_file_with_exception(fop->filename, "wb")); + FileHandle handle(open_file_with_exception(fop->filename, "wb")); + FILE* f = handle.get(); /* file_header */ fputw(0x4D42, f); /* bfType ("BM") */ diff --git a/src/app/file/file.cpp b/src/app/file/file.cpp index 4ff0a2a7b..ceb8e3899 100644 --- a/src/app/file/file.cpp +++ b/src/app/file/file.cpp @@ -422,7 +422,7 @@ FileOp* fop_to_save_document(Context* context, Document* document, const char* f base::SharedPtr format_options = fop->format->getFormatOptions(fop); // Does the user cancelled the operation? - if (format_options == NULL) { + if (!format_options) { fop_free(fop); return NULL; } @@ -472,7 +472,7 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress) fop->document->sprite()->setPalette(fop->seq.palette, true); \ } \ \ - old_image = fop->seq.image; \ + old_image = fop->seq.image.get(); \ fop->seq.image.reset(NULL); \ fop->seq.last_cel = NULL; \ } while (0) @@ -480,7 +480,7 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress) // Load the sequence frame_t frames(fop->seq.filename_list.size()); frame_t frame(0); - old_image = NULL; + old_image = nullptr; fop->seq.has_alpha = false; fop->seq.progress_offset = 0.0f; @@ -502,10 +502,10 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress) if (!old_image) { // Error reading the first frame if (!loadres || !fop->document || !fop->seq.last_cel) { - delete fop->seq.image; + fop->seq.image.reset(); delete fop->seq.last_cel; delete fop->document; - fop->document = NULL; + fop->document = nullptr; break; } // Read ok @@ -518,7 +518,7 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress) else { // All done (or maybe not enough memory) if (!loadres || !fop->seq.last_cel) { - delete fop->seq.image; + fop->seq.image.reset(); delete fop->seq.last_cel; break; } @@ -594,7 +594,7 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress) render::Render render; for (frame_t frame(0); frame < sprite->totalFrames(); ++frame) { // Draw the "frame" in "fop->seq.image" - render.renderSprite(fop->seq.image, sprite, frame); + render.renderSprite(fop->seq.image.get(), sprite, frame); // Setup the palette. sprite->palette(frame)->copyColorsTo(fop->seq.palette); @@ -702,7 +702,7 @@ void fop_post_load(FileOp* fop) frame_t(0), NULL)); fop->document->sprite()->resetPalettes(); - fop->document->sprite()->setPalette(palette, false); + fop->document->sprite()->setPalette(palette.get(), false); } } @@ -711,7 +711,7 @@ void fop_post_load(FileOp* fop) void fop_sequence_set_format_options(FileOp* fop, const base::SharedPtr& format_options) { - ASSERT(fop->seq.format_options == NULL); + ASSERT(!fop->seq.format_options); fop->seq.format_options = format_options; } diff --git a/src/app/file/fli_format.cpp b/src/app/file/fli_format.cpp index 54a5e51e1..618af2599 100644 --- a/src/app/file/fli_format.cpp +++ b/src/app/file/fli_format.cpp @@ -74,7 +74,8 @@ bool FliFormat::onLoad(FileOp* fop) #endif // Open the file to read in binary mode - FileHandle f(open_file_with_exception(fop->filename, "rb")); + FileHandle handle(open_file_with_exception(fop->filename, "rb")); + FILE* f = handle.get(); fli_read_header(f, &fli_header); fseek(f, 128, SEEK_SET); @@ -201,7 +202,8 @@ bool FliFormat::onSave(FileOp* fop) fli_header.oframe1 = fli_header.oframe2 = 0; /* open the file to write in binary mode */ - FileHandle f(open_file_with_exception(fop->filename, "wb")); + FileHandle handle(open_file_with_exception(fop->filename, "wb")); + FILE* f = handle.get(); fseek(f, 128, SEEK_SET); diff --git a/src/app/file/gif_format.cpp b/src/app/file/gif_format.cpp index b8548121a..bff053862 100644 --- a/src/app/file/gif_format.cpp +++ b/src/app/file/gif_format.cpp @@ -776,7 +776,7 @@ bool GifFormat::onSave(FileOp* fop) base::SharedPtr GifFormat::onGetFormatOptions(FileOp* fop) { base::SharedPtr gif_options; - if (fop->document->getFormatOptions() != NULL) + if (fop->document->getFormatOptions()) gif_options = base::SharedPtr(fop->document->getFormatOptions()); if (!gif_options) diff --git a/src/app/file/ico_format.cpp b/src/app/file/ico_format.cpp index 7fbf510f0..db66ff09f 100644 --- a/src/app/file/ico_format.cpp +++ b/src/app/file/ico_format.cpp @@ -80,7 +80,8 @@ struct BITMAPINFOHEADER { bool IcoFormat::onLoad(FileOp* fop) { - FileHandle f(open_file_with_exception(fop->filename, "rb")); + FileHandle handle(open_file_with_exception(fop->filename, "rb")); + FILE* f = handle.get(); // Read the icon header ICONDIR header; @@ -132,7 +133,7 @@ bool IcoFormat::onLoad(FileOp* fop) ImageRef image(Image::create(pixelFormat, width, height)); Cel* cel = new Cel(frame_t(0), image); layer->addCel(cel); - clear_image(image, 0); + clear_image(image.get(), 0); // Go to the entry start in the file fseek(f, entry.image_offset, SEEK_SET); @@ -178,16 +179,16 @@ bool IcoFormat::onLoad(FileOp* fop) c = fgetc(f); ASSERT(c >= 0 && c < numcolors); if (c >= 0 && c < numcolors) - put_pixel(image, x, y, c); + put_pixel(image.get(), x, y, c); else - put_pixel(image, x, y, 0); + put_pixel(image.get(), x, y, 0); break; case 24: b = fgetc(f); g = fgetc(f); r = fgetc(f); - put_pixel(image, x, y, rgba(r, g, b, 255)); + put_pixel(image.get(), x, y, rgba(r, g, b, 255)); break; } } @@ -207,7 +208,7 @@ bool IcoFormat::onLoad(FileOp* fop) v = 128; for (b=0; b<8; b++) { if ((m & v) == v) - put_pixel(image, x*8+b, y, 0); // TODO mask color + put_pixel(image.get(), x*8+b, y, 0); // TODO mask color v >>= 1; } } @@ -232,7 +233,8 @@ bool IcoFormat::onSave(FileOp* fop) int c, x, y, b, m, v; frame_t n, num = sprite->totalFrames(); - FileHandle f(open_file_with_exception(fop->filename, "wb")); + FileHandle handle(open_file_with_exception(fop->filename, "wb")); + FILE* f = handle.get(); offset = 6 + num*16; // ICONDIR + ICONDIRENTRYs diff --git a/src/app/file/jpeg_format.cpp b/src/app/file/jpeg_format.cpp index a510469d9..79fe61661 100644 --- a/src/app/file/jpeg_format.cpp +++ b/src/app/file/jpeg_format.cpp @@ -105,7 +105,8 @@ bool JpegFormat::onLoad(FileOp* fop) JDIMENSION buffer_height; int c; - FileHandle file(open_file_with_exception(fop->filename, "rb")); + FileHandle handle(open_file_with_exception(fop->filename, "rb")); + FILE* file = handle.get(); // Initialize the JPEG decompression object with error handling. jerr.fop = fop; @@ -234,14 +235,15 @@ bool JpegFormat::onSave(FileOp* fop) { struct jpeg_compress_struct cinfo; struct error_mgr jerr; - Image *image = fop->seq.image; + Image* image = fop->seq.image.get(); JSAMPARRAY buffer; JDIMENSION buffer_height; base::SharedPtr jpeg_options = fop->seq.format_options; int c; // Open the file for write in it. - FileHandle file(open_file_with_exception(fop->filename, "wb")); + FileHandle handle(open_file_with_exception(fop->filename, "wb")); + FILE* file = handle.get(); // Allocate and initialize JPEG compression object. jerr.fop = fop; @@ -350,7 +352,7 @@ bool JpegFormat::onSave(FileOp* fop) base::SharedPtr JpegFormat::onGetFormatOptions(FileOp* fop) { base::SharedPtr jpeg_options; - if (fop->document->getFormatOptions() != NULL) + if (fop->document->getFormatOptions()) jpeg_options = base::SharedPtr(fop->document->getFormatOptions()); if (!jpeg_options) diff --git a/src/app/file/pcx_format.cpp b/src/app/file/pcx_format.cpp index 7ba825b4e..4a9eb280f 100644 --- a/src/app/file/pcx_format.cpp +++ b/src/app/file/pcx_format.cpp @@ -55,7 +55,8 @@ bool PcxFormat::onLoad(FileOp* fop) int x, y; char ch = 0; - FileHandle f(open_file_with_exception(fop->filename, "rb")); + FileHandle handle(open_file_with_exception(fop->filename, "rb")); + FILE* f = handle.get(); fgetc(f); /* skip manufacturer ID */ fgetc(f); /* skip version flag */ @@ -178,7 +179,7 @@ bool PcxFormat::onLoad(FileOp* fop) #ifdef ENABLE_SAVE bool PcxFormat::onSave(FileOp* fop) { - Image *image = fop->seq.image; + Image* image = fop->seq.image.get(); int c, r, g, b; int x, y; int runcount; @@ -186,7 +187,8 @@ bool PcxFormat::onSave(FileOp* fop) char runchar; char ch = 0; - FileHandle f(open_file_with_exception(fop->filename, "wb")); + FileHandle handle(open_file_with_exception(fop->filename, "wb")); + FILE* f = handle.get(); if (image->pixelFormat() == IMAGE_RGB) { depth = 24; diff --git a/src/app/file/png_format.cpp b/src/app/file/png_format.cpp index 2b275d0b7..e169057cd 100644 --- a/src/app/file/png_format.cpp +++ b/src/app/file/png_format.cpp @@ -71,7 +71,8 @@ bool PngFormat::onLoad(FileOp* fop) png_bytep row_pointer; PixelFormat pixelFormat; - FileHandle fp(open_file_with_exception(fop->filename, "rb")); + FileHandle handle(open_file_with_exception(fop->filename, "rb")); + FILE* fp = handle.get(); /* Create and initialize the png_struct with the desired error handler * functions. If you want to use the default stderr and longjump method, @@ -321,7 +322,7 @@ bool PngFormat::onLoad(FileOp* fop) #ifdef ENABLE_SAVE bool PngFormat::onSave(FileOp* fop) { - Image *image = fop->seq.image; + Image* image = fop->seq.image.get(); png_uint_32 width, height, y; png_structp png_ptr; png_infop info_ptr; @@ -331,7 +332,8 @@ bool PngFormat::onSave(FileOp* fop) int pass, number_passes; /* open the file */ - FileHandle fp(open_file_with_exception(fop->filename, "wb")); + FileHandle handle(open_file_with_exception(fop->filename, "wb")); + FILE* fp = handle.get(); /* Create and initialize the png_struct with the desired error handler * functions. If you want to use the default stderr and longjump method, diff --git a/src/app/file/tga_format.cpp b/src/app/file/tga_format.cpp index 519c95270..cfac2fa33 100644 --- a/src/app/file/tga_format.cpp +++ b/src/app/file/tga_format.cpp @@ -197,7 +197,8 @@ bool TgaFormat::onLoad(FileOp* fop) unsigned int c, i, x, y, yc; int compressed; - FileHandle f(open_file_with_exception(fop->filename, "rb")); + FileHandle handle(open_file_with_exception(fop->filename, "rb")); + FILE* f = handle.get(); id_length = fgetc(f); palette_type = fgetc(f); @@ -381,13 +382,14 @@ bool TgaFormat::onLoad(FileOp* fop) // should be an array of at least 256 RGB structures). bool TgaFormat::onSave(FileOp* fop) { - Image *image = fop->seq.image; + Image* image = fop->seq.image.get(); unsigned char image_palette[256][3]; int x, y, c, r, g, b; int depth = (image->pixelFormat() == IMAGE_RGB) ? 32 : 8; bool need_pal = (image->pixelFormat() == IMAGE_INDEXED)? true: false; - FileHandle f(open_file_with_exception(fop->filename, "wb")); + FileHandle handle(open_file_with_exception(fop->filename, "wb")); + FILE* f = handle.get(); fputc(0, f); /* id length (no id saved) */ fputc((need_pal) ? 1 : 0, f); /* palette type */ diff --git a/src/app/flatten.cpp b/src/app/flatten.cpp index 5b0ac0598..ddd5be5db 100644 --- a/src/app/flatten.cpp +++ b/src/app/flatten.cpp @@ -42,7 +42,7 @@ LayerImage* create_flatten_layer_copy(Sprite* dstSprite, const Layer* srcLayer, cel->setPosition(bounds.x, bounds.y); // Render this frame. - render.renderLayer(image, srcLayer, frame, + render.renderLayer(image.get(), srcLayer, frame, gfx::Clip(0, 0, bounds)); // Add the cel (and release the base::UniquePtr). diff --git a/src/app/gui_xml.cpp b/src/app/gui_xml.cpp index 369fea258..6cf19a000 100644 --- a/src/app/gui_xml.cpp +++ b/src/app/gui_xml.cpp @@ -43,7 +43,7 @@ GuiXml::GuiXml() std::string GuiXml::version() { - TiXmlHandle handle(m_doc); + TiXmlHandle handle(m_doc.get()); TiXmlElement* xmlKey = handle.FirstChild("gui").ToElement(); if (xmlKey && xmlKey->Attribute("version")) { diff --git a/src/app/job.cpp b/src/app/job.cpp index 00424e11c..9f22ead9a 100644 --- a/src/app/job.cpp +++ b/src/app/job.cpp @@ -39,7 +39,7 @@ Job::Job(const char* jobName) m_progress = StatusBar::instance()->addProgress(); m_alert_window = ui::Alert::create("%s<Tick.connect(&Job::onMonitoringTick, this); m_timer->start(); } @@ -51,7 +51,7 @@ Job::~Job() ASSERT(!m_timer->isRunning()); ASSERT(m_thread == NULL); - if (m_alert_window != NULL) + if (m_alert_window) m_alert_window->closeWindow(NULL); if (m_progress) diff --git a/src/app/tools/tool_box.cpp b/src/app/tools/tool_box.cpp index ebb0d6958..c3e365262 100644 --- a/src/app/tools/tool_box.cpp +++ b/src/app/tools/tool_box.cpp @@ -167,7 +167,7 @@ void ToolBox::loadTools() PRINTF("Loading Aseprite tools\n"); XmlDocumentRef doc(GuiXml::instance()->doc()); - TiXmlHandle handle(doc); + TiXmlHandle handle(doc.get()); // For each group TiXmlElement* xmlGroup = handle.FirstChild("gui").FirstChild("tools").FirstChild("group").ToElement(); diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 30e80918d..93e58b769 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -205,7 +205,7 @@ void Editor::setStateInternal(const EditorStatePtr& newState) // Fire before change state event, set the state, and fire after // change state event. EditorState::BeforeChangeAction beforeChangeAction = - m_state->onBeforeChangeState(this, newState); + m_state->onBeforeChangeState(this, newState.get()); // Push a new state if (newState) { @@ -223,7 +223,7 @@ void Editor::setStateInternal(const EditorStatePtr& newState) m_state = m_statesHistory.top(); } - ASSERT(m_state != NULL); + ASSERT(m_state); // Change to the new state. m_state->onAfterChangeState(this); @@ -584,7 +584,7 @@ void Editor::drawSpriteClipped(const gfx::Region& updateRegion) for (const Rect& screenRect : screenRegion) { IntersectClip clip(&screenGraphics, screenRect); if (clip) - drawSpriteUnclippedRect(editorGraphics, updateRect); + drawSpriteUnclippedRect(editorGraphics.get(), updateRect); } } } @@ -670,9 +670,9 @@ void Editor::drawMaskSafe() GraphicsPtr g = getGraphics(getClientBounds()); for (const gfx::Rect& rc : region) { - IntersectClip clip(g, rc); + IntersectClip clip(g.get(), rc); if (clip) - drawMask(g); + drawMask(g.get()); } // Draw the cursor diff --git a/src/app/ui/editor/editor_states_history.cpp b/src/app/ui/editor/editor_states_history.cpp index 50a5554bb..a9ae175cd 100644 --- a/src/app/ui/editor/editor_states_history.cpp +++ b/src/app/ui/editor/editor_states_history.cpp @@ -29,7 +29,7 @@ EditorStatePtr EditorStatesHistory::top() void EditorStatesHistory::push(const EditorStatePtr& state) { - ASSERT(state != NULL); + ASSERT(state); m_states.push_back(state); } diff --git a/src/app/ui/editor/moving_pixels_state.cpp b/src/app/ui/editor/moving_pixels_state.cpp index e86e6cac0..03573ac31 100644 --- a/src/app/ui/editor/moving_pixels_state.cpp +++ b/src/app/ui/editor/moving_pixels_state.cpp @@ -121,7 +121,7 @@ void MovingPixelsState::translate(const gfx::Point& delta) EditorState::BeforeChangeAction MovingPixelsState::onBeforeChangeState(Editor* editor, EditorState* newState) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); ASSERT(editor == m_editor); // If we are changing to another state, we've to drop the image. @@ -153,7 +153,7 @@ EditorState::BeforeChangeAction MovingPixelsState::onBeforeChangeState(Editor* e void MovingPixelsState::onCurrentToolChange(Editor* editor) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); ASSERT(editor == m_editor); tools::Tool* current_tool = editor->getCurrentEditorTool(); @@ -170,7 +170,7 @@ void MovingPixelsState::onCurrentToolChange(Editor* editor) bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); ASSERT(editor == m_editor); // Set this editor as the active one and setup the ContextBar for @@ -246,7 +246,7 @@ bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg) bool MovingPixelsState::onMouseUp(Editor* editor, MouseMessage* msg) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); ASSERT(editor == m_editor); // Drop the image temporarily in this location (where the user releases the mouse) @@ -261,7 +261,7 @@ bool MovingPixelsState::onMouseUp(Editor* editor, MouseMessage* msg) bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); ASSERT(editor == m_editor); // If there is a button pressed @@ -305,7 +305,7 @@ bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg) bool MovingPixelsState::onSetCursor(Editor* editor) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); ASSERT(editor == m_editor); // Move selection @@ -321,7 +321,7 @@ bool MovingPixelsState::onSetCursor(Editor* editor) bool MovingPixelsState::onKeyDown(Editor* editor, KeyMessage* msg) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); if (!isActiveEditor()) return false; ASSERT(editor == m_editor); @@ -394,7 +394,7 @@ bool MovingPixelsState::onKeyDown(Editor* editor, KeyMessage* msg) bool MovingPixelsState::onKeyUp(Editor* editor, KeyMessage* msg) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); if (!isActiveEditor()) return false; ASSERT(editor == m_editor); @@ -405,7 +405,7 @@ bool MovingPixelsState::onKeyUp(Editor* editor, KeyMessage* msg) bool MovingPixelsState::onUpdateStatusBar(Editor* editor) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); ASSERT(editor == m_editor); const gfx::Transformation& transform(getTransformation(editor)); @@ -501,10 +501,10 @@ void MovingPixelsState::onDropPixels(ContextBarObserver::DropAction action) void MovingPixelsState::setTransparentColor(const app::Color& color) { - ASSERT(m_pixelsMovement != NULL); + ASSERT(m_pixelsMovement); Layer* layer = m_editor->layer(); - ASSERT(layer != NULL); + ASSERT(layer); m_pixelsMovement->setMaskColor( color_utils::color_for_target_mask(color, ColorTarget(layer))); diff --git a/src/app/ui/keyboard_shortcuts.cpp b/src/app/ui/keyboard_shortcuts.cpp index c0d067e55..fff165d96 100644 --- a/src/app/ui/keyboard_shortcuts.cpp +++ b/src/app/ui/keyboard_shortcuts.cpp @@ -454,7 +454,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source) void KeyboardShortcuts::importFile(const std::string& filename, KeySource source) { XmlDocumentRef doc = app::open_xml(filename); - TiXmlHandle handle(doc); + TiXmlHandle handle(doc.get()); TiXmlElement* xmlKey = handle.FirstChild("keyboard").ToElement(); importFile(xmlKey, source); diff --git a/src/app/ui/news_listbox.cpp b/src/app/ui/news_listbox.cpp index f2610d19b..e536f9e27 100644 --- a/src/app/ui/news_listbox.cpp +++ b/src/app/ui/news_listbox.cpp @@ -254,7 +254,7 @@ void NewsListBox::parseFile(const std::string& filename) return; } - TiXmlHandle handle(doc); + TiXmlHandle handle(doc.get()); TiXmlElement* itemXml = handle .FirstChild("rss") .FirstChild("channel") diff --git a/src/app/ui/skin/skin_property.cpp b/src/app/ui/skin/skin_property.cpp index b49402462..2186369fd 100644 --- a/src/app/ui/skin/skin_property.cpp +++ b/src/app/ui/skin/skin_property.cpp @@ -37,7 +37,7 @@ SkinPropertyPtr get_skin_property(ui::Widget* widget) SkinPropertyPtr skinProp; skinProp = widget->getProperty(SkinProperty::Name); - if (skinProp == NULL) { + if (!skinProp) { skinProp.reset(new SkinProperty); widget->setProperty(skinProp); } diff --git a/src/app/ui/skin/skin_theme.cpp b/src/app/ui/skin/skin_theme.cpp index a9017cc91..d63446f5d 100644 --- a/src/app/ui/skin/skin_theme.cpp +++ b/src/app/ui/skin/skin_theme.cpp @@ -369,7 +369,7 @@ void SkinTheme::onRegenerate() return; XmlDocumentRef doc = open_xml(rf.filename()); - TiXmlHandle handle(doc); + TiXmlHandle handle(doc.get()); // Load dimension { @@ -491,7 +491,7 @@ void SkinTheme::onRegenerate() PRINTF("Loading part '%s'...\n", part_id); SkinPartPtr part = m_parts_by_id[part_id]; - if (part == NULL) + if (!part) part = m_parts_by_id[part_id] = SkinPartPtr(new SkinPart); if (w > 0 && h > 0) { @@ -911,7 +911,7 @@ void SkinTheme::paintButton(PaintEvent& ev) // Tool buttons are smaller LookType look = NormalLook; SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name); - if (skinPropery != NULL) + if (skinPropery) look = skinPropery->getLook(); // Selected @@ -986,7 +986,7 @@ void SkinTheme::paintCheckBox(PaintEvent& ev) // Check box look LookType look = NormalLook; SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name); - if (skinPropery != NULL) + if (skinPropery) look = skinPropery->getLook(); // Background @@ -1040,7 +1040,7 @@ void SkinTheme::paintEntry(PaintEvent& ev) bool isMiniLook = false; SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name); - if (skinPropery != NULL) + if (skinPropery) isMiniLook = (skinPropery->getLook() == MiniLook); gfx::Color bg = colors.background(); @@ -1403,11 +1403,11 @@ void SkinTheme::paintSlider(PaintEvent& ev) ISliderBgPainter* bgPainter = NULL; SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name); - if (skinPropery != NULL) + if (skinPropery) isMiniLook = (skinPropery->getLook() == MiniLook); SkinSliderPropertyPtr skinSliderPropery = widget->getProperty(SkinSliderProperty::Name); - if (skinSliderPropery != NULL) + if (skinSliderPropery) bgPainter = skinSliderPropery->getBgPainter(); // Draw customized background @@ -1649,7 +1649,7 @@ void SkinTheme::paintViewScrollbar(PaintEvent& ev) bool isMiniLook = false; SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name); - if (skinPropery != NULL) + if (skinPropery) isMiniLook = (skinPropery->getLook() == MiniLook); skin::Style* bgStyle = (isMiniLook ? diff --git a/src/app/ui/skin/style.cpp b/src/app/ui/skin/style.cpp index 07695fa9a..b86875ded 100644 --- a/src/app/ui/skin/style.cpp +++ b/src/app/ui/skin/style.cpp @@ -39,7 +39,7 @@ void BackgroundRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const cha { SkinTheme* theme = static_cast(ui::CurrentTheme::get()); - if (m_part != NULL && m_part->size() > 0) { + if (m_part && m_part->size() > 0) { if (m_part->size() == 1) { if (!gfx::is_transparent(m_color)) g->fillRect(m_color, bounds); diff --git a/src/app/ui/skin/style_sheet.cpp b/src/app/ui/skin/style_sheet.cpp index 573c6a712..63d3c5dcd 100644 --- a/src/app/ui/skin/style_sheet.cpp +++ b/src/app/ui/skin/style_sheet.cpp @@ -101,7 +101,7 @@ SkinPartPtr StyleSheet::convertPart(const css::Value& value) if (value.type() == css::Value::String) { const std::string& part_id = value.string(); part = get_part_by_id(part_id); - if (part == NULL) + if (!part) throw base::Exception("Unknown part '%s'\n", part_id.c_str()); } return part; diff --git a/src/app/ui/tabs.cpp b/src/app/ui/tabs.cpp index c8fd7818f..cfb7b7750 100644 --- a/src/app/ui/tabs.cpp +++ b/src/app/ui/tabs.cpp @@ -71,7 +71,7 @@ Tabs::Tabs(TabsDelegate* delegate) Tabs::~Tabs() { - m_removedTab.reset(nullptr); + m_removedTab.reset(); // Stop animation stopAnimation(); @@ -104,7 +104,7 @@ void Tabs::removeTab(TabView* tabView, bool with_animation) return; if (m_hot == tab) - m_hot.reset(nullptr); + m_hot.reset(); if (m_selected == tab) { if (tab == m_list.back()) @@ -113,7 +113,7 @@ void Tabs::removeTab(TabView* tabView, bool with_animation) selectNextTab(); if (m_selected == tab) - m_selected.reset(nullptr); + m_selected.reset(); } TabsListIterator it = @@ -335,7 +335,7 @@ bool Tabs::onProcessMessage(Message* msg) case kMouseLeaveMessage: if (m_hot) { - m_hot.reset(nullptr); + m_hot.reset(); invalidate(); } return true; @@ -756,8 +756,8 @@ void Tabs::stopDrag(DropTabResult result) case DropTabResult::DOCKED_IN_OTHER_PLACE: { TabPtr tab = m_floatingTab; - m_floatingTab.reset(nullptr); - m_removedTab.reset(nullptr); + m_floatingTab.reset(); + m_removedTab.reset(); destroyFloatingTab(); //ASSERT(tab); // TODO check this state @@ -823,7 +823,7 @@ void Tabs::createFloatingTab(TabPtr& tab) resetOldPositions(); m_floatingTab = tab; - m_removedTab.reset(nullptr); + m_removedTab.reset(); startAnimation(ANI_REMOVING_TAB, ANI_REMOVING_TAB_TICKS); updateTabs(); } @@ -832,12 +832,12 @@ void Tabs::destroyFloatingTab() { if (m_floatingOverlay) { OverlayManager::instance()->removeOverlay(m_floatingOverlay.get()); - m_floatingOverlay.reset(nullptr); + m_floatingOverlay.reset(); } if (m_floatingTab) { TabPtr tab(m_floatingTab); - m_floatingTab.reset(nullptr); + m_floatingTab.reset(); resetOldPositions(); startAnimation(ANI_ADDING_TAB, ANI_ADDING_TAB_TICKS); diff --git a/src/app/util/expand_cel_canvas.cpp b/src/app/util/expand_cel_canvas.cpp index 45e0b3959..a2165bab5 100644 --- a/src/app/util/expand_cel_canvas.cpp +++ b/src/app/util/expand_cel_canvas.cpp @@ -164,7 +164,7 @@ void ExpandCelCanvas::commit() // Copy the destination to the cel image. m_transaction.execute(new cmd::CopyRegion( - m_celImage, m_dstImage, m_validDstRegion, dx, dy)); + m_celImage.get(), m_dstImage, m_validDstRegion, dx, dy)); } // If the size of both images are different, we have to // replace the entire image. @@ -252,7 +252,7 @@ void ExpandCelCanvas::validateSourceCanvas(const gfx::Region& rgn) fill_rect(m_srcImage, rc, m_srcImage->maskColor()); for (const auto& rc : rgnToValidate) - m_srcImage->copy(m_celImage, + m_srcImage->copy(m_celImage.get(), gfx::Clip(rc.x, rc.y, rc.x+m_bounds.x-m_origCelPos.x, rc.y+m_bounds.y-m_origCelPos.y, rc.w, rc.h)); @@ -276,7 +276,7 @@ void ExpandCelCanvas::validateDestCanvas(const gfx::Region& rgn) src_y = m_bounds.y; } else { - src = m_celImage; + src = m_celImage.get(); src_x = m_origCelPos.x; src_y = m_origCelPos.y; } diff --git a/src/app/util/pic_file.cpp b/src/app/util/pic_file.cpp index 4c82d3898..0da42d35b 100644 --- a/src/app/util/pic_file.cpp +++ b/src/app/util/pic_file.cpp @@ -38,7 +38,8 @@ Image* load_pic_file(const char* filename, int* x, int* y, Palette** palette) int byte; int bpp; - base::FileHandle f(base::open_file_with_exception(filename, "rb")); + base::FileHandle handle(base::open_file_with_exception(filename, "rb")); + FILE* f = handle.get(); // Animator format? magic = base::fgetw(f); @@ -83,8 +84,9 @@ Image* load_pic_file(const char* filename, int* x, int* y, Palette** palette) } // rewind - f.reset(NULL); - f = base::open_file_with_exception(filename, "rb"); + handle.reset(); + handle = base::open_file_with_exception(filename, "rb"); + f = handle.get(); // read a PIC/MSK Animator Pro file size = base::fgetl(f); // file size @@ -172,7 +174,8 @@ int save_pic_file(const char *filename, int x, int y, const Palette* palette, co if ((bpp == 8) && (!palette)) return -1; - base::FileHandle f(base::open_file_with_exception(filename, "wb")); + base::FileHandle handle(base::open_file_with_exception(filename, "wb")); + FILE* f = handle.get(); size = 64; // Bit-per-pixel image data block diff --git a/src/app/widget_loader.cpp b/src/app/widget_loader.cpp index a3c4e14aa..f5caa8e52 100644 --- a/src/app/widget_loader.cpp +++ b/src/app/widget_loader.cpp @@ -89,7 +89,7 @@ Widget* WidgetLoader::loadWidgetFromXmlFile( m_tooltipManager = NULL; XmlDocumentRef doc(open_xml(xmlFilename)); - TiXmlHandle handle(doc); + TiXmlHandle handle(doc.get()); // Search the requested widget. TiXmlElement* xmlElement = handle diff --git a/src/app/xml_document.cpp b/src/app/xml_document.cpp index deb625c6e..85c11715b 100644 --- a/src/app/xml_document.cpp +++ b/src/app/xml_document.cpp @@ -29,8 +29,8 @@ XmlDocumentRef open_xml(const std::string& filename) // Try to load the XML file XmlDocumentRef doc(new TiXmlDocument()); doc->SetValue(filename.c_str()); - if (!doc->LoadFile(file)) - throw XmlException(doc); + if (!doc->LoadFile(file.get())) + throw XmlException(doc.get()); return doc; } @@ -41,8 +41,8 @@ void save_xml(XmlDocumentRef doc, const std::string& filename) if (!file) throw Exception("Error loading file: " + filename); - if (!doc->SaveFile(file)) - throw XmlException(doc); + if (!doc->SaveFile(file.get())) + throw XmlException(doc.get()); } bool bool_attr_is_true(const TiXmlElement* elem, const char* attrName) diff --git a/src/base/shared_ptr.h b/src/base/shared_ptr.h index 486004dd9..1dc3f89d9 100644 --- a/src/base/shared_ptr.h +++ b/src/base/shared_ptr.h @@ -1,5 +1,5 @@ // Aseprite Base Library -// Copyright (c) 2001-2013 David Capello +// Copyright (c) 2001-2013, 2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -211,7 +211,7 @@ public: T* get() const { return m_ptr; } T& operator*() const { return *m_ptr; } T* operator->() const { return m_ptr; } - operator T*() const { return m_ptr; } + explicit operator bool() const { return (m_ptr != nullptr); } long use_count() const { return (m_refCount ? m_refCount->use_count(): 0); } bool unique() const { return use_count() == 1; } diff --git a/src/doc/cel_data_io.cpp b/src/doc/cel_data_io.cpp index dbfbff86f..14e72dc0b 100644 --- a/src/doc/cel_data_io.cpp +++ b/src/doc/cel_data_io.cpp @@ -22,7 +22,7 @@ namespace doc { using namespace base::serialization; using namespace base::serialization::little_endian; -void write_celdata(std::ostream& os, CelData* celdata) +void write_celdata(std::ostream& os, const CelData* celdata) { write32(os, celdata->id()); write16(os, (int16_t)celdata->position().x); diff --git a/src/doc/cel_data_io.h b/src/doc/cel_data_io.h index 4ec84b50a..8197e20e7 100644 --- a/src/doc/cel_data_io.h +++ b/src/doc/cel_data_io.h @@ -15,7 +15,7 @@ namespace doc { class CelData; class SubObjectsIO; - void write_celdata(std::ostream& os, CelData* cel); + void write_celdata(std::ostream& os, const CelData* cel); CelData* read_celdata(std::istream& is, SubObjectsIO* subObjects); } // namespace doc diff --git a/src/doc/cel_io.cpp b/src/doc/cel_io.cpp index f4ce40a91..09e192ea2 100644 --- a/src/doc/cel_io.cpp +++ b/src/doc/cel_io.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -22,7 +22,7 @@ namespace doc { using namespace base::serialization; using namespace base::serialization::little_endian; -void write_cel(std::ostream& os, Cel* cel) +void write_cel(std::ostream& os, const Cel* cel) { write32(os, cel->id()); write16(os, cel->frame()); diff --git a/src/doc/cel_io.h b/src/doc/cel_io.h index 3a10db5e9..66069bebd 100644 --- a/src/doc/cel_io.h +++ b/src/doc/cel_io.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -15,7 +15,7 @@ namespace doc { class Cel; class SubObjectsIO; - void write_cel(std::ostream& os, Cel* cel); + void write_cel(std::ostream& os, const Cel* cel); Cel* read_cel(std::istream& is, SubObjectsIO* subObjects); } // namespace doc diff --git a/src/doc/frame_tag_io.cpp b/src/doc/frame_tag_io.cpp index cc8b5e990..3410951b3 100644 --- a/src/doc/frame_tag_io.cpp +++ b/src/doc/frame_tag_io.cpp @@ -22,7 +22,7 @@ namespace doc { using namespace base::serialization; using namespace base::serialization::little_endian; -void write_frame_tag(std::ostream& os, FrameTag* tag) +void write_frame_tag(std::ostream& os, const FrameTag* tag) { std::string name = tag->name(); diff --git a/src/doc/frame_tag_io.h b/src/doc/frame_tag_io.h index 7db131626..76e39e1a7 100644 --- a/src/doc/frame_tag_io.h +++ b/src/doc/frame_tag_io.h @@ -14,7 +14,7 @@ namespace doc { class FrameTag; - void write_frame_tag(std::ostream& os, FrameTag* tag); + void write_frame_tag(std::ostream& os, const FrameTag* tag); FrameTag* read_frame_tag(std::istream& is); } // namespace doc diff --git a/src/doc/image_io.cpp b/src/doc/image_io.cpp index 63330505d..f88d5e744 100644 --- a/src/doc/image_io.cpp +++ b/src/doc/image_io.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -33,7 +33,7 @@ using namespace base::serialization::little_endian; // BYTE[2] for Grayscale images, or // BYTE for Indexed images -void write_image(std::ostream& os, Image* image) +void write_image(std::ostream& os, const Image* image) { write32(os, image->id()); write8(os, image->pixelFormat()); // Pixel format diff --git a/src/doc/image_io.h b/src/doc/image_io.h index 36bd2083c..c814baab7 100644 --- a/src/doc/image_io.h +++ b/src/doc/image_io.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -14,7 +14,7 @@ namespace doc { class Image; - void write_image(std::ostream& os, Image* image); + void write_image(std::ostream& os, const Image* image); Image* read_image(std::istream& is); } // namespace doc diff --git a/src/doc/layer_io.cpp b/src/doc/layer_io.cpp index 9e6eeda97..c697e55be 100644 --- a/src/doc/layer_io.cpp +++ b/src/doc/layer_io.cpp @@ -33,7 +33,7 @@ using namespace base::serialization::little_endian; // Serialized Layer data: -void write_layer(std::ostream& os, Layer* layer) +void write_layer(std::ostream& os, const Layer* layer) { std::string name = layer->name(); @@ -46,8 +46,8 @@ void write_layer(std::ostream& os, Layer* layer) switch (layer->type()) { case ObjectType::LayerImage: { - CelIterator it, begin = static_cast(layer)->getCelBegin(); - CelIterator end = static_cast(layer)->getCelEnd(); + CelConstIterator it, begin = static_cast(layer)->getCelBegin(); + CelConstIterator end = static_cast(layer)->getCelEnd(); // Images int images = 0; @@ -71,24 +71,24 @@ void write_layer(std::ostream& os, Layer* layer) for (it=begin; it != end; ++it) { Cel* cel = *it; if (!cel->link()) - write_celdata(os, cel->dataRef()); + write_celdata(os, cel->dataRef().get()); } // Cels - write16(os, static_cast(layer)->getCelsCount()); + write16(os, static_cast(layer)->getCelsCount()); for (it=begin; it != end; ++it) { - Cel* cel = *it; + const Cel* cel = *it; write_cel(os, cel); } break; } case ObjectType::LayerFolder: { - LayerIterator it = static_cast(layer)->getLayerBegin(); - LayerIterator end = static_cast(layer)->getLayerEnd(); + LayerConstIterator it = static_cast(layer)->getLayerBegin(); + LayerConstIterator end = static_cast(layer)->getLayerEnd(); // Number of sub-layers - write16(os, static_cast(layer)->getLayersCount()); + write16(os, static_cast(layer)->getLayersCount()); for (; it != end; ++it) write_layer(os, *it); diff --git a/src/doc/layer_io.h b/src/doc/layer_io.h index afe9a1238..16edfaaeb 100644 --- a/src/doc/layer_io.h +++ b/src/doc/layer_io.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -22,7 +22,7 @@ namespace doc { InvalidLayerType(const char* msg) throw() : base::Exception(msg) { } }; - void write_layer(std::ostream& os, Layer* layer); + void write_layer(std::ostream& os, const Layer* layer); Layer* read_layer(std::istream& is, SubObjectsIO* subObjects); } // namespace doc diff --git a/src/doc/mask.cpp b/src/doc/mask.cpp index 623136a03..c70897d51 100644 --- a/src/doc/mask.cpp +++ b/src/doc/mask.cpp @@ -74,7 +74,7 @@ bool Mask::isRectangular() const if (!m_bitmap) return false; - LockImageBits bits(m_bitmap); + LockImageBits bits(m_bitmap.get()); LockImageBits::iterator it = bits.begin(), end = bits.end(); for (; it != end; ++it) { @@ -95,7 +95,7 @@ void Mask::copyFrom(const Mask* sourceMask) add(sourceMask->bounds()); // And copy the "mask" bitmap - copy_image(m_bitmap, sourceMask->m_bitmap); + copy_image(m_bitmap.get(), sourceMask->m_bitmap.get()); } } @@ -106,7 +106,7 @@ void Mask::offsetOrigin(int dx, int dy) void Mask::clear() { - m_bitmap.reset(nullptr); + m_bitmap.reset(); m_bounds = gfx::Rect(0, 0, 0, 0); } @@ -115,7 +115,7 @@ void Mask::invert() if (!m_bitmap) return; - LockImageBits bits(m_bitmap); + LockImageBits bits(m_bitmap.get()); LockImageBits::iterator it = bits.begin(), end = bits.end(); for (; it != end; ++it) @@ -129,7 +129,7 @@ void Mask::replace(const gfx::Rect& bounds) m_bounds = bounds; m_bitmap.reset(Image::create(IMAGE_BITMAP, bounds.w, bounds.h, m_buffer)); - clear_image(m_bitmap, 1); + clear_image(m_bitmap.get(), 1); } void Mask::add(const gfx::Rect& bounds) @@ -137,7 +137,7 @@ void Mask::add(const gfx::Rect& bounds) if (m_freeze_count == 0) reserve(bounds); - fill_rect(m_bitmap, + fill_rect(m_bitmap.get(), bounds.x-m_bounds.x, bounds.y-m_bounds.y, bounds.x-m_bounds.x+bounds.w-1, @@ -149,7 +149,7 @@ void Mask::subtract(const gfx::Rect& bounds) if (!m_bitmap) return; - fill_rect(m_bitmap, + fill_rect(m_bitmap.get(), bounds.x-m_bounds.x, bounds.y-m_bounds.y, bounds.x-m_bounds.x+bounds.w-1, @@ -168,7 +168,7 @@ void Mask::intersect(const gfx::Rect& bounds) Image* image = NULL; if (!newBounds.isEmpty()) { - image = crop_image(m_bitmap, + image = crop_image(m_bitmap.get(), newBounds.x-m_bounds.x, newBounds.y-m_bounds.y, newBounds.w, @@ -185,7 +185,7 @@ void Mask::byColor(const Image *src, int color, int fuzziness) { replace(src->bounds()); - Image* dst = m_bitmap; + Image* dst = m_bitmap.get(); switch (src->pixelFormat()) { @@ -358,13 +358,13 @@ void Mask::reserve(const gfx::Rect& bounds) if (!m_bitmap) { m_bounds = bounds; m_bitmap.reset(Image::create(IMAGE_BITMAP, bounds.w, bounds.h, m_buffer)); - clear_image(m_bitmap, 0); + clear_image(m_bitmap.get(), 0); } else { gfx::Rect newBounds = m_bounds.createUnion(bounds); if (m_bounds != newBounds) { - Image* image = crop_image(m_bitmap, + Image* image = crop_image(m_bitmap.get(), newBounds.x-m_bounds.x, newBounds.y-m_bounds.y, newBounds.w, @@ -428,7 +428,7 @@ void Mask::shrink() m_bounds.w = x2 - x1 + 1; m_bounds.h = y2 - y1 + 1; - Image* image = crop_image(m_bitmap, m_bounds.x-u, m_bounds.y-v, m_bounds.w, m_bounds.h, 0); + Image* image = crop_image(m_bitmap.get(), m_bounds.x-u, m_bounds.y-v, m_bounds.w, m_bounds.h, 0); m_bitmap.reset(image); } diff --git a/src/doc/mask.h b/src/doc/mask.h index bdab19c16..be542b0c0 100644 --- a/src/doc/mask.h +++ b/src/doc/mask.h @@ -31,8 +31,8 @@ namespace doc { void setName(const char *name); const std::string& name() const { return m_name; } - const Image* bitmap() const { return m_bitmap; } - Image* bitmap() { return m_bitmap; } + const Image* bitmap() const { return m_bitmap.get(); } + Image* bitmap() { return m_bitmap.get(); } // Returns true if the mask is completely empty (i.e. nothing // selected) @@ -42,10 +42,10 @@ namespace doc { // Returns true if the point is inside the mask bool containsPoint(int u, int v) const { - return (m_bitmap && + return (m_bitmap.get() && u >= m_bounds.x && u < m_bounds.x+m_bounds.w && v >= m_bounds.y && v < m_bounds.y+m_bounds.h && - get_pixel(m_bitmap, u-m_bounds.x, v-m_bounds.y)); + get_pixel(m_bitmap.get(), u-m_bounds.x, v-m_bounds.y)); } const gfx::Rect& bounds() const { return m_bounds; } diff --git a/src/doc/mask_io.cpp b/src/doc/mask_io.cpp index 1a074a8ad..7d5323fad 100644 --- a/src/doc/mask_io.cpp +++ b/src/doc/mask_io.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -29,7 +29,7 @@ using namespace base::serialization::little_endian; // BYTE 8 pixels of the mask // BYTE for Indexed images -void write_mask(std::ostream& os, Mask* mask) +void write_mask(std::ostream& os, const Mask* mask) { const gfx::Rect& bounds = mask->bounds(); diff --git a/src/doc/mask_io.h b/src/doc/mask_io.h index 1aee78f37..1e6cdb378 100644 --- a/src/doc/mask_io.h +++ b/src/doc/mask_io.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -14,7 +14,7 @@ namespace doc { class Mask; - void write_mask(std::ostream& os, Mask* mask); + void write_mask(std::ostream& os, const Mask* mask); Mask* read_mask(std::istream& is); } // namespace doc diff --git a/src/doc/palette_io.cpp b/src/doc/palette_io.cpp index 7f9748b2c..f5e03fa44 100644 --- a/src/doc/palette_io.cpp +++ b/src/doc/palette_io.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -28,7 +28,7 @@ using namespace base::serialization::little_endian; // for each color ("ncolors" times) // DWORD _rgba color -void write_palette(std::ostream& os, Palette* palette) +void write_palette(std::ostream& os, const Palette* palette) { write16(os, palette->frame()); // Frame write16(os, palette->size()); // Number of colors diff --git a/src/doc/palette_io.h b/src/doc/palette_io.h index 2530cdc33..3e137600e 100644 --- a/src/doc/palette_io.h +++ b/src/doc/palette_io.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -14,7 +14,7 @@ namespace doc { class Palette; - void write_palette(std::ostream& os, Palette* palette); + void write_palette(std::ostream& os, const Palette* palette); Palette* read_palette(std::istream& is); } // namespace doc diff --git a/src/doc/sprite.cpp b/src/doc/sprite.cpp index e6dca363b..2e903ff17 100644 --- a/src/doc/sprite.cpp +++ b/src/doc/sprite.cpp @@ -105,7 +105,7 @@ Sprite* Sprite::createBasicSprite(doc::PixelFormat format, int width, int height // Create the main image. doc::ImageRef image(doc::Image::create(format, width, height)); - doc::clear_image(image, 0); + doc::clear_image(image.get(), 0); // Create the first transparent layer. { diff --git a/src/filters/convolution_matrix_filter.cpp b/src/filters/convolution_matrix_filter.cpp index 46a55aa26..0af3a7e15 100644 --- a/src/filters/convolution_matrix_filter.cpp +++ b/src/filters/convolution_matrix_filter.cpp @@ -155,7 +155,7 @@ void ConvolutionMatrixFilter::applyToRgba(FilterManager* filterMgr) continue; } - delegate.reset(m_matrix); + delegate.reset(m_matrix.get()); get_neighboring_pixels(src, x, y, m_matrix->getWidth(), m_matrix->getHeight(), @@ -222,7 +222,7 @@ void ConvolutionMatrixFilter::applyToGrayscale(FilterManager* filterMgr) continue; } - delegate.reset(m_matrix); + delegate.reset(m_matrix.get()); get_neighboring_pixels(src, x, y, m_matrix->getWidth(), m_matrix->getHeight(), @@ -277,7 +277,7 @@ void ConvolutionMatrixFilter::applyToIndexed(FilterManager* filterMgr) continue; } - delegate.reset(m_matrix); + delegate.reset(m_matrix.get()); get_neighboring_pixels(src, x, y, m_matrix->getWidth(), m_matrix->getHeight(), diff --git a/src/gen/gen.cpp b/src/gen/gen.cpp index ca31e4bbd..557e9261c 100644 --- a/src/gen/gen.cpp +++ b/src/gen/gen.cpp @@ -35,7 +35,7 @@ static void run(int argc, const char* argv[]) base::FileHandle inputFile(base::open_file(inputFilename, "rb")); doc = new TiXmlDocument(); doc->SetValue(inputFilename.c_str()); - if (!doc->LoadFile(inputFile)) + if (!doc->LoadFile(inputFile.get())) throw std::runtime_error("invalid input file"); } diff --git a/src/render/quantization.cpp b/src/render/quantization.cpp index c7631141d..5d803f3be 100644 --- a/src/render/quantization.cpp +++ b/src/render/quantization.cpp @@ -1,5 +1,5 @@ // Aseprite Render Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -61,7 +61,7 @@ Palette* create_palette_from_rgb( ImageRef flat_image(Image::create(sprite->pixelFormat(), sprite->width(), sprite->height())); - render::Render().renderSprite(flat_image, sprite, frameNumber); + render::Render().renderSprite(flat_image.get(), sprite, frameNumber); // Create an array of images std::vector image_array; @@ -76,7 +76,7 @@ Palette* create_palette_from_rgb( image_array.push_back(image); } } - image_array.push_back(flat_image); + image_array.push_back(flat_image.get()); // Generate an optimized palette for all images create_palette_from_images(image_array, palette, has_background_layer); diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 3fa11d186..c4b47e994 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -1326,7 +1326,7 @@ bool Widget::onProcessMessage(Message* msg) ASSERT(ptmsg->rect().h > 0); GraphicsPtr graphics = getGraphics(toClient(ptmsg->rect())); - return paintEvent(graphics); + return paintEvent(graphics.get()); } case kKeyDownMessage: