-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathezutil.c
More file actions
767 lines (665 loc) · 17.1 KB
/
Copy pathezutil.c
File metadata and controls
767 lines (665 loc) · 17.1 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/* ezutil.c
Copyright (C) 2013 "Andy Xuming" <xuming@users.sourceforge.net>
This file is part of EZTHUMB, a utility to generate thumbnails
EZTHUMB 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 3 of the License, or
(at your option) any later version.
EZTHUMB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#else
#error "Run configure first"
#endif
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <ctype.h>
#include <math.h>
#include "libcsoup.h"
#include "ezthumb.h"
/* re-use the debug convention in libcsoup */
#define CSOUP_DEBUG_LOCAL SLOG_CWORD(EZTHUMB_MOD_CORE, SLOG_LVL_WARNING)
#include "libcsoup_debug.h"
static int ezopt_profile_append(EZOPT *ezopt, char *ps);
static char *ezopt_profile_sprint(EZPROF *node, char *buf, int blen);
static EZPROF *ezopt_profile_new(EZOPT *opt, int flag, int wei);
static int ezopt_profile_free(EZPROF *node);
static EZPROF *ezopt_profile_insert(EZPROF *root, EZPROF *leaf);
/****************************************************************************
* Profile Functions
****************************************************************************/
int ezopt_profile_setup(EZOPT *opt, char *s)
{
char *tmp, *plist[64]; /* hope that's big enough */
int i, len;
/* duplicate the input profile string */
if ((tmp = csc_strcpy_alloc(s, 0)) == NULL) {
return -1;
}
/* Reset the profile control block pool */
memset(opt->pro_pool, 0, sizeof(EZPROF) * EZ_PROF_MAX_ENTRY);
opt->pro_grid = opt->pro_size = NULL;
len = csc_ziptoken(tmp, plist, sizeof(plist)/sizeof(char*), ":");
for (i = 0; i < len; i++) {
ezopt_profile_append(opt, plist[i]);
}
/* 20170515 using mask to enable or disable the profile */
opt->pro_mask = EZ_PROF_ALL;
smm_free(tmp);
return 0;
}
/* for debug purpose only */
int ezopt_profile_dump(EZOPT *opt, char *pmt_grid, char *pmt_size)
{
EZPROF *node;
char tmp[64];
CDB_SHOW(("%s", pmt_grid)); /* "Grid: " */
for (node = opt->pro_grid; node != NULL; node = node->next) {
CDB_SHOW(("%s ",ezopt_profile_sprint(node, tmp, sizeof(tmp))));
}
CDB_SHOW(("\n"));
CDB_SHOW(("%s", pmt_size)); /* "Size: " */
for (node = opt->pro_size; node != NULL; node = node->next) {
CDB_SHOW(("%s ",ezopt_profile_sprint(node, tmp, sizeof(tmp))));
}
CDB_SHOW(("\n"));
return 0;
}
int ezopt_profile_export(EZOPT *ezopt, char *buf, int blen)
{
EZPROF *p;
char tmp[80];
int idx, len;
idx = 0;
for (p = ezopt->pro_grid; p; p = p->next) {
ezopt_profile_sprint(p, tmp, sizeof(tmp));
strcat(tmp, ":");
len = strlen(tmp);
if (buf && ((idx + len) < blen)) {
strcpy(buf + idx, tmp);
}
idx += len;
}
for (p = ezopt->pro_size; p; p = p->next) {
ezopt_profile_sprint(p, tmp, sizeof(tmp));
strcat(tmp, ":");
len = strlen(tmp);
if (buf && ((idx + len) < blen)) {
strcpy(buf + idx, tmp);
}
idx += len;
}
/* remove the last delimiter */
if (idx) {
idx--;
if (buf) {
buf[idx] = 0;
}
}
CDB_DEBUG(("ezopt_profile_export: %s\n", buf));
return idx;
}
char *ezopt_profile_export_alloc(EZOPT *ezopt)
{
char *s;
int len;
len = ezopt_profile_export(ezopt, NULL, 0) + 4;
if ((s = smm_alloc(len)) != NULL) {
ezopt_profile_export(ezopt, s, len);
}
return s;
}
int ezopt_profile_enable(EZOPT *ezopt, int prof)
{
ezopt->pro_mask |= prof;
return ezopt_profile_stat(ezopt);
}
int ezopt_profile_disable(EZOPT *ezopt, int prof)
{
ezopt->pro_mask &= ~prof;
return ezopt_profile_stat(ezopt);
}
/*int ezopt_profile_disable(EZOPT *ezopt, int prof)
{
if (prof == EZ_PROF_LENGTH) {
ezopt->pro_grid = NULL;
} else if (prof == EZ_PROF_WIDTH) {
ezopt->pro_size = NULL;
} else if (prof == EZ_PROF_ALL) {
ezopt->pro_grid = NULL;
ezopt->pro_size = NULL;
}
return 0;
}*/
int ezopt_profile_stat(EZOPT *ezopt)
{
if ((ezopt->pro_mask == EZ_PROF_ALL) &&
ezopt->pro_grid && ezopt->pro_size) {
return EZ_PROF_ALL;
}
if ((ezopt->pro_mask & EZ_PROF_LENGTH) && ezopt->pro_grid) {
return EZ_PROF_LENGTH;
}
if ((ezopt->pro_mask & EZ_PROF_WIDTH) && ezopt->pro_size) {
return EZ_PROF_WIDTH;
}
return 0; /* totally disabled */
}
int ezopt_profile_sampling(EZOPT *ezopt, int vidsec, int *col, int *row)
{
EZPROF *node;
int snap;
if ((ezopt_profile_stat(ezopt) & EZ_PROF_LENGTH) == 0) {
return -1; /* profile disabled */
}
for (node = ezopt->pro_grid; node->next; node = node->next) {
if (vidsec <= node->weight) {
break;
}
}
switch (node->flag) {
case 's':
case 'S':
case 'm':
case 'M':
if (col) {
*col = node->x;
}
if (row) {
*row = node->y;
}
CDB_DEBUG(("ezopt_profile_sampling: %d x %d\n",
node->x, node->y));
return 0; /* returned the matrix */
case 'l':
case 'L':
snap = (int)(log(vidsec / 60 + node->x) / log(node->lbase))
- node->y;
CDB_DEBUG(("ezopt_profile_sampling: %d+\n", snap));
return snap; /* need more info to decide the matrix */
}
return -2; /* no effective profile found */
}
int ezopt_profile_sampled(EZOPT *ezopt, int vw, int bs, int *col, int *row)
{
EZPROF *node;
if ((ezopt_profile_stat(ezopt) & EZ_PROF_WIDTH) == 0) {
return bs; /* profile disabled so ignore it */
}
for (node = ezopt->pro_size; node->next; node = node->next) {
if (vw <= node->weight) {
break;
}
}
switch (node->flag) {
case 'f':
case 'F':
case 'r':
case 'R':
if (col) {
*col = node->x;
}
bs = (bs + node->x - 1) / node->x * node->x;
if (row) {
*row = bs / node->x;
}
break;
}
CDB_DEBUG(("ezopt_profile_sampled: %d\n", bs));
return bs;
}
int ezopt_profile_zooming(EZOPT *ezopt, int vw, int *wid, int *hei, int *ra)
{
EZPROF *node;
float ratio;
int neari;
if ((ezopt_profile_stat(ezopt) & EZ_PROF_WIDTH) == 0) {
return 0; /* profile disabled so ignore it */
}
for (node = ezopt->pro_size; node->next; node = node->next) {
if (vw <= node->weight) {
break;
}
}
switch (node->flag) {
case 'w':
case 'W':
if (ra) {
*ra = node->x;
}
break;
case 't':
case 'T':
if (wid) {
*wid = node->x;
}
if (hei) {
*hei = node->y;
}
break;
case 'f':
case 'F':
return node->y; /* return the canvas size if required */
case 'r':
case 'R':
/* find the zoom ratio */
if (vw > node->y) {
ratio = (float) vw / node->y; /* zoom out */
} else {
ratio = (float) node->y / vw; /* zoom in */
}
/* quantized the zoom ratio to base-2 exponential 1,2,4,8.. */
neari = 1 << (int)(log(ratio) / log(2) + 0.5);
CDB_DEBUG(("ezopt_profile_zooming: ratio=%f quant=%d\n",
ratio, neari));
/* checking the error between the reference width and the
* zoomed width. The error should be less than 20% */
ratio = abs(neari * node->y - vw) / (float) node->y;
if (ratio > 0.2) {
neari = node->y; /* error over 20% */
} else if (vw > node->y) {
neari = vw / neari;
} else {
neari = vw * neari;
}
if (wid) {
*wid = neari / 2 * 2; /* final quantizing width */
}
break;
}
//printf("ezopt_profile_zooming: %d %d\n", *wid, *hei);
return 0;
}
/* available profile field example:
* 12M4x6, 720s4x6, 720S4
* 160w200%, 320w100%, 320w160x120, 320w160 */
static int ezopt_profile_append(EZOPT *ezopt, char *ps)
{
EZPROF *node;
char pbuf[256], *argv[8];
int val;
csc_strlcpy(pbuf, ps, sizeof(pbuf));
val = (int) strtol(pbuf, &ps, 10);
if (*ps == 0) { /* pointed to the EOL; no flag error */
return -1;
}
csc_fixtoken(ps + 1, argv, sizeof(argv)/sizeof(char*), "xX");
node = ezopt_profile_new(ezopt, *ps, val);
switch (node->flag) {
case 'm':
case 'M':
node->weight *= 60; /* turn to seconds */
node->x = (int) strtol(argv[0], NULL, 10);
node->y = argv[1] ? (int) strtol(argv[1], NULL, 10) : 0;
ezopt->pro_grid = ezopt_profile_insert(ezopt->pro_grid, node);
break;
case 's':
case 'S':
node->x = (int) strtol(argv[0], NULL, 10);
node->y = argv[1] ? (int) strtol(argv[1], NULL, 10) : 0;
ezopt->pro_grid = ezopt_profile_insert(ezopt->pro_grid, node);
break;
case 'l':
case 'L':
if ((argv[1] == NULL) || (argv[2] == NULL)) {
ezopt_profile_free(node);
return -2;
}
node->weight *= 60; /* turn to seconds */
node->x = (int) strtol(argv[0], NULL, 10);
node->y = (int) strtol(argv[1], NULL, 10);
node->lbase = strtod(argv[2], NULL);
ezopt->pro_grid = ezopt_profile_insert(ezopt->pro_grid, node);
break;
case 'w':
case 'W':
node->x = (int) strtol(argv[0], NULL, 10);
ezopt->pro_size = ezopt_profile_insert(ezopt->pro_size, node);
break;
case 't':
case 'T':
node->x = (int) strtol(argv[0], NULL, 10);
node->y = argv[1] ? (int) strtol(argv[1], NULL, 10) : 0;
ezopt->pro_size = ezopt_profile_insert(ezopt->pro_size, node);
break;
case 'f':
case 'F':
case 'r':
case 'R':
node->x = (int) strtol(argv[0], NULL, 10);
if (argv[1] == NULL) {
ezopt_profile_free(node);
return -2;
}
node->y = (int) strtol(argv[1], NULL, 10);
if (node->y <= 0) {
ezopt_profile_free(node);
return -2;
}
ezopt->pro_size = ezopt_profile_insert(ezopt->pro_size, node);
break;
default:
ezopt_profile_free(node);
return -2;
}
return 0;
}
static char *ezopt_profile_sprint(EZPROF *node, char *buf, int blen)
{
char tmp[64];
if (blen < 32) { /* FIXME: very rough estimation */
return NULL;
}
switch (node->flag) {
case 'm':
case 'M':
sprintf(buf, "%dM%d", node->weight / 60, node->x);
if (node->y > 0) {
sprintf(tmp, "x%d", node->y);
strcat(buf, tmp);
}
break;
case 's':
case 'S':
sprintf(buf, "%dS%d", node->weight, node->x);
if (node->y > 0) {
sprintf(tmp, "x%d", node->y);
strcat(buf, tmp);
}
break;
case 'l':
case 'L':
sprintf(buf, "%dL%dx%dx%f", node->weight / 60,
node->x, node->y, (float) node->lbase);
break;
case 'w':
case 'W':
sprintf(buf, "%dW%d%%", node->weight, node->x);
break;
case 't':
case 'T':
sprintf(buf, "%dT%d", node->weight, node->x);
if (node->y > 0) {
sprintf(tmp, "x%d", node->y);
strcat(buf, tmp);
}
break;
case 'f':
case 'F':
sprintf(buf, "%dF%dx%d", node->weight, node->x, node->y);
break;
case 'r':
case 'R':
sprintf(buf, "%dR%dx%d", node->weight, node->x, node->y);
break;
default:
return NULL;
}
return buf;
}
static EZPROF *ezopt_profile_new(EZOPT *opt, int flag, int wei)
{
int i;
for (i = 0; i < EZ_PROF_MAX_ENTRY; i++) {
if (opt->pro_pool[i].flag == 0) {
break;
}
}
if (i == EZ_PROF_MAX_ENTRY) {
return NULL;
}
memset(&opt->pro_pool[i], 0, sizeof(EZPROF));
opt->pro_pool[i].next = NULL;
opt->pro_pool[i].flag = flag;
opt->pro_pool[i].weight = wei;
return &opt->pro_pool[i];
}
/* note that it's NOT a proper free since the 'next' point was not processed
* at all. It only serves as a quick release */
static int ezopt_profile_free(EZPROF *node)
{
memset(node, 0, sizeof(EZPROF));
return 0;
}
static EZPROF *ezopt_profile_insert(EZPROF *root, EZPROF *leaf)
{
EZPROF *prev, *now;
if (leaf == NULL) {
return root; /* do nothing */
}
CDB_DEBUG(("ezopt_profile_insert: %d\n", leaf->weight));
if (root == NULL) {
return leaf;
}
if (root->weight > leaf->weight) {
leaf->next = root;
return leaf;
}
prev = root;
for (now = root->next; now != NULL; prev = now, now = now->next) {
if (now->weight > leaf->weight) {
break;
}
}
if (now == NULL) {
prev->next = leaf;
} else {
leaf->next = prev->next;
prev->next = leaf;
}
return root;
}
/****************************************************************************
* Data transform Functions
****************************************************************************/
char *meta_filesize(int unit, int64_t size, char *buffer)
{
static char tmp[32];
if (buffer == NULL) {
buffer = tmp;
}
switch (unit) {
case 'b':
sprintf(buffer, "%llu Bytes", (unsigned long long) size);
break;
case 'k':
sprintf(buffer, "%.2f KB", size / 1024.0);
break;
case 'm':
sprintf(buffer, "%.2f MB", size / 1048576.0);
break;
case 'g':
sprintf(buffer, "%.2f GB", size / 1073741824.0);
break;
default: /* auto */
if (size < (int64_t)(1ULL << 20)) {
sprintf(buffer, "%.2f KB", size / 1024.0);
} else if (size < (int64_t)(1ULL << 30)) {
sprintf(buffer, "%.2f MB", size / 1048576.0);
} else {
sprintf(buffer, "%.2f GB", size / 1073741824.0);
}
break;
}
return buffer;
}
char *meta_timestamp(EZTIME ms, int enms, char *buffer)
{
static char tmp[32];
int hour, min, sec, msec;
if (buffer == NULL) {
buffer = tmp;
}
hour = ms / 3600000;
ms = ms % 3600000;
min = ms / 60000;
ms = ms % 60000;
sec = ms / 1000;
msec = ms % 1000;
if (enms) {
sprintf(buffer, "%d:%02d:%02d,%03d", hour, min, sec, msec);
} else {
sprintf(buffer, "%d:%02d:%02d", hour, min, sec);
}
return buffer;
}
/* input: jpg@85, gif@1000, png */
/* 20190510 In GUI configuration file the image format can be:
* "Jpeg", "Png", "Animated GIF" or "GIF", therefore the form like
* "Animated GIF@1000" is also supported. To be compatible with CLI version,
* the output string will be reformed to "jpg", "gif" or "png". */
int meta_image_format(char *input)
{
char *p, arg[128];
int format, quality = 0;
csc_strlcpy(arg, input, sizeof(arg));
if ((p = strchr(arg, '@')) != NULL) {
*p++ = 0;
quality = strtol(p, NULL, 0);
}
/* foolproof of the quality parameter */
if (!strcasecmp(arg, "png")) {
format = EZ_IMG_INIT(EZ_IMG_FMT_PNG, quality);
} else if (!strcasecmp(arg, "gif")) {
if (quality == 0) {
format = EZ_IMG_INIT(EZ_IMG_FMT_GIF, 0);
} else if (quality < 15) {
format = EZ_IMG_INIT(EZ_IMG_FMT_GIFA, 1000);
} else {
format = EZ_IMG_INIT(EZ_IMG_FMT_GIFA, quality);
}
} else if (!strcasecmp(arg, "Animated GIF")) {
if (quality == 0) {
format = EZ_IMG_INIT(EZ_IMG_FMT_GIFA, 1000);
} else {
format = EZ_IMG_INIT(EZ_IMG_FMT_GIFA, quality);
}
} else { /* jpeg is the default */
if ((quality < 5) || (quality > 100)) {
quality = 85; /* as default */
}
format = EZ_IMG_INIT(EZ_IMG_FMT_JPEG, quality);
}
return format;
}
char *meta_image_abbre(int fmt)
{
static const char *image[] = { "jpg", "png", "gif" };
switch (EZ_IMG_FMT_GET(fmt)) {
case EZ_IMG_FMT_PNG:
return (char*) image[1];
case EZ_IMG_FMT_GIF:
case EZ_IMG_FMT_GIFA:
return (char*) image[2];
}
return (char*) image[0];
}
int meta_make_color(char *s, EZBYTE *color)
{
unsigned rc;
rc = (unsigned) strtol(s, NULL, 16);
if (color) {
color[0] = (unsigned char)((rc >> 16) & 0xff);
color[1] = (unsigned char)((rc >> 8) & 0xff);
color[2] = (unsigned char)(rc & 0xff);
color[3] = (unsigned char)((rc >> 24) & 0xff);
}
return (int)rc;
}
int meta_export_color(EZBYTE *color, char *buf, int blen)
{
char tmp[16];
int rc, len;
rc = (color[3] << 24) | (color[0] << 16) | (color[1] << 8) | color[2];
len = sprintf(tmp, "%x", (unsigned) rc);
if (buf && (blen > len)) {
strcpy(buf, tmp);
}
return len;
}
char *meta_make_fontdir(char *s)
{
/* review whether the fontconfig pattern like "times:bold:italic"
* was specified. The fontconfig pattern could be used directly.
* Otherwise a full path like "/usr/local/share/ttf/Times.ttf" */
if (!csc_cmp_file_extname(s, "ttf") ||
!csc_cmp_file_extname(s, "ttc")) {
return smm_fontpath(s, NULL);
}
/* the fontconfig pattern like "times:bold:italic" shouldn't be messed
* with path like smb://sdfaadf/abc or c:\fonts\somefont */
if (strchr(s, '/') || strchr(s, '\\')) {
return smm_fontpath(s, NULL);
}
/* other forms were supposed to be fontconfig patterns */
if (gdFTUseFontConfig(1)) {
return csc_strcpy_alloc(s, 0);
}
/* FontConfig is not available then convert the font face to
* the full path of font file */
if ((s = ezttf_faceoff(s)) != NULL) {
return csc_strcpy_alloc(s, 0);
}
return NULL; /* default font */
}
static EZBYTE alpha_store = 0x80;
/* 20170530 Using this function instead of direct accessing the 'flag' field
* so the alpha channel data would be consistent.
* flag: EZOP_TRANSPARENT: set transparent
* 0: set opaque
* < 0: read the transparent status
*/
int meta_transparent_option(EZOPT *opt, int flag)
{
if (flag == EZOP_TRANSPARENT) { /* set transparent */
if ((opt->flags & EZOP_TRANSPARENT) == 0) {
opt->flags |= EZOP_TRANSPARENT;
alpha_store = opt->canvas_color[3];
opt->canvas_color[3] = 0;
}
}
if (flag == 0) { /* set opaque */
if (opt->flags & EZOP_TRANSPARENT) {
opt->flags &= ~EZOP_TRANSPARENT;
opt->canvas_color[3] = alpha_store;
}
}
return (opt->flags & EZOP_TRANSPARENT);
}