|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Thumbnail provider class inline functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32math.h> |
|
20 |
|
21 |
|
22 inline TSize CThumbnailProvider::FitToSize( const TSize& aOrigSize, |
|
23 const TSize& aTargetSize, |
|
24 TBool aCrop ) |
|
25 { |
|
26 TSize res; |
|
27 TReal32 srcAspect = |
|
28 static_cast<TReal32>( aOrigSize.iWidth ) / aOrigSize.iHeight; |
|
29 TReal32 reqAspect = |
|
30 static_cast<TReal32>( aTargetSize.iWidth ) / aTargetSize.iHeight; |
|
31 |
|
32 res = aTargetSize; |
|
33 |
|
34 // Check whether the width or the height is the limiting factor for |
|
35 // the size |
|
36 TBool widthLimited = srcAspect > reqAspect; |
|
37 if ( aCrop ) |
|
38 { |
|
39 // When cropping, this works exactly the opposite way |
|
40 widthLimited = srcAspect < reqAspect; |
|
41 } |
|
42 |
|
43 if ( res.iWidth >= aOrigSize.iWidth && |
|
44 res.iHeight >= aOrigSize.iHeight ) |
|
45 { |
|
46 // Original is smaller than requested. No scaling needed. |
|
47 res = aOrigSize; |
|
48 } |
|
49 else if ( widthLimited ) |
|
50 { |
|
51 // Width is the limiting factor, ie. the thumbnail is |
|
52 // wide compared to requested size. |
|
53 TReal trg; |
|
54 TReal src( aTargetSize.iWidth / srcAspect ); |
|
55 Math::Round( trg, src, 1 ); |
|
56 res.SetSize( |
|
57 aTargetSize.iWidth, |
|
58 trg ); |
|
59 } |
|
60 else |
|
61 { |
|
62 // Height is the limiting factor, ie. the thumbnail is |
|
63 // taller compared to requested size. |
|
64 TReal trg; |
|
65 TReal src( aTargetSize.iHeight * srcAspect ); |
|
66 Math::Round( trg, src, 1 ); |
|
67 res.SetSize( |
|
68 trg, |
|
69 aTargetSize.iHeight ); |
|
70 } |
|
71 return res; |
|
72 } |
|
73 |
|
74 |
|
75 inline void CThumbnailProvider::ResolveSize() |
|
76 { |
|
77 // Get the actual target size for the thumbnail. |
|
78 // This is the maximum of the non-cropped and cropped |
|
79 // target sizes. |
|
80 |
|
81 TSize scaledSize = FitToSize( iOriginalSize, iTargetSize, EFalse ); |
|
82 if ( iCroppedTargetSize.iHeight && iCroppedTargetSize.iWidth ) |
|
83 { |
|
84 TSize croppedSize = FitToSize( |
|
85 iOriginalSize, iCroppedTargetSize, ETrue ); |
|
86 scaledSize.iWidth = Max( scaledSize.iWidth, croppedSize.iWidth ); |
|
87 scaledSize.iHeight = Max( scaledSize.iHeight, croppedSize.iHeight ); |
|
88 } |
|
89 iTargetSize = scaledSize; |
|
90 TN_DEBUG3("CThumbnailProvider::ResolveSize() - iTargetSize=(%d, %d)", |
|
91 iTargetSize.iWidth, iTargetSize.iHeight); |
|
92 } |