From 340705c138f2d7f3218ae6e4bac1423d21196024 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 17 Apr 2006 11:16:11 +0000 Subject: Allocate LUT/YUV tables on the heap svn-id: r21971 --- graphics/scaler.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'graphics/scaler.cpp') diff --git a/graphics/scaler.cpp b/graphics/scaler.cpp index 1853742ce2..1f32d4cea6 100644 --- a/graphics/scaler.cpp +++ b/graphics/scaler.cpp @@ -43,9 +43,8 @@ extern "C" { #endif -// FIXME/TODO: The following two tables suck up 512 KB. -// They should at least be allocated on the heap, to reduce the size of the -// binary. +// FIXME/TODO: The following two tables suck up 512 KB. This is bad. +// In addition we never free them... // // Note: a memory lookup table is *not* necessarily faster than computing // these things on the fly, because of its size. Both tables together, plus @@ -69,9 +68,8 @@ extern "C" { // Of course, the above is largely a conjecture, and the actual speed // differences are likely to vary a lot between different architectures and // CPUs. -uint RGBtoYUVstorage[65536]; -uint *RGBtoYUV = RGBtoYUVstorage; -uint LUT16to32[65536]; +uint32 *RGBtoYUV = 0; +uint32 *LUT16to32 = 0; } template @@ -81,6 +79,12 @@ void InitLUT() { assert(T::kBytesPerPixel == 2); + // Allocate the YUV/LUT buffers on the fly if needed. + if (RGBtoYUV == 0) + RGBtoYUV = (uint32 *)malloc(65536 * sizeof(uint32)); + if (LUT16to32 == 0) + LUT16to32 = (uint32 *)malloc(65536 * sizeof(uint32)); + for (int color = 0; color < 65536; ++color) { r = ((color & T::kRedMask) >> T::kRedShift) << (8 - T::kRedBits); g = ((color & T::kGreenMask) >> T::kGreenShift) << (8 - T::kGreenBits); -- cgit v1.2.3