I'll ask again-- what was the purpose of this patch?  What specifically
did it fix?  If the libjpeg headers are conflict prone, then I think we
should work around the conflict rather than re-writing this class.


On 9/7/11 6:35 AM, ossm...@users.sourceforge.net wrote:
> Revision: 4669
>           http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4669&view=rev
> Author:   ossman_
> Date:     2011-09-07 11:35:04 +0000 (Wed, 07 Sep 2011)
> Log Message:
> -----------
> Internalise the libjpeg stuff into the JpegCompressor class as the libjpeg
> headers are a bit conflict prone.
> 
> Modified Paths:
> --------------
>     trunk/common/rfb/JpegCompressor.cxx
>     trunk/common/rfb/JpegCompressor.h
> 
> Modified: trunk/common/rfb/JpegCompressor.cxx
> ===================================================================
> --- trunk/common/rfb/JpegCompressor.cxx       2011-09-07 09:01:20 UTC (rev 
> 4668)
> +++ trunk/common/rfb/JpegCompressor.cxx       2011-09-07 11:35:04 UTC (rev 
> 4669)
> @@ -23,12 +23,24 @@
>  #include <rfb/PixelFormat.h>
>  #include <os/print.h>
>  
> +#include <stdio.h>
> +extern "C" {
> +#include <jpeglib.h>
> +}
> +#include <setjmp.h>
> +
>  using namespace rfb;
>  
>  //
>  // Error manager implmentation for the JPEG library
>  //
>  
> +struct JPEG_ERROR_MGR {
> +  struct jpeg_error_mgr pub;
> +  jmp_buf jmpBuffer;
> +  char lastError[JMSG_LENGTH_MAX];
> +};
> +
>  static void
>  JpegErrorExit(j_common_ptr cinfo)
>  {
> @@ -50,6 +62,11 @@
>  // Destination manager implementation for the JPEG library.
>  //
>  
> +struct JPEG_DEST_MGR {
> +  struct jpeg_destination_mgr pub;
> +  JpegCompressor *instance;
> +};
> +
>  static void
>  JpegInitDestination(j_compress_ptr cinfo)
>  {
> @@ -86,33 +103,42 @@
>  
>  JpegCompressor::JpegCompressor(int bufferLen) : MemOutStream(bufferLen)
>  {
> -  cinfo.err = jpeg_std_error(&err.pub);
> -  snprintf(err.lastError, JMSG_LENGTH_MAX, "No error");
> -  err.pub.error_exit = JpegErrorExit;
> -  err.pub.output_message = JpegOutputMessage;
> +  cinfo = new jpeg_compress_struct;
>  
> -  if(setjmp(err.jmpBuffer)) {
> +  err = new struct JPEG_ERROR_MGR;
> +  cinfo->err = jpeg_std_error(&err->pub);
> +  snprintf(err->lastError, JMSG_LENGTH_MAX, "No error");
> +  err->pub.error_exit = JpegErrorExit;
> +  err->pub.output_message = JpegOutputMessage;
> +
> +  if(setjmp(err->jmpBuffer)) {
>      // this will execute if libjpeg has an error
> -    throw rdr::Exception(err.lastError);
> +    throw rdr::Exception(err->lastError);
>    }
>  
> -  jpeg_create_compress(&cinfo);
> +  jpeg_create_compress(cinfo);
>  
> -  dest.pub.init_destination = JpegInitDestination;
> -  dest.pub.empty_output_buffer = JpegEmptyOutputBuffer;
> -  dest.pub.term_destination = JpegTermDestination;
> -  dest.instance = this;
> -  cinfo.dest = (struct jpeg_destination_mgr *)&dest;
> +  dest = new struct JPEG_DEST_MGR;
> +  dest->pub.init_destination = JpegInitDestination;
> +  dest->pub.empty_output_buffer = JpegEmptyOutputBuffer;
> +  dest->pub.term_destination = JpegTermDestination;
> +  dest->instance = this;
> +  cinfo->dest = (struct jpeg_destination_mgr *)dest;
>  }
>  
>  JpegCompressor::~JpegCompressor(void)
>  {
> -  if(setjmp(err.jmpBuffer)) {
> +  if(setjmp(err->jmpBuffer)) {
>      // this will execute if libjpeg has an error
>      return;
>    }
>  
> -  jpeg_destroy_compress(&cinfo);
> +  jpeg_destroy_compress(cinfo);
> +
> +  delete err;
> +  delete dest;
> +
> +  delete cinfo;
>  }
>  
>  void JpegCompressor::compress(rdr::U8 *buf, int pitch, const Rect& r,
> @@ -125,17 +151,17 @@
>    bool srcBufIsTemp = false;
>    JSAMPROW *rowPointer = NULL;
>  
> -  if(setjmp(err.jmpBuffer)) {
> +  if(setjmp(err->jmpBuffer)) {
>      // this will execute if libjpeg has an error
> -    jpeg_abort_compress(&cinfo);
> +    jpeg_abort_compress(cinfo);
>      if (srcBufIsTemp && srcBuf) delete[] srcBuf;
>      if (rowPointer) delete[] rowPointer;
> -    throw rdr::Exception(err.lastError);
> +    throw rdr::Exception(err->lastError);
>    }
>  
> -  cinfo.image_width = w;
> -  cinfo.image_height = h;
> -  cinfo.in_color_space = JCS_RGB;
> +  cinfo->image_width = w;
> +  cinfo->image_height = h;
> +  cinfo->in_color_space = JCS_RGB;
>    pixelsize = 3;
>  
>  #ifdef JCS_EXTENSIONS
> @@ -154,15 +180,15 @@
>      }
>  
>      if(redShift == 0 && greenShift == 8 && blueShift == 16)
> -      cinfo.in_color_space = JCS_EXT_RGBX;
> +      cinfo->in_color_space = JCS_EXT_RGBX;
>      if(redShift == 16 && greenShift == 8 && blueShift == 0)
> -      cinfo.in_color_space = JCS_EXT_BGRX;
> +      cinfo->in_color_space = JCS_EXT_BGRX;
>      if(redShift == 24 && greenShift == 16 && blueShift == 8)
> -      cinfo.in_color_space = JCS_EXT_XBGR;
> +      cinfo->in_color_space = JCS_EXT_XBGR;
>      if(redShift == 8 && greenShift == 16 && blueShift == 24)
> -      cinfo.in_color_space = JCS_EXT_XRGB;
> +      cinfo->in_color_space = JCS_EXT_XRGB;
>  
> -    if (cinfo.in_color_space != JCS_RGB) {
> +    if (cinfo->in_color_space != JCS_RGB) {
>        srcBuf = (rdr::U8 *)buf;
>        pixelsize = 4;
>      }
> @@ -171,46 +197,46 @@
>  
>    if (pitch == 0) pitch = w * pf.bpp / 8;
>  
> -  if (cinfo.in_color_space == JCS_RGB) {
> +  if (cinfo->in_color_space == JCS_RGB) {
>      srcBuf = new rdr::U8[w * h * pixelsize];
>      srcBufIsTemp = true;
>      pf.rgbFromBuffer(srcBuf, (const rdr::U8 *)buf, w, pitch, h);
>      pitch = w * pixelsize;
>    }
>  
> -  cinfo.input_components = pixelsize;
> +  cinfo->input_components = pixelsize;
>  
> -  jpeg_set_defaults(&cinfo);
> -  jpeg_set_quality(&cinfo, quality, TRUE);
> -  if(quality >= 96) cinfo.dct_method = JDCT_ISLOW;
> -  else cinfo.dct_method = JDCT_FASTEST;
> +  jpeg_set_defaults(cinfo);
> +  jpeg_set_quality(cinfo, quality, TRUE);
> +  if(quality >= 96) cinfo->dct_method = JDCT_ISLOW;
> +  else cinfo->dct_method = JDCT_FASTEST;
>  
>    switch (subsamp) {
>    case SUBSAMP_420:
> -    cinfo.comp_info[0].h_samp_factor = 2;
> -    cinfo.comp_info[0].v_samp_factor = 2;
> +    cinfo->comp_info[0].h_samp_factor = 2;
> +    cinfo->comp_info[0].v_samp_factor = 2;
>      break;
>    case SUBSAMP_422:
> -    cinfo.comp_info[0].h_samp_factor = 2;
> -    cinfo.comp_info[0].v_samp_factor = 1;
> +    cinfo->comp_info[0].h_samp_factor = 2;
> +    cinfo->comp_info[0].v_samp_factor = 1;
>      break;
>    case SUBSAMP_GRAY:
> -    jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE);
> +    jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
>    default:
> -    cinfo.comp_info[0].h_samp_factor = 1;
> -    cinfo.comp_info[0].v_samp_factor = 1;
> +    cinfo->comp_info[0].h_samp_factor = 1;
> +    cinfo->comp_info[0].v_samp_factor = 1;
>    }
>  
>    rowPointer = new JSAMPROW[h];
>    for (int dy = 0; dy < h; dy++)
>      rowPointer[dy] = (JSAMPROW)(&srcBuf[dy * pitch]);
>  
> -  jpeg_start_compress(&cinfo, TRUE);
> -  while (cinfo.next_scanline < cinfo.image_height)
> -    jpeg_write_scanlines(&cinfo, &rowPointer[cinfo.next_scanline],
> -      cinfo.image_height - cinfo.next_scanline);
> +  jpeg_start_compress(cinfo, TRUE);
> +  while (cinfo->next_scanline < cinfo->image_height)
> +    jpeg_write_scanlines(cinfo, &rowPointer[cinfo->next_scanline],
> +      cinfo->image_height - cinfo->next_scanline);
>  
> -  jpeg_finish_compress(&cinfo);
> +  jpeg_finish_compress(cinfo);
>  
>    if (srcBufIsTemp) delete[] srcBuf;
>    delete[] rowPointer;
> 
> Modified: trunk/common/rfb/JpegCompressor.h
> ===================================================================
> --- trunk/common/rfb/JpegCompressor.h 2011-09-07 09:01:20 UTC (rev 4668)
> +++ trunk/common/rfb/JpegCompressor.h 2011-09-07 11:35:04 UTC (rev 4669)
> @@ -29,27 +29,13 @@
>  #include <rfb/PixelFormat.h>
>  #include <rfb/Rect.h>
>  
> -#include <stdio.h>
> -extern "C" {
> -#include <jpeglib.h>
> -}
> -#include <setjmp.h>
> +struct jpeg_compress_struct;
>  
> +struct JPEG_ERROR_MGR;
> +struct JPEG_DEST_MGR;
> +
>  namespace rfb {
>  
> -  typedef struct {
> -    struct jpeg_error_mgr pub;
> -    jmp_buf jmpBuffer;
> -    char lastError[JMSG_LENGTH_MAX];
> -  } JPEG_ERROR_MGR;
> -
> -  class JpegCompressor;
> -
> -  typedef struct {
> -    struct jpeg_destination_mgr pub;
> -    JpegCompressor *instance;
> -  } JPEG_DEST_MGR;
> -
>    enum JPEG_SUBSAMP {
>      SUBSAMP_UNDEFINED = -1,
>      SUBSAMP_NONE = 0,
> @@ -78,10 +64,11 @@
>  
>    private:
>  
> -    struct jpeg_compress_struct cinfo;
> -    JPEG_ERROR_MGR err;
> -    JPEG_DEST_MGR dest;
> +    struct jpeg_compress_struct *cinfo;
>  
> +    struct JPEG_ERROR_MGR *err;
> +    struct JPEG_DEST_MGR *dest;
> +
>    };
>  
>  } // end of namespace rfb
> 
> This was sent by the SourceForge.net collaborative development platform, the 
> world's largest Open Source development site.
> 
> 
> ------------------------------------------------------------------------------
> Using storage to extend the benefits of virtualization and iSCSI
> Virtualization increases hardware utilization and delivers a new level of
> agility. Learn what those decisions are and how to modernize your storage 
> and backup environments for virtualization.
> http://www.accelacomm.com/jaw/sfnl/114/51434361/
> _______________________________________________
> Tigervnc-commits mailing list
> tigervnc-comm...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tigervnc-commits

------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Tigervnc-devel mailing list
Tigervnc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tigervnc-devel

Reply via email to