mirrored from https://gitlab.winehq.org/wine/wine.git
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
image.c
6139 lines (5171 loc) · 183 KB
/
image.c
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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2007 Google (Evan Stade)
* Copyright (C) 2012,2016 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <assert.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "wingdi.h"
#define COBJMACROS
#include "objbase.h"
#include "olectl.h"
#include "ole2.h"
#include "initguid.h"
#include "wincodec.h"
#include "gdiplus.h"
#include "gdiplus_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory**);
#define WMF_PLACEABLE_KEY 0x9ac6cdd7
static const struct
{
const WICPixelFormatGUID *wic_format;
PixelFormat gdip_format;
/* predefined palette type to use for pixel format conversions */
WICBitmapPaletteType palette_type;
} pixel_formats[] =
{
{ &GUID_WICPixelFormat1bppIndexed, PixelFormat1bppIndexed, WICBitmapPaletteTypeFixedBW },
{ &GUID_WICPixelFormatBlackWhite, PixelFormat1bppIndexed, WICBitmapPaletteTypeFixedBW },
{ &GUID_WICPixelFormat4bppIndexed, PixelFormat4bppIndexed, WICBitmapPaletteTypeFixedHalftone8 },
{ &GUID_WICPixelFormat8bppIndexed, PixelFormat8bppIndexed, WICBitmapPaletteTypeFixedHalftone256 },
{ &GUID_WICPixelFormat8bppGray, PixelFormat8bppIndexed, WICBitmapPaletteTypeFixedGray256 },
{ &GUID_WICPixelFormat16bppBGR555, PixelFormat16bppRGB555, 0 },
{ &GUID_WICPixelFormat24bppBGR, PixelFormat24bppRGB, 0 },
{ &GUID_WICPixelFormat32bppBGR, PixelFormat32bppRGB, 0 },
{ &GUID_WICPixelFormat32bppBGRA, PixelFormat32bppARGB, 0 },
{ &GUID_WICPixelFormat32bppPBGRA, PixelFormat32bppPARGB, 0 },
{ NULL }
};
static ColorPalette *get_palette(IWICBitmapFrameDecode *frame, WICBitmapPaletteType palette_type)
{
HRESULT hr;
IWICImagingFactory *factory;
IWICPalette *wic_palette;
ColorPalette *palette = NULL;
hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
if (hr != S_OK) return NULL;
hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
if (hr == S_OK)
{
hr = WINCODEC_ERR_PALETTEUNAVAILABLE;
if (frame)
hr = IWICBitmapFrameDecode_CopyPalette(frame, wic_palette);
if (hr != S_OK && palette_type != 0)
{
TRACE("using predefined palette %#x\n", palette_type);
hr = IWICPalette_InitializePredefined(wic_palette, palette_type, FALSE);
}
if (hr == S_OK)
{
WICBitmapPaletteType type;
BOOL alpha;
UINT count;
IWICPalette_GetColorCount(wic_palette, &count);
palette = malloc(2 * sizeof(UINT) + count * sizeof(ARGB));
IWICPalette_GetColors(wic_palette, count, (UINT *)palette->Entries, &palette->Count);
IWICPalette_GetType(wic_palette, &type);
switch(type) {
case WICBitmapPaletteTypeFixedGray4:
case WICBitmapPaletteTypeFixedGray16:
case WICBitmapPaletteTypeFixedGray256:
palette->Flags = PaletteFlagsGrayScale;
break;
case WICBitmapPaletteTypeFixedHalftone8:
case WICBitmapPaletteTypeFixedHalftone27:
case WICBitmapPaletteTypeFixedHalftone64:
case WICBitmapPaletteTypeFixedHalftone125:
case WICBitmapPaletteTypeFixedHalftone216:
case WICBitmapPaletteTypeFixedHalftone252:
case WICBitmapPaletteTypeFixedHalftone256:
palette->Flags = PaletteFlagsHalftone;
break;
default:
palette->Flags = 0;
}
IWICPalette_HasAlpha(wic_palette, &alpha);
if(alpha)
palette->Flags |= PaletteFlagsHasAlpha;
}
IWICPalette_Release(wic_palette);
}
IWICImagingFactory_Release(factory);
return palette;
}
static HRESULT set_palette(IWICBitmapFrameEncode *frame, ColorPalette *palette)
{
HRESULT hr;
IWICImagingFactory *factory;
IWICPalette *wic_palette;
hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
if (FAILED(hr))
return hr;
hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
IWICImagingFactory_Release(factory);
if (SUCCEEDED(hr))
{
hr = IWICPalette_InitializeCustom(wic_palette, (UINT *)palette->Entries, palette->Count);
if (SUCCEEDED(hr))
hr = IWICBitmapFrameEncode_SetPalette(frame, wic_palette);
IWICPalette_Release(wic_palette);
}
return hr;
}
GpStatus WINGDIPAPI GdipBitmapApplyEffect(GpBitmap* bitmap, CGpEffect* effect,
RECT* roi, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
{
FIXME("(%p %p %p %d %p %p): stub\n", bitmap, effect, roi, useAuxData, auxData, auxDataSize);
/*
* Note: According to Jose Roca's GDI+ docs, this function is not
* implemented in Windows's GDI+.
*/
return NotImplemented;
}
GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap** inputBitmaps,
INT numInputs, CGpEffect* effect, RECT* roi, RECT* outputRect,
GpBitmap** outputBitmap, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
{
FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps, numInputs, effect, roi, outputRect, outputBitmap, useAuxData, auxData, auxDataSize);
/*
* Note: According to Jose Roca's GDI+ docs, this function is not
* implemented in Windows's GDI+.
*/
return NotImplemented;
}
static inline void getpixel_1bppIndexed(BYTE *index, const BYTE *row, UINT x)
{
*index = (row[x/8]>>(7-x%8)) & 1;
}
static inline void getpixel_4bppIndexed(BYTE *index, const BYTE *row, UINT x)
{
if (x & 1)
*index = row[x/2]&0xf;
else
*index = row[x/2]>>4;
}
static inline void getpixel_8bppIndexed(BYTE *index, const BYTE *row, UINT x)
{
*index = row[x];
}
static inline void getpixel_16bppGrayScale(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
*r = *g = *b = row[x*2+1];
*a = 255;
}
static inline void getpixel_16bppRGB555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
WORD pixel = *((const WORD*)(row)+x);
*r = (pixel>>7&0xf8)|(pixel>>12&0x7);
*g = (pixel>>2&0xf8)|(pixel>>6&0x7);
*b = (pixel<<3&0xf8)|(pixel>>2&0x7);
*a = 255;
}
static inline void getpixel_16bppRGB565(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
WORD pixel = *((const WORD*)(row)+x);
*r = (pixel>>8&0xf8)|(pixel>>13&0x7);
*g = (pixel>>3&0xfc)|(pixel>>9&0x3);
*b = (pixel<<3&0xf8)|(pixel>>2&0x7);
*a = 255;
}
static inline void getpixel_16bppARGB1555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
WORD pixel = *((const WORD*)(row)+x);
*r = (pixel>>7&0xf8)|(pixel>>12&0x7);
*g = (pixel>>2&0xf8)|(pixel>>6&0x7);
*b = (pixel<<3&0xf8)|(pixel>>2&0x7);
if ((pixel&0x8000) == 0x8000)
*a = 255;
else
*a = 0;
}
static inline void getpixel_24bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
*r = row[x*3+2];
*g = row[x*3+1];
*b = row[x*3];
*a = 255;
}
static inline void getpixel_32bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
*r = row[x*4+2];
*g = row[x*4+1];
*b = row[x*4];
*a = 255;
}
static inline void getpixel_32bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
*r = row[x*4+2];
*g = row[x*4+1];
*b = row[x*4];
*a = row[x*4+3];
}
static inline void getpixel_32bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
*a = row[x*4+3];
if (*a == 0)
{
*r = row[x*4+2];
*g = row[x*4+1];
*b = row[x*4];
}
else
{
DWORD scaled_q = (255 << 15) / *a;
*r = (row[x*4+2] > *a) ? 0xff : (row[x*4+2] * scaled_q) >> 15;
*g = (row[x*4+1] > *a) ? 0xff : (row[x*4+1] * scaled_q) >> 15;
*b = (row[x*4] > *a) ? 0xff : (row[x*4] * scaled_q) >> 15;
}
}
static inline void getpixel_48bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
*r = row[x*6+5];
*g = row[x*6+3];
*b = row[x*6+1];
*a = 255;
}
static inline void getpixel_64bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
*r = row[x*8+5];
*g = row[x*8+3];
*b = row[x*8+1];
*a = row[x*8+7];
}
static inline void getpixel_64bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
const BYTE *row, UINT x)
{
*a = row[x*8+7];
if (*a == 0)
*r = *g = *b = 0;
else
{
*r = row[x*8+5] * 255 / *a;
*g = row[x*8+3] * 255 / *a;
*b = row[x*8+1] * 255 / *a;
}
}
GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
ARGB *color)
{
BYTE r, g, b, a;
BYTE index;
BYTE *row;
if(!bitmap || !color ||
x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
return InvalidParameter;
row = bitmap->bits+bitmap->stride*y;
switch (bitmap->format)
{
case PixelFormat1bppIndexed:
getpixel_1bppIndexed(&index,row,x);
break;
case PixelFormat4bppIndexed:
getpixel_4bppIndexed(&index,row,x);
break;
case PixelFormat8bppIndexed:
getpixel_8bppIndexed(&index,row,x);
break;
case PixelFormat16bppGrayScale:
getpixel_16bppGrayScale(&r,&g,&b,&a,row,x);
break;
case PixelFormat16bppRGB555:
getpixel_16bppRGB555(&r,&g,&b,&a,row,x);
break;
case PixelFormat16bppRGB565:
getpixel_16bppRGB565(&r,&g,&b,&a,row,x);
break;
case PixelFormat16bppARGB1555:
getpixel_16bppARGB1555(&r,&g,&b,&a,row,x);
break;
case PixelFormat24bppRGB:
getpixel_24bppRGB(&r,&g,&b,&a,row,x);
break;
case PixelFormat32bppRGB:
getpixel_32bppRGB(&r,&g,&b,&a,row,x);
break;
case PixelFormat32bppARGB:
getpixel_32bppARGB(&r,&g,&b,&a,row,x);
break;
case PixelFormat32bppPARGB:
getpixel_32bppPARGB(&r,&g,&b,&a,row,x);
break;
case PixelFormat48bppRGB:
getpixel_48bppRGB(&r,&g,&b,&a,row,x);
break;
case PixelFormat64bppARGB:
getpixel_64bppARGB(&r,&g,&b,&a,row,x);
break;
case PixelFormat64bppPARGB:
getpixel_64bppPARGB(&r,&g,&b,&a,row,x);
break;
default:
FIXME("not implemented for format 0x%x\n", bitmap->format);
return NotImplemented;
}
if (bitmap->format & PixelFormatIndexed)
*color = bitmap->image.palette->Entries[index];
else
*color = a<<24|r<<16|g<<8|b;
return Ok;
}
static unsigned int absdiff(unsigned int x, unsigned int y)
{
return x > y ? x - y : y - x;
}
static inline UINT get_palette_index(BYTE r, BYTE g, BYTE b, BYTE a, ColorPalette *palette)
{
BYTE index = 0;
int best_distance = 0x7fff;
int distance;
UINT i;
if (!palette) return 0;
/* This algorithm scans entire palette,
computes difference from desired color (all color components have equal weight)
and returns the index of color with least difference.
Note: Maybe it could be replaced with a better algorithm for better image quality
and performance, though better algorithm would probably need some pre-built lookup
tables and thus may actually be slower if this method is called only few times per
every image.
*/
for(i=0;i<palette->Count;i++) {
ARGB color=palette->Entries[i];
distance=absdiff(b, color & 0xff) + absdiff(g, color>>8 & 0xff) + absdiff(r, color>>16 & 0xff) + absdiff(a, color>>24 & 0xff);
if (distance<best_distance) {
best_distance=distance;
index=i;
}
}
return index;
}
static inline void setpixel_8bppIndexed(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x, ColorPalette *palette)
{
BYTE index = get_palette_index(r,g,b,a,palette);
row[x]=index;
}
static inline void setpixel_1bppIndexed(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x, ColorPalette *palette)
{
row[x/8] = (row[x/8] & ~(1<<(7-x%8))) | (get_palette_index(r,g,b,a,palette)<<(7-x%8));
}
static inline void setpixel_4bppIndexed(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x, ColorPalette *palette)
{
if (x & 1)
row[x/2] = (row[x/2] & 0xf0) | get_palette_index(r,g,b,a,palette);
else
row[x/2] = (row[x/2] & 0x0f) | get_palette_index(r,g,b,a,palette)<<4;
}
static inline void setpixel_16bppGrayScale(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
*((WORD*)(row)+x) = (r+g+b)*85;
}
static inline void setpixel_16bppRGB555(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
*((WORD*)(row)+x) = (r<<7&0x7c00)|
(g<<2&0x03e0)|
(b>>3&0x001f);
}
static inline void setpixel_16bppRGB565(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
*((WORD*)(row)+x) = (r<<8&0xf800)|
(g<<3&0x07e0)|
(b>>3&0x001f);
}
static inline void setpixel_16bppARGB1555(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
*((WORD*)(row)+x) = (a<<8&0x8000)|
(r<<7&0x7c00)|
(g<<2&0x03e0)|
(b>>3&0x001f);
}
static inline void setpixel_24bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
row[x*3+2] = r;
row[x*3+1] = g;
row[x*3] = b;
}
static inline void setpixel_32bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
*((DWORD*)(row)+x) = (r<<16)|(g<<8)|b;
}
static inline void setpixel_32bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
*((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
}
static inline void setpixel_32bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
r = (r * a + 127) / 255;
g = (g * a + 127) / 255;
b = (b * a + 127) / 255;
*((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
}
static inline void setpixel_48bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
row[x*6+5] = row[x*6+4] = r;
row[x*6+3] = row[x*6+2] = g;
row[x*6+1] = row[x*6] = b;
}
static inline void setpixel_64bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
UINT64 a64=a, r64=r, g64=g, b64=b;
*((UINT64*)(row)+x) = (a64<<56)|(a64<<48)|(r64<<40)|(r64<<32)|(g64<<24)|(g64<<16)|(b64<<8)|b64;
}
static inline void setpixel_64bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
BYTE *row, UINT x)
{
UINT64 a64, r64, g64, b64;
a64 = a * 257;
r64 = r * a / 255;
g64 = g * a / 255;
b64 = b * a / 255;
*((UINT64*)(row)+x) = (a64<<48)|(r64<<32)|(g64<<16)|b64;
}
GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y,
ARGB color)
{
BYTE a, r, g, b;
BYTE *row;
if(!bitmap || x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
return InvalidParameter;
a = color>>24;
r = color>>16;
g = color>>8;
b = color;
row = bitmap->bits + bitmap->stride * y;
switch (bitmap->format)
{
case PixelFormat16bppGrayScale:
setpixel_16bppGrayScale(r,g,b,a,row,x);
break;
case PixelFormat16bppRGB555:
setpixel_16bppRGB555(r,g,b,a,row,x);
break;
case PixelFormat16bppRGB565:
setpixel_16bppRGB565(r,g,b,a,row,x);
break;
case PixelFormat16bppARGB1555:
setpixel_16bppARGB1555(r,g,b,a,row,x);
break;
case PixelFormat24bppRGB:
setpixel_24bppRGB(r,g,b,a,row,x);
break;
case PixelFormat32bppRGB:
setpixel_32bppRGB(r,g,b,a,row,x);
break;
case PixelFormat32bppARGB:
setpixel_32bppARGB(r,g,b,a,row,x);
break;
case PixelFormat32bppPARGB:
setpixel_32bppPARGB(r,g,b,a,row,x);
break;
case PixelFormat48bppRGB:
setpixel_48bppRGB(r,g,b,a,row,x);
break;
case PixelFormat64bppARGB:
setpixel_64bppARGB(r,g,b,a,row,x);
break;
case PixelFormat64bppPARGB:
setpixel_64bppPARGB(r,g,b,a,row,x);
break;
case PixelFormat8bppIndexed:
setpixel_8bppIndexed(r,g,b,a,row,x,bitmap->image.palette);
break;
case PixelFormat4bppIndexed:
setpixel_4bppIndexed(r,g,b,a,row,x,bitmap->image.palette);
break;
case PixelFormat1bppIndexed:
setpixel_1bppIndexed(r,g,b,a,row,x,bitmap->image.palette);
break;
default:
FIXME("not implemented for format 0x%x\n", bitmap->format);
return NotImplemented;
}
return Ok;
}
GpStatus convert_pixels(INT width, INT height,
INT dst_stride, BYTE *dst_bits, PixelFormat dst_format,
ColorPalette *dst_palette,
INT src_stride, const BYTE *src_bits, PixelFormat src_format,
ColorPalette *src_palette)
{
INT x, y;
if (src_format == dst_format ||
(dst_format == PixelFormat32bppRGB && PIXELFORMATBPP(src_format) == 32))
{
UINT widthbytes = PIXELFORMATBPP(src_format) * width / 8;
for (y=0; y<height; y++)
memcpy(dst_bits+dst_stride*y, src_bits+src_stride*y, widthbytes);
return Ok;
}
#define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
for (y=0; y<height; y++) \
for (x=0; x<width; x++) { \
BYTE index; \
ARGB argb; \
BYTE *color = (BYTE *)&argb; \
getpixel_function(&index, src_bits+src_stride*y, x); \
argb = (src_palette && index < src_palette->Count) ? src_palette->Entries[index] : 0; \
setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
} \
return Ok; \
} while (0);
#define convert_indexed_to_indexed(getpixel_function, setpixel_function) do { \
for (y=0; y<height; y++) \
for (x=0; x<width; x++) { \
BYTE index; \
ARGB argb; \
BYTE *color = (BYTE *)&argb; \
getpixel_function(&index, src_bits+src_stride*y, x); \
argb = (src_palette && index < src_palette->Count) ? src_palette->Entries[index] : 0; \
setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x, dst_palette); \
} \
return Ok; \
} while (0);
#define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
for (y=0; y<height; y++) \
for (x=0; x<width; x++) { \
BYTE r, g, b, a; \
getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
} \
return Ok; \
} while (0);
#define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
for (y=0; y<height; y++) \
for (x=0; x<width; x++) { \
BYTE r, g, b, a; \
getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, dst_palette); \
} \
return Ok; \
} while (0);
switch (src_format)
{
case PixelFormat1bppIndexed:
switch (dst_format)
{
case PixelFormat4bppIndexed:
convert_indexed_to_indexed(getpixel_1bppIndexed, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_indexed_to_indexed(getpixel_1bppIndexed, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_24bppRGB);
case PixelFormat32bppRGB:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat4bppIndexed:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_indexed_to_indexed(getpixel_4bppIndexed, setpixel_1bppIndexed);
case PixelFormat8bppIndexed:
convert_indexed_to_indexed(getpixel_4bppIndexed, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_24bppRGB);
case PixelFormat32bppRGB:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat8bppIndexed:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_indexed_to_indexed(getpixel_8bppIndexed, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_indexed_to_indexed(getpixel_8bppIndexed, setpixel_4bppIndexed);
case PixelFormat16bppGrayScale:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_24bppRGB);
case PixelFormat32bppRGB:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat16bppGrayScale:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_16bppGrayScale, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_16bppGrayScale, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_rgb_to_indexed(getpixel_16bppGrayScale, setpixel_8bppIndexed);
case PixelFormat16bppRGB555:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_24bppRGB);
case PixelFormat32bppRGB:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat16bppRGB555:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_16bppRGB555, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_16bppRGB555, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_rgb_to_indexed(getpixel_16bppRGB555, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_16bppGrayScale);
case PixelFormat16bppRGB565:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_24bppRGB);
case PixelFormat32bppRGB:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat16bppRGB565:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_16bppRGB565, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_16bppRGB565, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_rgb_to_indexed(getpixel_16bppRGB565, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_16bppRGB555);
case PixelFormat16bppARGB1555:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_24bppRGB);
case PixelFormat32bppRGB:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat16bppARGB1555:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_16bppARGB1555, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_16bppARGB1555, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_rgb_to_indexed(getpixel_16bppARGB1555, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_16bppRGB565);
case PixelFormat24bppRGB:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_24bppRGB);
case PixelFormat32bppRGB:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat24bppRGB:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_24bppRGB, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_24bppRGB, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_rgb_to_indexed(getpixel_24bppRGB, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_16bppARGB1555);
case PixelFormat32bppRGB:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat32bppRGB:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_32bppRGB, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_32bppRGB, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_rgb_to_indexed(getpixel_32bppRGB, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_24bppRGB);
case PixelFormat32bppARGB:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_32bppARGB);
case PixelFormat32bppPARGB:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_32bppPARGB);
case PixelFormat48bppRGB:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat32bppARGB:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_32bppARGB, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_32bppARGB, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_rgb_to_indexed(getpixel_32bppARGB, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_24bppRGB);
case PixelFormat32bppPARGB:
convert_32bppARGB_to_32bppPARGB(width, height, dst_bits, dst_stride, src_bits, src_stride);
return Ok;
case PixelFormat48bppRGB:
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat32bppPARGB:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_32bppPARGB, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_32bppPARGB, setpixel_4bppIndexed);
case PixelFormat8bppIndexed:
convert_rgb_to_indexed(getpixel_32bppPARGB, setpixel_8bppIndexed);
case PixelFormat16bppGrayScale:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_16bppGrayScale);
case PixelFormat16bppRGB555:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_16bppRGB555);
case PixelFormat16bppRGB565:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_16bppRGB565);
case PixelFormat16bppARGB1555:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_16bppARGB1555);
case PixelFormat24bppRGB:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_24bppRGB);
case PixelFormat32bppRGB:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_32bppRGB);
case PixelFormat32bppARGB:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_32bppARGB);
case PixelFormat48bppRGB:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_48bppRGB);
case PixelFormat64bppARGB:
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_64bppARGB);
default:
break;
}
break;
case PixelFormat48bppRGB:
switch (dst_format)
{
case PixelFormat1bppIndexed:
convert_rgb_to_indexed(getpixel_48bppRGB, setpixel_1bppIndexed);
case PixelFormat4bppIndexed:
convert_rgb_to_indexed(getpixel_48bppRGB, setpixel_4bppIndexed);