File: Doc.cpp

package info (click to toggle)
paintlib 2.6.2-14
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,920 kB
  • ctags: 3,874
  • sloc: cpp: 25,209; sh: 10,605; ansic: 1,891; makefile: 120
file content (240 lines) | stat: -rw-r--r-- 6,379 bytes parent folder | download | duplicates (2)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
/--------------------------------------------------------------------
|
|      $Id: Doc.cpp,v 1.18 2004/09/09 16:52:50 artcom Exp $
|      DOC.CPP    Document class implementation (where the bitmaps live)
|
|      Copyright (c) 1998 Bernard Delme
|
\--------------------------------------------------------------------
*/

#include "stdafx.h"
#include "piclook.h"
#include "doc.h"

#include "MainFrm.h"

#include "pltiffencex.h"
#include "pljpegenc.h"
#include "plpngenc.h"
#include "plbmpenc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPLViewerDoc

IMPLEMENT_DYNCREATE(CPLViewerDoc, CDocument)

BEGIN_MESSAGE_MAP(CPLViewerDoc, CDocument)
    //{{AFX_MSG_MAP(CPLViewerDoc)
    ON_COMMAND(ID_FILE_SAVE, OnFileSave)
    ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPLViewerDoc construction/destruction

CPLViewerDoc::CPLViewerDoc()
{
    m_pDib = 0;
}

CPLViewerDoc::~CPLViewerDoc()
{
    DeleteContents();
}

BOOL CPLViewerDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
    // recycle document
    DeleteContents();

    m_pDib = new PLWinBmpEx;

    // have PaintLib perform I/O instead of Serialization
    bool bRet = true;
    try
    {
        // Jo Hagelberg 15.4.99: added "this" for progress notification
        thisApp.GetDecoder()->MakeBmpFromFile(lpszPathName, m_pDib, PLPixelFormat::DONTCARE, this);
    }
    catch (PLTextException e)
    {
        AfxMessageBox(e);
        DeleteContents();
        bRet = false;
    }

    if (bRet)
    {
        SetPathName(lpszPathName);
        SetModifiedFlag(false);      // start off with unmodified
        char *cp = strrchr(lpszPathName,'\\');
        if (cp) // establish this image's directory as our new wd
        {
            *cp = '\0';
            SetCurrentDirectory(lpszPathName);
            // pretend we did not touch that string
            *cp = '\\';
        }
    }

    return bRet;    // Belgian resolution enhancement technology :-)
}

// Jo Hagelberg 15.4.99: copied OnProgress from DibStatic
// (bad design, anyway, this is just for testing ;-)

void CPLViewerDoc::OnProgress
( double Part
)
{
    //TRACE ("V %.4f\n", Part);
    // Jo Hagelberg 13.4.99
    // added real progress info
    UINT ipart = UINT( Part * 100.0);
    ((CMainFrame*)AfxGetMainWnd())->SetProgressInfo(ipart);
}

void CPLViewerDoc::OnUpdateFileSave(CCmdUI* pCmdUI)
{
    pCmdUI->Enable (m_pDib != NULL);
}

void CPLViewerDoc::OnFileSave()
{
    CFileDialog  SaveDlg (false, ".jpg", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
                          "JPEG File (*.jpg)|*.jpg|Windows Bitmap (*.bmp)|*.bmp|TIFF File (*.tif)|*.tif|PNG File (*.png)|*.png|",
                          AfxGetMainWnd());
    if (SaveDlg.DoModal() == IDOK)
    {
      CString sFName = SaveDlg.GetPathName();
      CString sExt = SaveDlg.GetFileExt();
      sExt.MakeLower();
      try
        {
          if (sExt == "jpg")
          {
              PLJPEGEncoder Encoder;
              Encoder.MakeFileFromBmp(sFName, m_pDib);
          }
          else if (sExt == "tif")
          {
              PLTIFFEncoder Encoder;
              Encoder.MakeFileFromBmp(sFName, m_pDib);
          }
          else if (sExt == "png")
          {
              PLPNGEncoder Encoder;
              Encoder.MakeFileFromBmp(sFName, m_pDib);
          }
          else if (sExt == "bmp")
          {
              PLBmpEncoder Encoder;
              Encoder.MakeFileFromBmp(sFName, m_pDib);
          }
          else
          {
              // Extension must be one of the supported types. If not,
              // something is wrong in the user interface code.
              ASSERT (false);
          }
        }
      catch(PLTextException e)
        {
          CString bmpEx;
          bmpEx.Format("Error saving the file: %s", 
                       (LPCTSTR) e, 
                       (LPCTSTR) e.GetCode());
          AfxMessageBox(bmpEx);
        }
    }
}


//////////////////
// Delete contents of doc: delete the DIB
//
void CPLViewerDoc::DeleteContents()
{
    if (m_pDib) delete m_pDib;
    m_pDib = 0;
}

/////////////////////////////////////////////////////////////////////////////
// CPLViewerDoc diagnostics

#ifdef _DEBUG
void CPLViewerDoc::AssertValid() const
{
    CDocument::AssertValid();
}

void CPLViewerDoc::Dump(CDumpContext& dc) const
{
    CDocument::Dump(dc);
}

#endif //_DEBUG
/*
/--------------------------------------------------------------------
|
|      $Log: Doc.cpp,v $
|      Revision 1.18  2004/09/09 16:52:50  artcom
|      refactored PixelFormat
|
|      Revision 1.17  2004/04/15 16:39:30  uzadow
|      Initial Mac OS X port
|
|      Revision 1.16  2002/03/03 16:29:56  uzadow
|      Re-added BPPWanted.
|
|      Revision 1.15  2001/10/21 17:12:40  uzadow
|      Added PSD decoder beta, removed BPPWanted from all decoders, added PLFilterPixel.
|
|      Revision 1.14  2001/09/16 19:03:23  uzadow
|      Added global name prefix PL, changed most filenames.
|
|      Revision 1.13  2000/09/01 14:13:49  Administrator
|      Removed MFC from paintX, added MSCV paintX sample.
|
|      Revision 1.12  2000/07/11 17:49:04  Ulrich von Zadow
|      Added save in bitmap format (Thomas Hirschmann).
|
|      Revision 1.11  2000/03/31 11:53:31  Ulrich von Zadow
|      Added quantization support.
|
|      Revision 1.10  2000/03/28 21:05:03  Ulrich von Zadow
|      Added zoom capability.
|
|      Revision 1.8  2000/01/10 23:53:01  Ulrich von Zadow
|      Changed formatting & removed tabs.
|
|      Revision 1.7  2000/01/04 22:06:37  Ulrich von Zadow
|      Added png encoder by Neville Richards.
|
|      Revision 1.6  1999/12/02 17:07:35  Ulrich von Zadow
|      Changes by bdelmee.
|
|      Revision 1.5  1999/11/08 22:15:05  Ulrich von Zadow
|      Added File/SaveAs
|
|
\--------------------------------------------------------------------
*/

void CPLViewerDoc::ConvertTo8BPP(UINT iDitherPaletteType, UINT iDitherType)
{
  PLWinBmpEx* bpp8Copy = new PLWinBmpEx;
  bpp8Copy->SetQuantizationMode (iDitherType, iDitherPaletteType);
  bpp8Copy->CreateCopy((PLBmp&)*m_pDib, PLPixelFormat::I8);
  delete m_pDib;
  m_pDib = bpp8Copy;
}