/[winpt]/trunk/PTD/wptJPG.cpp
ViewVC logotype

Diff of /trunk/PTD/wptJPG.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC revision 33 by twoaday, Tue Oct 25 07:46:20 2005 UTC
# Line 2  Line 2 
2   *      Copyright (C) 2001 Dr.Yovav Gad <[email protected]>   *      Copyright (C) 2001 Dr.Yovav Gad <[email protected]>
3   *      Copyright (C) 2005 Timo Schulz   *      Copyright (C) 2005 Timo Schulz
4   *   *
5   * This file is part of PTD.   * This file is part of WinPT.
6   *   *
7   * PTD is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
8   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
9   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.   * (at your option) any later version.
11   *   *
12   * PTD is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.   * GNU General Public License for more details.
# Line 39  Line 39 
39    
40  #include "wptJPG.h"  #include "wptJPG.h"
41    
42  #define HIMETRIC_INCH 2540  #define HIMETRIC_INCH   2540
43  #define ERROR_TITLE "CJPG Error" /* Error Title (Related To This Class)...*/  #define ERROR_TITLE     "CJPG Error"
44    
45  #define out_of_core() do { \  #define out_of_core() do { \
46          MessageBox (NULL, "Can not allocate memory", ERROR_TITLE, MB_OK|MB_ICONSTOP); \          MessageBox (NULL, "Can not allocate memory", ERROR_TITLE, MB_OK|MB_ICONSTOP); \
# Line 60  CJPG::CJPG (void) Line 60  CJPG::CJPG (void)
60  CJPG::~CJPG (void)  CJPG::~CJPG (void)
61  {  {
62      if (m_IPicture != NULL)      if (m_IPicture != NULL)
63          FreePictureData ();          freePictureData ();
64  }  }
65    
66    
# Line 68  CJPG::~CJPG (void) Line 68  CJPG::~CJPG (void)
68  /* Free the allocated memory that holdes the IPicture Interface data  /* Free the allocated memory that holdes the IPicture Interface data
69     and clear picture information. */     and clear picture information. */
70  void  void
71  CJPG::FreePictureData (void)  CJPG::freePictureData (void)
72  {  {
73      if (m_IPicture != NULL) {      if (m_IPicture != NULL) {
74          m_IPicture->Release();          m_IPicture->Release();
# Line 82  CJPG::FreePictureData (void) Line 82  CJPG::FreePictureData (void)
82    
83  /* Open a JPG File And Load It Into IPicture (Interface) */  /* Open a JPG File And Load It Into IPicture (Interface) */
84  BOOL  BOOL
85  CJPG::Load (LPCSTR sFilePathName)  CJPG::load (LPCSTR sFilePathName)
86  {  {
87      BOOL bResult = FALSE;      BOOL bResult = FALSE;
88      FILE * f;      FILE * f;
89      int nSize = 0;      int nSize = 0;
90    
91      if (m_IPicture != NULL)      if (m_IPicture != NULL)
92          FreePictureData ();          freePictureData ();
93    
94      f = fopen (sFilePathName, "rb");      f = fopen (sFilePathName, "rb");
95      if (f) {      if (f) {
# Line 103  CJPG::Load (LPCSTR sFilePathName) Line 103  CJPG::Load (LPCSTR sFilePathName)
103          }          }
104          memset (pBuffer, 0, nSize);          memset (pBuffer, 0, nSize);
105          if (fread(pBuffer, 1, nSize, f) > 0) {          if (fread(pBuffer, 1, nSize, f) > 0) {
106              if (LoadPictureData (pBuffer, nSize))              if (loadPictureData (pBuffer, nSize))
107                  bResult = TRUE;                  bResult = TRUE;
108          }          }
109          fclose (f);          fclose (f);
# Line 137  CJPG::Load (LPCSTR sFilePathName) Line 137  CJPG::Load (LPCSTR sFilePathName)
137  /* read the picture data from a source (file / resource)  /* read the picture data from a source (file / resource)
138     and load it into the current IPicture object in use */     and load it into the current IPicture object in use */
139  BOOL  BOOL
140  CJPG::LoadPictureData (BYTE *pBuffer, int nSize)  CJPG::loadPictureData (BYTE *pBuffer, int nSize)
141    
142  {  {
143      BOOL bResult = FALSE;      BOOL bResult = FALSE;
# Line 157  CJPG::LoadPictureData (BYTE *pBuffer, in Line 157  CJPG::LoadPictureData (BYTE *pBuffer, in
157    
158      if (CreateStreamOnHGlobal (hGlobal, TRUE, &pStream) == S_OK) {      if (CreateStreamOnHGlobal (hGlobal, TRUE, &pStream) == S_OK) {
159          HRESULT hr;          HRESULT hr;
160          hr = OleLoadPicture (pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&m_IPicture);          hr = OleLoadPicture (pStream, nSize, FALSE, IID_IPicture,
161                                 (LPVOID *)&m_IPicture);
162          if (hr == E_NOINTERFACE) {          if (hr == E_NOINTERFACE) {
163              MessageBox (NULL, "IPicture interface is not supported", ERROR_TITLE, MB_OK|MB_ICONSTOP);              MessageBox (NULL, "IPicture interface is not supported",
164                            ERROR_TITLE, MB_OK|MB_ICONSTOP);
165              return FALSE;              return FALSE;
166          }          }
167          else { /* S_OK */          else { /* S_OK */
# Line 176  CJPG::LoadPictureData (BYTE *pBuffer, in Line 178  CJPG::LoadPictureData (BYTE *pBuffer, in
178    
179  /* Draw the loaded picture direct to the client DC */  /* Draw the loaded picture direct to the client DC */
180  BOOL  BOOL
181  CJPG::Show (HDC pDC, POINT *LeftTop, POINT *WidthHeight,  CJPG::show (HDC pDC, POINT *LeftTop, POINT *WidthHeight,
182              int MagnifyX, int MagnifyY)              int MagnifyX, int MagnifyY)
183    
184  {  {
# Line 189  CJPG::Show (HDC pDC, POINT *LeftTop, POI Line 191  CJPG::Show (HDC pDC, POINT *LeftTop, POI
191      m_IPicture->get_Width (&Width);      m_IPicture->get_Width (&Width);
192      m_IPicture->get_Height (&Height);      m_IPicture->get_Height (&Height);
193                    
194      if (MagnifyX == NULL)      if (MagnifyX == 0)
195          MagnifyX = 0;          MagnifyX = 0;
196      if (MagnifyY == NULL)      if (MagnifyY == 0)
197          MagnifyY = 0;          MagnifyY = 0;
198      MagnifyX = int(MulDiv (Width, GetDeviceCaps(pDC, LOGPIXELSX), HIMETRIC_INCH) * MagnifyX);      MagnifyX = int(MulDiv (Width, GetDeviceCaps(pDC, LOGPIXELSX), HIMETRIC_INCH) * MagnifyX);
199      MagnifyY = int(MulDiv (Height, GetDeviceCaps(pDC, LOGPIXELSY), HIMETRIC_INCH) * MagnifyY);      MagnifyY = int(MulDiv (Height, GetDeviceCaps(pDC, LOGPIXELSY), HIMETRIC_INCH) * MagnifyY);
# Line 225  CJPG::Show (HDC pDC, POINT *LeftTop, POI Line 227  CJPG::Show (HDC pDC, POINT *LeftTop, POI
227  /* Get the original picture pixel size (ignore what current DC is using)  /* Get the original picture pixel size (ignore what current DC is using)
228     pointer to a Device Context is needed for pixel calculation, */     pointer to a Device Context is needed for pixel calculation, */
229  BOOL  BOOL
230  CJPG::UpdateSizeOnDC (HDC pDC)  CJPG::updateSizeOnDC (HDC pDC)
231    
232  {        {      
233      if(pDC == NULL || m_IPicture == NULL) {      if(pDC == NULL || m_IPicture == NULL) {

Legend:
Removed from v.23  
changed lines
  Added in v.33

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26