Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    WINDOW *window = initscr();
    start_color();

    if (argc <= 1) {
        return pixedError("No image file specified!");
    }

    if (!has_colors()) {
        return pixedError("Colors not supported!");
    }

    Pixel *dataArray; /* Array of original image */
    Pixel *averagedArray; /* Array after averaging */

    FILE *file;
    file = fopen(argv[1], "rb");
    if (file == NULL) {
        return pixedError("File not found!");
    }

    unsigned int dataOffset = getDataOffset(file);
    unsigned int width = getWidth(file);
    unsigned int height = getHeight(file);
    unsigned int size = width * height;

    dataArray = malloc(sizeof(Pixel) * size);
    dataArray = getDataArray(file, dataOffset, size);
    averagedArray = getAveragedArray(dataArray, size, width, height);  
 
    displayImage(averagedArray, ceil(ceil(size/BLOCK_WIDTH)/BLOCK_HEIGHT), ceil(width/BLOCK_WIDTH), ceil(height/BLOCK_HEIGHT));
    
    free(dataArray);
    free(averagedArray);

    refresh();
    getch(); /* Preserve ncurses window */

    return EXIT_SUCCESS;
}
Exemplo n.º 2
0
int main(int argc, char** argv){      
  
    /* no image entered into stdin */
  if(argc < 1){    
    printw("Image file must be entered as standard input!\n");
    endwin();
    exit(-1);
  }
  
  WINDOW* win = initscr();
  start_color();
  
  if(!has_colors()){
   printf("No color available!");
   endwin();
   exit(-1);
  }
    
    /* original array of original image */
  struct pixel* dataArray;
    /* array after being averaged */
  struct pixel* averagedArray;
  
    /* file not found */
  FILE* fp;  
  if(!(fp = fopen(argv[1],"rb"))){
    printw("File not found\n");
    exit(-1);
  }      
  
  unsigned int dataOffset = getDataOffset(fp);
  unsigned int height	  = getHeight(fp);
  unsigned int width	  = getWidth(fp);
  unsigned int size	  = height*width;
  
  printw("%d",dataOffset);
  
  dataArray		  = malloc(sizeof(struct pixel) * size);
  dataArray		  = getDataArray(fp, dataOffset, size);
  
  averagedArray = getAveragedArray(dataArray, size, height, width);  
 
  /*printArray(dataArray, size, height, width);
  printArray(averagedArray, ceil(ceil(size/8)/14), height/14, width/8);*/
  
  /*printColor(averagedArray, ceil(ceil(size/8)/14));*/
  
  if(!can_change_color || hasParameter(argc, argv, "-8")){
    displayImageColor(averagedArray,ceil(ceil(size/8)/17),ceil(width/8),ceil(height/17));
  }
  else if(can_change_color() && hasParameter(argc, argv, "-bw")){
    displayImageGreyScale(averagedArray,ceil(ceil(size/8)/17), ceil(width/8), ceil(height/17));
  }
  else if(can_change_color()){
    displayImage16Color(averagedArray,ceil(ceil(size/8)/17),ceil(width/8),ceil(height/17));
  }  
  
  free(dataArray);
  free(averagedArray);
  
  refresh();
  getch();
  
  endwin();
  
}