openMSX
Multiply32.cc
Go to the documentation of this file.
1 #include "Multiply32.hh"
2 #include "PixelOperations.hh"
3 #include "enumerate.hh"
4 #include <cstring>
5 
6 namespace openmsx {
7 
8 // class Multiply32<uint32_t>
9 
11 {
12  // nothing
13 }
14 
15 
16 // class Multiply32<uint16_t>
17 
19 {
20  Rmask1 = pixelOps.getRmask();
21  Gmask1 = pixelOps.getGmask();
22  Bmask1 = pixelOps.getBmask();
23 
24  Rshift1 = ((2 + pixelOps.getRloss()) - pixelOps.getRshift()) & 31;
25  Gshift1 = ((2 + pixelOps.getGloss()) - pixelOps.getGshift()) & 31;
26  Bshift1 = ((2 + pixelOps.getBloss()) - pixelOps.getBshift()) & 31;
27 
28  Rmask2 = ((1 << (2 + pixelOps.getRloss())) - 1) <<
29  (10 + pixelOps.getRshift() - 2 * (2 + pixelOps.getRloss()));
30  Gmask2 = ((1 << (2 + pixelOps.getGloss())) - 1) <<
31  (10 + pixelOps.getGshift() - 2 * (2 + pixelOps.getGloss()));
32  Bmask2 = ((1 << (2 + pixelOps.getBloss())) - 1) <<
33  (10 + pixelOps.getBshift() - 2 * (2 + pixelOps.getBloss()));
34 
35  Rshift2 = (2 * (2 + pixelOps.getRloss()) - pixelOps.getRshift() - 10) & 31;
36  Gshift2 = (2 * (2 + pixelOps.getGloss()) - pixelOps.getGshift() - 10) & 31;
37  Bshift2 = (2 * (2 + pixelOps.getBloss()) - pixelOps.getBshift() - 10) & 31;
38 
39  Rshift3 = (Rshift1 + 0) & 31;
40  Gshift3 = (Gshift1 + 10) & 31;
41  Bshift3 = (Bshift1 + 20) & 31;
42 
43  factor = 0;
44  memset(tab, 0, sizeof(tab));
45 }
46 
48 {
49  if (factor == f) return;
50  factor = f;
51 
52  for (auto [p, t] : enumerate(tab)) {
53  uint32_t r = std::rotl((p & Rmask1), Rshift1) |
54  std::rotl((p & Rmask2), Rshift2);
55  uint32_t g = std::rotl((p & Gmask1), Gshift1) |
56  std::rotl((p & Gmask2), Gshift2);
57  uint32_t b = std::rotl((p & Bmask1), Bshift1) |
58  std::rotl((p & Bmask2), Bshift2);
59  t = (((r * factor) >> 8) << 0) |
60  (((g * factor) >> 8) << 10) |
61  (((b * factor) >> 8) << 20);
62  }
63 }
64 
65 } // namespace openmsx
int g
TclObject t
Helper class to perform 'pixel x scalar' calculations.
Definition: Multiply32.hh:16
constexpr auto enumerate(Iterable &&iterable)
Heavily inspired by Nathan Reed's blog post: Python-Like enumerate() In C++17 http://reedbeta....
Definition: enumerate.hh:28
This file implemented 3 utility functions:
Definition: Autofire.cc:9