aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2011-01-28 09:46:39 +0000
committerMax Horn2011-01-28 09:46:39 +0000
commit96d91ec1822a8bf898d900792a69cffd2f898ada (patch)
treed974435ff6ccbadf4a4a9f83a9a3ca56a16118f5
parentbaf6af4fa6f47885b0ffa7355860464a5628bb10 (diff)
downloadscummvm-rg350-96d91ec1822a8bf898d900792a69cffd2f898ada.tar.gz
scummvm-rg350-96d91ec1822a8bf898d900792a69cffd2f898ada.tar.bz2
scummvm-rg350-96d91ec1822a8bf898d900792a69cffd2f898ada.zip
GRAPHICS: Turn sqrt(2) and cosine values into constants ;)
svn-id: r55586
-rw-r--r--graphics/jpeg.cpp30
-rw-r--r--graphics/jpeg.h2
2 files changed, 18 insertions, 14 deletions
diff --git a/graphics/jpeg.cpp b/graphics/jpeg.cpp
index 2acfe308aa..82a08dbbaa 100644
--- a/graphics/jpeg.cpp
+++ b/graphics/jpeg.cpp
@@ -33,6 +33,10 @@
namespace Graphics {
+#ifndef M_SQRT2
+#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
+#endif /* M_SQRT2 */
+
// Order used to traverse the quantization tables
static const uint8 _zigZagOrder[64] = {
0, 1, 8, 16, 9, 2, 3, 10,
@@ -45,6 +49,17 @@ static const uint8 _zigZagOrder[64] = {
53, 60, 61, 54, 47, 55, 62, 63
};
+static const float _cosine32[32] = {
+ 1.000000000000000, 0.980785280403230, 0.923879532511287, 0.831469612302545,
+ 0.707106781186548, 0.555570233019602, 0.382683432365090, 0.195090322016128,
+ 0.000000000000000, -0.195090322016128, -0.382683432365090, -0.555570233019602,
+ -0.707106781186547, -0.831469612302545, -0.923879532511287, -0.980785280403230,
+ -1.000000000000000, -0.980785280403230, -0.923879532511287, -0.831469612302545,
+ -0.707106781186548, -0.555570233019602, -0.382683432365090, -0.195090322016129,
+ -0.000000000000000, 0.195090322016128, 0.382683432365090, 0.555570233019602,
+ 0.707106781186547, 0.831469612302545, 0.923879532511287, 0.980785280403230
+};
+
JPEG::JPEG() :
_stream(NULL), _w(0), _h(0), _numComp(0), _components(NULL), _numScanComp(0),
_scanComp(NULL), _currentComp(NULL) {
@@ -60,15 +75,6 @@ JPEG::JPEG() :
_huff[i].sizes = NULL;
_huff[i].codes = NULL;
}
-
- // Initialize sqrt_2 and cosine lookups
- _sqrt_2 = sqrt(2.0f);
- debug(2, "JPEG: _sqrt_2: %f", _sqrt_2);
-
- for(byte i = 0; i < 32; i++) {
- _cosine_32[i] = cos(i * PI / 16);
- debug(2, "JPEG: _cosine_32[%d]: %f", i, _cosine_32[i]);
- }
}
JPEG::~JPEG() {
@@ -504,13 +510,13 @@ bool JPEG::readMCU(uint16 xMCU, uint16 yMCU) {
float JPEG::idct(int x, int y, int weight, int fx, int fy) {
byte vx_in = ((int32)((2 * x) + 1) * fx) % 32;
byte vy_in = ((int32)((2 * y) + 1) * fy) % 32;
- float ret = (float)weight * _cosine_32[vx_in] * _cosine_32[vy_in];
+ float ret = (float)weight * _cosine32[vx_in] * _cosine32[vy_in];
if (fx == 0)
- ret /= _sqrt_2;
+ ret /= M_SQRT2;
if (fy == 0)
- ret /= _sqrt_2;
+ ret /= M_SQRT2;
return ret;
}
diff --git a/graphics/jpeg.h b/graphics/jpeg.h
index d6d031448b..c8e0cd5f9d 100644
--- a/graphics/jpeg.h
+++ b/graphics/jpeg.h
@@ -118,8 +118,6 @@ private:
uint8 _bitsData;
uint8 _bitsNumber;
- float _sqrt_2;
- float _cosine_32[32];
// Discrete Cosine Transformation
float idct(int x, int y, int weight, int fx, int fy);
};