当前位置: 首页>>代码示例>>C++>>正文


C++ imageStruct::convertTo方法代码示例

本文整理汇总了C++中imageStruct::convertTo方法的典型用法代码示例。如果您正苦于以下问题:C++ imageStruct::convertTo方法的具体用法?C++ imageStruct::convertTo怎么用?C++ imageStruct::convertTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imageStruct的用法示例。


在下文中一共展示了imageStruct::convertTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: save

bool imageJPEG::save(const imageStruct&constimage, const std::string&filename, const std::string&mimetype, const gem::Properties&props) {
  struct jpeg_compress_struct cinfo;

  /* More stuff */
  FILE * outfile=NULL;		/* target file */
  JSAMPROW row_pointer;	/* pointer to JSAMPLE row[s] */
  int row_stride;		/* physical row width in image buffer */

  // We set up the normal JPEG error routines, then override error_exit
  my_error_mgr jerr;
  cinfo.err = jpeg_std_error(&jerr.pub);
  jerr.pub.error_exit = my_error_exit;

  // Establish the setjmp return context for my_error_exit to use.
  if ( setjmp(jerr.setjmp_buffer) ) {
    // If we get here, the JPEG code has signaled an error.
    // We need to clean up the JPEG object, close the input file, and return.
    jpeg_destroy_compress(&cinfo);
    if(outfile)
      fclose(outfile);
    return(false);
  }

  double fquality=100;
  props.get("quality", fquality);
  int quality=fquality;

  if(GL_YUV422_GEM==constimage.format) {
    error("don't know how to write YUV-images with libJPEG");
    return false;
  }

  /* Now we can initialize the JPEG compression object. */
  jpeg_create_compress(&cinfo);

  if ((outfile = fopen(filename.c_str(), "wb")) == NULL) {
    error("can't open %s\n", filename.c_str());
    return (false);
  }
  jpeg_stdio_dest(&cinfo, outfile);

  imageStruct image;
  constimage.convertTo(&image, GL_RGB);
  //  image.fixUpDown();
  JSAMPLE *image_buffer = image.data;

  cinfo.image_width = image.xsize; 	/* image width and height, in pixels */
  cinfo.image_height = image.ysize;
  cinfo.input_components = 3;		/* # of color components per pixel */
  cinfo.in_color_space = JCS_RGB; 	/* colorspace of input image */

  jpeg_set_defaults(&cinfo);
  jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
  jpeg_start_compress(&cinfo, TRUE);

  row_stride = image.xsize * image.csize;	/* JSAMPLEs per row in image_buffer */

  while (cinfo.next_scanline < cinfo.image_height) {
    /* jpeg_write_scanlines expects an array of pointers to scanlines.
     * Here the array is only one element long, but you could pass
     * more than one scanline at a time if that's more convenient.
     */
    int rowindex=cinfo.next_scanline;
    if(!image.upsidedown)
      rowindex=(cinfo.image_height-cinfo.next_scanline-1);
    row_pointer = & image_buffer[rowindex * row_stride];

    if(jpeg_write_scanlines(&cinfo, &row_pointer, 1) < 0){
      error("GEM: could not write line %d to image %s", cinfo.next_scanline, filename.c_str());
      jpeg_finish_compress(&cinfo);
      fclose(outfile);
      jpeg_destroy_compress(&cinfo);
      return(false);
    }
  }

  jpeg_finish_compress(&cinfo);
  fclose(outfile);
  jpeg_destroy_compress(&cinfo);

  return true;
}
开发者ID:Jackovic,项目名称:Gem,代码行数:82,代码来源:imageJPEG.cpp


注:本文中的imageStruct::convertTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。