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
|
/* -*- mode: C++; tab-width: 4 -*- */
/* ===================================================================== *\
Copyright (c) 1999-2001 Palm, Inc. or its subsidiaries.
All rights reserved.
This file is part of the Palm OS Emulator.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
\* ===================================================================== */
#include "EmCommon.h"
#include "EmDocumentUnix.h"
#include "EmScreen.h" // EmScreen
// !!! Need to get rid of this dependancy on FLTK
#include <FL/filename.h> // filename_setext
#include <stdio.h> // fopen, fprintf, fwrite, fclose, FILE
EmDocumentUnix* gHostDocument;
// ---------------------------------------------------------------------------
// ¥ EmDocument::HostCreateDocument
// ---------------------------------------------------------------------------
// Create our document instance. This is the one and only function that
// creates the document. Being in a platform-specific file, it can create
// any subclass of EmDocument it likes (in particular, one specific to our
// platform).
EmDocument* EmDocument::HostCreateDocument (void)
{
return new EmDocumentUnix;
}
#pragma mark -
/***********************************************************************
*
* FUNCTION: EmDocumentUnix::EmDocumentUnix
*
* DESCRIPTION: Constructor. Sets the global host application variable
* to point to us.
*
* PARAMETERS: None
*
* RETURNED: Nothing
*
***********************************************************************/
EmDocumentUnix::EmDocumentUnix (void) :
EmDocument ()
{
EmAssert (gHostDocument == NULL);
gHostDocument = this;
}
/***********************************************************************
*
* FUNCTION: EmDocumentUnix::~EmDocumentUnix
*
* DESCRIPTION: Destructor. Closes our window and sets the host
* application variable to NULL.
*
* PARAMETERS: None
*
* RETURNED: Nothing
*
***********************************************************************/
EmDocumentUnix::~EmDocumentUnix (void)
{
EmAssert (gHostDocument == this);
gHostDocument = NULL;
}
#pragma mark -
// ---------------------------------------------------------------------------
// ¥ EmDocumentUnix::HostSaveScreen
// ---------------------------------------------------------------------------
// Save the current contents of the LCD buffer to the given file.
void EmDocumentUnix::HostSaveScreen (const EmFileRef& destRef)
{
// Make sure the extension is right.
string fullPath = destRef.GetFullPath ();
char* fNameExt = (char*) malloc (fullPath.size () + 4);
strcpy (fNameExt, fullPath.c_str ());
filename_setext (fNameExt, ".ppm");
FILE* f = fopen (fNameExt, "wb");
if (f)
{
EmScreen::InvalidateAll ();
EmScreenUpdateInfo info;
EmScreen::GetBits (info);
EmScreen::InvalidateAll ();
info.fImage.ConvertToFormat (kPixMapFormat24RGB);
// PPM format is:
//
// File type tag
// Width
// Height
// Max component value
// Width * Height pixels
//
// The first items in the file are all text and
// seperated by whitespace. The array of pixels
// is in text format if the file type is P3, and
// is in binary format if the type is P6.
EmPoint size = info.fImage.GetSize ();
fprintf (f, "P6 %ld %ld 255\x0D", size.fX, size.fY);
uint8* bits = (uint8*) info.fImage.GetBits ();
for (long yy = 0; yy < size.fY; ++yy)
{
long rowBytes = info.fImage.GetRowBytes ();
uint8* basePtr = bits + yy * rowBytes;
fwrite (basePtr, 1, rowBytes, f);
}
fclose (f);
}
free (fNameExt);
}
|