1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2007 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
22 #include <GdiPlus.h>
\r
24 using namespace Gdiplus;
\r
26 # define stdstring std::wstring
\r
28 # define stdstring std::string
\r
33 * Class for showing picture files.
\r
34 * Use this class to show pictures of different file formats: BMP, DIB, EMF, GIF, ICO, JPG, WMF
\r
35 * If Gdi+ is installed (default on XP and later, optional on Win2k), other image formats can
\r
36 * be shown too: png, tiff.
\r
37 * The class uses the IPicture interface, the same way as internet explorer does.
\r
41 * CPicture m_picture;
\r
42 * //load picture data into the IPicture interface
\r
43 * m_picture.Load("Test.jpg"); //load from a file
\r
44 * m_picture.Load(IDR_TEST, "JPG"); //load from a resource
\r
46 * //when using in a dialog based application (CPaintDC dc(this);)
\r
47 * m_picture.UpdateSizeOnDC(&dc); //get picture dimensions in pixels
\r
48 * m_picture.Show(&dc, CPoint(0,0), CPoint(m_picture.m_Width, m_picture.m_Height), 0, 0);
\r
49 * m_picture.Show(&dc, CRect(0,0,100,100)); //change original dimensions
\r
50 * m_picture.ShowBitmapResource(&dc, IDB_TEST, CPoint(0,0)); //show bitmap resource
\r
52 * //when using in a regular mfc application (CDC* pDC)
\r
53 * m_picture.UpdateSizeOnDC(pDC); //get picture dimensions in pixels
\r
54 * m_picture.Show(pDC, CPoint(0,0), CPoint(m_picture.m_Width, m_picture.m_Height), 0, 0);
\r
55 * m_picture.Show(pDC, CRect(0,0,100,100)); //change original dimensions
\r
56 * m_picture.ShowBitmapResource(pDC, IDB_TEST, CPoint(0,0)); //show bitmap resource
\r
58 * //to show picture information
\r
60 * s.Format("Size = %4d\nWidth = %4d\nHeight = %4d\nWeight = %4d\n",
\r
61 * m_picture.m_Weigth, m_picture.m_Width, m_picture.m_Height, m_picture.m_Weight);
\r
64 * \remark GDI+ is only used if it is installed. If you link with gdiplus.lib and mark the gdiplus.dll
\r
65 * as a delay-loaded dll, then your application won't throw an error if it isn't installed, but of course
\r
66 * png and tiff images can't be shown.
\r
72 * open a picture file and load it (BMP, DIB, EMF, GIF, ICO, JPG, WMF).
\r
74 * \param sFilePathName the path of the picture file
\r
75 * \return TRUE if succeeded.
\r
77 bool Load(stdstring sFilePathName);
\r
79 * draws the loaded picture directly to the given device context.
\r
81 * if the given size is not the actual picture size, then the picture will
\r
82 * be drawn stretched to the given dimensions.
\r
83 * \param pDC the device context to draw on
\r
84 * \param DrawRect the dimensions to draw the picture on
\r
85 * \return TRUE if succeeded
\r
87 bool Show(HDC hDC, RECT DrawRect);
\r
89 * get the original picture pixel size. A pointer to a device context is needed
\r
90 * for the pixel calculation (DPI). Also updates the classes height and width
\r
92 * \param pDC the device context to perform the calculations on
\r
93 * \return TRUE if succeeded
\r
95 bool UpdateSizeOnDC(HDC hDC);
\r
98 * Return the horizontal resolutions in dpi of the loaded picture.
\r
99 * \remark this only works if gdi+ is installed.
\r
101 float GetHorizontalResolution() {return pBitmap ? pBitmap->GetHorizontalResolution() : 0.0f;}
\r
103 * Return the vertical resolution in dpi of the loaded picture.
\r
104 * \remark this only works if gdi+ is installed.
\r
106 float GetVerticalResolution() {return pBitmap ? pBitmap->GetVerticalResolution() : 0.0f;}
\r
108 * Returns the picture height in pixels.
\r
109 * \remark this only works if gdi+ is installed.
\r
111 UINT GetHeight() const;
\r
113 * Returns the picture width in pixels.
\r
114 * \remark this only works if gdi+ is installed.
\r
116 UINT GetWidth() const;
\r
118 * Returns the pixel format of the loaded picture.
\r
119 * \remark this only works if gdi+ is installed.
\r
121 PixelFormat GetPixelFormat() const;
\r
123 * Returns the color depth in bits.
\r
124 * \remark this only works if gdi+ is installed.
\r
126 UINT GetColorDepth() const;
\r
129 * Sets the interpolation used for drawing the image.
\r
130 * The interpolation mode is one of the following:
\r
131 * InterpolationModeInvalid
\r
132 * InterpolationModeDefault
\r
133 * InterpolationModeLowQuality
\r
134 * InterpolationModeHighQuality
\r
135 * InterpolationModeBilinear
\r
136 * InterpolationModeBicubic
\r
137 * InterpolationModeNearestNeighbor
\r
138 * InterpolationModeHighQualityBilinear
\r
139 * InterpolationModeHighQualityBicubic
\r
141 void SetInterpolationMode(InterpolationMode ip) {m_ip = ip;}
\r
144 * Returns the number of frames in the specified dimension of the image.
\r
146 UINT GetNumberOfFrames(int dimension);
\r
148 * Returns the number of dimensions in the image.
\r
149 * For example, icons can have multiple dimensions (sizes).
\r
151 UINT GetNumberOfDimensions();
\r
154 * Sets the active frame which is used when drawing the image.
\r
155 * \return the delay value for this frame, i.e. how long this frame
\r
158 long SetActiveFrame(UINT frame);
\r
160 DWORD GetFileSize() {return m_nSize;}
\r
161 stdstring GetFileSizeAsText(bool bAbbrev = true);
\r
163 virtual ~CPicture();
\r
168 IPicture* m_IPicture; ///< Same As LPPICTURE (typedef IPicture __RPC_FAR *LPPICTURE)
\r
170 LONG m_Height; ///< Height (in pixels)
\r
171 LONG m_Width; ///< Width (in pixels)
\r
172 BYTE m_ColorDepth;///< the color depth
\r
173 LONG m_Weight; ///< Size Of The Image Object In Bytes (File OR Resource)
\r
174 stdstring m_Name; ///< The FileName of the Picture as used in Load()
\r
178 * reads the picture data from a source and loads it into the current IPicture object in use.
\r
179 * \param pBuffer buffer of data source
\r
180 * \param nSize the size of the buffer
\r
181 * \return TRUE if succeeded
\r
183 bool LoadPictureData(BYTE* pBuffer, int nSize);
\r
186 * frees the allocated memory that holds the IPicture interface data and
\r
187 * clear picture information
\r
189 void FreePictureData();
\r
192 GdiplusStartupInput gdiplusStartupInput;
\r
193 ULONG_PTR gdiplusToken;
\r
196 InterpolationMode m_ip;
\r
203 #pragma pack(push, r1, 2) // n = 16, pushed to stack
\r
207 BYTE bWidth; // Width of the image
\r
208 BYTE bHeight; // Height of the image (times 2)
\r
209 BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
\r
210 BYTE bReserved; // Reserved
\r
211 WORD wPlanes; // Color Planes
\r
212 WORD wBitCount; // Bits per pixel
\r
213 DWORD dwBytesInRes; // how many bytes in this resource?
\r
214 DWORD dwImageOffset; // where in the file is this image
\r
215 } ICONDIRENTRY, *LPICONDIRENTRY;
\r
218 WORD idReserved; // Reserved
\r
219 WORD idType; // resource type (1 for icons)
\r
220 WORD idCount; // how many images?
\r
221 ICONDIRENTRY idEntries[1]; // the entries for each image
\r
222 } ICONDIR, *LPICONDIR;
\r
223 #pragma pack(pop, r1)
\r