Exemple #1
0
//read a PNM image
int readPNMImage(char *filename, unsigned char **image, int& height, int& width, int& depth, bool& color)
{
  color = true; //assume PPM format
  int error = readPPMImage(filename, image, height, width, depth);
  if(error == PPM_UNKNOWN_FORMAT) {
    color = false;
    error = readPGMImage(filename, image, height, width, depth);
  }
  return error;
}
Exemple #2
0
int main() {
   Image * input = readPPMImage("test.ppm");
   Image * output = new Image(input->width, input->height);  
   //Run for each color yo 
   pi_blur(input->width, input->height, input->rd,output->rd); 
   pi_blur(input->width, input->height, input->gd,output->gd); 
   pi_blur(input->width, input->height, input->bd,output->bd); 
   writePPMImage(output,"outtest.ppm");  
   return 0;
}
Exemple #3
0
//read image data
int CmCReadImage(char *filename, unsigned char **image, int& height, int& width, int& dim)
{  
  if(!filename) return EXE_NULL_PTR;
  int filetype = CmCGetImageFormat(filename);
  int error = filetype; //possible error in reading file header
  switch(filetype) {
  case FILE_PPM:
    error = readPPMImage(filename, image, height, width, dim);
    dim   = 3;
    break;
  case FILE_PGM:
    error = readPGMImage(filename, image, height, width, dim);
    dim   = 1;
    break;
  case FILE_PNM: {
    bool color;
    error = readPNMImage(filename, image, height, width, dim, color);
    if(color) {
      dim = 3;
    } else {
      dim = 1;
    }
    break;
  }
  default:
    if(filetype == FILE_UNKNOWN) return EXE_UNKNOWN_FILE_FORMAT;
  }

  if(!error)
    {
      //due to LUV conversion must always work in 5D
      if(dim == 1) {
	dim = 3;
	unsigned char *rgbImage = new unsigned char [height * width * dim];
	int i;
	for(i = 0; i < height * width; i++) {
	  rgbImage[3*i] = rgbImage[3*i+1] = rgbImage[3*i+2] = (*image)[i];
	}
	delete [] *image;
	*image = rgbImage;
      }
      return NO_ERRORS;
    }
  else
    return EXE_FILE_READ_ERROR;
}
//////////////////////////////////////////////////////////////////////////////
// Main function
//////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv) {
	ppm_t image;

	if(argc != 4)
		return 1;

	/* Create the encoder */
	jpeg::JPEGEncoder encoder(CL_DEVICE_TYPE_ALL, atoi(argv[3]));

	/* Read input image */
	if(readPPMImage(argv[1], &image.w, &image.h, &image.pixel))
	{
		fprintf(stderr, "Error Reading input file\naborting...\n");
		return 0x2;
	}

	/* Encode the image */
	encoder.encode_image((unsigned char*)image.pixel, image.w, image.h, argv[2]);

	/* Free image memory */
	free(image.pixel);

	return 0;
}
Exemple #5
0
//read image data
int CmCReadImage(char *filename, unsigned char **image, int& height, int& width, int& dim)
{  
	int error = readPPMImage(filename, image, height, width, dim);
	dim   = 3;
}