Esempio n. 1
0
const PPMImage& PPMImage::operator =(const PPMImage& img)
{
    FreePixels();
    this->p_miHeight = img.p_miHeight;
    this->p_miWidth = img.p_miWidth;
    this->p_mlpPixels = new PIXEL[ GetWidth() * GetHeight() ];
    memcpy(this->p_mlpPixels, img.p_mlpPixels, sizeof(PIXEL)*GetWidth()*GetHeight());

    return *this;
}
Esempio n. 2
0
void PPMImage::AllocPixels(int iWidth, int iHeight)
{
	// prevent accidental memory leaks
	if(p_mlpPixels != NULL)
	{
		FreePixels();
	}

	p_miWidth = iWidth;
	p_miHeight = iHeight;

	// and make new pixel memory
	p_mlpPixels = new PIXEL[p_miHeight * p_miWidth];
}
Esempio n. 3
0
void
goodbye(int sig)
{

  int Command;

  PSClose(); /* free PS file and data structure space */

  if (pixelSetFlag) FreePixels(dsply,colorMap,smoothConst);
  if (!viewAloned) {
     Command = viewportClosing;
     check(write(Socket,&Command,intSize));
     }

  XCloseDisplay(dsply);
  exit(0);
}           /* goodbye */
Esempio n. 4
0
int
AllocCells(Display *dsply, Colormap colorMap, int smoothHue)
{
    unsigned long plane_masks[1];
    int i, count;
    float lightness;
    RGB rgb;
    XColor xcolor;
    HLS hls;

    count = 0;
    for (i = 0; i < (smoothConst + 1); i++) {
        lightness = (float) (i) / (float) (smoothConst);
        hls.h = (float) smoothHue;
        hls.l = lightness;
        hls.s = saturation;
        rgb = HLStoRGB(hls);
        xcolor.red    = rgb.r *((1<<16)-1);
        xcolor.green  = rgb.g *((1<<16)-1);
        xcolor.blue   = rgb.b *((1<<16)-1);
        xcolor.flags = DoRed | DoGreen | DoBlue;
        /*
          fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b);
          fprintf(stderr,"%d\t%d\t%d\n",xcolor.red,xcolor.green,xcolor.blue);
          */
        if (XAllocColor(dsply, colorMap, &xcolor)) {
            pixels[count] = xcolor.pixel;
            count++;
        }
    }
    /* count says how many succeeded */
    if (count != (smoothConst+1) ) {
      /* we have failed to get all of them - free the ones we got */
      FreePixels(dsply,colorMap,count);
      return (0);
    }
    if (XAllocColorCells(dsply, colorMap, False,
                          plane_masks, 0, pixels, smoothConst + 1)) {
        return (smoothConst + 1);
    }
    else {
        return (0);
    }
}
Esempio n. 5
0
int
makeNewColorMap(Display *dsply, Colormap colorMap, int smoothHue)

{

    int count, i;
    float lightness;
    RGB rgb;
    XColor xcolor;
    HLS hls;

    count = 0;
    for (i = 0; i < (smoothConst + 1); i++) {             /* i = 0 .. smoothConst */
        lightness = (float) (i) / (float) (smoothConst);  /* lightnes = 0.0 .. 1.0 */
        hls.h = (float) smoothHue;
        hls.l = lightness;
        hls.s = saturation;
        rgb = HLStoRGB(hls);

        xcolor.red    = rgb.r *((1<<16)-1);
        xcolor.green  = rgb.g *((1<<16)-1);
        xcolor.blue   = rgb.b *((1<<16)-1);
        xcolor.flags = DoRed | DoGreen | DoBlue;
        /*
           fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b);
           fprintf(stderr,"%d\t%d\t%d\n",xcolor.red,xcolor.green,xcolor.blue);
           */
        if (XAllocColor(dsply, colorMap, &xcolor)) {
            pixels[count] = xcolor.pixel;
            count++;
        }
    }
    /* count says how many succeeded */
    if (count != (smoothConst+1) ) {

      /* we have failed to get all of them - free the ones we got */

      FreePixels(dsply,colorMap,count);
      return (0);
    }
    return (1);
}
Esempio n. 6
0
PPMImage::~PPMImage()
{
	FreePixels();
}
Esempio n. 7
0
JRTPPMImage::~JRTPPMImage()
{
    FreePixels();
}
Esempio n. 8
0
void
changeColorMap(void)
{
  int         okay, i, hue, *index;
  poly        *cp;
  viewTriple  *pt;

  strcpy(control->message,"         Make New Color Map         ");
  writeControlMessage();
  if ((viewport->hueOffset == viewport->hueTop) &&
      !mono && !viewport->monoOn) {

     /* colormap is not an even distribution across spectrum */
     /* see spadcolors.c code to understand why this is done */

    if (viewport->hueTop < 11) smoothHue = viewport->hueTop * 6;
    else
      if (viewport->hueTop > 10 && viewport->hueTop < 16) {
        smoothHue = viewport->hueTop*20 - 140;
      }
      else {
        smoothHue = viewport->hueTop*12 - 12;
      }

    if (redoColor) {
       /* reallocate colormap for new hue */
      redoColor = no;
      if (pixelSetFlag) {
        FreePixels(dsply,colorMap,smoothConst+1);
      }
      okay = makeNewColorMap(dsply,colorMap,smoothHue);
      if (okay) {
        pixelSetFlag = yes;
        smoothError = no; }
      else {
        pixelSetFlag = no;
        smoothError = yes; }
    } /* if redoColor */
  } else {
    redoDither = no;
    if (pixelSetFlag && !mono) {
      FreePixels(dsply,colorMap,smoothConst);
      pixelSetFlag = no;
      redoColor = no;
      multiColorFlag = yes;
    }
    if (!mono && !viewport->monoOn) {
      cp = quickList;
      while (cp != NIL(poly) && keepDrawingViewport()) {
        for (i = 0, index = cp->indexPtr;
             i < cp->numpts; i++, index++) {
          pt = refPt3D(viewData,*(index));
          /* get hue for each point if multi-dithering is used */
          if (absolute(cp->color) > 1.0)
            hue = floor(absolute(cp->color));
          else
            hue = floor(absolute(cp->color) * viewport->numberOfHues) +
                  viewport->hueOffset;
          pt->sc = (float)hue;
        } /* for each point in polygon */
        cp = cp->next;
      }
    } /* multi-color dither */
  } /* else hueOffset != hueTop */
}