Esempio n. 1
0
void clsCynoType::CynoType(GlobalHelper &g_GH)
{
	BYTE r,g,b,c,y,m,k;
	int iWStep, iJStep;
	int tmp;
	for(int i=0;i<iNR;i++)
	{
		iWStep = i*pImgSource->widthStep;
		for(int j=0;j<iNC;j++)
		{
			iJStep = j*3;

			r = *(uchar*)(pImgSource->imageData + iWStep + iJStep + 2);

			g = *(uchar*)(pImgSource->imageData + iWStep + iJStep + 1);

			b = *(uchar*)(pImgSource->imageData + iWStep + iJStep + 0);
			RGB2CMYK(r,g,b,c,m,y,k);
			if(c>m)
				if(c>y)
					CMYK2RGB(c,0,0,k,r,g,b);
				else
					CMYK2RGB(0,0,0,k,r,g,b);
			else
				CMYK2RGB(0,0,0,k,r,g,b);
			/*if(c>m)
				if(c>y)
						CMYK2RGB(c,0,0,0,r,g,b);
				else
						CMYK2RGB(0,0,y,0,r,g,b);
			else
				if(m>y)
						CMYK2RGB(0,m,0,0,r,g,b);
				else
						CMYK2RGB(0,0,y,0,r,g,b);
			*/
/*			if(r == 255 && g==255 && b==255)
			{
				tmp = (*(uchar*)(pImgSource->imageData + iWStep + iJStep + 2) +
						*(uchar*)(pImgSource->imageData + iWStep + iJStep + 1) +
						*(uchar*)(pImgSource->imageData + iWStep + iJStep + 0))/3;
				r = g = b = tmp;
			}*/
			*(uchar*)(pImgSource->imageData + iWStep + iJStep + 2) = r;//tmp*0.5 + 220*0.40 + 17*0.10;
			*(uchar*)(pImgSource->imageData + iWStep + iJStep + 1) = g;//tmp*0.5 + 227*0.40 + 24*0.10;
			*(uchar*)(pImgSource->imageData + iWStep + iJStep + 0) = b;//btmp*0.5 + 84*0.40 + 66*0.10;

		}
	}

}
Esempio n. 2
0
RL2_PRIVATE int
rl2_decode_jpeg_scaled (int scale, const unsigned char *jpeg, int jpeg_size,
			unsigned int *width, unsigned int *height,
			unsigned char *xpixel_type, unsigned char **pixels,
			int *pixels_size)
{
/* attempting to create a raster from a JPEG image - supporting rescaled size */
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    unsigned char pixel_type = RL2_PIXEL_UNKNOWN;
    int nBands;
    int channels;
    int inverted = 0;
    unsigned char *data = NULL;
    unsigned char *p_data;
    int data_size;
    int i;
    int row_stride;
    JSAMPARRAY buffer;

    if (scale == 1 || scale == 2 || scale == 4 || scale == 8)
	;
    else
	goto error;

    cinfo.err = jpeg_std_error (&jerr);
    jpeg_create_decompress (&cinfo);
    rl2_jpeg_src (&cinfo, (unsigned char *) jpeg, jpeg_size);
    jpeg_read_header (&cinfo, TRUE);
    if (scale == 8)
      {
	  /* requesting 1:8 scaling */
	  cinfo.scale_num = 1;
      }
    else if (scale == 4)
      {
	  /* requesting 1:4 scaling */
	  cinfo.scale_num = 2;
      }
    else if (scale == 2)
      {
	  /* requesting 1:2 scaling */
	  cinfo.scale_num = 4;
      }
    else
      {
	  /* no scaling, full dimension */
	  cinfo.scale_num = 8;
      }
    cinfo.scale_denom = 8;
    if ((cinfo.jpeg_color_space == JCS_CMYK)
	|| (cinfo.jpeg_color_space == JCS_YCCK))
	cinfo.out_color_space = JCS_CMYK;
    if (!jpeg_start_decompress (&cinfo))
	goto error;
    channels = cinfo.output_components;
    if (cinfo.out_color_space == JCS_RGB && channels == 3)
      {
	  pixel_type = RL2_PIXEL_RGB;
	  nBands = 3;
      }
    else if (cinfo.out_color_space == JCS_GRAYSCALE && channels == 1)
      {
	  pixel_type = RL2_PIXEL_GRAYSCALE;
	  nBands = 1;
      }
    else if (cinfo.out_color_space == JCS_CMYK && channels == 4)
      {
	  jpeg_saved_marker_ptr marker;
	  pixel_type = RL2_PIXEL_RGB;
	  nBands = 3;
	  marker = cinfo.marker_list;
	  while (marker)
	    {
		if ((marker->marker == (JPEG_APP0 + 14))
		    && (marker->data_length >= 12)
		    && (!strncmp ((const char *) marker->data, "Adobe", 5)))
		  {
		      inverted = 1;
		      break;
		  }
		marker = marker->next;
	    }
      }
    else
	goto error;
/* creating the scanline buffer */
    row_stride = cinfo.output_width * cinfo.output_components;
    buffer =
	(*cinfo.mem->alloc_sarray) ((j_common_ptr) & cinfo, JPOOL_IMAGE,
				    row_stride, 1);
    if (buffer == NULL)
	goto error;
/* creating the raster data */
    data_size = cinfo.output_width * cinfo.output_height * nBands;
    data = malloc (data_size);
    if (data == NULL)
	goto error;
    p_data = data;
    while (cinfo.output_scanline < cinfo.output_height)
      {
	  /* reading all decompressed scanlines */
	  jpeg_read_scanlines (&cinfo, buffer, 1);
	  if (cinfo.out_color_space == JCS_CMYK)
	    {
		JSAMPROW row = buffer[0];
		for (i = 0; i < (int) (cinfo.output_width); i++)
		  {
		      CMYK2RGB (*(row + 0), *(row + 1), *(row + 2),
				*(row + 3), inverted, p_data);
		      row += 4;
		      p_data += 3;
		  }
	    }
	  else if (cinfo.out_color_space == JCS_GRAYSCALE)
	    {
		JSAMPROW row = buffer[0];
		for (i = 0; i < (int) (cinfo.output_width); i++)
		    *p_data++ = *row++;
	    }
	  else
	    {
		/* RGB */
		JSAMPROW row = buffer[0];
		for (i = 0; i < (int) (cinfo.output_width); i++)
		  {
		      *p_data++ = *row++;
		      *p_data++ = *row++;
		      *p_data++ = *row++;
		  }
	    }
      }
    *width = cinfo.output_width;
    *height = cinfo.output_height;
    *xpixel_type = pixel_type;
    *pixels = data;
    *pixels_size = data_size;
/* memory cleanup */
    jpeg_finish_decompress (&cinfo);
    jpeg_destroy_decompress (&cinfo);
    return RL2_OK;

  error:
    jpeg_destroy_decompress (&cinfo);
    if (data != NULL)
	free (data);
    return RL2_ERROR;
}