Exemple #1
0
int main(void)
{
	static const unsigned char answers[COLS] = { 31, 32, 34, 35, 36 };
	unsigned long x;
	for (x = 0; x < sizeof(p)/sizeof(p[0]); x++) {
		p[x].b = (x + 34) | 1;
	}
	for (x = 0; x < columns; x++) {
		double total_r = 0, total_g = 0, total_b = 0;
		double saved_r = 0, saved_g = 0, saved_b = 0;
		Minify(2*x +  0,  3.0);
		Minify(2*x +  1,  7.0);
		Minify(2*x +  2,  7.0);
		saved_r = total_r;
		saved_g = total_g;
		Minify(2*x + 11, 15.0);
		Minify(2*x + 12,  7.0);
		Minify(2*x + 18,  7.0);
		Minify(2*x + 19, 15.0);
		Minify(2*x + 20, 15.0);
		Minify(2*x + 21,  7.0);
		q[x].r = (unsigned char)(total_r/128.0 + 0.5);
		q[x].g = (unsigned char)(total_g/128.0 + 0.5);
		q[x].b = (unsigned char)(total_b/128.0 + 0.5);
		fprintf(stderr, "r:%f g:%f b:%f\n", saved_r, saved_g, saved_b);
	}
	for (x = 0; x < COLS; x++) {
		if (answers[x] != q[x].b)
			abort();
	}
	return 0;
}
Exemple #2
0
unsigned long *HalfImage(unsigned long *image,int colums,int rows)
{
#define Minify(weight)                          \
  total.red+=(weight)*(r->red);                 \
  total.green+=(weight)*(r->green);             \
  total.blue+=(weight)*(r->blue);               \
  total.opacity+=(weight)*(r->opacity);         \
  r++;

  unsigned long *minify_image;

  long y;
 
  /*
    Initialize minified image.
  */
  minify_image= image;
  /*
    Reduce each row.
  */
  {
    unsigned long row_count=0,zero=0;
    float red,green,blue,opacity;

    zero=0;
    for (y=0; y < (long) minify_image->rows; y++)
      {
        DoublePixelPacket
          total;

        register const PixelPacket
          *p,
          *r;

        register long
          x;

        register PixelPacket
          *q;

        MagickBool
          thread_status;


        p=AcquireImagePixels(image,-2,2*(y-1),image->columns+4,4,exception);
        q=SetImagePixelsEx(minify_image,0,y,minify_image->columns,1,exception);
        for (x=0; x < columns/2; x++)
              {
                /*
                  Compute weighted average of target pixel color components.
                */
                total=zero;
                r=p;
                Minify(3.0); Minify(7.0);  Minify(7.0);  Minify(3.0);
                r=p+(image->columns+4);
                Minify(7.0); Minify(15.0); Minify(15.0); Minify(7.0);
                r=p+2*(image->columns+4);
                Minify(7.0); Minify(15.0); Minify(15.0); Minify(7.0);
                r=p+3*(image->columns+4);
                Minify(3.0); Minify(7.0);  Minify(7.0);  Minify(3.0);
                q->red=(Quantum) (total.red/128.0+0.5);
                q->green=(Quantum) (total.green/128.0+0.5);
                q->blue=(Quantum) (total.blue/128.0+0.5);
                q->opacity=(Quantum) (total.opacity/128.0+0.5);
                p+=2;
                q++;
              }
            if (!SyncImagePixelsEx(minify_image,exception))
              thread_status=MagickFail;
#if defined(HAVE_OPENMP)
#  pragma omp critical (GM_MinifyImage)
#endif
        {
          row_count++;
          if (QuantumTick(row_count,image->rows))
            if (!MagickMonitorFormatted(row_count,image->rows,exception,
                                        MinifyImageText,image->filename))
              thread_status=MagickFail;
          
          if (thread_status == MagickFail)
            status=MagickFail;
        }
      }
  }
  minify_image->is_grayscale=image->is_grayscale;
  return(minify_image);
}