/** Save LUT to file.
 * @param filename file name
 */
void
BayesHistosToLut::save(std::string filename)
{
	ColormapFile cmf;
	cmf.add_colormap(lut);
	cmf.write(filename.c_str());
}
/** Save LUT to file.
 * @param file file name
 */
void
BayesHistosToLut::saveLut(char *file)
{
	ColormapFile cmf;
	cmf.add_colormap(lut);
	cmf.write(file);
}
Example #3
0
  /** Upload LUT.
   * @param lut_id LUT ID.
   */
  void
  set_colormap(const char *lut_id)
  {
    ColormapFile cmf;
    cmf.read(__file);
    Colormap *cm = cmf.get_colormap();
    FuseLutContent *lc = new FuseLutContent(lut_id, cm->get_buffer(),
					    cm->width(), cm->height(), cm->depth(),
					    /* bytes per cell */ 1);
    delete cm;

    __client->enqueue(new FuseNetworkMessage(FUSE_MT_SET_LUT, lc));
  }
Example #4
0
Colormap &
YuvColormap::operator+=(const char *filename)
{
	ColormapFile cmf;
	cmf.read(filename);
	Colormap *   tcm  = cmf.get_colormap();
	YuvColormap *tycm = dynamic_cast<YuvColormap *>(tcm);
	if (!tycm) {
		delete tcm;
		throw TypeMismatchException("File does not contain a YUV colormap");
	}
	*this += *tycm;
	delete tcm;
	return *this;
}
Example #5
0
  virtual void
  fuse_inbound_received(FuseNetworkMessage *m) throw()
  {
    // printf("Received message of type %u\n", m->type());

    switch (m->type() ) {
    case FUSE_MT_IMAGE:
      // we got an image, save it to the given file
      try {
	FuseImageContent *ic = m->msgc<FuseImageContent>();
	if ( ic->format() == FUSE_IF_RAW ) {
	  FvRawWriter *w = new FvRawWriter(__file, ic->pixel_width(), ic->pixel_height(),
					   (colorspace_t)ic->colorspace(), ic->buffer());
	  w->write();
	  delete w;
	} else if ( ic->format() == FUSE_IF_JPEG ) {
	  FILE *f = fopen(__file, "w");
	  if (fwrite(ic->buffer(), ic->buffer_size(), 1, f) == 0) {
	    printf("Failed to write data to file");
	  }
	  fclose(f);
	} else {
	  printf("Image of unknown format (%u) received.\n", ic->format());
	}
	delete ic;
      } catch (Exception &e) {
	printf("Received message cannot be casted to FuseImageMessage\n");
	e.print_trace();
      }
      __client->cancel();
      break;
    case FUSE_MT_IMAGE_LIST:
      try {
	FuseImageListContent *ilc = m->msgc<FuseImageListContent>();
	if ( ilc->has_next() ) {
	  printf("Available images:\n");
	  while ( ilc->has_next() ) {
	    FUSE_imageinfo_t *ii = ilc->next();
	    char tmp[IMAGE_ID_MAX_LENGTH + 1];
	    tmp[IMAGE_ID_MAX_LENGTH] = 0;
	    strncpy(tmp, ii->image_id, IMAGE_ID_MAX_LENGTH);
	    printf("  %s (%u x %u, %s)\n", tmp, ntohl(ii->width), ntohl(ii->height),
		   colorspace_to_string((colorspace_t)ntohs(ii->colorspace)));
	  }
	} else {
	  printf("No images available\n");
	}
      delete ilc;
      } catch (Exception &e) {
	printf("Received message cannot be casted to FuseImageListMessage\n");
	e.print_trace();
      }
      break;
    case FUSE_MT_LUT_LIST:
      try {
	FuseLutListContent *llc = m->msgc<FuseLutListContent>();
	if ( llc->has_next() ) {
	  printf("Available lookup tables:\n");
	  while ( llc->has_next() ) {
	    FUSE_lutinfo_t *li = llc->next();
	    char tmp[LUT_ID_MAX_LENGTH + 1];
	    tmp[LUT_ID_MAX_LENGTH] = 0;
	    strncpy(tmp, li->lut_id, LUT_ID_MAX_LENGTH);
	    printf("  %s (%u x %u x %u, %u bpc)\n", tmp,
		   ntohl(li->width), ntohl(li->height),
		   ntohl(li->depth), ntohl(li->bytes_per_cell));
	  }
	} else {
	  printf("No lookup tables available\n");
	}
	delete llc;
      } catch (Exception &e) {
	printf("Received message cannot be casted to FuseImageListMessage\n");
	e.print_trace();
      }
      __client->cancel();
      break;

    case FUSE_MT_LUT:
      // we got a LUT, save it to the given file
      try {
	FuseLutContent *lc = m->msgc<FuseLutContent>();
	// Currently we expect colormaps, so make sure we get sensible dimensions
	if ( lc->width() != 256 ) {
	  printf("Invalid dimensions for LUT received, colormap width %u != 256", lc->width());
	} else if ( lc->height() != 256 ) {
	  printf("Invalid dimensions for LUT received, colormap height %u != 256", lc->height());
	} else if ( lc->depth() > 256 ) {
	  printf("Invalid dimensions for LUT received, colormap depth %u > 256", lc->depth());
	} else {
	  try {
	    YuvColormap yuvcm(lc->depth());
	    yuvcm.set(lc->buffer());
	    ColormapFile cmf;
	    cmf.add_colormap(&yuvcm);
	    cmf.write(__file);
	  } catch (Exception &e) {
	    e.append("Failed to save colormap");
	    e.print_trace();
	  }
	}
	delete lc;
      } catch (Exception &e) {
	printf("Received message cannot be casted to FuseLutMessage\n");
	e.print_trace();
      }
      __client->cancel();
      break;

    case FUSE_MT_SET_LUT_SUCCEEDED:
      {
	FUSE_lutdesc_message_t *lutdesc = m->msg<FUSE_lutdesc_message_t>();
	char lut_id[LUT_ID_MAX_LENGTH + 1];
	lut_id[LUT_ID_MAX_LENGTH] = 0;
	strncpy(lut_id, lutdesc->lut_id, LUT_ID_MAX_LENGTH);
	printf("LUT %s has been uploaded successfully.\n", lut_id);
	__client->cancel();
      }
      break;

    case FUSE_MT_SET_LUT_FAILED:
      {
	FUSE_lutdesc_message_t *lutdesc = m->msg<FUSE_lutdesc_message_t>();
	char lut_id[LUT_ID_MAX_LENGTH + 1];
	lut_id[LUT_ID_MAX_LENGTH] = 0;
	strncpy(lut_id, lutdesc->lut_id, LUT_ID_MAX_LENGTH);
	printf("LUT upload of %s has failed.\n", lut_id);
	__client->cancel();
      }
      break;

    default:
      printf("Unhandled message of type %u received\n", m->type());
      __client->cancel();
      break;
    }
  }
Example #6
0
int
main(int argc, char **argv)
{

  const char *filename = "qatest.colormap";
  if ( argc > 1 ) {
    filename = argv[1];
  }

  printf("Creating simple one-plane colormap\n");
  YuvColormap *cm = new YuvColormap();

  for (unsigned int u = 100; u < 150; ++u) {
    for (unsigned int v = 100; v < 150; ++v) {
      cm->set(128, u, v, C_ORANGE);
    }
  }

  unsigned char *imgb = malloc_buffer(YUV422_PLANAR, cm->width() * 2, cm->height() * 2);
  cm->to_image(imgb);

  ImageDisplay *imgd = new ImageDisplay(cm->width() * 2, cm->height() * 2);
  imgd->show(imgb);

  imgd->loop_until_quit();

  delete cm;

  printf("Trying to create colormap with illegal depth, should throw an exception..");
  try {
    cm = new YuvColormap(3);
    printf(" Test failed, colormap was created\n");
    delete cm;
  } catch (Exception &e) {
    printf(" Test succeeded, caught exception\n");
  }

  printf("Trying colormap with depth of %u\n", BIGDEPTH);
  cm = new YuvColormap(BIGDEPTH);

  for (unsigned int d = 0; d < cm->depth(); ++d) {
    unsigned int y = 256 / cm->depth() * d;
    printf("d=%u   y=%u   u=[%u,%u]  v=[%u,%u]\n", d, y,
	   cm->depth() * d, cm->depth() * (d+1), cm->depth() * d, cm->depth() * (d+1));

    for (unsigned int u = cm->deepness() / cm->depth() * d; u < cm->deepness() / cm->depth() * (d+1); ++u) {
      for (unsigned int v = cm->deepness() / cm->depth() * d; v < cm->deepness() / cm->depth() * (d+1); ++v) {
	cm->set(y, u, v, C_ORANGE);
      }
    }

    cm->to_image(imgb, d);
    imgd->show(imgb);
    imgd->loop_until_quit();
  }

  printf("Saving colormap to a file\n");
  ColormapFile cmf;
  cmf.add_colormap(cm);
  cmf.write(filename);

  ColormapFile::ColormapBlockVector *blocks = cmf.colormap_blocks();
  printf("Written, created %zu blocks\n", blocks->size());
  delete blocks;
  delete cm;

  cmf.clear();

  printf("Reading colormap from file\n");
  cmf.read(filename);

  Colormap *tcm = cmf.get_colormap();
  if ( (cm = dynamic_cast<YuvColormap *>(tcm)) == 0 ) {
    printf("Error, did not get valid yuv colormap\n");
  } else {
    printf("Showing all %u colormap levels\n", cm->depth());
    for (unsigned int d = 0; d < cm->depth(); ++d) {
      cm->to_image(imgb, d);
      imgd->show(imgb);
      imgd->loop_until_quit();
    }
  }

  delete cm;

  unsigned int depth = 4, width = 128, height = 128;
  printf("Trying colormap with low resolution, choosing %dx%dx%d\n", depth, width, height);
  cm = new YuvColormap(depth, width, height);
  printf("YuvColormap dimensions: %dx%dx%d\n", cm->depth(), cm->width(), cm->height());
  ColormapFile cmfr(depth, width, height);
  delete cm;
  cmfr.write(filename);
  cmfr.clear();
  cmfr.read(filename);
  cm = dynamic_cast<YuvColormap *>(cmfr.get_colormap());
  printf("Read back colormap dimensions %dx%dx%d\n",
	 cm->depth(), cm->width(), cm->height());
  delete cm;

  //delete imgd;
  //free(imgb);
  return 0;
}