Subversion Repositories Kolibri OS

Rev

Rev 2680 | Rev 3014 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2680 dunkaist 1
use32
2
org 0x0
3
 
4
db 'MENUET01'
5
dd 0x01, START, I_END, 0x1000, 0x1000, 0, 0
6
 
7
;-----------------------------------------------------------------------------
8
 
9
include '../../../../../proc32.inc'
10
include '../../../../../macros.inc'
11
include '../dll.inc'
12
 
13
include '../../libio/libio.inc'
14
include '../../libimg/libimg.inc'
15
 
16
;-----------------------------------------------------------------------------
17
 
18
START:
19
	mcall	68, 11
20
 
21
	stdcall dll.Load, @IMPORT
22
	or	eax, eax
23
	jnz	exit
24
 
25
	invoke	file.open, input_file, O_READ
26
	or	eax, eax
27
	jz	exit
28
	mov	[fh], eax
29
 
30
	invoke	file.size, input_file
31
	mov	[img_data_len], ebx
32
	stdcall mem.Alloc, ebx
33
	or	eax, eax
34
	jz	exit
35
	mov	[img_data], eax
36
 
37
	invoke	file.read, [fh], eax, [img_data_len]
38
	cmp	eax, -1
39
	je	exit
40
	cmp	eax, [img_data_len]
41
	jne	exit
42
 
43
	invoke	file.close, [fh]
44
	inc	eax
45
	jz	exit
46
 
47
	invoke	img.decode, [img_data], [img_data_len], 0
48
	or	eax, eax
49
	jz	exit
50
	mov	[image_initial], eax
51
 
52
	stdcall	mem.Free, [img_data]
53
	test	eax, eax
54
	jz	exit
55
 
56
;-----------------------------------------------------------------------------
57
 
58
	mov	eax, [image_initial]
59
	stdcall	[img.create], [eax + Image.Width], [eax + Image.Height], Image.bpp24
60
	test	eax, eax
61
	jz	exit
62
	mov	[image_to_rgb2] ,eax
63
	stdcall [img.to_rgb2], [image_initial], [eax + Image.Data]
64
 
65
	mov	eax, [image_to_rgb2]
66
	mov	esi, [eax + Image.Data]
67
	mov	edi, esi
68
	mov	ecx, [eax + Image.Width]
69
	imul	ecx, [eax + Image.Height]
70
	lea	ecx, [ecx*3]
71
    @@:
72
	lodsb
73
	not	al
74
	stosb
75
	dec	ecx
76
	jnz	@b
2685 dunkaist 77
 
78
	stdcall	[img.encode], [image_to_rgb2], (LIBIMG_FORMAT_ID_PNM), 0
79
;	stdcall	[img.encode], [image_initial], (LIBIMG_FORMAT_ID_PNM), 0
80
	test	eax, eax
81
	jz	exit
82
	mov	[encoded_file], eax
83
	mov	[encoded_file_size], ecx
84
 
85
	invoke	file.open, output_file, O_WRITE OR O_CREATE
86
	or	eax, eax
87
	jz	exit
88
	mov	[fh], eax
89
 
90
	invoke	file.write, [fh], [encoded_file], [encoded_file_size]
91
	cmp	eax, [encoded_file_size]
92
	jne	exit
93
 
94
	invoke	file.close, [fh]
95
	inc	eax
96
	jz	exit
97
 
98
	stdcall	mem.Free, [encoded_file]
2680 dunkaist 99
;-----------------------------------------------------------------------------
100
 
101
redraw:
102
	call	draw_window
103
 
104
still:
105
	mcall	10
106
	cmp	eax, 1
107
	je	redraw
108
	cmp	eax, 2
109
	je	key
110
	cmp	eax, 3
111
	je	button
112
	jmp	still
113
 
114
  key:
115
	mcall	2
116
	jmp	still
117
 
118
  button:
119
	mcall	17
120
	shr	eax, 8
121
 
122
	cmp	eax, 1
123
	jne	still
124
 
125
  exit:
126
	cmp	[image_initial], 0
127
	je	@f
128
	stdcall	[img.destroy], [image_initial]
129
    @@:
130
	cmp	[image_to_rgb2], 0
131
	je	@f
132
	stdcall	[img.destroy], [image_to_rgb2]
133
    @@:
134
	mcall	-1
135
 
136
 
137
draw_window:
138
	mcall	12, 1
139
	mcall	0, <100, 388>, <100, 350>, 0x33FFFFFF, , window_title
140
 
141
	mov	eax, [image_initial]
142
	stdcall	[img.draw], eax, 0, 0, [eax + Image.Width], [eax + Image.Height], 0, 0
143
 
144
	mov	eax, [image_to_rgb2]
145
	stdcall	[img.draw], eax, 0, [eax + Image.Height], [eax + Image.Width], [eax + Image.Height], 0, 0
146
 
147
	mcall	12, 2
148
	ret
149
 
150
;-----------------------------------------------------------------------------
151
proc mem.Alloc, size ;////////////////////////////////////////////////////////
152
;-----------------------------------------------------------------------------
153
	push	ebx ecx
154
	mov	ecx, [size]
155
	add	ecx, 4
156
	mcall	68, 12
157
	add	ecx, -4
158
	mov	[eax], ecx
159
	add	eax, 4
160
	pop	ecx ebx
161
	ret
162
endp
163
 
164
;-----------------------------------------------------------------------------
165
proc mem.ReAlloc, mptr, size ;////////////////////////////////////////////////
166
;-----------------------------------------------------------------------------
167
	push	ebx ecx edx
168
	mov	ecx, [size]
169
	or	ecx, ecx
170
	jz	@f
171
	add	ecx, 4
172
    @@: mov	edx, [mptr]
173
	or	edx, edx
174
	jz	@f
175
	add	edx, -4
176
    @@: mcall	68, 20
177
	or	eax, eax
178
	jz	@f
179
	add	ecx, -4
180
	mov	[eax], ecx
181
	add	eax, 4
182
    @@: pop	edx ecx ebx
183
	ret
184
endp
185
 
186
;-----------------------------------------------------------------------------
187
proc mem.Free, mptr ;/////////////////////////////////////////////////////////
188
;-----------------------------------------------------------------------------
189
	push	ebx ecx
190
	mov	ecx, [mptr]
191
	or	ecx, ecx
192
	jz	@f
193
	add	ecx, -4
194
    @@: mcall	68, 13
195
	pop	ecx ebx
196
	ret
197
endp
198
 
199
;-----------------------------------------------------------------------------
200
 
2685 dunkaist 201
window_title	db 'libimg to_rgb2 & encode demo',0
2680 dunkaist 202
 
2685 dunkaist 203
;input_file	db '/hd0/1/in_1bpp.wbmp',0
204
;input_file	db '/hd0/1/in_8bpp.tiff',0
2680 dunkaist 205
input_file	db '/hd0/1/in_32bpp.png',0
2685 dunkaist 206
 
207
;output_file	db '/hd0/1/out_1bpp.pnm',0
208
;output_file	db '/hd0/1/out_8bpp.pnm',0
209
output_file	db '/hd0/1/out_24bpp.pnm',0
2680 dunkaist 210
;-----------------------------------------------------------------------------
211
 
212
align 16
213
@IMPORT:
214
 
215
library 			\
216
	libio  , 'libio.obj'  , \
217
	libimg , 'libimg.obj'
218
 
219
import	libio			  , \
220
	libio.init , 'lib_init'   , \
221
	file.size  , 'file_size'  , \
222
	file.open  , 'file_open'  , \
223
	file.read  , 'file_read'  , \
2685 dunkaist 224
	file.write , 'file_write' , \
2680 dunkaist 225
	file.close , 'file_close'
226
 
227
import	libimg			   , \
228
	libimg.init , 'lib_init'   , \
229
	img.draw    , 'img_draw'   , \
230
	img.decode  , 'img_decode' , \
2685 dunkaist 231
	img.encode  , 'img_encode' , \
2680 dunkaist 232
	img.create  , 'img_create' , \
233
	img.destroy , 'img_destroy', \
2685 dunkaist 234
	img.to_rgb2 , 'img_to_rgb2', \
235
	img.formats_table, 'img_formats_table'
2680 dunkaist 236
 
237
;-----------------------------------------------------------------------------
238
 
239
I_END:
240
 
2685 dunkaist 241
img_data	  dd ?
242
img_data_len	  dd ?
243
fh		  dd ?
2680 dunkaist 244
 
2685 dunkaist 245
image_initial	  dd ?
246
image_to_rgb2	  dd ?
247
 
248
encoded_file	  dd ?
249
encoded_file_size dd ?