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

📄 image.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
         dest[i] = (p[0] << 24)                 | (p[1] << 16)                 | (p[2] <<  8)                 | (p[3]      );         p += 4;      }      _mesa_free(ptrn);   }}/* * Pack polygon stipple into user memory given current pixel packing * settings. */void_mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest,                            const struct gl_pixelstore_attrib *packing ){   /* Convert pattern from GLuints to GLubytes to handle big/little    * endian differences.    */   GLubyte ptrn[32*4];   GLint i;   for (i = 0; i < 32; i++) {      ptrn[i * 4 + 0] = (GLubyte) ((pattern[i] >> 24) & 0xff);      ptrn[i * 4 + 1] = (GLubyte) ((pattern[i] >> 16) & 0xff);      ptrn[i * 4 + 2] = (GLubyte) ((pattern[i] >> 8 ) & 0xff);      ptrn[i * 4 + 3] = (GLubyte) ((pattern[i]      ) & 0xff);   }   _mesa_pack_bitmap(32, 32, ptrn, dest, packing);}/* * Unpack bitmap data.  Resulting data will be in most-significant-bit-first * order with row alignment = 1 byte. */GLvoid *_mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels,                     const struct gl_pixelstore_attrib *packing ){   GLint bytes, row, width_in_bytes;   GLubyte *buffer, *dst;   if (!pixels)      return NULL;   /* Alloc dest storage */   bytes = ((width + 7) / 8 * height);   buffer = (GLubyte *) _mesa_malloc( bytes );   if (!buffer)      return NULL;   width_in_bytes = CEILING( width, 8 );   dst = buffer;   for (row = 0; row < height; row++) {      const GLubyte *src = (const GLubyte *)         _mesa_image_address2d(packing, pixels, width, height,                               GL_COLOR_INDEX, GL_BITMAP, row, 0);      if (!src) {         _mesa_free(buffer);         return NULL;      }      if ((packing->SkipPixels & 7) == 0) {         _mesa_memcpy( dst, src, width_in_bytes );         if (packing->LsbFirst) {            flip_bytes( dst, width_in_bytes );         }      }      else {         /* handling SkipPixels is a bit tricky (no pun intended!) */         GLint i;         if (packing->LsbFirst) {            GLubyte srcMask = 1 << (packing->SkipPixels & 0x7);            GLubyte dstMask = 128;            const GLubyte *s = src;            GLubyte *d = dst;            *d = 0;            for (i = 0; i < width; i++) {               if (*s & srcMask) {                  *d |= dstMask;               }               if (srcMask == 128) {                  srcMask = 1;                  s++;               }               else {                  srcMask = srcMask << 1;               }               if (dstMask == 1) {                  dstMask = 128;                  d++;                  *d = 0;               }               else {                  dstMask = dstMask >> 1;               }            }         }         else {            GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7);            GLubyte dstMask = 128;            const GLubyte *s = src;            GLubyte *d = dst;            *d = 0;            for (i = 0; i < width; i++) {               if (*s & srcMask) {                  *d |= dstMask;               }               if (srcMask == 1) {                  srcMask = 128;                  s++;               }               else {                  srcMask = srcMask >> 1;               }               if (dstMask == 1) {                  dstMask = 128;                  d++;                  *d = 0;               }               else {                  dstMask = dstMask >> 1;               }            }         }      }      dst += width_in_bytes;   }   return buffer;}/* * Pack bitmap data. */void_mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,                   GLubyte *dest, const struct gl_pixelstore_attrib *packing ){   GLint row, width_in_bytes;   const GLubyte *src;   if (!source)      return;   width_in_bytes = CEILING( width, 8 );   src = source;   for (row = 0; row < height; row++) {      GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, dest,                       width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);      if (!dst)         return;      if ((packing->SkipPixels & 7) == 0) {         _mesa_memcpy( dst, src, width_in_bytes );         if (packing->LsbFirst) {            flip_bytes( dst, width_in_bytes );         }      }      else {         /* handling SkipPixels is a bit tricky (no pun intended!) */         GLint i;         if (packing->LsbFirst) {            GLubyte srcMask = 128;            GLubyte dstMask = 1 << (packing->SkipPixels & 0x7);            const GLubyte *s = src;            GLubyte *d = dst;            *d = 0;            for (i = 0; i < width; i++) {               if (*s & srcMask) {                  *d |= dstMask;               }               if (srcMask == 1) {                  srcMask = 128;                  s++;               }               else {                  srcMask = srcMask >> 1;               }               if (dstMask == 128) {                  dstMask = 1;                  d++;                  *d = 0;               }               else {                  dstMask = dstMask << 1;               }            }         }         else {            GLubyte srcMask = 128;            GLubyte dstMask = 128 >> (packing->SkipPixels & 0x7);            const GLubyte *s = src;            GLubyte *d = dst;            *d = 0;            for (i = 0; i < width; i++) {               if (*s & srcMask) {                  *d |= dstMask;               }               if (srcMask == 1) {                  srcMask = 128;                  s++;               }               else {                  srcMask = srcMask >> 1;               }               if (dstMask == 1) {                  dstMask = 128;                  d++;                  *d = 0;               }               else {                  dstMask = dstMask >> 1;               }            }         }      }      src += width_in_bytes;   }}/** * Apply various pixel transfer operations to an array of RGBA pixels * as indicated by the transferOps bitmask */void_mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLbitfield transferOps,                              GLuint n, GLfloat rgba[][4]){   /* scale & bias */   if (transferOps & IMAGE_SCALE_BIAS_BIT) {      _mesa_scale_and_bias_rgba(n, rgba,                                ctx->Pixel.RedScale, ctx->Pixel.GreenScale,                                ctx->Pixel.BlueScale, ctx->Pixel.AlphaScale,                                ctx->Pixel.RedBias, ctx->Pixel.GreenBias,                                ctx->Pixel.BlueBias, ctx->Pixel.AlphaBias);   }   /* color map lookup */   if (transferOps & IMAGE_MAP_COLOR_BIT) {      _mesa_map_rgba( ctx, n, rgba );   }   /* GL_COLOR_TABLE lookup */   if (transferOps & IMAGE_COLOR_TABLE_BIT) {      _mesa_lookup_rgba_float(&ctx->ColorTable[COLORTABLE_PRECONVOLUTION], n, rgba);   }   /* convolution */   if (transferOps & IMAGE_CONVOLUTION_BIT) {      /* this has to be done in the calling code */      _mesa_problem(ctx, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");   }   /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */   if (transferOps & IMAGE_POST_CONVOLUTION_SCALE_BIAS) {      _mesa_scale_and_bias_rgba(n, rgba,                                ctx->Pixel.PostConvolutionScale[RCOMP],                                ctx->Pixel.PostConvolutionScale[GCOMP],                                ctx->Pixel.PostConvolutionScale[BCOMP],                                ctx->Pixel.PostConvolutionScale[ACOMP],                                ctx->Pixel.PostConvolutionBias[RCOMP],                                ctx->Pixel.PostConvolutionBias[GCOMP],                                ctx->Pixel.PostConvolutionBias[BCOMP],                                ctx->Pixel.PostConvolutionBias[ACOMP]);   }   /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */   if (transferOps & IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT) {      _mesa_lookup_rgba_float(&ctx->ColorTable[COLORTABLE_POSTCONVOLUTION], n, rgba);   }   /* color matrix transform */   if (transferOps & IMAGE_COLOR_MATRIX_BIT) {      _mesa_transform_rgba(ctx, n, rgba);   }   /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */   if (transferOps & IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT) {      _mesa_lookup_rgba_float(&ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX], n, rgba);   }   /* update histogram count */   if (transferOps & IMAGE_HISTOGRAM_BIT) {      _mesa_update_histogram(ctx, n, (CONST GLfloat (*)[4]) rgba);   }   /* update min/max values */   if (transferOps & IMAGE_MIN_MAX_BIT) {      _mesa_update_minmax(ctx, n, (CONST GLfloat (*)[4]) rgba);   }   /* clamping to [0,1] */   if (transferOps & IMAGE_CLAMP_BIT) {      GLuint i;      for (i = 0; i < n; i++) {         rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], 0.0F, 1.0F);         rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], 0.0F, 1.0F);         rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], 0.0F, 1.0F);         rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F);      }   }}/* * Apply color index shift and offset to an array of pixels. */static voidshift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] ){   GLint shift = ctx->Pixel.IndexShift;   GLint offset = ctx->Pixel.IndexOffset;   GLuint i;   if (shift > 0) {      for (i=0;i<n;i++) {         indexes[i] = (indexes[i] << shift) + offset;      }   }   else if (shift < 0) {      shift = -shift;      for (i=0;i<n;i++) {         indexes[i] = (indexes[i] >> shift) + offset;      }   }   else {      for (i=0;i<n;i++) {         indexes[i] = indexes[i] + offset;      }   }}/** * Apply color index shift, offset and table lookup to an array * of color indexes; */void_mesa_apply_ci_transfer_ops(const GLcontext *ctx, GLbitfield transferOps,                            GLuint n, GLuint indexes[]){   if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {      shift_and_offset_ci(ctx, n, indexes);   }   if (transferOps & IMAGE_MAP_COLOR_BIT) {      const GLuint mask = ctx->PixelMaps.ItoI.Size - 1;      GLuint i;      for (i = 0; i < n; i++) {         const GLuint j = indexes[i] & mask;         indexes[i] = IROUND(ctx->PixelMaps.ItoI.Map[j]);      }   }}/** * Apply stencil index shift, offset and table lookup to an array * of stencil values. */void_mesa_apply_stencil_transfer_ops(const GLcontext *ctx, GLuint n,                                 GLstencil stencil[]){   if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset != 0) {      const GLint offset = ctx->Pixel.IndexOffset;      GLint shift = ctx->Pixel.IndexShift;      GLuint i;      if (shift > 0) {         for (i = 0; i < n; i++) {            stencil[i] = (stencil[i] << shift) + offset;         }      }      else if (shift < 0) {         shift = -shift;         for (i = 0; i < n; i++) {            stencil[i] = (stencil[i] >> shift) + offset;         }      }      else {         for (i = 0; i < n; i++) {            stencil[i] = stencil[i] + offset;         }      }   }   if (ctx->Pixel.MapStencilFlag) {      GLuint mask = ctx->PixelMaps.StoS.Size - 1;      GLuint i;      for (i = 0; i < n; i++) {         stencil[i] = ctx->PixelMaps.StoS.Map[ stencil[i] & mask ];      }   }}/** * Used to pack an array [][4] of RGBA float colors as specified

⌨️ 快捷键说明

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