summaryrefslogtreecommitdiff
path: root/src/corelib/render/software/util/agg_color_conv.pas
blob: f73a3590c87a18864e3fdaa0c9fcbaec8cc5868f (plain)
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
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4 (Public License)
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
// Pascal Port By: Milan Marusinec alias Milano
//                 milan@marusinec.sk
//                 http://www.aggpas.org
// Copyright (c) 2005-2006
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
//          mcseemagg@yahoo.com
//          http://www.antigrain.com
//
//----------------------------------------------------------------------------
//
// Conversion from one colorspace/pixel format to another
//
// [Pascal Port History] -----------------------------------------------------
//
// 23.06.2006-Milano: ptrcomp adjustments
// 16.12.2005-Milano: Unit port establishment
//
{ agg_color_conv.pas }
unit
 agg_color_conv ;

INTERFACE

{$I agg_mode.inc }

uses
 agg_basics ,
 agg_color ,
 agg_rendering_buffer ;

{ TYPES DEFINITION }
type
 CopyRow = procedure(dst ,src : int8u_ptr; width : unsigned );

{ GLOBAL PROCEDURES }
 procedure color_conv(dst ,src : rendering_buffer_ptr; copy_row_functor : CopyRow );

 procedure color_conv_gray8_to_bgr24  (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_gray8_to_rgb24  (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_gray16_to_gray8 (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_rgb555_to_rgb555(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgb555_to_rgb565(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgb555_to_rgb24 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgb555_to_bgr24 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgb555_to_abgr32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgb555_to_argb32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgb555_to_bgra32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgb555_to_rgba32(dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_rgb565_to_rgb555(dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_bgr24_to_gray8  (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_gray16 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_rgb555 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_rgb565 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_rgb24  (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_bgr24  (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_abgr32 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_argb32 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_bgra32 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_rgba32 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_rgb48  (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_bgr48  (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_abgr64 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_argb64 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_bgra64 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgr24_to_rgba64 (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_rgb24_to_bgr24  (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgb24_to_bgra32 (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_bgra32_to_rgb555(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgra32_to_rgb565(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgra32_to_rgb24 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgra32_to_bgr24 (dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgra32_to_abgr32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgra32_to_argb32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgra32_to_bgra32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgra32_to_rgba32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_bgra64_to_bgra32(dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_abgr32_to_argb32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_abgr32_to_bgra32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_abgr64_to_bgra32(dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_rgba32_to_argb32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_rgba32_to_bgra32(dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_argb32_to_bgra32(dst ,src : int8u_ptr; width : unsigned );
 procedure color_conv_argb64_to_bgra32(dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_rgbAAA_to_bgr24 (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_bgrAAA_to_bgr24 (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_rgbBBA_to_bgr24 (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_bgrABB_to_bgr24 (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_rgb48_to_bgr24  (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_bgr48_to_bgr24  (dst ,src : int8u_ptr; width : unsigned );

 procedure color_conv_rgba64_to_bgra32(dst ,src : int8u_ptr; width : unsigned );


IMPLEMENTATION
{ LOCAL VARIABLES & CONSTANTS }
{ UNIT IMPLEMENTATION }
{ COLOR_CONV }
procedure color_conv;
var
 y ,width ,height : unsigned;

begin
 width :=src._width;
 height:=src._height;

 if dst._width < width then
  width:=dst._width;

 if dst._height < height then
  height:=dst._height;

 if width > 0 then
  for y:=0 to height - 1 do
   copy_row_functor(dst.row(y ) ,src.row(y ) ,width );

end;

{ color_conv_bgr24_to_gray8 {..}
procedure color_conv_bgr24_to_gray8;
begin
end;

{ color_conv_gray8_to_bgr24 }
procedure color_conv_gray8_to_bgr24;
begin
 repeat
  int8u_ptr(ptrcomp(dst ) + bgr_order.R )^:=src^;
  int8u_ptr(ptrcomp(dst ) + bgr_order.G )^:=src^;
  int8u_ptr(ptrcomp(dst ) + bgr_order.B )^:=src^;

  inc(ptrcomp(dst ) ,3 );
  inc(ptrcomp(src ) );
  dec(width );

 until width = 0;

end;

{ color_conv_gray8_to_rgb24 }
procedure color_conv_gray8_to_rgb24;
begin
 repeat
  int8u_ptr(ptrcomp(dst ) + rgb_order.R )^:=src^;
  int8u_ptr(ptrcomp(dst ) + rgb_order.G )^:=src^;
  int8u_ptr(ptrcomp(dst ) + rgb_order.B )^:=src^;

  inc(ptrcomp(dst ) ,3 );
  inc(ptrcomp(src ) );
  dec(width );

 until width = 0;

end;

{ color_conv_bgr24_to_gray16 {..}
procedure color_conv_bgr24_to_gray16;
begin
end;

{ color_conv_rgb555_to_rgb555 {..}
procedure color_conv_rgb555_to_rgb555;
begin
end;

{ color_conv_bgr24_to_rgb555 {..}
procedure color_conv_bgr24_to_rgb555;
begin
end;

{ color_conv_bgra32_to_rgb555 {..}
procedure color_conv_bgra32_to_rgb555;
begin
end;

{ color_conv_rgb555_to_rgb565 {..}
procedure color_conv_rgb555_to_rgb565;
begin
end;

{ color_conv_bgr24_to_rgb565 {..}
procedure color_conv_bgr24_to_rgb565;
begin
end;

{ color_conv_bgra32_to_rgb565 {..}
procedure color_conv_bgra32_to_rgb565;
begin
end;

{ color_conv_rgb555_to_rgb24 {..}
procedure color_conv_rgb555_to_rgb24;
begin
end;

{ color_conv_bgr24_to_rgb24 }
procedure color_conv_bgr24_to_rgb24;
begin
 repeat
  int8u_ptr(ptrcomp(dst ) + bgr_order.R )^:=int8u_ptr(ptrcomp(src ) + rgb_order.R )^;
  int8u_ptr(ptrcomp(dst ) + bgr_order.G )^:=int8u_ptr(ptrcomp(src ) + rgb_order.G )^;
  int8u_ptr(ptrcomp(dst ) + bgr_order.B )^:=int8u_ptr(ptrcomp(src ) + rgb_order.B )^;

  inc(ptrcomp(dst ) ,3 );
  inc(ptrcomp(src ) ,3 );
  dec(width );

 until width = 0;

end;

{ color_conv_bgra32_to_rgb24 {..}
procedure color_conv_bgra32_to_rgb24;
begin
end;

{ color_conv_rgb555_to_bgr24 {..}
procedure color_conv_rgb555_to_bgr24;
begin
end;

{ color_conv_bgr24_to_bgr24 }
procedure color_conv_bgr24_to_bgr24;
begin
 move(src^ ,dst^ ,width * 3 );

end;

{ color_conv_bgra32_to_bgr24 {..}
procedure color_conv_bgra32_to_bgr24;
begin
end;

{ color_conv_bgr24_to_rgb48 {..}
procedure color_conv_bgr24_to_rgb48;
begin
end;

{ color_conv_bgr24_to_bgr48 {..}
procedure color_conv_bgr24_to_bgr48;
begin
end;

{ color_conv_rgb555_to_abgr32 {..}
procedure color_conv_rgb555_to_abgr32;
begin
end;

{ color_conv_bgr24_to_abgr32 {..}
procedure color_conv_bgr24_to_abgr32;
begin
end;

{ color_conv_bgra32_to_abgr32 {..}
procedure color_conv_bgra32_to_abgr32;
begin
end;

{ color_conv_rgb555_to_argb32 {..}
procedure color_conv_rgb555_to_argb32;
begin
end;

{ color_conv_bgr24_to_argb32 {..}
procedure color_conv_bgr24_to_argb32;
begin
end;

{ color_conv_bgra32_to_argb32 }
procedure color_conv_bgra32_to_argb32;
begin
 repeat
  int8u_ptr(ptrcomp(dst ) + argb_order.R )^:=int8u_ptr(ptrcomp(src ) + bgra_order.R )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.G )^:=int8u_ptr(ptrcomp(src ) + bgra_order.G )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.B )^:=int8u_ptr(ptrcomp(src ) + bgra_order.B )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.A )^:=int8u_ptr(ptrcomp(src ) + bgra_order.A )^;

  inc(ptrcomp(dst ) ,4 );
  inc(ptrcomp(src ) ,4 );
  dec(width );

 until width = 0;

end;

{ color_conv_abgr32_to_argb32 }
procedure color_conv_abgr32_to_argb32;
begin
 repeat
  int8u_ptr(ptrcomp(dst ) + argb_order.R )^:=int8u_ptr(ptrcomp(src ) + abgr_order.R )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.G )^:=int8u_ptr(ptrcomp(src ) + abgr_order.G )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.B )^:=int8u_ptr(ptrcomp(src ) + abgr_order.B )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.A )^:=int8u_ptr(ptrcomp(src ) + abgr_order.A )^;

  inc(ptrcomp(dst ) ,4 );
  inc(ptrcomp(src ) ,4 );
  dec(width );

 until width = 0;

end;

{ color_conv_rgba32_to_argb32 }
procedure color_conv_rgba32_to_argb32;
begin
 repeat
  int8u_ptr(ptrcomp(dst ) + argb_order.R )^:=int8u_ptr(ptrcomp(src ) + rgba_order.R )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.G )^:=int8u_ptr(ptrcomp(src ) + rgba_order.G )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.B )^:=int8u_ptr(ptrcomp(src ) + rgba_order.B )^;
  int8u_ptr(ptrcomp(dst ) + argb_order.A )^:=int8u_ptr(ptrcomp(src ) + rgba_order.A )^;

  inc(ptrcomp(dst ) ,4 );
  inc(ptrcomp(src ) ,4 );
  dec(width );

 until width = 0;
 
end;

{ color_conv_rgb555_to_bgra32 {..}
procedure color_conv_rgb555_to_bgra32;
begin
end;

{ color_conv_bgr24_to_bgra32 }
procedure color_conv_bgr24_to_bgra32;
begin
 repeat
  int8u_ptr(ptrcomp(dst ) + 0 )^:=src^; inc(ptrcomp(src ) );
  int8u_ptr(ptrcomp(dst ) + 1 )^:=src^; inc(ptrcomp(src ) );
  int8u_ptr(ptrcomp(dst ) + 2 )^:=src^; inc(ptrcomp(src ) );
  int8u_ptr(ptrcomp(dst ) + 3 )^:=255;

  inc(ptrcomp(dst ) ,4 );
  dec(width );

 until width = 0;

end;

{ color_conv_bgra32_to_bgra32 {..}
procedure color_conv_bgra32_to_bgra32;
begin
end;

{ color_conv_rgb555_to_rgba32 {..}
procedure color_conv_rgb555_to_rgba32;
begin
end;

{ color_conv_bgr24_to_rgba32 {..}
procedure color_conv_bgr24_to_rgba32;
begin
end;

{ color_conv_bgra32_to_rgba32 {..}
procedure color_conv_bgra32_to_rgba32;
begin
end;

{ color_conv_bgr24_to_abgr64 {..}
procedure color_conv_bgr24_to_abgr64;
begin
end;

{ color_conv_bgr24_to_argb64 {..}
procedure color_conv_bgr24_to_argb64;
begin
end;

{ color_conv_bgr24_to_bgra64 {..}
procedure color_conv_bgr24_to_bgra64;
begin
end;

{ color_conv_bgr24_to_rgba64 {..}
procedure color_conv_bgr24_to_rgba64;
begin
end;

{ color_conv_gray16_to_gray8 {..}
procedure color_conv_gray16_to_gray8;
begin
end;

{ color_conv_rgb565_to_rgb555 }
procedure color_conv_rgb565_to_rgb555;
var
 rgb : int;

begin
 repeat
  rgb:=int16u(p32(src ).ptr^ );

  int16u(p32(dst ).ptr^ ):=((rgb shr 1 ) and $7FE0 ) or (rgb and $1F );

  inc(ptrcomp(src ) ,2 );
  inc(ptrcomp(dst ) ,2 );
  dec(width );

 until width = 0;

end;

{ color_conv_rgbAAA_to_bgr24 {..}
procedure color_conv_rgbAAA_to_bgr24;
begin
end;

{ color_conv_bgrAAA_to_bgr24 {..}
procedure color_conv_bgrAAA_to_bgr24;
begin
end;

{ color_conv_rgbBBA_to_bgr24 {..}
procedure color_conv_rgbBBA_to_bgr24;
begin
end;

{ color_conv_bgrABB_to_bgr24 {..}
procedure color_conv_bgrABB_to_bgr24;
begin
end;

{ color_conv_rgb24_to_bgr24 }
procedure color_conv_rgb24_to_bgr24;
begin
 repeat
  int8u_ptr(p32(dst ).int + 0 )^:=int8u_ptr(p32(src ).int + 2 )^;
  int8u_ptr(p32(dst ).int + 1 )^:=int8u_ptr(p32(src ).int + 1 )^;
  int8u_ptr(p32(dst ).int + 2 )^:=int8u_ptr(p32(src ).int + 0 )^;

  inc(ptrcomp(src ) ,3 );
  inc(ptrcomp(dst ) ,3 );
  dec(width );

 until width = 0;

end;

{ color_conv_rgb48_to_bgr24 {..}
procedure color_conv_rgb48_to_bgr24;
begin
end;

{ color_conv_bgr48_to_bgr24 {..}
procedure color_conv_bgr48_to_bgr24;
begin
end;

{ color_conv_abgr32_to_bgra32 }
procedure color_conv_abgr32_to_bgra32;
begin
 repeat
  int8u_ptr(p32(dst ).int + 0 )^:=int8u_ptr(p32(src ).int + 1 )^;
  int8u_ptr(p32(dst ).int + 1 )^:=int8u_ptr(p32(src ).int + 2 )^;
  int8u_ptr(p32(dst ).int + 2 )^:=int8u_ptr(p32(src ).int + 3 )^;
  int8u_ptr(p32(dst ).int + 3 )^:=int8u_ptr(p32(src ).int + 0 )^;

  inc(ptrcomp(src ) ,4 );
  inc(ptrcomp(dst ) ,4 );
  dec(width );

 until width = 0;

end;

{ color_conv_argb32_to_bgra32 }
procedure color_conv_argb32_to_bgra32;
begin
 repeat
  int8u_ptr(p32(dst ).int + 0 )^:=int8u_ptr(p32(src ).int + 3 )^;
  int8u_ptr(p32(dst ).int + 1 )^:=int8u_ptr(p32(src ).int + 2 )^;
  int8u_ptr(p32(dst ).int + 2 )^:=int8u_ptr(p32(src ).int + 1 )^;
  int8u_ptr(p32(dst ).int + 3 )^:=int8u_ptr(p32(src ).int + 0 )^;

  inc(ptrcomp(src ) ,4 );
  inc(ptrcomp(dst ) ,4 );
  dec(width );

 until width = 0;

end;

{ color_conv_rgba32_to_bgra32 }
procedure color_conv_rgba32_to_bgra32;
begin
 repeat
  int8u_ptr(p32(dst ).int + 0 )^:=int8u_ptr(p32(src ).int + 2 )^;
  int8u_ptr(p32(dst ).int + 1 )^:=int8u_ptr(p32(src ).int + 1 )^;
  int8u_ptr(p32(dst ).int + 2 )^:=int8u_ptr(p32(src ).int + 0 )^;
  int8u_ptr(p32(dst ).int + 3 )^:=int8u_ptr(p32(src ).int + 3 )^;

  inc(ptrcomp(src ) ,4 );
  inc(ptrcomp(dst ) ,4 );
  dec(width );

 until width = 0;

end;

{ color_conv_bgra64_to_bgra32 {..}
procedure color_conv_bgra64_to_bgra32;
begin
end;

{ color_conv_abgr64_to_bgra32 {..}
procedure color_conv_abgr64_to_bgra32;
begin
end;

{ color_conv_argb64_to_bgra32 {..}
procedure color_conv_argb64_to_bgra32;
begin
end;

{ color_conv_rgba64_to_bgra32 {..}
procedure color_conv_rgba64_to_bgra32;
begin
end;

{ color_conv_rgb24_to_bgra32 }
procedure color_conv_rgb24_to_bgra32;
begin
 repeat
  int8u_ptr(ptrcomp(dst ) + bgra_order.R )^:=src^; inc(ptrcomp(src ) );
  int8u_ptr(ptrcomp(dst ) + bgra_order.G )^:=src^; inc(ptrcomp(src ) );
  int8u_ptr(ptrcomp(dst ) + bgra_order.B )^:=src^; inc(ptrcomp(src ) );
  int8u_ptr(ptrcomp(dst ) + bgra_order.A )^:=255;

  inc(ptrcomp(dst ) ,4 );
  dec(width );

 until width = 0;

end;

END.