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

📄 wrsprite.c

📁 这是从一款商业嵌入式浏览器中节选出来的代码
💻 C
📖 第 1 页 / 共 4 页
字号:
{  int i;  JSAMPROW colormap0 = cinfo->colormap[0];  JSAMPROW colormap1 = cinfo->colormap[1];  JSAMPROW colormap2 = cinfo->colormap[2];#ifdef PALETTE_VIDC  int R, G, B;  int colormaplen = 256;  for (i = 0; i < colormaplen; i++)  {    R = ((i & 0x10) << 3) | ((i & 0x07) << 4);    R |= R >> 4;    G = ((i & 0x60) << 1) | ((i & 0x03) << 4);    G |= G >> 4;    B = (i & 0x80) | ((i & 0x08) << 3) | ((i & 0x03) << 4);    B |= B >> 4;    colormap0[i] = (JSAMPLE) R;    colormap1[i] = (JSAMPLE) G;    colormap2[i] = (JSAMPLE) B;    cinfo->actual_number_of_colors++;  }#else  unsigned int *pal = win32_palette();  for ( i=0; i<256; i++ )  {    colormap0[i] = (JSAMPLE) ((pal[i] >> 8 ) & 0xff);    colormap1[i] = (JSAMPLE) ((pal[i] >> 16 ) & 0xff);    colormap2[i] = (JSAMPLE) ((pal[i] >> 24 ) & 0xff);  }  cinfo->actual_number_of_colors = 256;#endif}/* * Build color map for an 4bpp Greyscale Sprite file. */static voidread_sprite4bpp_map (j_decompress_ptr cinfo){  int i, colormaplen;  int R;  JSAMPROW colormap0 = cinfo->colormap[0];  JSAMPROW colormap1 = cinfo->colormap[1];  JSAMPROW colormap2 = cinfo->colormap[2];  /* OK, fetch it. */  colormaplen = 16;  for (i = 0; i < colormaplen; i++)  {    R = i | (i << 4);    colormap0[i] = colormap1[i] = colormap2[i] = (JSAMPLE) R;    cinfo->actual_number_of_colors++;  }}/* * Build color map for an 8bpp Greyscale Sprite file. */static voidread_sprite8bpp_map (j_decompress_ptr cinfo){  int i, colormaplen;  int R;  JSAMPROW colormap0 = cinfo->colormap[0];  JSAMPROW colormap1 = cinfo->colormap[1];  JSAMPROW colormap2 = cinfo->colormap[2];  /* OK, fetch it. */  colormaplen = 256;  for (i = 0; i < colormaplen; i++)  {    R = i | (i << 4);    colormap0[i] = colormap1[i] = colormap2[i] = (JSAMPLE) R;    cinfo->actual_number_of_colors++;  }}/* * Finish up at the end of the file. */static voidfinish_output_sprite (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo){  sprite_dest_ptr dest = (sprite_dest_ptr) dinfo;  /* Make sure we wrote the output file OK */  if (!dest->outfile)  {    fflush(dinfo->output_file);    if (ferror(dinfo->output_file)) ERREXIT(cinfo, JERR_FILE_WRITE);  }}/* * The module selection routine for SPRITE format output. */djpeg_dest_ptrjinit_write_sprite (j_decompress_ptr cinfo, void *userdst, void *putdst, void *seekdst, void *getdst, BOOL use_16bpp, BOOL yuv_out, int rotate){  sprite_dest_ptr dest;  int width;  int height;  /* Create module interface object, fill in method pointers */  dest = (sprite_dest_ptr)      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,				  SIZEOF(sprite_dest_struct));  dest->pub.start_output = start_output_sprite;  dest->pub.finish_output = finish_output_sprite;  /* Calculate output image dimensions so we can allocate space */  jpeg_calc_output_dimensions(cinfo);  width = cinfo->output_width;  height = cinfo->output_height;#if LAYERS_FB_32BITS  if (yuv_out)  {      /* buffer used as intermediate stage containing 24bit YUV */      dest->pub.buffer = (*cinfo->mem->alloc_sarray)          ((j_common_ptr) cinfo, JPOOL_IMAGE,           cinfo->output_width * 3, (JDIMENSION) 16);            dest->pub.buffer_height = 16;  }  else#endif  {#if LAYERS_FB_32BITS      dest->pub.buffer_height = (rotate==webimage_rotate_LEFT_90 || rotate==webimage_rotate_LEFT_270) ? 16 : 1;#else      dest->pub.buffer_height = 1;#endif      dest->pub.buffer = (*cinfo->mem->alloc_sarray)          ((j_common_ptr) cinfo, JPOOL_IMAGE,           cinfo->output_width * cinfo->output_components, dest->pub.buffer_height);  }  dest->outfile = userdst;  dest->putdst = *((putdst_func *) putdst);  dest->seekdst = *((seekdst_func *) seekdst);  dest->getdst = *((getdst_func *) getdst);      dest->yuv_out = yuv_out;  dest->rotate = (webimage_rotate) rotate;  if (cinfo->quantize_colors)  {    /* Create physical I/O buffer */    dest->samples_per_row = cinfo->output_width;    if (cinfo->out_color_space == JCS_GRAYSCALE)    {      if (cinfo->desired_number_of_colors <= 16)      {        /* fprintf(stderr, "gray quant 4bpp\n");  */        ASSERT(rotate==webimage_rotate_NONE);        if ((width % 8) != 0) width += (8 - (width % 8));        dest->buffer_width = width / 2;        dest->pub.put_pixel_rows = put_pixel4bpp_rows;        dest->iobuffer = (char *) (*cinfo->mem->alloc_small)          ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);        /* Allocate space for a color map of maximum supported size. */        cinfo->colormap = (*cinfo->mem->alloc_sarray)          ((j_common_ptr) cinfo, JPOOL_IMAGE,           (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);        cinfo->actual_number_of_colors = 0; /* initialize map to empty */        read_sprite4bpp_map(cinfo);      }      else      {        /* fprintf(stderr, "gray 8bpp\n");  */        dest->samples_per_row = cinfo->output_width;        switch (rotate)        {        case webimage_rotate_NONE:            dest->pub.put_pixel_rows = put_pixel_rows;            if ((width % 4) != 0) width += (4 - (width % 4));            dest->buffer_width = width;            break;        case webimage_rotate_LEFT_90:            dest->pub.put_pixel_rows = put_pixel_rows_rotate_left_90;            if ((height % 4) != 0) height += (4 - (height % 4));            dest->buffer_width = height;            break;        case webimage_rotate_LEFT_180:            dest->pub.put_pixel_rows = put_pixel_rows_rotate_left_180;            if ((width % 4) != 0) width += (4 - (width % 4));            dest->buffer_width = width;            break;        case webimage_rotate_LEFT_270:            dest->pub.put_pixel_rows = put_pixel_rows_rotate_left_270;            if ((height % 4) != 0) height += (4 - (height % 4));            dest->buffer_width = height;            break;        }        dest->iobuffer = (char *) (*cinfo->mem->alloc_small)          ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);        cinfo->quantize_colors = TRUE;        /* Allocate space for a color map of maximum supported size. */        cinfo->colormap = (*cinfo->mem->alloc_sarray)          ((j_common_ptr) cinfo, JPOOL_IMAGE,           (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);        cinfo->actual_number_of_colors = 0; /* initialize map to empty */        read_sprite8bpp_map(cinfo);      }    }    else    {      /* fprintf(stderr, "quant 8bpp\n"); */      ASSERT(rotate==webimage_rotate_NONE);      if ((width % 4) != 0) width += (4 - (width % 4));      dest->buffer_width = width;      dest->pub.put_pixel_rows = put_pixel_rows;      dest->iobuffer = (char *) (*cinfo->mem->alloc_small)        ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);      /* Allocate space for a color map of maximum supported size. */      cinfo->colormap = (*cinfo->mem->alloc_sarray)        ((j_common_ptr) cinfo, JPOOL_IMAGE,         (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);      cinfo->actual_number_of_colors = 0; /* initialize map to empty */      read_sprite_map(cinfo);    }  }#if LAYERS_FB_32BITS  else if (yuv_out)  {      switch(rotate)      {      case webimage_rotate_NONE:          dest->pub.put_pixel_rows = put_pixel422_rows;          if ((width % 2) != 0) width += (2 - (width % 2));          dest->buffer_width = width * (2 * SIZEOF(char));          break;      case webimage_rotate_LEFT_90:          dest->pub.put_pixel_rows = put_pixel422_rows_rotate_left_90;          if ((height % 2) != 0) height += (2 - (height % 2));          dest->buffer_width = height * (2 * SIZEOF(char));          break;      case webimage_rotate_LEFT_180:          dest->pub.put_pixel_rows = put_pixel422_rows_rotate_left_180;          if ((width % 2) != 0) width += (2 - (width % 2));          dest->buffer_width = width * (2 * SIZEOF(char));          break;      case webimage_rotate_LEFT_270:          dest->pub.put_pixel_rows = put_pixel422_rows_rotate_left_270;          if ((height % 2) != 0) height += (2 - (height % 2));          dest->buffer_width = height * (2 * SIZEOF(char));          break;      }      dest->iobuffer = (char *) (*cinfo->mem->alloc_small)        ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);  }#endif  else  {    /* Create physical I/O buffer */    if (cinfo->out_color_space == JCS_GRAYSCALE)    {      /* fprintf(stderr, "gray 8bpp\n");  */      dest->samples_per_row = cinfo->output_width;      switch (rotate)      {      case webimage_rotate_NONE:          dest->pub.put_pixel_rows = put_pixel_rows;          if ((width % 4) != 0) width += (4 - (width % 4));          dest->buffer_width = width;          break;      case webimage_rotate_LEFT_90:          dest->pub.put_pixel_rows = put_pixel_rows_rotate_left_90;          if ((height % 4) != 0) height += (4 - (height % 4));          dest->buffer_width = height;          break;      case webimage_rotate_LEFT_180:          dest->pub.put_pixel_rows = put_pixel_rows_rotate_left_180;          if ((width % 4) != 0) width += (4 - (width % 4));          dest->buffer_width = width;          break;      case webimage_rotate_LEFT_270:          dest->pub.put_pixel_rows = put_pixel_rows_rotate_left_270;          if ((height % 4) != 0) height += (4 - (height % 4));          dest->buffer_width = height;          break;      }      dest->iobuffer = (char *) (*cinfo->mem->alloc_small)        ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);      cinfo->quantize_colors = TRUE;      /* Allocate space for a color map of maximum supported size. */      cinfo->colormap = (*cinfo->mem->alloc_sarray)        ((j_common_ptr) cinfo, JPOOL_IMAGE,         (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);      cinfo->actual_number_of_colors = 0; /* initialize map to empty */      read_sprite8bpp_map(cinfo);    }    else    {      /* fprintf(stderr, "16bpp\n");  */      dest->samples_per_row = cinfo->output_width * cinfo->out_color_components;      dest->use_16bpp = use_16bpp;#if LAYERS_FB_32BITS      if ( !use_16bpp )      {          dest->buffer_width = width * SIZEOF(int);          switch (rotate)          {          case webimage_rotate_NONE:              dest->pub.put_pixel_rows = put_pixel32bpp_rows;              break;          case webimage_rotate_LEFT_90:              dest->pub.put_pixel_rows = put_pixel32bpp_rows_rotate_left_90;              break;          case webimage_rotate_LEFT_180:              dest->pub.put_pixel_rows = put_pixel32bpp_rows_rotate_left_180;              break;          case webimage_rotate_LEFT_270:              dest->pub.put_pixel_rows = put_pixel32bpp_rows_rotate_left_270;              break;          }      }      else#endif      {          if ((width % 2) != 0) width += (2 - (width % 2));          dest->buffer_width = width * (2 * SIZEOF(char));          dest->pub.put_pixel_rows = put_pixel16bpp_rows;      }      dest->iobuffer = (char *) (*cinfo->mem->alloc_small)        ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);    }  }  if (dest->iobuffer)  {      memset(dest->iobuffer, 0, dest->buffer_width);  }  return (djpeg_dest_ptr) dest;}

⌨️ 快捷键说明

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