693 Commits

Author SHA1 Message Date
David Capello
699342fe9d Add function to copy non-shared properties between cels
At the moment it's the z-index, but if in the future we add new
non-shared properties, we can move those here.
2024-11-19 13:04:47 -03:00
Gaspar Capello
ff520c14d2 Fix transparency issue with new color criterias (fix #4686)
Prior to this fix, the following particular conditions caused
an incorrect conversion of an opaque color to a transparent color
during RGBA->Indexed conversion:
- RGBA image with black color (#000000 a=255) painted on the canvas
- The black color is absent from the palette.
- The mask color is present in the palette
- Converts the sprite to indexed color mode using
  Sprite > Color Mode > More Options
- Select Advanced Options, select a Color Best Fit Criteria other than
  Default (for example CIELAB) and press OK
- The original black color becomes the mask color.
2024-10-04 10:37:28 -03:00
David Capello
ec42689b82 Avoid setting an invalid mask color (-1) in doc::Image (fix #4651)
This regression came from 09bb5cc3d3676e88048d5cd845b075ea30ca8e66 as
now we don't Sprite::setTransparentColor() on each undo/redo and only
when needed. This brought a new kind of error where the mask color for
images was set to -1 after convert_pixel_format().

This also fixes a conversion from Indexed -> RGB where the transparent
color was not set back to 0. And the transparent color is always set
when we are in indexed mode to avoid any assert in debug mode.
2024-09-11 12:35:21 -03:00
Gaspar Capello
5798e27993 Fix mask color turns to opaque on RGBA->INDEXED conversion (fix #4438)
Original issue title: When using a background layer, switching to
Indexed Color Mode fills all layer bounding rectangles with
Color 0.
Conditions to reproduce the original issue:
- Opaque RGBA sprite, i.e. the bottom layer is 'Background'.
- There is a second layer with an ellipse (for example).
- There is a mask color #000000 alpha=0 is in the palette.
- The mask color index is greater and not equal than 0.
- Go to Sprite > Color Mode > Indexed.
Result: the transparent color of the second layer will change to
index color = 0 (usually black).

Also added test for RGBA->INDEXED conversion
2024-09-04 13:48:56 -03:00
Gaspar Capello
e1bd7990a3 Add color fit criteria for Color Mode conversion (fix #2787, #4416)
Added other color comparison criterias (fit criteria) during
color mode conversion RGBA to Indexed or Grayscale to Indexed.
The 'fit criteria' will help us to recolor an RGB image with
a limited color palette taking into account different color
perception criteria (color spaces: RGB, linearized RGB,
CIE XYZ, CIE LAB).
2024-09-03 13:17:09 -03:00
Gaspar Capello
3cc1c63274 Add different best fit criteria to compare colors for RgbMaps (fix #2787, #4416) 2024-09-03 13:17:06 -03:00
Gaspar Capello
e12233a19d Tests for new function make_aligned_mask 2024-09-03 11:44:25 -03:00
Gaspar Capello
95513af267 Fix multiple tileset layers selection move is broken (fix #3144)
Before this fix, a multi-layer mask movement/scaling (with mixed layer
types: normal layer and tilemap layers with different grids) caused
loss of drawing areas.

The heart of this solution is to correctly align the 'selection mask'
and 'transform data' according to the layer's grid, and also, forcing
'site' TilemapMode/TilesetMode before each
reproduceAllTransformationsWithInnerCmds() iteration.
During the life of a PixelMovement object there is a tilemap mode lock.

Additionally arrow keys now work to move a selected area in
TilemapMode::Tiles.
2024-09-03 11:44:25 -03:00
Martín Capello
712d84e44e
Avoid div by zero by preventing entering/returning a grid bounds w/zero width/height (fix #4146, #4597) 2024-08-19 18:07:40 -03:00
David Capello
abe872aeb2 Convert the tileset serialization format in its own type
To match the new SerialFormat enum (uint16_t), we now have
TilesetSerialFormat enum (uint8_t).
2024-06-26 11:24:09 -03:00
David Capello
cdea6004bd Refactor app::DocFormat to doc::SerialFormat
This fixes a violation of module layers (circular dependency)
introduced in e6cd13d7e13775de2a687e55e59819cb7f19e7e9 where doc-lib
started to depend on app-lib (which cannot happen, as app-lib depends
on doc-lib).

This DocFormat/SerialFormat was used only from app-lib previously, but
when properties were introduced in user data, the serialization format
version was needed to read user properties too. So now it makes sense
to move this type/its values to the doc-lib.

A couple of extra issues were found in this refactor:
1) The recursive call inside read_layer() didn't receive this "serial"
   argument
2) read_grid() doesn't need the setId parameter
2024-06-26 10:42:30 -03:00
David Capello
8f7bf09263 Fix doc::blend_image() to support different color modes (fix #4530, fix #4531)
The code was refactored moving the BlenderHelper class from "render"
to "doc", and now doc::blend_image() supports blending different color
modes.

Some work is still needed to work with grayscale images correctly.
2024-06-11 21:48:57 -03:00
David Capello
2ed584541b [msvc] Use a workaround to fix compiler bug (fix #4526)
Reported in https://developercommunity.visualstudio.com/t/Invalid-optimized-x64-codegen-with-inlin/10678815
possible duplicated of https://developercommunity.visualstudio.com/t/Optimisation-of-right-bit-shift-switches/10453852
not yet available in official VS release.

Here we changed signed ints to unsigned ints to avoid this bug.
2024-06-10 08:59:10 -03:00
requizm
aa152963d4 [cli] Add -list-layer-hierarchy option
Example output:
group1/
  layer1.1
  layer1.2
  group1.1/
    layer1.1.1
group2/
  layer2.1
2024-06-06 11:30:01 -03:00
Gaspar Capello
dd9f1ce988 Fix crash when previewing a sprite sheet export when selecting an empty layer group located at the bottom of the layer stack in the "Layers" combo box. 2024-05-27 20:22:36 -03:00
David Capello
577f50b713 Fix crashes using flood fill algorithm in a large canvas (fix #4481) 2024-05-23 10:56:05 -03:00
David Capello
2596d44732 Fix incorrect diff between layers debugging the restoration of a backup (TEST_BACKUP_INTEGRITY)
Only in debug mode with TEST_BACKUP_INTEGRITY flag, we now don't
detect as a layer diff between the doc in memory and the restore doc
from backup if only some layer flags like visibility/collapse changed.
2024-05-20 22:04:21 -03:00
David Capello
92edd5f700 Add Brush::clone() functions to fix/simplify some Brush-related code
This refactor includes:

- In Lua now we can clone a custom brush with Brush(Image) and the new
  brush doesn't share the image with the original one (added a new test
  for this).

- Avoid creating extra images when it's not needed using
  Brush::cloneWithExistingImages() (we can inject existing images in
  the brush itself).

- Delete Brush-copy contructor & assign operator to use
  Brush::clone() functions instead (which are more explicit).

- Some code from 12d81352647e96c8ac6d70e4a252c37ce5a29ade (#4023)
  reverted to avoid recreating brushes on left-click or in the brush
  preview, i.e. moving the mouse (#4013 refers only to right-click, so
  only on right-click we have to adjust the custom brush).
2024-05-03 11:35:36 -03:00
Gaspar Capello
12d8135264 Fix secondary color with custom brush paints the FgColor instead the BgColor (fix #4013)
Before this fix to change the main color of the image brush,
it was necessary to choose a new color from the palette.
The secondary color can now also be used.

Also added some tests for image brushes.
2024-04-29 17:20:56 -03:00
Gaspar Capello
99e6e7bd82 Fix nested tag with "Ping-Pong" repeat mode causes to skip the first frame of the parent tag (fix #4271) 2024-04-12 10:41:18 -03:00
David Capello
30f55d196b Show "Apply pixel ratio" option in File > Export only when needed (#4308)
If the sprite doesn't have a custom pixel aspect ratio configured
there is no need to show this option.
2024-03-12 15:14:45 -03:00
David Capello
cfb663f820 Some fixes to readability-else-after-return 2024-02-29 10:26:47 -03:00
David Capello
83d83cd8c6 Add const to lock_guards 2024-02-28 12:32:08 -03:00
David Capello
edc248d418 Removing some unnecessary #includes 2024-02-28 10:16:11 -03:00
Martín Capello
7b9594f4e0 Avoid moving the playback cue when decrementing a ping-pong tag's repeat field that has only one frame (fix #4336) 2024-02-26 22:07:31 -03:00
David Capello
d70801e88b Throw a bad_alloc when there is not enough memory for ImageBuffer (fix #4316)
Fix regression introduced in aeeef8e255c2d83a1b3e3cb2858939233d5a5d0b
when we replaced the std::vector with aligned memory allocations (or
just malloc/free).
2024-02-19 11:21:53 -03:00
Martín Capello
a7d4c23af9 Fix exporting one tag without "play subtags/repeats" and changing its anidir (fix #4297) 2024-02-09 17:31:25 -03:00
Martín Capello
9ef6c4848d Avoid exposing doc::frames types to the global namespace 2024-02-07 14:04:35 -03:00
David Capello
9318ce4941 Merge branch 'export-with-play-subtags' (#4173, #4211) 2024-02-07 11:58:28 -03:00
Martín Capello
012da4da1b Add SelectedFrames.displace() tests 2024-02-02 17:53:09 -03:00
Martín Capello
982df4db1c Add FramesSequence tests 2024-02-02 17:53:09 -03:00
Martín Capello
eb45c4adf5 Add support to "play subtags & repetitions" when exporting an animation (fix #4173) 2024-02-02 17:52:58 -03:00
Martín Capello
a6556bb4f2 Fix exit frame handling for "PlayAll" playback mode
Without this when the playback cue is on the highest frame in "PlayAll"
mode it doesn't take into account the direction of the current tag that
is being played and assumes the end of the animation was reached
2024-02-02 17:52:58 -03:00
David Capello
5900605549 Fix "Too much data to uncompress" error recovering sessions (fix #4291)
This is due zlib returning Z_OK (instead of Z_STREAM_END) after
inflate() when all the output buffer was filled (avail_out = 0) but it
reports like there is still available uncompressed data (avail_in > 0).
It makes no sense but an extra inflate() call with avail_out=0
consumes the whole avail_in and the expected Z_STREAM_END is finally
reported.
2024-02-02 14:01:07 -03:00
David Capello
40863a3a5e Copy hex text to native clipboard when copy colors from the palette (fix #4289) 2024-01-31 11:45:12 -03:00
David Capello
8722c8ec16 Lock document in Tx() ctor (part of #2430)
This already fixes a lot of possible problems that can happen when a
script is running and modifying some part of a sprite that is being
backed up in a background thread.

We still need some work to being able to lock a sprite two or more
times in the same thread to write it. E.g. an app.transaction() should
lock the sprite for write access, but the script transaction function
could call a command, and that command could use a ContextWriter to
lock the sprite again. At the moment this is not possible because we
need a re-entrant RWLock implementation.
2023-12-27 11:05:15 -03:00
David Capello
a8885105e9 Move rows array back to the beginning of ImageImpl buffer
We are not sure, but due to new bug reports about a lagging mouse
movement (#4174), it might be because some memory cache issues: having
the rows array at the end of the pixels data might not be the best
decision.

It was moved at the end because we didn't need that rows array to be
aligned, only the pixels data. But with this patch we're trying to see
if this fixes the issue. So now we moved back the rows array at the
beginning of the image buffer as it was before aeeef8e255c2d83a1b3e3cb2858939233d5a5d0b
2023-11-28 11:34:50 -03:00
David Capello
28a140f736 Add missing #includes to use ASSERT() macro 2023-11-26 21:44:16 -03:00
David Capello
eafb779ef0 Possible fix to some RotSprite crashes (#2780) 2023-11-21 12:58:31 -03:00
David Capello
dd5fb871b5 Remap tiles with flags correctly 2023-11-10 11:55:23 -03:00
David Capello
25015a6e18 Fix eyedropper in Tiles mode to pick tiles that are flipped and have masked areas
Sprite::pickCels() wasn't taking care of the tile flags to pick
tilemap layers correctly with flipped tiles.
2023-11-09 16:44:46 -03:00
David Capello
302d998218 Add support to match flipped tiles automatically in Auto/Stack modes
By default Aseprite will not try to match flipped versions of the
tiles (as it requires more CPU), but when we create a tileset we can
specify which flips can be matched automatically (new
Tileset::matchFlags() property).

These flags are just for the Auto mode, if we manually insert a
flipped tile, that is always supported, even when the matchFlags() are
not specified.
2023-11-09 16:44:46 -03:00
David Capello
3606a54826 Fix eyedropper to pick colors/tiles correctly from flipped tiles
* Added a new app::Color type for tiles, to store the flags of the
  picked tile.
* Fixed color bar/status bar with a new draw_tile() to draw tiles
  with flip flags.
2023-11-09 16:44:46 -03:00
David Capello
d114b62483 New tile flags meaning (x/y/diagonal flip) + serialize then correctly
* Changed the "90cw" flag to "diagonal flip" (the tile should be
  rendered with X/Y axis switched in this case)
* Each time we read/write an .aseprite file we have to convert
  the mask/shift from the file to the values expected in
  memory (tile_f_xflip/yflip/dflip)
2023-11-09 16:44:46 -03:00
Gaspar Capello
309a64de9f Fix export sprite sheet to RGB is not exporting the palette (fix #3881) 2023-11-09 12:16:53 -03:00
Martín Capello
3cfa5ef1da [lua] Fix crash when saving tilemap's cel image (fix #4069) 2023-11-02 14:12:55 -03:00
David Capello
9800d0ba1a Support scaling down bits (e.g. from 10 to 8) with scale_xbits_to_8bits() doing a bit shift 2023-10-25 16:38:23 -03:00
David Capello
4387432ad3 Take some tests out from a loop they don't depend on 2023-10-25 11:59:28 -03:00
David Capello
dbb89b02a9 Rename scale_xxbits_to_8bits() -> scale_xbits_to_8bits() 2023-10-25 11:57:38 -03:00
David Capello
5e34ae0ce2 Fix unused variable warnings 2023-09-27 19:57:41 -03:00