public
Description: A Mac OS X photo uploader program for my photo album.
Homepage: http://bleu.west.spy.net/~dustin/projects/photoupload/
Clone URL: git://github.com/dustin/photoupload.git
photoupload / SizeScaler.m
100644 47 lines (36 sloc) 0.915 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// SizeScaler.m
// PhotoUpload
// arch-tag: 4D8FC084-9196-11D8-85E4-000A957659CC
//
// Created by Dustin Sallings on Sun Oct 06 2002.
// Copyright (c) 2002 SPY internetworking. All rights reserved.
//
 
#import "SizeScaler.h"
 
 
@implementation SizeScaler
 
-initWithSize: (NSSize)base
{
    [super init];
    baseSize=base;
    return(self);
}
 
-(NSSize)scaleTo: (NSSize)size
{
    float x=(float)baseSize.width;
    float y=(float)baseSize.height;
    float aspect=x/y;
  NSSize rv;
  rv.width=x;
  rv.height=y;
 
    if(size.width <= rv.width || size.height <= rv.height) {
 
        rv.width=size.width;
        rv.height=(int)((float)rv.width/aspect);
 
        // If it exceeds the boundaries, do it the other way.
        if(rv.width > size.width || rv.height > size.height) {
            rv.height=size.height;
            rv.width=(int)((float)rv.height*aspect);
        }
    }
 
    return(rv);
}
 
@end