<commit_before>/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkBitmapProcState.h"
#include "SkBitmap.h"
#include "SkColor.h"
#include "SkColorPriv.h"
#include "SkUnPreMultiply.h"
#include "SkShader.h"
#include "SkRTConf.h"
#include "SkMath.h"

void highQualityFilter(const SkBitmapProcState& s, int x, int y,
                   SkPMColor* SK_RESTRICT colors, int count) {

    const int maxX = s.fBitmap->width() - 1;
    const int maxY = s.fBitmap->height() - 1;

    while (count-- > 0) {
        SkPoint srcPt;
        s.fInvProc(*s.fInvMatrix, SkFloatToScalar(x + 0.5),
                    SkFloatToScalar(y + 0.5), &srcPt);
        srcPt.fX -= SK_ScalarHalf;
        srcPt.fY -= SK_ScalarHalf;

        int sx = SkScalarFloorToInt(srcPt.fX);
        int sy = SkScalarFloorToInt(srcPt.fY);

        SkFixed weight = 0;
        SkFixed fr = 0, fg = 0, fb = 0, fa = 0;

        int y0 = SkClampMax(sk_float_ceil2int(SkScalarToFloat(srcPt.fY)-s.getBitmapFilter()->width()), maxY);
        int y1 = SkClampMax(sk_float_floor2int(SkScalarToFloat(srcPt.fY)+s.getBitmapFilter()->width()), maxY);
        int x0 = SkClampMax(sk_float_ceil2int(SkScalarToFloat(srcPt.fX)-s.getBitmapFilter()->width()), maxX);
        int x1 = SkClampMax(sk_float_floor2int(SkScalarToFloat(srcPt.fX)+s.getBitmapFilter()->width()), maxX);

        for (int src_y = y0; src_y <= y1; src_y++) {
            SkFixed yweight = s.getBitmapFilter()->lookup((srcPt.fY - src_y));

            for (int src_x = x0; src_x <= x1 ; src_x++) {
                SkFixed xweight = s.getBitmapFilter()->lookup((srcPt.fX - src_x));

                SkFixed combined_weight = SkFixedMul(xweight, yweight);

                SkPMColor c = *s.fBitmap->getAddr32(src_x, src_y);
                fr += combined_weight * SkGetPackedR32(c);
                fg += combined_weight * SkGetPackedG32(c);
                fb += combined_weight * SkGetPackedB32(c);
                fa += combined_weight * SkGetPackedA32(c);
                weight += combined_weight;
            }
        }

        fr = SkFixedDiv(fr, weight);
        fg = SkFixedDiv(fg, weight);
        fb = SkFixedDiv(fb, weight);
        fa = SkFixedDiv(fa, weight);

        int a = SkClampMax(SkFixedRoundToInt(fa), 255);
        int r = SkClampMax(SkFixedRoundToInt(fr), a);
        int g = SkClampMax(SkFixedRoundToInt(fg), a);
        int b = SkClampMax(SkFixedRoundToInt(fb), a);

        *colors++ = SkPackARGB32(a, r, g, b);

        x++;
    }
}

void highQualityFilter_ScaleOnly(const SkBitmapProcState &s, int x, int y,
                             SkPMColor *SK_RESTRICT colors, int count) {
     const int maxX = s.fBitmap->width() - 1;
     const int maxY = s.fBitmap->height() - 1;

     SkPoint srcPt;

     s.fInvProc(*s.fInvMatrix, SkFloatToScalar(x + 0.5),
                 SkFloatToScalar(y + 0.5), &srcPt);
     srcPt.fY -= SK_ScalarHalf;
     int sy = SkScalarFloorToInt(srcPt.fY);
     int y0 = SkClampMax(sk_float_ceil2int(SkScalarToFloat(srcPt.fY)-s.getBitmapFilter()->width()), maxY);
     int y1 = SkClampMax(sk_float_floor2int(SkScalarToFloat(srcPt.fY)+s.getBitmapFilter()->width()), maxY);

     while (count-- > 0) {
         s.fInvProc(*s.fInvMatrix, SkFloatToScalar(x + 0.5),
                     SkFloatToScalar(y + 0.5), &srcPt);
         srcPt.fX -= SK_ScalarHalf;
         srcPt.fY -= SK_ScalarHalf;

         int sx = SkScalarFloorToInt(srcPt.fX);

         SkFixed weight = 0;
         SkFixed fr = 0, fg = 0, fb = 0, fa = 0;

         int x0 = SkClampMax(sk_float_ceil2int(SkScalarToFloat(srcPt.fX)-s.getBitmapFilter()->width()), maxX);
         int x1 = SkClampMax(sk_float_floor2int(SkScalarToFloat(srcPt.fX)+s.getBitmapFilter()->width()), maxX);

         for (int src_y = y0; src_y <= y1; src_y++) {
             SkFixed yweight = s.getBitmapFilter()->lookup((srcPt.fY - src_y));

             for (int src_x = x0; src_x <= x1 ; src_x++) {
                 SkFixed xweight = s.getBitmapFilter()->lookup((srcPt.fX - src_x));

                 SkFixed combined_weight = SkFixedMul(xweight, yweight);

                 SkPMColor c = *s.fBitmap->getAddr32(src_x, src_y);
                 fr += combined_weight * SkGetPackedR32(c);
                 fg += combined_weight * SkGetPackedG32(c);
                 fb += combined_weight * SkGetPackedB32(c);
                 fa += combined_weight * SkGetPackedA32(c);
                 weight += combined_weight;
             }
         }

         fr = SkFixedDiv(fr, weight);
         fg = SkFixedDiv(fg, weight);
         fb = SkFixedDiv(fb, weight);
         fa = SkFixedDiv(fa, weight);<commit_msg>remove unused variables<commit_after>/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkBitmapProcState.h"
#include "SkBitmap.h"
#include "SkColor.h"
#include "SkColorPriv.h"
#include "SkUnPreMultiply.h"
#include "SkShader.h"
#include "SkRTConf.h"
#include "SkMath.h"

void highQualityFilter(const SkBitmapProcState& s, int x, int y,
                   SkPMColor* SK_RESTRICT colors, int count) {

    const int maxX = s.fBitmap->width() - 1;
    const int maxY = s.fBitmap->height() - 1;

    while (count-- > 0) {
        SkPoint srcPt;
        s.fInvProc(*s.fInvMatrix, SkFloatToScalar(x + 0.5),
                    SkFloatToScalar(y + 0.5), &srcPt);
        srcPt.fX -= SK_ScalarHalf;
        srcPt.fY -= SK_ScalarHalf;

        SkFixed weight = 0;
        SkFixed fr = 0, fg = 0, fb = 0, fa = 0;

        int y0 = SkClampMax(sk_float_ceil2int(SkScalarToFloat(srcPt.fY)-s.getBitmapFilter()->width()), maxY);
        int y1 = SkClampMax(sk_float_floor2int(SkScalarToFloat(srcPt.fY)+s.getBitmapFilter()->width()), maxY);
        int x0 = SkClampMax(sk_float_ceil2int(SkScalarToFloat(srcPt.fX)-s.getBitmapFilter()->width()), maxX);
        int x1 = SkClampMax(sk_float_floor2int(SkScalarToFloat(srcPt.fX)+s.getBitmapFilter()->width()), maxX);

        for (int src_y = y0; src_y <= y1; src_y++) {
            SkFixed yweight = s.getBitmapFilter()->lookup((srcPt.fY - src_y));

            for (int src_x = x0; src_x <= x1 ; src_x++) {
                SkFixed xweight = s.getBitmapFilter()->lookup((srcPt.fX - src_x));

                SkFixed combined_weight = SkFixedMul(xweight, yweight);

                SkPMColor c = *s.fBitmap->getAddr32(src_x, src_y);
                fr += combined_weight * SkGetPackedR32(c);
                fg += combined_weight * SkGetPackedG32(c);
                fb += combined_weight * SkGetPackedB32(c);
                fa += combined_weight * SkGetPackedA32(c);
                weight += combined_weight;
            }
        }

        fr = SkFixedDiv(fr, weight);
        fg = SkFixedDiv(fg, weight);
        fb = SkFixedDiv(fb, weight);
        fa = SkFixedDiv(fa, weight);

        int a = SkClampMax(SkFixedRoundToInt(fa), 255);
        int r = SkClampMax(SkFixedRoundToInt(fr), a);
        int g = SkClampMax(SkFixedRoundToInt(fg), a);
        int b = SkClampMax(SkFixedRoundToInt(fb), a);

        *colors++ = SkPackARGB32(a, r, g, b);

        x++;
    }
}

void highQualityFilter_ScaleOnly(const SkBitmapProcState &s, int x, int y,
                             SkPMColor *SK_RESTRICT colors, int count) {
     const int maxX = s.fBitmap->width() - 1;
     const int maxY = s.fBitmap->height() - 1;

     SkPoint srcPt;

     s.fInvProc(*s.fInvMatrix, SkFloatToScalar(x + 0.5),
                 SkFloatToScalar(y + 0.5), &srcPt);
     srcPt.fY -= SK_ScalarHalf;
     int y0 = SkClampMax(sk_float_ceil2int(SkScalarToFloat(srcPt.fY)-s.getBitmapFilter()->width()), maxY);
     int y1 = SkClampMax(sk_float_floor2int(SkScalarToFloat(srcPt.fY)+s.getBitmapFilter()->width()), maxY);

     while (count-- > 0) {
         s.fInvProc(*s.fInvMatrix, SkFloatToScalar(x + 0.5),
                     SkFloatToScalar(y + 0.5), &srcPt);
         srcPt.fX -= SK_ScalarHalf;
         srcPt.fY -= SK_ScalarHalf;

         SkFixed weight = 0;
         SkFixed fr = 0, fg = 0, fb = 0, fa = 0;

         int x0 = SkClampMax(sk_float_ceil2int(SkScalarToFloat(srcPt.fX)-s.getBitmapFilter()->width()), maxX);
         int x1 = SkClampMax(sk_float_floor2int(SkScalarToFloat(srcPt.fX)+s.getBitmapFilter()->width()), maxX);

         for (int src_y = y0; src_y <= y1; src_y++) {
             SkFixed yweight = s.getBitmapFilter()->lookup((srcPt.fY - src_y));

             for (int src_x = x0; src_x <= x1 ; src_x++) {
                 SkFixed xweight = s.getBitmapFilter()->lookup((srcPt.fX - src_x));

                 SkFixed combined_weight = SkFixedMul(xweight, yweight);

                 SkPMColor c = *s.fBitmap->getAddr32(src_x, src_y);
                 fr += combined_weight * SkGetPackedR32(c);
                 fg += combined_weight * SkGetPackedG32(c);
                 fb += combined_weight * SkGetPackedB32(c);
                 fa += combined_weight * SkGetPackedA32(c);
                 weight += combined_weight;
             }
         }

         fr = SkFixedDiv(fr, weight);
         fg = SkFixedDiv(fg, weight);
         fb = SkFixedDiv(fb, weight);
         fa = SkFixedDiv(fa, weight);
{'fraction_non_alphanumeric': 0.13401169084217363, 'fraction_numerical': 0.017536263260445984, 'mean_word_length': 2.360858493997817, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4863801', 'n_tokens_mistral': 3337, 'n_tokens_neox': 3146, 'n_words': 641}