1// Aseprite Document Library
2// Copyright (C) 2020-2022 Igara Studio S.A.
3// Copyright (C) 2001-2016 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifndef DOC_COLOR_SCALES_H_INCLUDED
9#define DOC_COLOR_SCALES_H_INCLUDED
10#pragma once
11
12#include "base/debug.h"
13
14namespace doc {
15
16 inline int scale_3bits_to_8bits(const int v) {
17 ASSERT(v >= 0 && v < 8);
18 return (v << 5) | (v << 2) | (v >> 1);
19 }
20
21 inline int scale_5bits_to_8bits(const int v) {
22 ASSERT(v >= 0 && v < 32);
23 return (v << 3) | (v >> 2);
24 }
25
26 inline int scale_6bits_to_8bits(const int v) {
27 ASSERT(v >= 0 && v < 64);
28 return (v << 2) | (v >> 4);
29 }
30
31 inline int scale_xxbits_to_8bits(const int xx, const int v) {
32 switch (xx) {
33 case 3:
34 return scale_3bits_to_8bits(v);
35 case 5:
36 return scale_5bits_to_8bits(v);
37 case 6:
38 return scale_6bits_to_8bits(v);
39 }
40 return (int)(255.0 / (double(1<<xx) - 1.0) * (double)v);
41 }
42
43} // namespace doc
44
45#endif
46