| | 1 | | // <copyright file="AlphaBox.cs" company="Jérémy Ansel"> |
| | 2 | | // Copyright (c) 2014-2019 Jérémy Ansel |
| | 3 | | // </copyright> |
| | 4 | | // <license> |
| | 5 | | // Licensed under the MIT license. See LICENSE.txt |
| | 6 | | // </license> |
| | 7 | |
|
| | 8 | | namespace JeremyAnsel.ColorQuant |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// A box color cube with alpha. |
| | 12 | | /// </summary> |
| | 13 | | internal sealed class AlphaBox |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// The index bits. |
| | 17 | | /// </summary> |
| | 18 | | private const int IndexBits = 6; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// The index alpha bits. |
| | 22 | | /// </summary> |
| | 23 | | private const int IndexAlphaBits = 4; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Gets or sets the min red value, exclusive. |
| | 27 | | /// </summary> |
| | 28 | | public int R0; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets or sets the max red value, inclusive. |
| | 32 | | /// </summary> |
| | 33 | | public int R1; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Gets or sets the min green value, exclusive. |
| | 37 | | /// </summary> |
| | 38 | | public int G0; |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Gets or sets the max green value, inclusive. |
| | 42 | | /// </summary> |
| | 43 | | public int G1; |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Gets or sets the min blue value, exclusive. |
| | 47 | | /// </summary> |
| | 48 | | public int B0; |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Gets or sets the max blue value, inclusive. |
| | 52 | | /// </summary> |
| | 53 | | public int B1; |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Gets or sets the min alpha value, exclusive. |
| | 57 | | /// </summary> |
| | 58 | | public int A0; |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Gets or sets the max alpha value, inclusive. |
| | 62 | | /// </summary> |
| | 63 | | public int A1; |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// Gets or sets the volume. |
| | 67 | | /// </summary> |
| | 68 | | public int Volume; |
| | 69 | |
|
| | 70 | | public int Index1111; |
| | 71 | | public int Index1110; |
| | 72 | | public int Index1101; |
| | 73 | | public int Index1100; |
| | 74 | | public int Index1011; |
| | 75 | | public int Index1010; |
| | 76 | | public int Index1001; |
| | 77 | | public int Index1000; |
| | 78 | | public int Index0111; |
| | 79 | | public int Index0110; |
| | 80 | | public int Index0101; |
| | 81 | | public int Index0100; |
| | 82 | | public int Index0011; |
| | 83 | | public int Index0010; |
| | 84 | | public int Index0001; |
| | 85 | | public int Index0000; |
| | 86 | |
|
| | 87 | | public void Update() |
| | 88 | | { |
| 3182 | 89 | | Volume = (R1 - R0) * (G1 - G0) * (B1 - B0) * (A1 - A0); |
| | 90 | |
|
| 3182 | 91 | | int r1 = (R1 << ((IndexBits * 2) + IndexAlphaBits)) + (R1 << (IndexBits + IndexAlphaBits + 1)) + (R1 << (Ind |
| 3182 | 92 | | int r0 = (R0 << ((IndexBits * 2) + IndexAlphaBits)) + (R0 << (IndexBits + IndexAlphaBits + 1)) + (R0 << (Ind |
| 3182 | 93 | | int g1 = (G1 << (IndexBits + IndexAlphaBits)) + (G1 << IndexBits) + (G1 << IndexAlphaBits) + G1; |
| 3182 | 94 | | int g0 = (G0 << (IndexBits + IndexAlphaBits)) + (G0 << IndexBits) + (G0 << IndexAlphaBits) + G0; |
| 3182 | 95 | | int b1 = (B1 << IndexAlphaBits) + B1; |
| 3182 | 96 | | int b0 = (B0 << IndexAlphaBits) + B0; |
| 3182 | 97 | | int a1 = A1; |
| 3182 | 98 | | int a0 = A0; |
| | 99 | |
|
| 3182 | 100 | | Index1111 = r1 + g1 + b1 + a1; |
| 3182 | 101 | | Index1110 = r1 + g1 + b1 + a0; |
| 3182 | 102 | | Index1101 = r1 + g1 + b0 + a1; |
| 3182 | 103 | | Index1100 = r1 + g1 + b0 + a0; |
| 3182 | 104 | | Index1011 = r1 + g0 + b1 + a1; |
| 3182 | 105 | | Index1010 = r1 + g0 + b1 + a0; |
| 3182 | 106 | | Index1001 = r1 + g0 + b0 + a1; |
| 3182 | 107 | | Index1000 = r1 + g0 + b0 + a0; |
| 3182 | 108 | | Index0111 = r0 + g1 + b1 + a1; |
| 3182 | 109 | | Index0110 = r0 + g1 + b1 + a0; |
| 3182 | 110 | | Index0101 = r0 + g1 + b0 + a1; |
| 3182 | 111 | | Index0100 = r0 + g1 + b0 + a0; |
| 3182 | 112 | | Index0011 = r0 + g0 + b1 + a1; |
| 3182 | 113 | | Index0010 = r0 + g0 + b1 + a0; |
| 3182 | 114 | | Index0001 = r0 + g0 + b0 + a1; |
| 3182 | 115 | | Index0000 = r0 + g0 + b0 + a0; |
| 3182 | 116 | | } |
| | 117 | | } |
| | 118 | | } |
| | 119 | |
|