Ticket #8174: cmi-room-saturation2.diff

File cmi-room-saturation2.diff, 4.4 KB (added by eriktorbjorn, 22 years ago)

Patch against a February 19 CVS snapshot

  • scummvm/scumm/gfx.cpp

    diff -ur ScummVM-cvs20030219/scummvm/scumm/gfx.cpp ScummVM-cvs20030219+hack/scummvm/scumm/gfx.cpp
    old new  
    28802880        }
    28812881}
    28822882
     2883static double value(double n1, double n2, double hue)
     2884{
     2885        if (hue > 360.0)
     2886                hue = hue - 360.0;
     2887        else if (hue < 0.0)
     2888                hue = hue + 360.0;
     2889
     2890        if (hue < 60.0)
     2891                return n1 + (n2 - n1) * hue / 60.0;
     2892        if (hue < 180.0)
     2893                return n2;
     2894        if (hue < 240.0)
     2895                return n1 + (n2 - n1) * (240.0 - hue) / 60.0;
     2896        return n1;
     2897}
     2898
     2899void Scumm::desaturatePalette(int hueScale, int satScale, int lightScale, int startColor, int endColor)
     2900{
     2901        // This function scales the HSL (Hue, Saturation and Lightness)
     2902        // components of the palette colours. It's used in CMI when Guybrush
     2903        // walks from the beach towards the swamp.
     2904        //
     2905        // I don't know if this function is correct, but the output seems to
     2906        // match the original fairly closely.
     2907        //
     2908        // FIXME: Rewrite using integer arithmetics only?
     2909
     2910        if (startColor <= endColor) {
     2911                byte *cptr, *cur;
     2912                int j;
     2913
     2914                cptr = getPalettePtr() + startColor * 3;
     2915                cur = _currentPalette + startColor * 3;
     2916
     2917                for (j = startColor; j <= endColor; j++) {
     2918                        double R, G, B;
     2919                        double H, S, L;
     2920                        double min, max;
     2921                        int red, green, blue;
     2922
     2923                        R = ((double) *cptr++) / 255.0;
     2924                        G = ((double) *cptr++) / 255.0;
     2925                        B = ((double) *cptr++) / 255.0;
     2926
     2927                        // RGB to HLS (Foley and VanDam)
     2928
     2929                        min = MIN(R, MIN(G, B));
     2930                        max = MAX(R, MAX(G, B));
     2931
     2932                        L = (max + min) / 2.0;
     2933
     2934                        if (max != min) {
     2935                                if (L <= 0.5)
     2936                                        S = (max - min) / (max + min);
     2937                                else
     2938                                        S = (max - min) / (2.0 - max - min);
     2939
     2940                                if (R == max)
     2941                                        H = (G - B) / (max - min);
     2942                                else if (G == max)
     2943                                        H = 2.0 + (B - R) / (max - min);
     2944                                else
     2945                                        H = 4.0 + (R - G) / (max - min);
     2946
     2947                                H = H * 60.0;
     2948                                if (H < 0.0)
     2949                                        H = H + 360.0;
     2950                        } else {
     2951                                S = 0.0;
     2952                                H = 0.0; // undefined
     2953                        }
     2954
     2955                        // Scale the result
     2956
     2957                        H = (H * hueScale) / 255.0;
     2958                        S = (S * satScale) / 255.0;
     2959                        L = (L * lightScale) / 255.0;
     2960
     2961                        // HLS to RGB (Foley and VanDam)
     2962
     2963                        double m1, m2;
     2964
     2965                        if (min != max) {
     2966                                if (L <= 0.5)
     2967                                        m2 = L * (1 + S);
     2968                                else
     2969                                        m2 = L + S - L * S;
     2970
     2971                                m1 = 2.0 * L - m2;
     2972
     2973                                R = value(m1, m2, H + 120);
     2974                                G = value(m1, m2, H);
     2975                                B = value(m1, m2, H - 120);
     2976                        } else {
     2977                                R = L;
     2978                                G = L;
     2979                                B = L;
     2980                        }
     2981
     2982                        red = (int) (255.0 * R + 0.5);
     2983                        green = (int) (255.0 * G + 0.5);
     2984                        blue = (int) (255.0 * B + 0.5);
     2985
     2986                        *cur++ = red;
     2987                        *cur++ = green;
     2988                        *cur++ = blue;
     2989                }
     2990
     2991                setDirtyColors(startColor, endColor);
     2992        }
     2993}
     2994
    28832995int Scumm::remapPaletteColor(int r, int g, int b, uint threshold)
    28842996{
    28852997        int i;
  • scummvm/scumm/script_v8.cpp

    diff -ur ScummVM-cvs20030219/scummvm/scumm/script_v8.cpp ScummVM-cvs20030219+hack/scummvm/scumm/script_v8.cpp
    old new  
    10181018                c = pop();
    10191019                b = pop();
    10201020                a = pop();
    1021                 // FIXME - this probably has the same format as for darkenPalette:
    1022                 // thre values for R, G, B and a start/end palette range to modify.
    1023                 // Now, how on earth does on modify the saturation of a single color channel?
    1024                 // Change the hue/saturation of a color, no problem, I know how to do that,
    1025                 // but for only a channel alone, I don't even know what that should mean... :-/
    1026 //              warning("o8_roomOps: SO_ROOM_SATURATION(%d, %d, %d, %d, %d)", a, b, c, d, e);
     1021                desaturatePalette(a, b, c, d, e);
    10271022                break;
    10281023        default:
    10291024                error("o8_roomOps: default case 0x%x", subOp);
  • scummvm/scumm/scumm.h

    diff -ur ScummVM-cvs20030219/scummvm/scumm/scumm.h ScummVM-cvs20030219+hack/scummvm/scumm/scumm.h
    old new  
    775775        void setupShadowPalette(int slot, int redScale, int greenScale, int blueScale, int startColor, int endColor);
    776776        void setupShadowPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor);
    777777        void darkenPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor);
     778        void desaturatePalette(int hueScale, int satScale, int lightScale, int startColor, int endColor);
    778779
    779780        void setCursor(int cursor);
    780781        void setCursorImg(uint img, uint room, uint imgindex);