Ejemplo n.º 1
0
Archivo: cdl.c Proyecto: airhuman/cwf
static Quantum
CdlQuantum(const Quantum quantum, const double slope, const double offset,
	   const double power, const double saturation)
{
  double
    v,
    t;

  t=(((double) quantum)/MaxRGBDouble)*slope+offset;
  if (t < 0.0)
    t = 0.0;
  else if (t > 1.0)
    t = 1.0;
  v = (pow(t,power)+saturation)*MaxRGBDouble;
  return RoundDoubleToQuantum(v);
}
Ejemplo n.º 2
0
static Image *ReadIdentityImage(const ImageInfo *image_info,
				ExceptionInfo *exception)
{
#define IdentityImageText  "[%s] Generating Hald CLUT identity image..."

  Image
    *image;

  unsigned long
    cube_size;

  long
    order,
    y;

  unsigned long
    row_count=0;

  unsigned int
    status=MagickPass;

  /*
    Initialize Image structure.
  */
  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  assert(exception != (ExceptionInfo *) NULL);
  assert(exception->signature == MagickSignature);

  image=(Image *) NULL;
  order=8;
  if (image_info->filename[0] != '\0')
    order=MagickAtoL(image_info->filename);
  if (order < 2)
    order=8;
  
  image=AllocateImage(image_info);
  cube_size=order*order;
  image->columns=image->rows=order*order*order;

#if defined(HAVE_OPENMP)
#  if defined(TUNE_OPENMP)
#    pragma omp parallel for schedule(runtime) shared(row_count, status)
#  else
#    pragma omp parallel for shared(row_count, status)
#  endif
#endif
  for (y=0; y < (long) image->rows; y += order)
    {
      MagickPassFail
        thread_status;

      register PixelPacket
        *q;

#if defined(HAVE_OPENMP)
#  pragma omp critical (GM_IdentityImage)
#endif
      thread_status=status;
      if (thread_status == MagickFail)
        continue;

      q=SetImagePixelsEx(image,0,y,image->columns,order,&image->exception);
      if (q == (PixelPacket *) NULL)
        thread_status=MagickFail;

      if (q != (PixelPacket *) NULL)
        {
	  double
	    value;

	  unsigned int
	    red,
	    green,
	    blue;

	  blue=y/order;
	  for(green = 0; green < cube_size; green++)
	    {
	      for(red = 0; red < cube_size; red++)
		{
		  value=MaxRGBDouble * (double)red / (double)(cube_size - 1);
		  q->red   = RoundDoubleToQuantum(value);
		  value     = MaxRGBDouble * (double)green / (double)(cube_size - 1);
		  q->green = RoundDoubleToQuantum(value);
		  value    = MaxRGBDouble * (double)blue / (double)(cube_size - 1);
		  q->blue  = RoundDoubleToQuantum(value);
		  q->opacity = OpaqueOpacity;
		  q++;
		}
	    }

          if (!SyncImagePixelsEx(image,&image->exception))
            thread_status=MagickFail;
        }

#if defined(HAVE_OPENMP)
#  pragma omp critical (GM_IdentityImage)
#endif
      {
        row_count++;
        if (QuantumTick(row_count,image->rows))
          if (!MagickMonitorFormatted(row_count,image->rows,&image->exception,
                                      IdentityImageText,image->filename))
            thread_status=MagickFail;

        if (thread_status == MagickFail)
          status=MagickFail;
      }
    }

  if (status == MagickFail)
    {
      DestroyImage(image);
      image=(Image *) NULL;
    }

  return(image);
}