Example #1
0
main() {
  uint8 colors[256*3];
  int i;

  /* Initialize the image array */
  static uint8 raster_data8[HEIGHT][WIDTH] = {
    0, 1, 2, 3, 4,
    50, 51, 52, 53, 54,
    100, 101, 102, 103, 104,
    150, 151, 152, 153, 154,
    200, 201, 202, 203, 204,
    251, 252, 253, 254, 255
  };

  static uint8 raster_data24[HEIGHT][WIDTH][PIXEL_DEPTH] = {
     0, 1, 2,     3, 4, 5,     6, 7, 8,      9,10,11,     12,13,14,
     50,51,52,   53,54,55,    56,57,58,     59,60,61,     62,63,64,
    100,101,102, 103,104,105, 106,107,108, 109,110,111,  112,113,114,
    150,151,152, 153,154,155, 156,157,158, 159,160,161,  162,163,164,
    200,201,202, 203,204,205, 206,207,208, 209,210,211,  212,213,214,
    241,242,243, 244,245,246, 247,248,249, 250,251,252,  253,254,255
  };

  for(i=0; i<256; i++) {
    colors[i*3+0] = i;
    colors[i*3+1] = i;
    colors[i*3+2] = 255-i;
  }

  /* remove old HDF file, if it exists */
  unlink(FILE_NAME);
  
  if(DFR8setpalette(colors)==FAIL)
    return 1;

  if(DFR8addimage(FILE_NAME, raster_data8, WIDTH, HEIGHT, 0)==FAIL)
    return 1;

  if(DF24addimage(FILE_NAME, raster_data24, WIDTH, HEIGHT)==FAIL)
    return 1;

  if(DF24addimage(FILE_NAME, raster_data24, WIDTH, HEIGHT)==FAIL)
    return 1;

  printf("%d 8-bit images and %d 24-bit images\n",
	 DFR8nimages(FILE_NAME), DF24nimages(FILE_NAME));

  printf("Success!\n");
  return 0;
}
Example #2
0
int
getR8(int xdim, int ydim, char *image, char *pal, int compress)
{
    FILE       *fp;
    int32       length;
    char       *buf;

    if (!fileOpen())
      {
          noFile();
          return FAIL;
      }
    if (pal)
        if (setPal(pal) < 0)
            /* Error already signalled by setPal */
            return FAIL;

    length = xdim * ydim;
    buf = (char *) HDmalloc(length);

    if ((fp = fopen(image, "r")) == NULL)
      {
          fprintf(stderr, "Error opening image file: %s.\n", image);
          return FAIL;
      }
    if (fread(buf, (size_t)xdim, (size_t)ydim, fp) < (size_t)ydim)
      {
          fprintf(stderr, "Error reading image file: %s.\n", image);
          return FAIL;
      }
    fclose(fp);

    if (DFR8addimage(he_file, buf, (int32) xdim, (int32) ydim, (uint16) compress) < 0)
      {
          HEprint(stderr, 0);
          return FAIL;
      }
    HDfree(buf);

    if (updateDesc() < 0)
        return FAIL;

    return HE_OK;
}
Example #3
0
int
imconv(char *outfile, char *imfile, uint16 compress)
{
    int         ret;
    char       *space;
    FILE       *fp;

    if ((fp = fopen(imfile, "rb")) == NULL)
      {
          printf("Error opening image file\n");
          exit(1);
      }

    if ((space = (char *) HDmalloc((size_t) (xdim * ydim))) == NULL)
      {
          printf("Not enough memory to convert image\n");
          exit(1);
      }

    if ((ret = (int)fread(space, (size_t) xdim, (size_t) ydim, fp)) <= 0)
      {
          printf("Cannot read image file\n");
          fclose(fp);
          exit(1);
      }

    ret = DFR8addimage(outfile, space, xdim, ydim, compress);

    if (ret < 0)
      {
          printf(" Error: %d, in writing image %s\n", HEvalue(1), outfile);
          exit(1);
      }

    HDfree(space);
    fclose(fp);
    return (0);
}