~ubuntu-branches/ubuntu/lucid/squeak-vm/lucid

« back to all changes in this revision

Viewing changes to platforms/unix/src/vm/intplugins/BMPReadWriterPlugin/BMPReadWriterPlugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2005-07-15 11:44:08 UTC
  • Revision ID: james.westby@ubuntu.com-20050715114408-lgcvpntigab09l00
Tags: upstream-3.7.7
ImportĀ upstreamĀ versionĀ 3.7.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Automatically generated from Squeak on #(19 March 2005 10:08:38 am) */
 
2
 
 
3
#include <math.h>
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
#include <string.h>
 
7
#include <time.h>
 
8
 
 
9
/* Default EXPORT macro that does nothing (see comment in sq.h): */
 
10
#define EXPORT(returnType) returnType
 
11
 
 
12
/* Do not include the entire sq.h file but just those parts needed. */
 
13
/*  The virtual machine proxy definition */
 
14
#include "sqVirtualMachine.h"
 
15
/* Configuration options */
 
16
#include "sqConfig.h"
 
17
/* Platform specific definitions */
 
18
#include "sqPlatformSpecific.h"
 
19
 
 
20
#define true 1
 
21
#define false 0
 
22
#define null 0  /* using 'null' because nil is predefined in Think C */
 
23
#ifdef SQUEAK_BUILTIN_PLUGIN
 
24
#undef EXPORT
 
25
// was #undef EXPORT(returnType) but screws NorCroft cc
 
26
#define EXPORT(returnType) static returnType
 
27
#endif
 
28
 
 
29
/* memory access macros */
 
30
#define byteAt(i) (*((unsigned char *) (i)))
 
31
#define byteAtput(i, val) (*((unsigned char *) (i)) = val)
 
32
#define longAt(i) (*((int *) (i)))
 
33
#define longAtput(i, val) (*((int *) (i)) = val)
 
34
 
 
35
 
 
36
/*** Constants ***/
 
37
 
 
38
/*** Function Prototypes ***/
 
39
#pragma export on
 
40
EXPORT(const char*) getModuleName(void);
 
41
#pragma export off
 
42
static int halt(void);
 
43
static int msg(char *s);
 
44
#pragma export on
 
45
EXPORT(int) primitiveRead24BmpLine(void);
 
46
EXPORT(int) primitiveWrite24BmpLine(void);
 
47
EXPORT(int) setInterpreter(struct VirtualMachine* anInterpreter);
 
48
#pragma export off
 
49
/*** Variables ***/
 
50
 
 
51
#ifdef SQUEAK_BUILTIN_PLUGIN
 
52
extern
 
53
#endif
 
54
struct VirtualMachine* interpreterProxy;
 
55
static const char *moduleName =
 
56
#ifdef SQUEAK_BUILTIN_PLUGIN
 
57
        "BMPReadWriterPlugin 19 March 2005 (i)"
 
58
#else
 
59
        "BMPReadWriterPlugin 19 March 2005 (e)"
 
60
#endif
 
61
;
 
62
 
 
63
 
 
64
 
 
65
/*      Note: This is hardcoded so it can be run from Squeak.
 
66
        The module name is used for validating a module *after*
 
67
        it is loaded to check if it does really contain the module
 
68
        we're thinking it contains. This is important! */
 
69
 
 
70
EXPORT(const char*) getModuleName(void) {
 
71
        return moduleName;
 
72
}
 
73
 
 
74
static int halt(void) {
 
75
        ;
 
76
}
 
77
 
 
78
static int msg(char *s) {
 
79
        fprintf(stderr, "\n%s: %s", moduleName, s);
 
80
}
 
81
 
 
82
EXPORT(int) primitiveRead24BmpLine(void) {
 
83
    int formBitsOop;
 
84
    unsigned char * pixelLine;
 
85
    unsigned int * formBits;
 
86
    int formBitsSize;
 
87
    int formBitsIndex;
 
88
    int pixelLineOop;
 
89
    int pixelLineSize;
 
90
    int width;
 
91
 
 
92
        if (!((interpreterProxy->methodArgumentCount()) == 4)) {
 
93
                return interpreterProxy->primitiveFail();
 
94
        }
 
95
        width = interpreterProxy->stackIntegerValue(0);
 
96
        formBitsIndex = interpreterProxy->stackIntegerValue(1);
 
97
        formBitsOop = interpreterProxy->stackObjectValue(2);
 
98
        pixelLineOop = interpreterProxy->stackObjectValue(3);
 
99
        if (interpreterProxy->failed()) {
 
100
                return null;
 
101
        }
 
102
        if (!(interpreterProxy->isWords(formBitsOop))) {
 
103
                return interpreterProxy->primitiveFail();
 
104
        }
 
105
        if (!(interpreterProxy->isBytes(pixelLineOop))) {
 
106
                return interpreterProxy->primitiveFail();
 
107
        }
 
108
        formBitsSize = interpreterProxy->slotSizeOf(formBitsOop);
 
109
        formBits = interpreterProxy->firstIndexableField(formBitsOop);
 
110
        pixelLineSize = interpreterProxy->slotSizeOf(pixelLineOop);
 
111
        pixelLine = interpreterProxy->firstIndexableField(pixelLineOop);
 
112
        if (!(((formBitsIndex + width) <= formBitsSize) && ((width * 3) <= pixelLineSize))) {
 
113
                return interpreterProxy->primitiveFail();
 
114
        }
 
115
        
 
116
        formBits += formBitsIndex-1;
 
117
        while(width--) {
 
118
                unsigned int rgb;
 
119
                rgb = (*pixelLine++);
 
120
                rgb += (*pixelLine++) << 8;
 
121
                rgb += (*pixelLine++) << 16;
 
122
                if(rgb) rgb |= 0xFF000000; else rgb |= 0xFF000001;
 
123
                *formBits++ = rgb;
 
124
        }
 
125
        ;
 
126
        interpreterProxy->pop(4);
 
127
}
 
128
 
 
129
EXPORT(int) primitiveWrite24BmpLine(void) {
 
130
    int formBitsOop;
 
131
    unsigned char * pixelLine;
 
132
    unsigned int * formBits;
 
133
    int formBitsSize;
 
134
    int formBitsIndex;
 
135
    int pixelLineOop;
 
136
    int pixelLineSize;
 
137
    int width;
 
138
 
 
139
        if (!((interpreterProxy->methodArgumentCount()) == 4)) {
 
140
                return interpreterProxy->primitiveFail();
 
141
        }
 
142
        width = interpreterProxy->stackIntegerValue(0);
 
143
        formBitsIndex = interpreterProxy->stackIntegerValue(1);
 
144
        formBitsOop = interpreterProxy->stackObjectValue(2);
 
145
        pixelLineOop = interpreterProxy->stackObjectValue(3);
 
146
        if (interpreterProxy->failed()) {
 
147
                return null;
 
148
        }
 
149
        if (!(interpreterProxy->isWords(formBitsOop))) {
 
150
                return interpreterProxy->primitiveFail();
 
151
        }
 
152
        if (!(interpreterProxy->isBytes(pixelLineOop))) {
 
153
                return interpreterProxy->primitiveFail();
 
154
        }
 
155
        formBitsSize = interpreterProxy->slotSizeOf(formBitsOop);
 
156
        formBits = interpreterProxy->firstIndexableField(formBitsOop);
 
157
        pixelLineSize = interpreterProxy->slotSizeOf(pixelLineOop);
 
158
        pixelLine = interpreterProxy->firstIndexableField(pixelLineOop);
 
159
        if (!(((formBitsIndex + width) <= formBitsSize) && ((width * 3) <= pixelLineSize))) {
 
160
                return interpreterProxy->primitiveFail();
 
161
        }
 
162
        
 
163
        formBits += formBitsIndex-1;
 
164
 
 
165
        while(width--) {
 
166
                unsigned int rgb;
 
167
                rgb = *formBits++;
 
168
                (*pixelLine++) = (rgb      ) & 0xFF;
 
169
                (*pixelLine++) = (rgb >> 8 ) & 0xFF;
 
170
                (*pixelLine++) = (rgb >> 16) & 0xFF;
 
171
        }
 
172
 
 
173
        ;
 
174
        interpreterProxy->pop(4);
 
175
}
 
176
 
 
177
 
 
178
/*      Note: This is coded so that is can be run from Squeak. */
 
179
 
 
180
EXPORT(int) setInterpreter(struct VirtualMachine* anInterpreter) {
 
181
    int ok;
 
182
 
 
183
        interpreterProxy = anInterpreter;
 
184
        ok = interpreterProxy->majorVersion() == VM_PROXY_MAJOR;
 
185
        if (ok == 0) {
 
186
                return 0;
 
187
        }
 
188
        ok = interpreterProxy->minorVersion() >= VM_PROXY_MINOR;
 
189
        return ok;
 
190
}
 
191
 
 
192
 
 
193
#ifdef SQUEAK_BUILTIN_PLUGIN
 
194
 
 
195
 
 
196
void* BMPReadWriterPlugin_exports[][3] = {
 
197
        {"BMPReadWriterPlugin", "primitiveRead24BmpLine", (void*)primitiveRead24BmpLine},
 
198
        {"BMPReadWriterPlugin", "getModuleName", (void*)getModuleName},
 
199
        {"BMPReadWriterPlugin", "primitiveWrite24BmpLine", (void*)primitiveWrite24BmpLine},
 
200
        {"BMPReadWriterPlugin", "setInterpreter", (void*)setInterpreter},
 
201
        {NULL, NULL, NULL}
 
202
};
 
203
 
 
204
 
 
205
#endif /* ifdef SQ_BUILTIN_PLUGIN */
 
206