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

📄 dither.c

📁 linux下将各类格式图片转换工具
💻 C
📖 第 1 页 / 共 4 页
字号:
		  *dst++ = r_table [R] | g_table [G] | b_table [B];		  *dst++ = r_table [R] | g_table [G] | b_table [B];#ifdef HAVE_SIGNED_SHIFT		  yval  = (*yptr2++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  yval  = *yptr2++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R = yval + Cr_r_tab [crval];		  G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval];		  B = yval + Cb_b_tab [cbval];		  *dst2++ = r_table [R] | g_table [G] | b_table [B];		  *dst2++ = r_table [R] | g_table [G] | b_table [B];#ifdef HAVE_SIGNED_SHIFT		  yval  = (*yptr2++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  yval  = *yptr2++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R = yval + Cr_r_tab [crval];		  G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval];		  B = yval + Cb_b_tab [cbval];		  *dst2++ = r_table [R] | g_table [G] | b_table [B];		  *dst2++ = r_table [R] | g_table [G] | b_table [B];	       }	       memcpy (dst, dst - 2 * image->width,		       2 * image->width * sizeof (u_word_t));	       memcpy (dst2, dst2 - 2 * image->width,		       2 * image->width * sizeof (u_word_t));	       yptr  += image->width;	       yptr2 += image->width;	       dst   += 3 * image->width * 2;	       dst2  += 3 * image->width * 2;	    }	 }	 else	 {	    yptr2 = yptr + image->width;	    dst  = (u_word_t *) out;	    dst2 = dst + image->width;	    	    for (y = image->height / 2; y; y--)	    {	       for (x = image->width / 2; x; x--)	       {#ifdef HAVE_SIGNED_SHIFT		  crval = *crptr++ >> 4;		  cbval = *cbptr++ >> 4;		  yval  = (*yptr++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  crval = *crptr++ / 16;		  cbval = *cbptr++ / 16;		  yval  = *yptr++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R = yval + Cr_r_tab [crval];		  G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval];		  B = yval + Cb_b_tab [cbval];		  *dst++ = r_table [R] | g_table [G] | b_table [B];	       #ifdef HAVE_SIGNED_SHIFT		  yval  = (*yptr++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  yval  = *yptr++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R = yval + Cr_r_tab [crval];		  G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval];		  B = yval + Cb_b_tab [cbval];		  *dst++ = r_table [R] | g_table [G] | b_table [B];#ifdef HAVE_SIGNED_SHIFT		  yval  = (*yptr2++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  yval  = *yptr2++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R = yval + Cr_r_tab [crval];		  G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval];		  B = yval + Cb_b_tab [cbval];		  *dst2++ = r_table [R] | g_table [G] | b_table [B];#ifdef HAVE_SIGNED_SHIFT		  yval  = (*yptr2++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  yval  = *yptr2++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R = yval + Cr_r_tab [crval];		  G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval];		  B = yval + Cb_b_tab [cbval];		  *dst2++ = r_table [R] | g_table [G] | b_table [B];	       }	       yptr  += image->width;	       yptr2 += image->width;	       dst   += image->width;	       dst2  += image->width;	    }	 }      }      else				/* 4:4:4 format */      {	 if (private->double_resolution)	 {	    unsigned int *dst;		/* pointer to dithered pixels */	    	    dst  = (unsigned int *) out;	    	    for (y = image->height; y; y--)	    {	       for (x = image->width; x; x--)	       {#ifdef HAVE_SIGNED_SHIFT		  crval = *crptr++ >> 4;		  cbval = *cbptr++ >> 4;		  yval  = (*yptr++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  crval = *crptr++ / 16;		  cbval = *cbptr++ / 16;		  yval  = *yptr++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R = yval + Cr_r_tab [crval];		  G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval];		  B = yval + Cb_b_tab [cbval];		  		  *dst++ = r_table [R] | g_table [G] | b_table [B];	       }	       memcpy (dst, dst - image->width,		       image->width * sizeof (unsigned int));	       dst += image->width;	    }	 }	 else	 {	    u_word_t *dst;		/* pointer to dithered pixels */	    dst  = (u_word_t *) out;	    	    for (n = image->width * image->height; n; n--)	    {#ifdef HAVE_SIGNED_SHIFT	       crval = *crptr++ >> 4;	       cbval = *cbptr++ >> 4;	       yval  = (*yptr++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */	       crval = *crptr++ / 16;	       cbval = *cbptr++ / 16;	       yval  = *yptr++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */	       R = yval + Cr_r_tab [crval];	       G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval];	       B = yval + Cb_b_tab [cbval];	       *dst++ = r_table [R] | g_table [G] | b_table [B];	    }	 }      }   }   else   {      unsigned int *dst;		/* pointer to dithered pixels */      word_t	   *src;		/* current pixel of frame */      unsigned int *y_table;      y_table = private->y_table;      dst     = (unsigned int *) out;      src     = image->pixels [GRAY];            if (private->double_resolution)      {	 int x, y;			/* pixel coordinates */  	    	 for (y = image->height; y; y--)	 {	    for (x = image->width; x; x--)	    {	       int value;	       #ifdef HAVE_SIGNED_SHIFT	       value = y_table [*src++ >> 4];#else /* not HAVE_SIGNED_SHIFT */	       value = y_table [*src++ / 16];#endif /* not HAVE_SIGNED_SHIFT */	       *dst++ = (value << 16) | value;	    }	    	    memcpy (dst, dst - image->width,		    image->width * sizeof (unsigned int));	    dst += image->width;	 }      }      else      {	 int n;				/* pixel counter */	 	 for (n = image->width * image->height / 2; n; n--, src += 2)#ifdef HAVE_SIGNED_SHIFT#	ifndef WORDS_BIGENDIAN	    *dst++ = (y_table [src [1] >> 4] << 16) | y_table [src [0] >> 4];#	else /* not WORDS_BIGENDIAN  */	    *dst++ = (y_table [src [0] >> 4] << 16) | y_table [src [1] >> 4];#	endif#else /* not HAVE_SIGNED_SHIFT */#	ifndef WORDS_BIGENDIAN	    *dst++ = (y_table [src [1] / 16] << 16) | y_table [src [0] / 16];#	else /* not WORDS_BIGENDIAN  */	    *dst++ = (y_table [src [0] / 16] << 16) | y_table [src [1] / 16];#	endif#endif /* not HAVE_SIGNED_SHIFT */      }   }   return 1;}static int display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage,		    const fiasco_image_t *fiasco_image)/* *  Convert 'image' to 16 bit color bitmap. *  If 'double_resolution' is true then double image size in both directions. * *  No return value. * *  Side effects: *	'out[]'	is filled with dithered image */{   unsigned 	      *gray_clip = init_clipping ();   const image_t      *image;   renderer_private_t *private;   byte_t	      *out;   if (!gray_clip)      return 0;   if (!this)   {      set_error (_("Parameter `%s' not defined (NULL)."), "this");      return 0;   }   if (!ximage)   {      set_error (_("Parameter `%s' not defined (NULL)."), "ximage");      return 0;   }   if (!fiasco_image)   {      set_error (_("Parameter `%s' not defined (NULL)."), "fiasco_image");      return 0;   }   out 	   = (byte_t *) ximage;   image   = cast_image ((fiasco_image_t *) fiasco_image);   if (!image)      return 0;   private = (renderer_private_t *) this->private;      if (image->color)   {      word_t 	   *cbptr, *crptr;	/* pointer to chroma bands */      word_t 	   *yptr;		/* pointers to lumincance band */      int 	   *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab;      unsigned int *r_table, *g_table, *b_table;      Cr_g_tab = private->Cr_g_tab;      Cr_r_tab = private->Cr_r_tab;      Cb_b_tab = private->Cb_b_tab;      Cb_g_tab = private->Cb_g_tab;      r_table  = private->r_table;      g_table  = private->g_table;      b_table  = private->b_table;      yptr     = image->pixels [Y];      cbptr    = image->pixels [Cb];      crptr    = image->pixels [Cr];      if (image->format == FORMAT_4_2_0)      {	 if (private->double_resolution)	 {	    int		  yval1;	/* lumincance pixel */	    int 	  crval1, cbval1; /* chroma pixels */	    int		  yval2;	/* pixel in YCbCr color space */	    unsigned int  R1, G1, B1;	/* pixel in RGB color space */	    unsigned int  R2, G2, B2;	/* pixel in RGB color space */	    int		  x, y;		/* pixel counter */	    unsigned int *dst;		/* pointer to dithered pixels */	    unsigned int *dst2;		/* pointers to dithered pixels */	    word_t	 *yptr2;	/* pointers to lumincance band */	    	    dst   = (unsigned int *) out;	    dst2  = dst + (image->width >> 1) * 3 * 2;	    yptr2 = yptr + image->width;	    	    for (y = image->height >> 1; y; y--)	    {	       for (x = image->width >> 1; x; x--)	       {#ifdef HAVE_SIGNED_SHIFT		  yval1  = (*yptr++ >> 4) + 128;		  yval2  = (*yptr++ >> 4) + 128;		  crval1 = *crptr++ >> 4;		  cbval1 = *cbptr++ >> 4;#else /* not HAVE_SIGNED_SHIFT */		  yval1  = *yptr++  / 16 + 128;		  yval2  = *yptr++  / 16 + 128;		  crval1 = *crptr++ / 16;		  cbval1 = *cbptr++ / 16;#endif /* not HAVE_SIGNED_SHIFT */		  R1 = gray_clip [yval1 + Cr_r_tab [crval1]];		  G1 = gray_clip [yval1 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B1 = gray_clip [yval1 + Cb_b_tab [cbval1]];		  R2 = gray_clip [yval2 + Cr_r_tab [crval1]];		  G2 = gray_clip [yval2 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B2 = gray_clip [yval2 + Cb_b_tab [cbval1]];		  *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24);		  *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24);		  *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24);#ifdef HAVE_SIGNED_SHIFT		  yval1  = (*yptr2++ >> 4) + 128;		  yval2  = (*yptr2++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  yval1  = *yptr2++  / 16 + 128;		  yval2  = *yptr2++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R1 = gray_clip [yval1 + Cr_r_tab [crval1]];		  G1 = gray_clip [yval1 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B1 = gray_clip [yval1 + Cb_b_tab [cbval1]];		  R2 = gray_clip [yval2 + Cr_r_tab [crval1]];		  G2 = gray_clip [yval2 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B2 = gray_clip [yval2 + Cb_b_tab [cbval1]];		  *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24);		  *dst2++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24);		  *dst2++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24);	       }	       memcpy (dst, dst - (image->width >> 1) * 3,		       (image->width >> 1) * 3 * sizeof (unsigned int));	       memcpy (dst2, dst2 - (image->width >> 1) * 3, 		       (image->width >> 1) * 3 * sizeof (unsigned int));	       dst   += (image->width >> 1) * 3 * 3;	       dst2  += (image->width >> 1) * 3 * 3;	       yptr  += image->width;	       yptr2 += image->width;	    }	 }	 else	 {	    int		  yval1;	/* lumincance pixel */	    int 	  crval1, cbval1; /* chroma pixels */	    int		  yval2;	/* pixel in YCbCr color space */	    unsigned int  R1, G1, B1;	/* pixel in RGB color space */	    unsigned int  R2, G2, B2;	/* pixel in RGB color space */	    int		  x, y;		/* pixel counter */	    unsigned int *dst;		/* pointer to dithered pixels */	    unsigned int *dst2;		/* pointers to dithered pixels */	    word_t	 *yptr2;	/* pointers to lumincance band */	    	    dst   = (unsigned int *) out;	    dst2  = dst + (image->width >> 2) * 3;	    yptr2 = yptr + image->width;	    	    for (y = image->height >> 1; y; y--)	    {	       for (x = image->width >> 2; x; x--)	       {#ifdef HAVE_SIGNED_SHIFT		  yval1  = (*yptr++ >> 4) + 128;		  yval2  = (*yptr++ >> 4) + 128;		  crval1 = *crptr++ >> 4;		  cbval1 = *cbptr++ >> 4;#else /* not HAVE_SIGNED_SHIFT */		  yval1  = *yptr++  / 16 + 128;		  yval2  = *yptr++  / 16 + 128;		  crval1 = *crptr++ / 16;		  cbval1 = *cbptr++ / 16;#endif /* not HAVE_SIGNED_SHIFT */		  R1 = gray_clip [yval1 + Cr_r_tab [crval1]];		  G1 = gray_clip [yval1 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B1 = gray_clip [yval1 + Cb_b_tab [cbval1]];		  R2 = gray_clip [yval2 + Cr_r_tab [crval1]];		  G2 = gray_clip [yval2 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B2 = gray_clip [yval2 + Cb_b_tab [cbval1]];		  *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24);		  *dst   = G2 | (R2 << 8);#ifdef HAVE_SIGNED_SHIFT		  yval1  = (*yptr2++ >> 4) + 128;		  yval2  = (*yptr2++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  yval1  = *yptr2++  / 16 + 128;		  yval2  = *yptr2++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R1 = gray_clip [yval1 + Cr_r_tab [crval1]];		  G1 = gray_clip [yval1 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B1 = gray_clip [yval1 + Cb_b_tab [cbval1]];		  R2 = gray_clip [yval2 + Cr_r_tab [crval1]];		  G2 = gray_clip [yval2 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B2 = gray_clip [yval2 + Cb_b_tab [cbval1]];		  *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24);		  *dst2   = G2 | (R2 << 8);	       #ifdef HAVE_SIGNED_SHIFT		  yval1  = (*yptr++ >> 4) + 128;		  yval2  = (*yptr++ >> 4) + 128;		  crval1 = *crptr++ >> 4;		  cbval1 = *cbptr++ >> 4;#else /* not HAVE_SIGNED_SHIFT */		  yval1  = *yptr++  / 16 + 128;		  yval2  = *yptr++  / 16 + 128;		  crval1 = *crptr++ / 16;		  crval2 = *crptr++ / 16;		  cbval1 = *cbptr++ / 16;		  cbval2 = *cbptr++ / 16;#endif /* not HAVE_SIGNED_SHIFT */		  R1 = gray_clip [yval1 + Cr_r_tab [crval1]];		  G1 = gray_clip [yval1 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B1 = gray_clip [yval1 + Cb_b_tab [cbval1]];		  R2 = gray_clip [yval2 + Cr_r_tab [crval1]];		  G2 = gray_clip [yval2 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B2 = gray_clip [yval2 + Cb_b_tab [cbval1]];		  *dst++ |= (B1 << 16) | (G1 << 24);		  *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24);#ifdef HAVE_SIGNED_SHIFT		  yval1  = (*yptr2++ >> 4) + 128;		  yval2  = (*yptr2++ >> 4) + 128;#else /* not HAVE_SIGNED_SHIFT */		  yval1  = *yptr2++  / 16 + 128;		  yval2  = *yptr2++  / 16 + 128;#endif /* not HAVE_SIGNED_SHIFT */		  R1 = gray_clip [yval1 + Cr_r_tab [crval1]];		  G1 = gray_clip [yval1 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B1 = gray_clip [yval1 + Cb_b_tab [cbval1]];		  R2 = gray_clip [yval2 + Cr_r_tab [crval1]];		  G2 = gray_clip [yval2 + Cr_g_tab [crval1]				 + Cb_g_tab [cbval1]];		  B2 = gray_clip [yval2 + Cb_b_tab [cbval1]];		  *dst2++ |= (B1 << 16) | (G1 << 24);		  *dst2++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24);	       }	       dst   += (image->width >> 2) * 3;	       dst2  += (image->width >> 2) * 3;	       yptr  += image->width;	       yptr2 += image->width;	    }	 }      }      else				/* 4:4:4 format */      {	 if (private->double_resolution)	 {	    unsigned int R1, G1, B1;		/* pixel1 in RGB color space */	    unsigned int R2, G2, B2;		/* pixel2 in RGB color space */	    int		 yval1, crval1, cbval1;	/* pixel1 in YCbCr space */	    int		 yval2, crval2, cbval2;	/* pixel2 in YCbCr space */

⌨️ 快捷键说明

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