-
Notifications
You must be signed in to change notification settings - Fork 6
/
etc2.txt
1875 lines (1615 loc) · 88.2 KB
/
etc2.txt
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) 2014-2019 The Khronos Group Inc.
// Copyright notice at https://www.khronos.org/registry/speccopyright.html
[[ETC2]]
== ETC2 Compressed Texture Image Formats
_This description is derived from the ``ETC Compressed Texture Image Formats''
section of the OpenGL 4.4 specification._
The ETC formats form a family of related compressed texture image formats.
They are designed to do different tasks, but also to be similar enough
that hardware can be reused between them. Each one is described in detail
below, but we will first give an overview of each format and describe how
it is similar to others and the main differences.
_RGB ETC2_ is a format for compressing _RGB_ data. It
is a superset of the older ETC1
format. This means that an older ETC1 texture can be decoded using an
ETC2-compliant decoder. The main difference is that the
newer version contains three new modes; the `T-mode' and the `H-mode'
which are good for sharp chrominance blocks and the `Planar' mode
which is good for smooth blocks.
_RGB ETC2 with sRGB encoding_ is the same as linear RGB ETC2 with the
difference that the values should be interpreted as being encoded
with the sRGB transfer function instead of linear _RGB_-values.
_RGBA ETC2_ encodes _RGBA_ 8-bit data. The _RGB_ part is
encoded exactly the same way as RGB ETC2. The
alpha part is encoded separately.
_RGBA ETC2 with sRGB encoding_ is the same as
RGBA ETC2 but here the _RGB_ values (but not
the alpha value) should be interpreted as being encoded
with the sRGB transfer function.
_Unsigned R11 EAC_ is a one-channel unsigned format. It is
similar to the alpha part of RGBA ETC2 but not exactly the same;
it delivers higher precision. It is possible to make hardware that can
decode both formats with minimal overhead.
_Unsigned RG11 EAC_ is a two-channel unsigned format. Each
channel is decoded exactly as Unsigned R11 EAC.
_Signed R11 EAC_ is a one-channel signed
format. This is good in situations when it is important to be able to
preserve zero exactly, and still use both positive and negative
values. It is designed to be similar enough to
Unsigned R11 EAC so that hardware can decode both with
minimal overhead, but it is not exactly the same. For example; the
signed version does not add 0.5 to the _base codeword_, and the
extension from 11 bits differ. For all details, see the corresponding
sections.
_Signed RG11 EAC_ is a two-channel signed
format. Each channel is decoded exactly as
signed R11 EAC.
_RGB ETC2 with ``punchthrough'' alpha_ is very similar to
RGB ETC2, but has the ability to represent
``punchthrough'' alpha (completely opaque or transparent). Each block
can select to be completely opaque using one bit. To fit this bit,
there is no individual mode in
RGB ETC2 with punchthrough alpha. In other respects,
the opaque blocks are decoded as in RGB ETC2. For
the transparent blocks, one index is reserved to represent
transparency, and the decoding of the _RGB_ channels are also
affected. For details, see the corresponding sections.
_RGB ETC2 with punchthrough alpha and sRGB encoding_ is the same as
linear RGB ETC2 with punchthrough alpha but the _RGB_ channel values
should be interpreted as being encoded with the sRGB transfer function.
A texture compressed using any of the ETC texture image formats is
described as a number of 4{times}4 pixel blocks.
<<<
Pixel _a_~1~ (see <<ETC28x8>>) of the first block in
memory will represent the texture coordinate (_u_=0,_ v_=0). Pixel
_a_~2~ in the second block in memory will be adjacent to pixel _m_~1~
in the first block, etc. until the width of the texture. Then pixel
_a_~3~ in the following block (third block in memory for an 8{times}8
texture) will be adjacent to pixel _d_~1~ in the first block, etc.
until the height of the texture.
The data storage for an 8{times}8 texture using the first, second, third and
fourth block if stored in that order in memory would have the texels encoded in
the same order as a simple linear format as if the bytes describing the pixels came
in the following memory order:
_a_~1~ _e_~1~ _i_~1~ _m_~1~ _a_~2~ _e_~2~ _i_~2~ _m_~2~
_b_~1~ _f_~1~ _i_~1~ _n_~1~ _b_~2~ _f_~2~ _i_~2~ _n_~2~
_c_~1~ _g_~1~ _k_~1~ _o_~1~ _c_~2~ _g_~2~ _k_~2~ _o_~2~
_d_~1~ _h_~1~ _l_~1~ _p_~1~ _d_~2~ _h_~2~ _l_~2~ _p_~2~
_a_~3~ _e_~3~ _i_~3~ _m_~3~ _a_~4~ _e_~4~ _i_~4~ _m_~4~
_b_~3~ _f_~3~ _i_~3~ _n_~3~ _b_~4~ _f_~4~ _i_~4~ _n_~4~
_c_~3~ _g_~3~ _k_~3~ _o_~3~ _c_~4~ _g_~4~ _k_~4~ _o_~4~
_d_~3~ _h_~3~ _l_~3~ _p_~3~ _d_~4~ _h_~4~ _l_~4~ _p_~4~.
[[ETC28x8]]
.Pixel layout for an 8×8 texture using four ETC2 compressed blocks
image::images/ETCletter8x8.{svgpdf}[width="{svgpdf@pdf:218pt:327}",align="center"]
Note how pixel _a_~3~ in the third block is adjacent to pixel _d_~1~ in the first block.
If the width or height of the texture (or a particular mip-level) is
not a multiple of four, then padding is added to ensure that the
texture contains a whole number of 4{times}4 blocks in each
dimension. The padding does not affect the texel coordinates. For
example, the texel shown as _a_~1~ in <<ETC28x8>>
always has coordinates (_i_=0,_ j_=0). The values of padding texels
are irrelevant, e.g., in a 3{times}3 texture, the texels marked as
_m_~1~, _n_~1~, _o_~1~, _d_~1~, _h_~1~, _l_~1~ and _p_~1~ form padding and
have no effect on the final texture image.
The number of bits that represent a 4{times}4 texel block is 64 bits
if the format is RGB ETC2, RGB ETC2 with sRGB encoding, RGBA ETC2 with punchthrough
alpha, or RGB ETC2 with punchthrough alpha and sRGB encoding.
In those cases the data for a block is stored as a number of bytes,
\{_q_~0~, _q_~1~, _q_~2~, _q_~3~, _q_~4~, _q_~5~, _q_~6~, _q_~7~\}, where byte
_q_~0~ is located at the lowest memory address and _q_~7~ at the highest. The 64
bits specifying the block are then represented by the following 64 bit integer:
[latexmath]
++++++
\begin{align*}
\mathit{int64bit} & = 256\times (256\times (256\times (256\times (256\times (256\times (256\times q_0+q_1)+q_2)+q_3)+q_4)+q_5)+q_6)+q_7
\end{align*}
++++++
The number of bits that represent a 4{times}4 texel block is 128
bits if the format is RGBA ETC2 with a linear or sRGB transfer function. In
those cases the data for a block is stored as a number of bytes:
\{_q_~0~, _q_~1~, _q_~2~, _q_~3~, _q_~4~, _q_~5~, _q_~6~, _q_~7~,
_q_~8~, _q_~9~, _q_~10~, _q_~11~, _q_~12~, _q_~13~, _q_~14~, _q_~15~\},
where byte _q_~0~ is located at the lowest memory address and _q_~15~ at
the highest.
This is split into two 64-bit integers, one used for color channel
decompression and one for alpha channel decompression:
[latexmath]
++++++
\begin{align*}
\mathit{int64bit_{Alpha}} & = 256\times (256\times (256\times (256\times (256\times (256\times (256\times q_0+q_1)+q_2)+q_3)+q_4)+q_5)+q_6)+q_7 \\
\mathit{int64bit_{Color}} & = 256\times (256\times (256\times (256\times (256\times (256\times (256\times q_8+q_9)+q_{10})+q_{11})+q_{12})+q_{13})+q_{14})+q_{15}
\end{align*}
++++++
<<<
[[RGBETC2]]
=== Format RGB ETC2
For RGB ETC2, each 64-bit word contains information about
a three-channel 4{times}4 pixel block as shown in
<<Figure-etc2-pixellayout>>.
[[Figure-etc2-pixellayout]]
.Pixel layout for an ETC2 compressed block
image::images/ETCletterdirections.{svgpdf}[width="{svgpdf@pdf:115pt:173}",align="center"]
[[Table-etc2-dataformat]]
.Texel Data format for ETC2 compressed texture formats
[cols="1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1",width="97%"]
|====================
32+| [[ETC2ModeSelection]] *a) Location of bits for mode selection*
^| ~63~ ^| ~62~ ^| ~61~ ^| ~60~ ^| ~59~ ^| ~58~ ^| ~57~ ^| ~56~ ^| ~55~ ^| ~54~ ^| ~53~ ^| ~52~ ^| ~51~ ^| ~50~ ^| ~49~ ^| ~48~ ^| ~47~ ^| ~46~ ^| ~45~ ^| ~44~ ^| ~43~ ^| ~42~ ^| ~41~ ^| ~40~ ^| ~39~ ^| ~38~ ^| ~37~ ^| ~36~ ^| ~35~ ^| ~34~ ^| ~33~ ^| ~32~
5+^| _R_ 3+^| _R_~d~ 5+^| _G_ 3+^| _G_~d~ 5+^| _B_ 3+^| _B_~d~ 6+^| ...... ^| _D_ ^| .
32+| [[ETC2IndividualLayout]] *b) Bit layout for bits 63 through 32 for `individual' mode*
^| ~63~ ^| ~62~ ^| ~61~ ^| ~60~ ^| ~59~ ^| ~58~ ^| ~57~ ^| ~56~ ^| ~55~ ^| ~54~ ^| ~53~ ^| ~52~ ^| ~51~ ^| ~50~ ^| ~49~ ^| ~48~ ^| ~47~ ^| ~46~ ^| ~45~ ^| ~44~ ^| ~43~ ^| ~42~ ^| ~41~ ^| ~40~ ^| ~39~ ^| ~38~ ^| ~37~ ^| ~36~ ^| ~35~ ^| ~34~ ^| ~33~ ^| ~32~
4+^| _R_ 4+^| _R_~2~ 4+^| _G_ 4+^| _G_~2~ 4+^| _B_ 4+^| _B_~2~ 3+^| _table_~1~ 3+^| _table_~2~ ^| 0 ^| _F~B~_
32+| [[ETC2DifferentialLayout]] *c) Bit layout for bits 63 through 32 for `differential' mode*
^| ~63~ ^| ~62~ ^| ~61~ ^| ~60~ ^| ~59~ ^| ~58~ ^| ~57~ ^| ~56~ ^| ~55~ ^| ~54~ ^| ~53~ ^| ~52~ ^| ~51~ ^| ~50~ ^| ~49~ ^| ~48~ ^| ~47~ ^| ~46~ ^| ~45~ ^| ~44~ ^| ~43~ ^| ~42~ ^| ~41~ ^| ~40~ ^| ~39~ ^| ~38~ ^| ~37~ ^| ~36~ ^| ~35~ ^| ~34~ ^| ~33~ ^| ~32~
5+^| _R_ 3+^| _R_~d~ 5+^| _G_ 3+^| _G_~d~ 5+^| _B_ 3+^| _B_~d~ 3+^| _table_~1~ 3+^| _table_~2~ ^| 1 ^| _F~B~_
32+| [[ETC2TLayout]] *d) Bit layout for bits 63 through 32 for `T' mode*
^| ~63~ ^| ~62~ ^| ~61~ ^| ~60~ ^| ~59~ ^| ~58~ ^| ~57~ ^| ~56~ ^| ~55~ ^| ~54~ ^| ~53~ ^| ~52~ ^| ~51~ ^| ~50~ ^| ~49~ ^| ~48~ ^| ~47~ ^| ~46~ ^| ~45~ ^| ~44~ ^| ~43~ ^| ~42~ ^| ~41~ ^| ~40~ ^| ~39~ ^| ~38~ ^| ~37~ ^| ~36~ ^| ~35~ ^| ~34~ ^| ~33~ ^| ~32~
3+^| ... 2+^| _R_^3..2^ ^| . 2+^| _R_^1..0^ 4+^| _G_ 4+^| _B_ 4+^| _R_~2~ 4+^| _G_~2~ 4+^| _B_~2~ 2+^| _d_~a~ ^| 1 ^| _d_~b~
32+| [[ETC2HLayout]] *e) Bit layout for bits 63 through 32 for `H' mode*
^| ~63~ ^| ~62~ ^| ~61~ ^| ~60~ ^| ~59~ ^| ~58~ ^| ~57~ ^| ~56~ ^| ~55~ ^| ~54~ ^| ~53~ ^| ~52~ ^| ~51~ ^| ~50~ ^| ~49~ ^| ~48~ ^| ~47~ ^| ~46~ ^| ~45~ ^| ~44~ ^| ~43~ ^| ~42~ ^| ~41~ ^| ~40~ ^| ~39~ ^| ~38~ ^| ~37~ ^| ~36~ ^| ~35~ ^| ~34~ ^| ~33~ ^| ~32~
^| . 4+^| _R_ 3+^| _G_^3..1^ 3+^| ... ^| _G_^0^ ^| _B_^3^ ^| . 3+^| _B_^2..0^ 4+^| _R_~2~ 4+^| _G_~2~ 4+^| _B_~2~ ^| _d~a~_ ^| 1 ^| _d~b~_
32+| [[ETC2LowBits]] *f) Bit layout for bits 31 through 0 for `individual', `differential', `T' and `H' modes*
^| ~31~ ^| ~30~ ^| ~29~ ^| ~28~ ^| ~27~ ^| ~26~ ^| ~25~ ^| ~24~ ^| ~23~ ^| ~22~ ^| ~21~ ^| ~20~ ^| ~19~ ^| ~18~ ^| ~17~ ^| ~16~ ^| ~15~ ^| ~14~ ^| ~13~ ^| ~12~ ^| ~11~ ^| ~10~ ^| ~9~ ^| ~8~ ^| ~7~ ^| ~6~ ^| ~5~ ^| ~4~ ^| ~3~ ^| ~2~ ^| ~1~ ^| ~0~
^| _p_^1^ ^| _o_^1^ ^| _n_^1^ ^| _m_^1^ ^| _l_^1^ ^| _k_^1^ ^| _j_^1^ ^| _i_^1^ ^| _h_^1^ ^| _g_^1^ ^| _f_^1^ ^| _e_^1^ ^| _d_^1^ ^| _c_^1^ ^| _b_^1^ ^| _a_^1^ ^| _p_^0^ ^| _o_^0^ ^| _n_^0^ ^| _m_^0^ ^| _l_^0^ ^| _k_^0^ ^| _j_^0^ ^| _i_^0^ ^| _h_^0^ ^| _g_^0^ ^| _f_^0^ ^| _e_^0^ ^| _d_^0^ ^| _c_^0^ ^| _b_^0^ ^| _a_^0^
32+| [[ETC2Planar]] *g) Bit layout for bits 63 through 0 for `planar' mode*
^| ~63~ ^| ~62~ ^| ~61~ ^| ~60~ ^| ~59~ ^| ~58~ ^| ~57~ ^| ~56~ ^| ~55~ ^| ~54~ ^| ~53~ ^| ~52~ ^| ~51~ ^| ~50~ ^| ~49~ ^| ~48~ ^| ~47~ ^| ~46~ ^| ~45~ ^| ~44~ ^| ~43~ ^| ~42~ ^| ~41~ ^| ~40~ ^| ~39~ ^| ~38~ ^| ~37~ ^| ~36~ ^| ~35~ ^| ~34~ ^| ~33~ ^| ~32~
^| . 6+^| _R_ ^| _G_^6^ ^| . 6+^| _G_^5..0^ ^| _B_^5^ 3+^| ... 2+^| _B_^4..3^ ^| . 3+^| _B_^2..0^ 5+^| _R_~h~^5..1^ ^| 1 ^| _R~h~_^0^
^| ~31~ ^| ~30~ ^| ~29~ ^| ~28~ ^| ~27~ ^| ~26~ ^| ~25~ ^| ~24~ ^| ~23~ ^| ~22~ ^| ~21~ ^| ~20~ ^| ~19~ ^| ~18~ ^| ~17~ ^| ~16~ ^| ~15~ ^| ~14~ ^| ~13~ ^| ~12~ ^| ~11~ ^| ~10~ ^| ~9~ ^| ~8~ ^| ~7~ ^| ~6~ ^| ~5~ ^| ~4~ ^| ~3~ ^| ~2~ ^| ~1~ ^| ~0~
7+^| _G_~h~ 6+^| _B_~h~ 6+^| _R_~v~ 7+^| _G_~v~ 6+^| _B_~v~
|====================
<<<
The blocks are compressed using one of five different `modes'.
<<ETC2ModeSelection,Section a>> of <<Table-etc2-dataformat>> shows the
bits used for determining the mode used in a given block.
First, if the `differential bit' marked _D_ is set to 0, the `individual'
mode is used. Otherwise, the three 5-bit values _R_, _G_ and _B_, and the three
3-bit values _R_~d~, _G_~d~ and _B_~d~ are examined.
_R_, _G_ and _B_ are treated as integers between 0 and 31 and _R_~d~, _G_~d~ and
_B_~d~ as two's-complement integers between -4 and +3.
First, _R_ and _R_~d~ are added, and if the sum is not within the interval
[0..31], the `T' mode is selected.
Otherwise, if the sum of _G_ and _G_~d~ is outside the interval [0..31],
the `H' mode is selected.
Otherwise, if the sum of _B_ and _B_~d~ is outside of the interval [0..31],
the `planar' mode is selected.
Finally, if the _D_ bit is set to 1 and all of the aforementioned sums
lie between 0 and 31, the `differential' mode is selected.
The layout of the bits used to decode the `individual' and
`differential' modes are shown in
<<ETC2IndividualLayout,section b>> and <<ETC2DifferentialLayout,section c>>
of <<Table-etc2-dataformat>>, respectively.
Both of these modes share several characteristics.
In both modes, the 4{times}4 block is split into two subblocks of either
size 2{times}4 or 4{times}2.
This is controlled by bit 32, which we dub the _flip bit_ (_F~B~_ in
<<Table-etc2-dataformat>> (b) and (c)).
If the _flip bit_ is 0, the block is divided into two 2{times}4
subblocks side-by-side, as shown in <<Table-etc2-sidebyside>>.
If the _flip bit_ is 1, the block is divided into two 4{times}2 subblocks
on top of each other, as shown in <<Table-etc2-ontop>>.
In both modes, a _base color_ for each subblock is stored, but the way
they are stored is different in the two modes:
[[Table-etc2-sidebyside]]
.Two 2{times}4-pixel ETC2 subblocks side-by-side
image::images/ETC2x4.{svgpdf}[width="{svgpdf@pdf:142pt:213}",align="center"]
[[Table-etc2-ontop]]
.Two 4{times}2-pixel ETC2 subblocks on top of each other
image::images/ETC4x2.{svgpdf}[width="{svgpdf@pdf:142pt:213}",align="center"]
In the `individual' mode, following the layout shown in
<<ETC2IndividualLayout,section b>> of <<Table-etc2-dataformat>>, the
_base color_ for subblock 1 is derived from the codewords _R_ (bits 63..60),
_G_ (bits 55..52) and _B_ (bits 47..44).
These four bit values are extended to _RGB_:888 by replicating the four higher
order bits in the four lower order bits.
For instance, if _R_ = 14 = 1110 binary (1110b for short), _G_ = 3 = 0011b
and _B_ = 8 = 1000b, then the red component of the _base color_
of subblock 1 becomes 11101110b = 238, and the green and blue
components become 00110011b = 51 and 10001000b = 136.
The _base color_ for subblock 2 is decoded the same way, but using the
4-bit codewords _R_~2~ (bits 59..56), _G_~2~ (bits 51..48) and _B_~2~ (bits 43..40)
instead.
In summary, the _base colors_ for the subblocks in the individual mode are:
[latexmath]
++++++
\begin{align*}
\mathit{base\ color_{subblock1}} & = \mathit{extend4to8bits}(\mathit{R}, \mathit{G}, \mathit{B}) \\
\mathit{base\ color_{subblock2}} & = \mathit{extend4to8bits}(\mathit{R}_2, \mathit{G}_2, \mathit{B}_2)
\end{align*}
++++++
<<<
In the `differential' mode, following the layout shown in
<<ETC2DifferentialLayout,section c>> of <<Table-etc2-dataformat>>, the
_base color_ for subblock 1 is derived from the five-bit codewords _R_, _G_ and _B_.
These five-bit codewords are extended to eight bits by replicating the top
three highest-order bits to the three lowest-order bits.
For instance, if _R_ = 28 = 11100b, the resulting eight-bit
red color component becomes 11100111b = 231.
Likewise, if _G_ = 4 = 00100b and
_B_ = 3 = 00011b, the green and blue components become
00100001b = 33 and 00011000b = 24 respectively.
Thus, in this example, the _base color_ for subblock 1 is
(231, 33, 24).
The five-bit representation for the _base color_ of subblock 2 is obtained
by modifying the five-bit codewords _R_, _G_ and _B_ by the codewords _R_~d~, _G_~d~
and _B_~d~.
Each of _R_~d~, _G_~d~ and _B_~d~ is a 3-bit two's-complement number that can
hold values between -4 and {plus}3.
For instance, if _R_ = 28 as above, and
_R_~d~ = 100b = y - 4,
then the five bit representation for the red color component is
28{plus}(-4) = 24 = 11000b, which is then extended to
eight bits to 11000110b = 198.
Likewise, if _G_ = 4, _G_~d~ = 2, _B_ = 3 and
_B_~d~ = 0, the _base color_ of subblock 2 will be
_RGB _= 198, 49, 24.
In summary, the _base colors_ for the subblocks in the `differential' mode
are:
[latexmath]
++++++
\begin{align*}
\mathit{base\ color_{subblock1}} & = \mathit{extend5to8bits}(\mathit{R}, \mathit{G}, \mathit{B}) \\
\mathit{base\ color_{subblock2}} & = \mathit{extend5to8bits}(\mathit{R}+\mathit{R}_\mathrm{d}, \mathit{G}+\mathit{G}_\mathrm{d}, \mathit{B}+\mathit{B}_\mathrm{d})
\end{align*}
++++++
Note that these additions will not under- or overflow, or one of the
alternative decompression modes would have been chosen instead of the
`differential' mode.
After obtaining the _base color_, the operations are the same for the
two modes `individual' and `differential'. First a table is chosen
using the _table codewords_: For subblock 1, _table codeword 1_ is used
(bits 39..37), and for subblock 2, _table codeword 2_ is used (bits
36..34), see <<ETC2IndividualLayout,section b>> or <<ETC2DifferentialLayout,section c>>
of <<Table-etc2-dataformat>>. The _table codeword_ is used to select
one of eight modifier tables, see <<Table-etc2-modifiers>>. For
instance, if the _table codeword_ is 010 binary = 2, then the modifier
table [-29, -9, 9, 29] is selected for the corresponding sub-block.
Note that the values in <<Table-etc2-modifiers>> are valid for all
textures and can therefore be hardcoded into the decompression unit.
[[Table-etc2-modifiers]]
.ETC2 intensity modifier sets for `individual' and `differential' modes
[cols="2,1,1,1,1",width="45%"]
|==============
^| *_Table codeword_* 4+^.^| Modifier table
^| 0 >| -8 >| -2 >| 2 >| 8
^| 1 >| -17 >| -5 >| 5 >| 17
^| 2 >| -29 >| -9 >| 9 >| 29
^| 3 >| -42 >| -13 >| 13 >| 42
^| 4 >| -60 >| -18 >| 18 >| 60
^| 5 >| -80 >| -24 >| 24 >| 80
^| 6 >| -106 >| -33 >| 33 >| 106
^| 7 >| -183 >| -47 >| 47 >| 183
|==============
[[Table-etc2-pixelindices]]
.Mapping from pixel index values to modifier values for RGB ETC2 compressed textures
[cols="1,1,3",width="50%"]
|============
2+^.^| *_Pixel index_ value* .2+^.^| *Resulting _modifier_ value*
^| *MSB* ^| *LSB*
^| 1 ^| 1 | -b (large negative value)
^| 1 ^| 0 | -a (small negative value)
^| 0 ^| 0 | {plus}a (small positive value)
^| 0 ^| 1 | {plus}b (large positive value)
|============
Next, we identify which _modifier_ value to use from the modifier table
using the two _pixel index_ bits. The _pixel index_ bits are unique for
each pixel. For instance, the _pixel index_ for pixel _d_ (see
<<Figure-etc2-pixellayout>>) can be found in bits 19 (most
significant bit, MSB), and 3 (least significant bit, LSB), see
<<ETC2LowBits,section f>> of <<Table-etc2-dataformat>>.
Note that the pixel index for a particular texel is always stored in
the same bit position,
irrespectively of bits _diff bit_ and _flip bit_. The _pixel index_ bits
are decoded using <<Table-etc2-pixelindices>>.
If, for instance, the _pixel index_ bits are 01 binary = 1, and the
modifier table [-29, -9, 9, 29] is used, then the _modifier_
value selected for that pixel is 29 (see <<Table-etc2-pixelindices>>).
This _modifier_ value is now used to additively modify the _base color_.
For example, if we have the _base color_ (231, 8, 16), we should add
the _modifier_ value 29 to all three components: (231+29, 8+29, 16+29)
resulting in (260, 37, 45).
These values are then clamped to [0..255], resulting in the color
(255, 37, 45), and we are finished decoding the texel.
[NOTE]
====
[[etc2-individual-example]]
<<Figure-etc2-individual>> shows an example `individual mode' ETC2 block.
The two _base colors_ are shown as circles, and _modifiers_ are applied
to each channel to give the `paint colors' selectable by each _pixel index_,
shown as small diamonds.
Since the same _modifier_ is applied to each channel, each _paint color_
for a subblock falls on a line (shown dashed) parallel to the grayscale
(0, 0, 0) to (255, 255, 255) axis, unless the
channels are modified by clamping to the range [0..255].
[[Figure-etc2-individual]]
.ETC2 `individual' mode
image::images/ETC1Ind.{svgpdf}[width="{svgpdf@pdf:190.5pt:382.5}",align="center"]
In this example, one _base color_ is encoded as the 4-bit triple
(4, 11, 9), which is expanded by _extend4to8bits_ to
(68, 187, 153).
Modifier table 4 [-60, -18, 18, 60] is selected for this subblock,
giving the following _paint colors_:
[options="header",width="25%",cols="2,1,1,1"]
|=====
^| Modifier ^| _R_ ^| _G_ ^| _B_
^| -60 >| 8 >| 127 >| 93
^| -18 >| 58 >| 169 >| 135
^| 18 >| 86 >| 205 >| 171
^| 60 >| 128 >| 247 >| 213
|=====
The other _base color_ is encoded as the 4-bit triple
(14, 3, 8), which is expanded by _extend4to8bits_ to
(238, 51, 136).
Modifier table 0 [-8, -2, 2, 8] is selected for this
subblock, giving the following _paint colors_ for the subblock:
[options="header",width="25%",cols="2,1,1,1"]
|=====
^| Modifier ^| _R_ ^| _G_ ^| _B_
^| -8 >| 230 >| 43 >| 128
^| -2 >| 236 >| 49 >| 134
^| 2 >| 240 >| 53 >| 138
^| 8 >| 246 >| 59 >| 144
|=====
In this example, none of the _paint colors_ are modified by the process of
clipping the channels to the range [0..255].
Since there is no difference in the way the _base colors_ are encoded
in `individual mode', either _base color_ could correspond to either
subblock.
====
[NOTE]
====
[[etc2-differential-example]]
<<Figure-etc2-differential>> shows an example `differential mode' ETC2 block.
The two _base colors_ are shown as circles; an arrow shows the _base color_
of the second subblock (the upper left circle) derived from the first
subblock's _base color_ (lower right circle).
_Modifiers_ to the _base colors_ give `paint colors' selectable by each
_pixel index_, shown as small diamonds.
Since the same _modifier_ is applied to each channel, each _paint color_
for a subblock falls on a line (shown dashed) parallel to the grayscale
(0, 0, 0) to (255, 255, 255) axis, unless channels are
modified by clamping to [0..255].
[[Figure-etc2-differential]]
.ETC2 `differential' mode
image::images/ETC1Diff.{svgpdf}[width="{svgpdf@pdf:190.5pt:382.5}",align="center"]
Here the first subblock's _base color_ is encoded as the 5-bit triple
(29, 26, 8), and expanded by _extend5to8bits_ to
(239, 214, 66).
Note that not every color representable in `individual mode', exists
in `differential mode', or vice-versa.
The _base color_ of subblock 2 is the five-bit representation of the
_base color_ of subblock 1 (29, 26, 8) plus a
(_R_~d~,_ G_~d~,_ B_~d~) offset of (-4, -3, {plus}3),
for a new _base color_ of (25, 23, 11) - expanded by
_extend5to8bits_ to (206, 189, 90).
The offset cannot exceed the range [0..31] (expanded to [0..255]):
this would select the `T', `H' or `planar' modes.
For `differential mode', the _base colors_ must be similar in each
channel.
The two's complement offset gives an asymmetry: we could not swap the
subblocks of this example, since a _R_~d~ offset of {plus}4 is unrepresentable.
In this example, modifier table 2 [-29, -9, 9, 29] is
applied to subblock 1's _base color_ of (239, 214, 66):
[options="header",width="25%",cols="2,1,1,1"]
|=====
^| Modifier ^| _R_ ^| _G_ ^| _B_
^| -29 >| 210 >| 185 >| 37
^| -9 >| 230 >| 205 >| 57
^| 9 >| 248 >| 223 >| 75
^| 29 >| 268 >| 243 >| 95
|=====
The last row is clamped to (255, 243, 95), so subblock 1's
_paint colors_ are not colinear in this example.
With _modifiers_, all grays [0..255] are representable.
Similarly, modifier table 3 [-42, -13, 13, 42] is applied to
the _base color_ of subblock 2, (206, 189, 90):
[options="header",width="25%",cols="2,1,1,1"]
|=====
^| Modifier ^| _R_ ^| _G_ ^| _B_
^| -42 >| 164 >| 147 >| 48
^| -13 >| 193 >| 176 >| 77
^| 13 >| 219 >| 202 >| 103
^| 42 >| 248 >| 231 >| 132
|=====
====
<<<
The `T' and `H' compression modes also share some characteristics:
both use two _base colors_ stored using 4 bits per channel decoded as in
the individual mode. Unlike the `individual' mode however, these bits
are not stored sequentially, but in the layout shown in
<<ETC2TLayout,section d>> and <<ETCHLayout,section e>> of
<<Table-etc2-dataformat>>. To clarify, in the `T' mode, the two
colors are constructed as follows:
[latexmath]
++++++
\begin{align*}
\mathit{base\ color\ 1} & = \mathit{extend4to8bits}(\: (\mathit{R}^{3..2} \ll 2)\: | \: \mathit{R}^{1..0}, \: \mathit{G}, \: \mathit{B}) \\
\mathit{base\ color\ 2} & = \mathit{extend4to8bits}(\mathit{R}_2, \: \mathit{G}_2, \: \mathit{B}_2)
\end{align*}
++++++
Here, latexmath:[$\ll$] denotes bit-wise left shift and latexmath:[$|$]
denotes bit-wise OR.
In the `H' mode, the two colors are constructed as follows:
[latexmath]
++++++
\begin{align*}
\mathit{base\ color\ 1} & = \mathit{extend4to8bits}(\mathit{R}, \: (\mathit{G}^{3..1} \ll 1) \: | \: \mathit{G}^0, \: (\mathit{B}^3 \ll 3) \: | \: \mathit{B}^{2..0}) \\
\mathit{base\ color\ 2} & = \mathit{extend4to8bits}(\mathit{R}_2, \: \mathit{G}_2, \: \mathit{B}_2)
\end{align*}
++++++
Both the `T' and `H' modes have four _paint colors_ which are the
colors that will be used in the decompressed block, but they are
assigned in a different manner.
In the `T' mode, _paint color 0_ is simply the first _base color_,
and _paint color 2_ is the second _base color_.
To obtain the other _paint colors_, a `distance' is first
determined, which will be used to modify the luminance of one of the
_base colors_.
This is done by combining the values _d~a~_ and _d~b~_ shown
in <<ETC2TLayout,section d>> of <<Table-etc2-dataformat>> by
(_d~a~_ latexmath:[$\ll$] 1) | _d~b~_,
and then using this value as an index into the small look-up table shown
in <<Table-etc2-distancetable>>.
For example, if _d~a~_ is 10 binary and _d~b~_ is 1 binary, the _distance index_
is 101 binary and the selected `distance' _d_ will be 32.
_Paint color 1_ is then equal to the second _base color_ with the `distance' _d_
added to each channel, and _paint color 3_ is the second _base color_ with
the `distance' _d_ subtracted.
[[Table-etc2-distancetable]]
.Distance table for ETC2 `T' and `H' modes
[options="header",width="25%"]
|================
^.^| Distance index ^.^| Distance _d_
^| 0 ^| 3
^| 1 ^| 6
^| 2 ^| 11
^| 3 ^| 16
^| 4 ^| 23
^| 5 ^| 32
^| 6 ^| 41
^| 7 ^| 64
|================
In summary, to determine the four _paint colors_ for a `T' block:
[latexmath]
+++++++++++
\begin{align*}
\mathit{paint\ color\ 0} & = \mathit{base\ color\ 1} \\
\mathit{paint\ color\ 1} & = \mathit{base\ color\ 2 + (d, d, d)} \\
\mathit{paint\ color\ 2} & = \mathit{base\ color\ 2} \\
\mathit{paint\ color\ 3} & = \mathit{base\ color\ 2 - (d, d, d)}
\end{align*}
+++++++++++
In both cases, the value of each channel is clamped to within [0..255].
[NOTE]
====
<<Figure-etc2-T>> shows an example `T-mode' ETC2 block.
The two _base colors_ are shown as circles, and _modifiers_ are applied
to _base color 2_ to give the other two `paint colors', shown as small
diamonds.
Since the same _modifier_ is applied to each channel, _base color 2_ and the
two _paint colors_ derived from it fall on a line (shown dashed) parallel
to the grayscale (0, 0, 0) to (255, 255, 255) axis, unless
channels are modified by clamping to [0..255].
[[Figure-etc2-T]]
.ETC2 `T' mode
image::images/ETC2T.{svgpdf}[width="{svgpdf@pdf:190.5pt:382.5}",align="center"]
In this example, the first _base color_ is defined as the triple of 4-bit
_RGB_ values (13, 1, 8), which is expanded by _extend4to8bits_ to
(221, 17, 136).
This becomes _paint color 0_.
The second _base color_ is encoded as the triple of 4-bit _RGB_ values
(4, 12, 13), which is expanded by _extend4to8bits_ to
(68, 204, 221).
_Distance index_ 5 is used to select a distance value _d_ of 32, which
is added to and subtracted from the second base color, giving
(100, 236, 253) as _paint color 1_ and (36, 172, 189)
as _paint color 3_.
On this occasion, the channels of these _paint colors_ are not modified
by the process of clamping them to [0..255].
====
A `distance' value is computed for the `H' mode as well, but doing so
is slightly more complex. In order to construct the three-bit index
into the distance table shown in <<Table-etc2-distancetable>>, _d~a~_
and _d~b~_ shown in <<ETC2HLayout,section e>> of <<Table-etc2-dataformat>> are used as the
most significant bit and middle bit, respectively, but the least
significant bit is computed as (_base color 1_ value latexmath:[$\geq$] _base color 2_
value), the `value' of a color for the comparison being equal to
(_R_ latexmath:[$\ll$] 16) {plus} (_G_ latexmath:[$\ll$] 8) +_ B_.
Once the `distance' _d_ has been determined for an `H' block, the four
_paint colors_ will be:
[latexmath]
+++++++++++
\begin{align*}
\mathit{paint\ color\ 0} & = \mathit{base\ color\ 1 + (d, d, d)} \\
\mathit{paint\ color\ 1} & = \mathit{base\ color\ 1 - (d, d, d)} \\
\mathit{paint\ color\ 2} & = \mathit{base\ color\ 2 + (d, d, d)} \\
\mathit{paint\ color\ 3} & = \mathit{base\ color\ 2 - (d, d, d)}
\end{align*}
+++++++++++
Again, all color components are clamped to within [0..255].
[NOTE]
====
<<Figure-etc2-H>> shows an example `H mode' ETC2 block.
The two _base colors_ are shown as circles, and _modifiers_ are applied
to each channel to give the `paint colors' selectable by each _pixel index_,
shown as small diamonds.
Since the same _modifier_ is applied to each channel, each _paint color_
falls on a line through the _base color_ from which it is derived (shown
dashed) parallel to the grayscale (0, 0, 0) to
(255, 255, 255) axis, unless the channels are modified by clamping
to the range [0..255].
[[Figure-etc2-H]]
.ETC2 `H' mode
image::images/ETC2H.{svgpdf}[width="{svgpdf@pdf:190.5pt:382.5}",align="center"]
In this example, the first _base color_ is defined as the triple of 4-bit
_RGB_ values (13, 1, 8), as in the `T mode' case above.
This is expanded by _extend4to8bits_ to (221, 17, 136).
The second _base color_ is defined as the 4-bit triple (4, 12, 13),
which expands to (68, 204, 221).
The block encodes a _distance index_ of 5 (this means that _base color 1_
must be greater than _base color 2_), corresponding to a distance _d_
of 32. This leads to the following _paint colors_:
[width="50%",cols="2,1,1,1,2,1,1,1"]
|=====
.2+^.^| *_Paint color_ id* 3+^| *_Base color_* ^| *Distance* 3+^| *_Paint color_*
^| *_R_* ^| *_G_* ^| *_B_* ^| *_d_* ^| *_R_* ^| *_G_* ^| *_B_*
^| 0 .2+>.^| 221 .2+>.^| 17 .2+>.^| 136 ^| {plus}32 >| 253 >| 49 >| 168
^| 1 ^| -32 >| 189 >| -15 >| 104
^| 2 .2+>.^| 68 .2+>.^| 204 .2+>.^| 221 ^| {plus}32 >| 100 >| 236 >| 253
^| 3 ^| -32 >| 36 >| 172 >| 189
|=====
The _G_ channel of _paint color 1_ is clamped to 0, giving
(189, 0, 104). This stops _paint color_ 1 being
colinear with _paint color 0_ and _base color 1_.
====
Finally, in both the `T' and `H' modes, every pixel is assigned one of the four
_paint colors_ in the same way the four _modifier_ values are
distributed in `individual' or `differential' blocks. For example, to
choose a _paint color_ for pixel _d_, an index is constructed using bit 19
as most significant bit and bit 3 as least significant bit. Then, if a
pixel has index 2, for example, it will be assigned _paint color 2_.
<<<
The final mode possible in an RGB ETC2-compressed block is the
`planar' mode. Here, three _base colors_ are supplied and used to form
a color plane used to determine the color of the individual pixels in
the block.
All three _base colors_ are stored in _RGB_:676 format, and stored in the
manner shown in <<ETC2Planar,section g>> of <<Table-etc2-dataformat>>.
The two secondary colors are given the suffix `h' and `v', so that the
red component of the three colors are _R_, _R_~h~ and _R_~v~, for example.
Some color channels are split into non-consecutive bit-ranges; for
example _B_ is reconstructed using _B_^5^ as the most-significant bit,
_B_^4..3^ as the two following bits, and _B_^2..0^ as the three
least-significant bits.
Once the bits for the _base colors_ have been extracted, they must be
extended to 8 bits per channel in a manner analogous to the method
used for the _base colors_ in other modes. For example, the 6-bit blue
and red channels are extended by replicating the two most significant
of the six bits to the two least significant of the final 8 bits.
With three _base colors_ in _RGB_:888 format, the color of each pixel can
then be determined as:
[latexmath]
++++++++++++
\begin{align*}
\mathit{R}(x,y) & = {x\times (\mathit{R}_\mathrm{h}-\mathit{R})\over 4.0} + {y\times (\mathit{R}_\mathrm{v}-\mathit{R})\over 4.0} + \mathit{R} \\
\mathit{G}(x,y) & = {x\times (\mathit{G}_\mathrm{h}-\mathit{G})\over 4.0} + {y\times (\mathit{G}_\mathrm{v}-\mathit{G})\over 4.0} + \mathit{G} \\
\mathit{B}(x,y) & = {x\times (\mathit{B}_\mathrm{h}-\mathit{B})\over 4.0} + {y\times (\mathit{B}_\mathrm{v}-\mathit{B})\over 4.0} + \mathit{B}
\end{align*}
++++++++++++
where _x_ and _y_ are values from 0 to 3 corresponding
to the pixels coordinates within the block, _x_ being in the
_u_ direction and _y_ in the _v_ direction.
For example, the pixel _g_ in <<Figure-etc2-pixellayout>> would have
_x _= 1 and _y _= 2.
These values are then rounded to the nearest integer (to the larger
integer if there is a tie) and then clamped to a value between 0 and 255.
Note that this is equivalent to
[latexmath]
++++++++++++++
\begin{align*}
\mathit{R}(x,y) & = \mathit{clamp255}((x\times (\mathit{R}_\mathrm{h}-\mathit{R}) + y\times (\mathit{R}_\mathrm{v}-\mathit{R}) + 4\times \mathit{R} + 2) \gg 2) \\
\mathit{G}(x,y) & = \mathit{clamp255}((x\times (\mathit{G}_\mathrm{h}-\mathit{G}) + y\times (\mathit{G}_\mathrm{v}-\mathit{G}) + 4\times \mathit{G} + 2) \gg 2) \\
\mathit{B}(x,y) & = \mathit{clamp255}((x\times (\mathit{B}_\mathrm{h}-\mathit{B}) + y\times (\mathit{B}_\mathrm{v}-\mathit{B}) + 4\times \mathit{B} + 2) \gg 2)
\end{align*}
++++++++++++++
where _clamp255_({cdot}) clamps the value to a number in the range
[0..255] and where latexmath:[$\gg$] performs bit-wise right shift.
This specification gives the output for each compression mode in 8-bit
integer colors between 0 and 255, and these values all need to be
divided by 255 for the final floating point representation.
[NOTE]
====
<<Figure-etc2-planar>> shows an example `planar mode' ETC2 block.
The three _base colors_ are shown as circles, and the interpolated
values are shown as small diamonds.
[[Figure-etc2-planar]]
.ETC2 `planar' mode
image::images/ETC2P.{svgpdf}[width="{svgpdf@pdf:190.5pt:382.5}",align="center"]
In this example, the origin (_R_,_ G_,_ B_) is encoded as the 6-7-6-bit
value (12, 64, 62), which is expanded to (48, 129, 251).
The `horizontal' (interpolated by _x_) _base color_
(_R_~h~,_ G_~h~,_ B_~h~) = (50, 5, 37) and `vertical'
(interpolated by _y_) _base color_ (_R_~v~,_ G_~v~,_ B_~v~) =
(40, 112, 45) expand to (203, 10, 150) and
(162, 225, 182) respectively.
The resulting texel colors are then:
[options="header",width="25%",cols="1,1,1,1,1"]
|=====
^| _x_ ^| _y_ ^| _R_ ^| _G_ ^| _B_
^| 0 ^| 0 >| 48 >| 129 >| 251
^| 1 ^| 0 >| 87 >| 99 >| 226
^| 2 ^| 0 >| 126 >| 70 >| 201
^| 3 ^| 0 >| 164 >| 40 >| 175
^| 0 ^| 1 >| 77 >| 153 >| 234
^| 1 ^| 1 >| 115 >| 123 >| 209
^| 2 ^| 1 >| 154 >| 94 >| 183
^| 3 ^| 1 >| 193 >| 64 >| 158
^| 0 ^| 2 >| 105 >| 177 >| 217
^| 1 ^| 2 >| 144 >| 147 >| 191
^| 2 ^| 2 >| 183 >| 118 >| 166
^| 3 ^| 2 >| 221 >| 88 >| 141
^| 0 ^| 3 >| 134 >| 201 >| 199
^| 1 ^| 3 >| 172 >| 171 >| 174
^| 2 ^| 3 >| 211 >| 142 >| 149
^| 3 ^| 3 >| 250 >| 112 >| 124
|=====
====
=== Format RGB ETC2 with sRGB encoding
Decompression of floating point sRGB values in RGB ETC2 with sRGB encoding
follows that of floating point _RGB_ values of linear RGB ETC2.
The result is sRGB-encoded values between 0.0 and 1.0.
The further conversion from an sRGB encoded component _cs_
to a linear component _cl_ is done according to the formulae
in <<TRANSFER_SRGB>>.
Assume _cs_ is the sRGB component in the range [0, 1].
<<<
[[RGBAETC2]]
=== Format RGBA ETC2
Each 4{times}4 block of _RGBA_:8888 information is compressed to 128
bits.
To decode a block, the two 64-bit integers _int64bit~Alpha~_ and
_int64bit~Color~_ are calculated as described in
<<RGBETC2>>.
The _RGB_ component is then decoded the same way as for RGB ETC2
(see <<RGBETC2>>), using _int64bit~Color~_ as the _int64bit_ codeword.
[[Table-etc2eac-dataformat]]
.Texel Data format for alpha part of RGBA ETC2 compressed textures
ifdef::a2xhtml[]
[width="60%"]
endif::[]
ifndef::a2xhtml[]
[width="60%"]
endif::[]
|=============
16+| *a) Bit layout in bits 63 through 48*
^| ~63~ ^| ~62~ ^| ~61~ ^| ~60~ ^| ~59~ ^| ~58~ ^| ~57~ ^| ~56~ ^| ~55~ ^| ~54~ ^| ~53~ ^| ~52~ ^| ~51~ ^| ~50~ ^| ~49~ ^| ~48~
8+^| _base codeword_ 4+^| _multiplier_ 4+^| _table index_
16+| *b) Bit layout in bits 47 through 0, with pixels as name in <<Figure-etc2-pixellayout>>,*
*bits labeled from 0 being the LSB to 47 being the MSB*
^| ~47~ ^| ~46~ ^| ~45~ ^| ~44~ ^| ~43~ ^| ~42~ ^| ~41~ ^| ~40~ ^| ~39~ ^| ~38~ ^| ~37~ ^| ~36~ ^| ~35~ ^| ~34~ ^| ~33~ ^| ~32~
^| _a_~{alpha}~^2^ ^| _a_~{alpha}~^1^ ^| _a_~{alpha}~^0^ ^| _b_~{alpha}~^2^ ^| _b_~{alpha}~^1^ ^| _b_~{alpha}~^0^ ^| _c_~{alpha}~^2^ ^| _c_~{alpha}~^1^ ^| _c_~{alpha}~^0^ ^| _d_~{alpha}~^2^ ^| _d_~{alpha}~^1^ ^| _d_~{alpha}~^0^ ^| _e_~{alpha}~^2^ ^| _e_~{alpha}~^1^ ^| _e_~{alpha}~^0^ ^| _f_~{alpha}~^2^
^| ~31~ ^| ~30~ ^| ~29~ ^| ~28~ ^| ~27~ ^| ~26~ ^| ~25~ ^| ~24~ ^| ~23~ ^| ~22~ ^| ~21~ ^| ~20~ ^| ~19~ ^| ~18~ ^| ~17~ ^| ~16~
^| _f_~{alpha}~^1^ ^| _f_~{alpha}~^0^ ^| _g_~{alpha}~^2^ ^| _g_~{alpha}~^1^ ^| _g_~{alpha}~^0^ ^| _h_~{alpha}~^2^ ^| _h_~{alpha}~^1^ ^| _h_~{alpha}~^0^ ^| _i_~{alpha}~^2^ ^| _i_~{alpha}~^1^ ^| _i_~{alpha}~^0^ ^| _j_~{alpha}~^2^ ^| _j_~{alpha}~^1^ ^| _j_~{alpha}~^0^ ^| _k_~{alpha}~^2^ ^| _k_~{alpha}~^1^
^| ~15~ ^| ~14~ ^| ~13~ ^| ~12~ ^| ~11~ ^| ~10~ ^| ~9~ ^| ~8~ ^| ~7~ ^| ~6~ ^| ~5~ ^| ~4~ ^| ~3~ ^| ~2~ ^| ~1~ ^| ~0~
^| _k_~{alpha}~^0^ ^| _l_~{alpha}~^2^ ^| _l_~{alpha}~^1^ ^| _l_~{alpha}~^0^ ^| _m_~{alpha}~^2^ ^| _m_~{alpha}~^1^ ^| _m_~{alpha}~^0^ ^| _n_~{alpha}~^2^ ^| _n_~{alpha}~^1^ ^| _n_~{alpha}~^0^ ^| _o_~{alpha}~^2^ ^| _o_~{alpha}~^1^ ^| _o_~{alpha}~^0^ ^| _p_~{alpha}~^2^ ^| _p_~{alpha}~^1^ ^| _p_~{alpha}~^0^
|=============
The 64-bits in _int64bit~Alpha~_ used to decompress the alpha channel
are laid out as shown in <<Table-etc2eac-dataformat>>. The information
is split into two parts. The first 16 bits comprise a _base codeword_,
a _table codeword_ and a _multiplier_, which are used together to compute
8 pixel values to be used in the block. The remaining 48 bits are
divided into 16 3-bit indices, which are used to select one of these 8
possible values for each pixel in the block.
[NOTE]
====
The color pixel indices are stored in _a_.._p_ order in increasing bit
order in a big-endian word representation, with the low bit stored
separately from the high bit.
However, the alpha indices are stored in _p_.._a_ order in increasing
bit order in a big-endian word representation, with each bit of each
alpha index stored consecutively.
====
The decoded value of a pixel is a value between 0 and 255 and is
calculated the following way:
[[Equation-etc2eac-eqn-base]]
.ETC2 base
[latexmath]
++++++
\begin{align*}
\mathit{clamp255}(\mathit{base\ codeword} + \mathit{modifier}\times \mathit{multiplier})
\end{align*}
++++++
where _clamp255_({cdot}) maps values outside the range
[0..255] to 0.0 or 255.0.
The _base codeword_ is stored in the first 8 bits (bits 63..56) as
shown in <<Table-etc2eac-dataformat>> part (a).
This is the first term in <<Equation-etc2eac-eqn-base>>.
<<<
Next, we want to obtain the _modifier_. Bits 51..48 in
<<Table-etc2eac-dataformat>> part (a) form a 4-bit index used to select
one of 16 pre-determined `modifier tables', shown in
<<Table-etc2eac-modifiers>>.
[[Table-etc2eac-modifiers]]
.Intensity modifier sets for RGBA ETC2 alpha component
[cols="20%,10%,10%,10%,10%,10%,10%,10%,10%",width="60%",options="header"]
|=================
^| _Table index_ 8+^| Modifier table
>| 0 >| -3 >| -6 >| -9 >| -15 >| 2 >| 5 >| 8 >| 14
>| 1 >| -3 >| -7 >| -10 >| -13 >| 2 >| 6 >| 9 >| 12
>| 2 >| -2 >| -5 >| -8 >| -13 >| 1 >| 4 >| 7 >| 12
>| 3 >| -2 >| -4 >| -6 >| -13 >| 1 >| 3 >| 5 >| 12
>| 4 >| -3 >| -6 >| -8 >| -12 >| 2 >| 5 >| 7 >| 11
>| 5 >| -3 >| -7 >| -9 >| -11 >| 2 >| 6 >| 8 >| 10
>| 6 >| -4 >| -7 >| -8 >| -11 >| 3 >| 6 >| 7 >| 10
>| 7 >| -3 >| -5 >| -8 >| -11 >| 2 >| 4 >| 7 >| 10
>| 8 >| -2 >| -6 >| -8 >| -10 >| 1 >| 5 >| 7 >| 9
>| 9 >| -2 >| -5 >| -8 >| -10 >| 1 >| 4 >| 7 >| 9
>| 10 >| -2 >| -4 >| -8 >| -10 >| 1 >| 3 >| 7 >| 9
>| 11 >| -2 >| -5 >| -7 >| -10 >| 1 >| 4 >| 6 >| 9
>| 12 >| -3 >| -4 >| -7 >| -10 >| 2 >| 3 >| 6 >| 9
>| 13 >| -1 >| -2 >| -3 >| -10 >| 0 >| 1 >| 2 >| 9
>| 14 >| -4 >| -6 >| -8 >| -9 >| 3 >| 5 >| 7 >| 8
>| 15 >| -3 >| -5 >| -7 >| -9 >| 2 >| 4 >| 6 >| 8
|=================
For example, a _table index_ of 13 (1101 binary) means that we should
use table [-1, -2 -3, -10, 0, 1, 2, 9].
To select which of these values we should use, we consult the _pixel index_ of the
pixel we want to decode.
As shown in <<Table-etc2eac-dataformat>> part (b), bits 47..0 are used to store
a 3-bit index for each pixel in the block, selecting one of the 8
possible values.
Assume we are interested in pixel _b_.
Its pixel index is stored in bits 44..42, with the most significant bit stored
in 44 and the least significant bit stored in 42.
If the _pixel index_ is 011 binary = 3, this means we should take the value 3 from the
left in the table, which is -10.
This is now our _modifier_, which is the starting point of our second term in the addition.
In the next step we obtain the _multiplier_ value; bits 55..52 form a
four-bit _multiplier_ between 0 and 15. This value should be
multiplied with the _modifier_.
An encoder is not allowed to produce a _multiplier_ of zero, but the decoder should
still be able to handle this case (and produce 0 {times} _modifier_ = 0 in that case).
The _modifier_ times the _multiplier_ now provides the third and final
term in the sum in <<Equation-etc2eac-eqn-base>>. The sum is
calculated and the value is clamped to the interval [0..255]. The
resulting value is the 8-bit output value.
For example, assume a _base codeword_ of 103, a _table index_ of 13, a
_pixel index_ of 3 and a _multiplier_ of 2.
We will then start with the _base codeword_ 103 (01100111 binary).
Next, a _table index_ of 13 selects table
[-1, -2, -3, -10, 0, 1, 2, 9],
and using a _pixel index_ of 3 will result in a _modifier_ of -10.
The _multiplier_ is 2, forming -10 {times} 2 = -20.
We now add this to the base value and get 103 - 20 = 83.
After clamping we still get 83 = 01010011 binary.
This is our 8-bit output value.
This specification gives the output for each channel in 8-bit integer
values between 0 and 255, and these values all need to be divided by
255 to obtain the final floating point representation.
Note that hardware can be effectively shared between the alpha
decoding part of this format and that of R11 EAC texture. For
details on how to reuse hardware, see <<Section-r11eac>>.
=== Format RGBA ETC2 with sRGB encoding
Decompression of floating point sRGB values in RGBA ETC2 with sRGB encoding
follows that of floating point _RGB_ values of linear RGBA ETC2. The
result is sRGB values between 0.0 and 1.0.
The further conversion from an sRGB encoded component _cs_ to a linear
component _cl_ is according to the formula in <<TRANSFER_SRGB>>. Assume
_cs_ is the sRGB component in the range [0, 1].
The alpha component of RGBA ETC2 with sRGB encoding is done in the
same way as for linear RGBA ETC2.
<<<
[[Section-r11eac]]
=== Format Unsigned R11 EAC
The number of bits to represent a 4{times}4 texel block is 64 bits.
if format is R11 EAC. In that case the
data for a block is stored as a number of bytes,
{_q_~0~, _q_~1~, _q_~2~, _q_~3~, _q_~4~, _q_~5~, _q_~6~, _q_~7~},
where byte _q_~0~ is located at the lowest memory address and _q_~7~ at
the highest. The red component of the 4{times}4 block is then represented
by the following 64-bit integer:
[latexmath]
++++++
\begin{align*}
\mathit{int64bit} & = 256\times (256\times (256\times (256\times (256\times (256\times (256\times q_0+q_1)+q_2)+q_3)+q_4)+q_5)+q_6)+q_7
\end{align*}
++++++
This 64-bit word contains information about a single-channel 4{times}4
pixel block as shown in <<Figure-etc2-pixellayout>>. The 64-bit word
is split into two parts.
The first 16 bits comprise a _base codeword_, a _table
codeword_ and a _multiplier_.
The remaining 48 bits are divided into 16 3-bit indices, which are used
to select one of the 8 possible values for each pixel in the block, as
shown in <<Table-etc2eac-dataformat>>.
The decoded value is calculated as:
[[Equation-r11eac-eqn-start]]
.Unsigned R11 EAC start
[latexmath]
++++++
\begin{align*}
\mathit{clamp1}\left((\mathit{base\ codeword}+0.5)\times \frac{1}{255.875} + \mathit{modifier}\times\mathit{multiplier}\times\frac{1}{255.875}\right)
\end{align*}
+++++++
where _clamp1_({cdot}) maps values outside the range [0.0, 1.0] to 0.0
or 1.0.
We will now go into detail how the decoding is done. The result will
be an 11-bit fixed point number where 0 represents 0.0 and 2047
represents 1.0. This is the exact representation for the decoded
value. However, some implementations may use, e.g., 16-bits of
accuracy for filtering. In such a case the 11-bit value will be
extended to 16 bits in a predefined way, which we will describe later.
To get a value between 0 and 2047 we must multiply
<<Equation-r11eac-eqn-start>> by 2047.0:
[latexmath]
+++++++