<commit_before>/*
File: blurfilter.c

Implementation of blurfilter function.

*/
#include <stdio.h>
#include <stdlib.h>
#include "blurfilter.h"
#include "ppmio.h"


pixel_t* pix(pixel_t* image, const int xx, const int yy, const int xsize)
{
  register int off = xsize*yy + xx;

  #ifdef DBG
  if(off >= MAX_PIXELS) {
    fprintf(stderr, "\n Terribly wrong: %d %d %d\n",xx,yy,xsize);
  }
  #endif
  return (image + off);
}

void blurfilter(const int xsize, const int ysize, pixel_t* src, const int radius,
  const double *w, const int my_rank, const int n_tasks)
  {
    int x,y,x2,y2, wi;
    double r,g,b,n, wc;
    pixel_t* dst = malloc(sizeof(pixel_t)*MAX_PIXELS);

    // Set start and stop values
    int y_start = 0, y_stop = ysize;
    int x_start = 0, x_stop = xsize;

    for (y=y_start; y<y_stop; y++) {
      for (x=x_start; x<x_stop; x++) {
        r = w[0] * pix(src, x, y, xsize)->r;
        g = w[0] * pix(src, x, y, xsize)->g;
        b = w[0] * pix(src, x, y, xsize)->b;
        n = w[0];
        for ( wi=1; wi <= radius; wi++) {
          wc = w[wi];
          x2 = x - wi;
          if(x2 >= 0) {
            r += wc * pix(src, x2, y, xsize)->r;
            g += wc * pix(src, x2, y, xsize)->g;
            b += wc * pix(src, x2, y, xsize)->b;
            n += wc;<commit_msg>Optimizing memory usage<commit_after>/*
File: blurfilter.c

Implementation of blurfilter function.

*/
#include <stdio.h>
#include <stdlib.h>
#include "blurfilter.h"
#include "ppmio.h"


pixel_t* pix(pixel_t* image, const int xx, const int yy, const int xsize)
{
  register int off = xsize*yy + xx;

  #ifdef DBG
  if(off >= MAX_PIXELS) {
    fprintf(stderr, "\n Terribly wrong: %d %d %d\n",xx,yy,xsize);
  }
  #endif
  return (image + off);
}

void blurfilter(const int xsize, const int ysize, pixel_t* src, const int radius,
  const double *w, const int my_rank, const int n_tasks)
  {
    int x,y,x2,y2, wi;
    double r,g,b,n, wc;
    pixel_t* dst = malloc(sizeof(pixel_t)*xsize*ysize);

    // Set start and stop values
    int y_start = 0, y_stop = ysize;
    int x_start = 0, x_stop = xsize;

    for (y=y_start; y<y_stop; y++) {
      for (x=x_start; x<x_stop; x++) {
        r = w[0] * pix(src, x, y, xsize)->r;
        g = w[0] * pix(src, x, y, xsize)->g;
        b = w[0] * pix(src, x, y, xsize)->b;
        n = w[0];
        for ( wi=1; wi <= radius; wi++) {
          wc = w[wi];
          x2 = x - wi;
          if(x2 >= 0) {
            r += wc * pix(src, x2, y, xsize)->r;
            g += wc * pix(src, x2, y, xsize)->g;
            b += wc * pix(src, x2, y, xsize)->b;
            n += wc;
{'fraction_non_alphanumeric': 0.17018824433346139, 'fraction_numerical': 0.01152516327314637, 'mean_word_length': 2.3256704980842913, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '771455', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1072, 'n_words': 305}