⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screenchattingclientdlg.cpp

📁 Screen Chatting source
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  if (cinfo->src == NULL)
  {   /* first time for this JPEG object? */
      cinfo->src = (struct jpeg_source_mgr *)
        (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
                                            sizeof(struct jpeg_source_mgr));
  }

  /* Jo Hagelberg 15.4.99               
   * added progress notification for JPEG 
   */
  if ( cinfo->progress == NULL)
  {   /* first time and progress notification wanted? */
      cinfo->progress = (struct jpeg_progress_mgr *)
        (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
                                            sizeof(struct jpeg_progress_mgr));
      /* static callback function in JpegDecoder */
      cinfo->progress->progress_monitor = notifyCppWorld;
  }

  /* Jo Hagelberg 15.4.99               
   * put CDataSource instance ptr into client data, so we can use it in the callback
   * NOTE: define a client data struct if this should be needed for other stuff, too
   */
//  cinfo->client_data = pDataSrc ;

  src = cinfo->src;

  /* Set up function pointers */
  src->init_source = init_source;
  src->fill_input_buffer = fill_input_buffer;
  src->skip_input_data = skip_input_data;
  src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
  src->term_source = term_source;

  /* Set up data pointer */
  src->bytes_in_buffer = FileSize;
  src->next_input_byte = pData;
}

/*
/--------------------------------------------------------------------
|
|      $log$
|
--------------------------------------------------------------------
*/

/*
 * Initialize source --- called by jpeg_read_header
 * before any data is actually read.
 */

void init_source (j_decompress_ptr cinfo)
{
  my_src_ptr src = (my_src_ptr) cinfo->src;

  /* We reset the empty-input-file flag for each image,
   * but we don't clear the input buffer.
   * This is correct behavior for reading a series of images from one source.
   */
  src->start_of_file = TRUE;
}


/*
 * Fill the input buffer --- called whenever buffer is emptied.
 *
 * In typical applications, this should read fresh data into the buffer
 * (ignoring the current state of next_input_byte & bytes_in_buffer),
 * reset the pointer & count to the start of the buffer, and return TRUE
 * indicating that the buffer has been reloaded.  It is not necessary to
 * fill the buffer entirely, only to obtain at least one more byte.
 *
 * There is no such thing as an EOF return.  If the end of the file has been
 * reached, the routine has a choice of ERREXIT() or inserting fake data into
 * the buffer.  In most cases, generating a warning message and inserting a
 * fake EOI marker is the best course of action --- this will allow the
 * decompressor to output however much of the image is there.  However,
 * the resulting error message is misleading if the real problem is an empty
 * input file, so we handle that case specially.
 *
 * In applications that need to be able to suspend compression due to input
 * not being available yet, a FALSE return indicates that no more data can be
 * obtained right now, but more may be forthcoming later.  In this situation,
 * the decompressor will return to its caller (with an indication of the
 * number of scanlines it has read, if any).  The application should resume
 * decompression after it has loaded more data into the input buffer.  Note
 * that there are substantial restrictions on the use of suspension --- see
 * the documentation.
 *
 * When suspending, the decompressor will back up to a convenient restart point
 * (typically the start of the current MCU). next_input_byte & bytes_in_buffer
 * indicate where the restart point will be if the current call returns FALSE.
 * Data beyond this point must be rescanned after resumption, so move it to
 * the front of the buffer rather than discarding it.
 */

boolean fill_input_buffer (j_decompress_ptr cinfo)
{
  my_src_ptr src = (my_src_ptr) cinfo->src;
  size_t nbytes;

  nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);

  if (nbytes <= 0) {
    if (src->start_of_file)	/* Treat empty input file as fatal error */
      ERREXIT(cinfo, JERR_INPUT_EMPTY);
    WARNMS(cinfo, JWRN_JPEG_EOF);
    /* Insert a fake EOI marker */
    src->buffer[0] = (JOCTET) 0xFF;
    src->buffer[1] = (JOCTET) JPEG_EOI;
    nbytes = 2;
  }

  src->pub.next_input_byte = src->buffer;
  src->pub.bytes_in_buffer = nbytes;
  src->start_of_file = FALSE;

  return TRUE;
}


/*
 * Skip data --- used to skip over a potentially large amount of
 * uninteresting data (such as an APPn marker).
 *
 * Writers of suspendable-input applications must note that skip_input_data
 * is not granted the right to give a suspension return.  If the skip extends
 * beyond the data currently in the buffer, the buffer can be marked empty so
 * that the next read will cause a fill_input_buffer call that can suspend.
 * Arranging for additional bytes to be discarded before reloading the input
 * buffer is the application writer's problem.
 */

void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
  my_src_ptr src = (my_src_ptr) cinfo->src;

  /* Just a dumb implementation for now.  Could use fseek() except
   * it doesn't work on pipes.  Not clear that being smart is worth
   * any trouble anyway --- large skips are infrequent.
   */
  if (num_bytes > 0) {
    while (num_bytes > (long) src->pub.bytes_in_buffer) {
      num_bytes -= (long) src->pub.bytes_in_buffer;
      (void) fill_input_buffer(cinfo);
      /* note we assume that fill_input_buffer will never return FALSE,
       * so suspension need not be handled.
       */
    }
    src->pub.next_input_byte += (size_t) num_bytes;
    src->pub.bytes_in_buffer -= (size_t) num_bytes;
  }
}


/*
 * An additional method that can be provided by data source modules is the
 * resync_to_restart method for error recovery in the presence of RST markers.
 * For the moment, this source module just uses the default resync method
 * provided by the JPEG library.  That method assumes that no backtracking
 * is possible.
 */


/*
 * Terminate source --- called by jpeg_finish_decompress
 * after all data has been read.  Often a no-op.
 *
 * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
 * application must deal with any cleanup that should happen even
 * for error exit.
 */

void term_source (j_decompress_ptr cinfo)
{
  /* no work necessary here */
	cinfo->mem->free_pool((j_common_ptr)cinfo,JPOOL_PERMANENT);
}

/*
 * Find the next JPEG marker, save it in cinfo->unread_marker.
 * Returns FALSE if had to suspend before reaching a marker;
 * in that case cinfo->unread_marker is unchanged.
 *
 * Note that the result might not be a valid marker code,
 * but it will never be 0 or FF.
 */

boolean next_marker (j_decompress_ptr cinfo)
{
  int c;
  INPUT_VARS(cinfo);

  for (;;) {
    INPUT_BYTE(cinfo, c, return FALSE);
    /* Skip any non-FF bytes.
     * This may look a bit inefficient, but it will not occur in a valid file.
     * We sync after each discarded byte so that a suspending data source
     * can discard the byte from its buffer.
     */
    while (c != 0xFF) {
      cinfo->marker->discarded_bytes++;
      INPUT_SYNC(cinfo);
      INPUT_BYTE(cinfo, c, return FALSE);
    }
    /* This loop swallows any duplicate FF bytes.  Extra FFs are legal as
     * pad bytes, so don't count them in discarded_bytes.  We assume there
     * will not be so many consecutive FF bytes as to overflow a suspending
     * data source's input buffer.
     */
    do {
      INPUT_BYTE(cinfo, c, return FALSE);
    } while (c == 0xFF);
    if (c != 0)
      break;			/* found a valid marker, exit loop */
    /* Reach here if we found a stuffed-zero data sequence (FF/00).
     * Discard it and loop back to try again.
     */
    cinfo->marker->discarded_bytes += 2;
    INPUT_SYNC(cinfo);
  }

  if (cinfo->marker->discarded_bytes != 0) {
    WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
    cinfo->marker->discarded_bytes = 0;
  }

  cinfo->unread_marker = c;

  INPUT_SYNC(cinfo);
  return TRUE;
}

BYTE * decodeRGB
    ( jpeg_decompress_struct *cinfo,
	  int w,
      int h,
      int * pDestBPP
    )
    // Assumes IJPEG decoder is already set up.
{
  BYTE * pDst;
  int CurLine = 0,BitsPerPixel=*pDestBPP;
  JSAMPARRAY ppDst = &pDst;

  BYTE *pBits = new BYTE [GetBitsMemNeeded (w, h, BitsPerPixel)];
  BYTE **pLineArray = new BYTE * [h];
  int LineLen=GetBytesPerLine(w, h, BitsPerPixel);

  for (int y=0; y<h; y++)
    pLineArray[h-y-1] = pBits + y*LineLen;

  while (CurLine < h)
  {
    pDst = pLineArray[CurLine];
    jpeg_read_scanlines (cinfo, ppDst, 1);
    CurLine++;
  }

  delete pLineArray;

  return pBits;
}

long GetBitsMemNeeded
    ( LONG width,
      LONG height,
      WORD BitsPerPixel
    )
    // Returns memory needed by bitmap bits.
{
  // Calculate memory per line.
  int LineMem = width*BitsPerPixel/8;

  // bdelmee code change
  if (BitsPerPixel == 1 && width % 8)
    ++LineMem;

  // Multiply by number of lines
  return LineMem*height;
}

long GetBytesPerLine
    (LONG width,
      LONG height,
      WORD BitsPerPixel)
    // Returns number of bytes used per line.
{
  // bdelmee code change
  int nBytes = width * BitsPerPixel / 8;
  if (BitsPerPixel == 1 && width % 8)
    ++nBytes;
  return nBytes;
}

BYTE* decodeGray
    ( 
	  jpeg_decompress_struct *cinfo,
	  int w,
      int h,
      int * pDestBPP
    )
    // Assumes IJPEG decoder is already set up.
{
  BYTE * pDst;
  int CurLine = 0,BitsPerPixel=*pDestBPP;
  BYTE * pBuf = new BYTE [w];
  JSAMPARRAY ppBuf = &pBuf;

  BYTE *pBits = new BYTE [GetBitsMemNeeded (w, h, BitsPerPixel)];
  BYTE     **pLineArray = new BYTE * [h];
  int LineLen = GetBytesPerLine(w, h, BitsPerPixel);

  for (int y=0; y<h; y++)
    pLineArray[y] = pBits + y*LineLen;

  while (CurLine < h)
  {
    if (*pDestBPP == 32)
    {
      jpeg_read_scanlines (cinfo, ppBuf, 1);

      pDst = pLineArray[CurLine];

      for (int i=0; i<w; i++)
      {
        pDst[i*4] = pBuf[i];
        pDst[i*4+1] = pBuf[i];
        pDst[i*4+2] = pBuf[i];
        pDst[i*4+3] = 0xFF;
      }
    }
    else
    {
      ppBuf = &pDst;
      *ppBuf = pLineArray[CurLine];
      jpeg_read_scanlines (cinfo, ppBuf, 1);

    }
    CurLine++;
  }
  delete pBuf;
  return pBits;
}


void error_exit (j_common_ptr pcinfo)
// This procedure is called by the IJPEG library when an error
// occurs.
{
  /* Create the message string */
  char sz[256];
  (pcinfo->err->format_message) (pcinfo, sz);
  strcat (sz, "\n");

 }

void JNotification (j_common_ptr cinfo)
{
  double       part;

  /* calculated according to jpeg lib manual
   * note: this may not be precice when using buffered image mode
   * todo: think hard of alternatives 4 this case ... :-)
   */
  part = ( (double)cinfo->progress->completed_passes +
 	         ((double)cinfo->progress->pass_counter/cinfo->progress->pass_limit) ) /
	       (double)cinfo->progress->total_passes;
}

BYTE* BGRToRGB(BYTE *pByteBGR,int nByteSize)
{
	BYTE *pByteRGB=pByteBGR;

	for(int i=0;i<nByteSize/3;i++)
	{
		BYTE *pByteTemp1=pByteRGB+i*3;
//		BYTE *pByteTemp2=pByteBGR+i*3+1;
		BYTE *pByteTemp3=pByteRGB+i*3+2;

		BYTE byteTemp2=*pByteTemp1;
		*pByteTemp1=*pByteTemp3;
		*pByteTemp3=byteTemp2;
	}

	return pByteRGB;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -