Skip to content

Commit

Permalink
fix preview of option "keep image original size"
Browse files Browse the repository at this point in the history
a fix for issue #23
  • Loading branch information
Waitsnake committed Sep 12, 2017
1 parent 01866d5 commit ebe0919
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Binary file not shown.
35 changes: 24 additions & 11 deletions AnimatedGif/AnimatedGifView.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,13 @@ - (BOOL)isOpaque
- (void)animateOneFrame
{
// set some values screensaver and GIF image size
NSRect mainScreenRect = [[NSScreen mainScreen] frame];
NSRect screenRect = [self bounds];
NSRect target = screenRect;
float screenRatio = [self pictureRatioFromWidth:screenRect.size.width andHeight:screenRect.size.height];
float imgRatio = [self pictureRatioFromWidth:img.size.width andHeight:img.size.height];
CGFloat scaledHeight;
CGFloat scaledWidth;

if (viewOption==VIEW_OPT_STRETCH_OPTIMAL)
{
Expand All @@ -269,11 +272,24 @@ - (void)animateOneFrame
}
else if (viewOption==VIEW_OPT_KEEP_ORIG_SIZE)
{
// keep original size of image
target.size.height = img.size.height;
target.size.width = img.size.width;
target.origin.y = (screenRect.size.height - img.size.height)/2;
target.origin.x = (screenRect.size.width - img.size.width)/2;
if ([self isPreview] == FALSE)
{
// in case of NO preview mode: simply keep original size of image
target.size.height = img.size.height;
target.size.width = img.size.width;
target.origin.y = (screenRect.size.height - img.size.height)/2;
target.origin.x = (screenRect.size.width - img.size.width)/2;
}
else
{
// in case of preview mode: we also need to calculate the ratio between the size of the physical main screen and the size of the preview window to scale the image down.
scaledHeight = screenRect.size.height / mainScreenRect.size.height * img.size.height;
scaledWidth = screenRect.size.width / mainScreenRect.size.width * img.size.width;
target.size.height = scaledHeight;
target.size.width = scaledWidth;
target.origin.y = (screenRect.size.height - scaledHeight)/2;
target.origin.x = (screenRect.size.width - scaledWidth)/2;
}
}
else if (viewOption==VIEW_OPT_STRETCH_SMALL_SIDE)
{
Expand All @@ -295,12 +311,9 @@ - (void)animateOneFrame
}
else
{
/*default is VIEW_OPT_KEEP_ORIG_SIZE*/
// in case option in defaults file was too large we set it to last valid value
target.size.height = img.size.height;
target.size.width = img.size.width;
target.origin.y = (screenRect.size.height - img.size.height)/2;
target.origin.x = (screenRect.size.width - img.size.width)/2;
/*default is VIEW_OPT_STRETCH_MAXIMAL*/
// stretch image maximal to screen
target = screenRect;
}

if (currFrameCount == FRAME_COUNT_NOT_USED)
Expand Down
Binary file modified Release/AnimatedGif.saver.zip
Binary file not shown.

0 comments on commit ebe0919

Please sign in to comment.