Skip to content

Conversation

@mjkkirschner
Copy link
Collaborator

@mjkkirschner mjkkirschner commented Aug 16, 2021

This PR fixes an issue where animated gifs were not optimized at all. There are a few issues.

  • gifs/animated gifs are quite complex - if they have been optimized before using certain methods -they cannot be optimized again - for example, if they contain frames with different internal sizes. (an optimization technique)
    it's possible to undo this and then optimize with image magick, but I found this to be too slow ~ 10 minutes for 40 gifs.
    Instead I found that using quantization (color reduction to 32k colors) works very well, is quite fast, and produces results about 10% - 50% reduction per gif.

  • running the tool on RevitNodes.dll and Revit dictionary takes 33 seconds before this change, and 99 seconds after this change - the folder is reduced from 44megs to 38 megs. (we don't have that many .gifs in the Revit dictionary content today, only 40.)

  • because reducing the .gif's is still quite slow overall, and ⚠️not lossless I added a separate flag for it, this is handy for quickly debugging other parts of the tool or avoiding the gif image changes.

  • also now in debug mode leave console open until console.readline for easier log reading.

this is a pathologically bad example because it has a ton of colors used in the animation.

1Meg
OverrideInView

900kB
Revit Elements Element OverrideInView_img

add gif compression by quantization to 32k colors
in debug leave console open until readline for easy log reading
@mjkkirschner mjkkirschner requested a review from SHKnudsen August 16, 2021 23:23
@SHKnudsen
Copy link
Owner

LGTM

//images.Optimize();
//images.OptimizeTransparency();
//reduce color bit depth from 8 to 5.
images.Quantize(new QuantizeSettings() { Colors = 32768 });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 32768 ?
any special meaning ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15-bit high color ?

Copy link
Collaborator Author

@mjkkirschner mjkkirschner Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes (2^5) bits per red, green, and blue 32*32*32 = 32k colors. Normal 8 bit per channel can support: 16777216 colors.

Copy link

@pinzart90 pinzart90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SHKnudsen SHKnudsen merged commit 9d88dd2 into SHKnudsen:Node-Markdown-generator-tool Aug 18, 2021
@aparajit-pratap
Copy link

@mjkkirschner I thought that gifs never worked for documentation. Is it that after this change they now can be rendered or were they always supported and this is only for compression?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants