Image deduplication doesn't work properly

Report Construct 2 bugs here.

Post » Tue Oct 28, 2014 2:31 am

Problem Description
Image deduplication doesn't work properly

Attach a Capx
Attached

Description of Capx
There are 5 sprite objects:
The Number 1 has the image #1
The Number 2 has the image #2
The Number 3 has the image #3
The Number 4 has the image #4
The Number 5 has all the images (#1, 2, 3 and 4)

Image

Image

Steps to Reproduce Bug
  • Step 1 Export project
  • Step 2 Open the "images" folder
  • Step 3 Check the exported images

Observed Result
There are duplicated images

Expected Result
I expect that Construct 2 removes the duplicated images

Affected Browsers
  • Chrome: (YES)
  • FireFox: (YES)
  • Internet Explorer: (YES)

Operating System and Service Pack
Windows 8.1 Update 1 (64-bits)

Construct 2 Version ID
R185 (64-bits)
You do not have the required permissions to view the files attached to this post.
B
86
S
25
G
11
Posts: 652
Reputation: 11,047

Post » Tue Oct 28, 2014 7:48 pm

I can reproduce it here, at first i thought that the pictures are not pixel-perfect identical, so i saved 4 pictures from capx above to my desktop, started a new project, created 4 sprites (0, 2, 3 ,4) and 1 sprite with 4 images(5), load pictures from my desktop there (to be sure that sprite5 and others have identical images) and i have the same result after export, but i can reproduce it only if i "Import frames - From Files" to sprite5, if i create 4 empty frames in sprite5 and then "Load an image from a file" for each frame, everythings is exported right! This sounds like i lost my mind so heres the .capx

Here i import frames to sprite5 and the bug appears
importframes.capx


Here i "Load an image from a file(folder icon in the editor and open the picture)" and everything exports fine
loadfromafile.capx
You do not have the required permissions to view the files attached to this post.
Last edited by Sisyphus on Tue Oct 28, 2014 8:09 pm, edited 1 time in total.
B
22
S
9
G
7
Posts: 421
Reputation: 6,543

Post » Tue Oct 28, 2014 8:03 pm

@Sisyphus Yep. You are right, pretty weird ah!
B
86
S
25
G
11
Posts: 652
Reputation: 11,047

Post » Tue Oct 28, 2014 9:51 pm

I'm only 90% sure how this works. Image de-pulication only occurs with the frames in a single Sprite type and all of it's instances. C2 doesn't sadly doesn't use an Image Atlas. Instead all Sprite frames belong to that Sprite. If you have duplicate image frames in different sprites such as

WeaponSpriteA has image Handle
WeaponSpriteB has image Handle
then no de-duplicaition will occur.

However if you have
WeaponSpriteAB has ImageFrames or Animations, 0-Handle, 1-Handle
Then de-duplication will occur as having all the same images in the same Sprite.

Since your saying you have 5 Sprite Objects(ie not instances, but full on separate objects) then yes. There is no de-duplication by design/limitation in the overall c2 architecture.

I would personally feel better if C2 used an ImageAtlas and the Sprite/Frames/Animations referenced the atlas. Then there would be a solid de-duplication across all sprites. In the mean time. You will often hear me saying. Batch your sprite images into less sprite objects based on type and/or layers.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Wed Oct 29, 2014 9:47 am

jayderyu wrote:However if you have
WeaponSpriteAB has ImageFrames or Animations, 0-Handle, 1-Handle
Then de-duplication will occur as having all the same images in the same Sprite.

Since your saying you have 5 Sprite Objects(ie not instances, but full on separate objects) then yes. There is no de-duplication by design/limitation in the overall c2 architecture.

I'm not sure it's something with deduplication, see my post above, deduplication works as it's described in manual, but only if "Import Frames - From Files" is not used.
B
22
S
9
G
7
Posts: 421
Reputation: 6,543

Post » Wed Oct 29, 2014 4:57 pm

I checked in the debugger and the images have different hashes. Therefore they must have at least one tiny difference anywhere in the image. Image deduplication does work between different sprite objects, and I verified this works by replacing the first two images with an all-blue and all-red opaque rectangle, and it correctly deduplicates on export. So it is working. The question is how the images end up different.

I would guess that happens due to alpha premultiplication somehow. Premultiplying then unpremultiplying is a lossy operation, but I don't know how that could happen. I checked and if you use "Import frames - from files" and choose a .png file, it simply copies the file to the project without touching it, so it should remain identical. Hmm...
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,684

Post » Wed Oct 29, 2014 5:12 pm

Ashley wrote:I checked in the debugger and the images have different hashes. Therefore they must have at least one tiny difference anywhere in the image. Image deduplication does work between different sprite objects, and I verified this works by replacing the first two images with an all-blue and all-red opaque rectangle, and it correctly deduplicates on export. So it is working. The question is how the images end up different.

I would guess that happens due to alpha premultiplication somehow. Premultiplying then unpremultiplying is a lossy operation, but I don't know how that could happen. I checked and if you use "Import frames - from files" and choose a .png file, it simply copies the file to the project without touching it, so it should remain identical. Hmm...

Yeah, at first i tried it with the rectangles, and i can't reproduce. But if i try circles like the ones in the bug description, the import frames bug appears.

Maybe the problem is in "Load an image from a file" ?
B
22
S
9
G
7
Posts: 421
Reputation: 6,543


Return to Bugs

Who is online

Users browsing this forum: No registered users and 0 guests