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

📄 texstore.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
               ASSERT(ctx->Pixel.Convolution1DEnabled);               _mesa_convolve_1d_image(ctx, &convWidth, src, convImage);            }            else {               if (ctx->Pixel.Convolution2DEnabled) {                  _mesa_convolve_2d_image(ctx, &convWidth, &convHeight,                                          src, convImage);               }               else {                  ASSERT(ctx->Pixel.Separable2DEnabled);                  _mesa_convolve_sep_image(ctx, &convWidth, &convHeight,                                           src, convImage);               }            }         }         /* do post-convolution transfer and pack into tempImage */         {            const GLint logComponents               = _mesa_components_in_format(logicalBaseFormat);            const GLfloat *src = convImage;            GLfloat *dst = tempImage + img * (convWidth * convHeight * 4);            for (row = 0; row < convHeight; row++) {               _mesa_pack_rgba_span_float(ctx, convWidth,                                          (GLfloat (*)[4]) src,                                          logicalBaseFormat, GL_FLOAT,                                          dst, &ctx->DefaultPacking,                                          postConvTransferOps);               src += convWidth * 4;               dst += convWidth * logComponents;            }         }      } /* loop over 3D image slices */      _mesa_free(convImage);      /* might need these below */      srcWidth = convWidth;      srcHeight = convHeight;   }   else {      /* no convolution */      const GLint components = _mesa_components_in_format(logicalBaseFormat);      const GLint srcStride = _mesa_image_row_stride(srcPacking,                                                 srcWidth, srcFormat, srcType);      GLfloat *dst;      GLint img, row;      tempImage = (GLfloat *) _mesa_malloc(srcWidth * srcHeight * srcDepth                                           * components * sizeof(GLfloat));      if (!tempImage)         return NULL;      dst = tempImage;      for (img = 0; img < srcDepth; img++) {         const GLubyte *src            = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,                                                    srcWidth, srcHeight,                                                    srcFormat, srcType,                                                    img, 0, 0);         for (row = 0; row < srcHeight; row++) {            _mesa_unpack_color_span_float(ctx, srcWidth, logicalBaseFormat,                                          dst, srcFormat, srcType, src,                                          srcPacking, transferOps);            dst += srcWidth * components;            src += srcStride;         }      }   }   if (logicalBaseFormat != textureBaseFormat) {      /* more work */      GLint texComponents = _mesa_components_in_format(textureBaseFormat);      GLint logComponents = _mesa_components_in_format(logicalBaseFormat);      GLfloat *newImage;      GLint i, n;      GLubyte map[6];      /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */      ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||             textureBaseFormat == GL_LUMINANCE_ALPHA);      /* The actual texture format should have at least as many components       * as the logical texture format.       */      ASSERT(texComponents >= logComponents);      newImage = (GLfloat *) _mesa_malloc(srcWidth * srcHeight * srcDepth                                          * texComponents * sizeof(GLfloat));      if (!newImage) {         _mesa_free(tempImage);         return NULL;      }      compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);      n = srcWidth * srcHeight * srcDepth;      for (i = 0; i < n; i++) {         GLint k;         for (k = 0; k < texComponents; k++) {            GLint j = map[k];            if (j == ZERO)               newImage[i * texComponents + k] = 0.0F;            else if (j == ONE)               newImage[i * texComponents + k] = 1.0F;            else               newImage[i * texComponents + k] = tempImage[i * logComponents + j];         }      }      _mesa_free(tempImage);      tempImage = newImage;   }   return tempImage;}/** * Make a temporary (color) texture image with GLchan components. * Apply all needed pixel unpacking and pixel transfer operations. * Note that there are both logicalBaseFormat and textureBaseFormat parameters. * Suppose the user specifies GL_LUMINANCE as the internal texture format * but the graphics hardware doesn't support luminance textures.  So, might * use an RGB hardware format instead. * If logicalBaseFormat != textureBaseFormat we have some extra work to do. * * \param ctx  the rendering context * \param dims  image dimensions: 1, 2 or 3 * \param logicalBaseFormat  basic texture derived from the user's *    internal texture format value * \param textureBaseFormat  the actual basic format of the texture * \param srcWidth  source image width * \param srcHeight  source image height * \param srcDepth  source image depth * \param srcFormat  source image format * \param srcType  source image type * \param srcAddr  source image address * \param srcPacking  source image pixel packing * \return resulting image with format = textureBaseFormat and type = GLchan. */GLchan *_mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,                           GLenum logicalBaseFormat,                           GLenum textureBaseFormat,                           GLint srcWidth, GLint srcHeight, GLint srcDepth,                           GLenum srcFormat, GLenum srcType,                           const GLvoid *srcAddr,                           const struct gl_pixelstore_attrib *srcPacking){   GLuint transferOps = ctx->_ImageTransferState;   const GLint components = _mesa_components_in_format(logicalBaseFormat);   GLboolean freeSrcImage = GL_FALSE;   GLint img, row;   GLchan *tempImage, *dst;   ASSERT(dims >= 1 && dims <= 3);   ASSERT(logicalBaseFormat == GL_RGBA ||          logicalBaseFormat == GL_RGB ||          logicalBaseFormat == GL_LUMINANCE_ALPHA ||          logicalBaseFormat == GL_LUMINANCE ||          logicalBaseFormat == GL_ALPHA ||          logicalBaseFormat == GL_INTENSITY);   ASSERT(textureBaseFormat == GL_RGBA ||          textureBaseFormat == GL_RGB ||          textureBaseFormat == GL_LUMINANCE_ALPHA ||          textureBaseFormat == GL_LUMINANCE ||          textureBaseFormat == GL_ALPHA ||          textureBaseFormat == GL_INTENSITY);   if ((dims == 1 && ctx->Pixel.Convolution1DEnabled) ||       (dims >= 2 && ctx->Pixel.Convolution2DEnabled) ||       (dims >= 2 && ctx->Pixel.Separable2DEnabled)) {      /* get convolved image */      GLfloat *convImage = make_temp_float_image(ctx, dims,                                                 logicalBaseFormat,                                                 logicalBaseFormat,                                                 srcWidth, srcHeight, srcDepth,                                                 srcFormat, srcType,                                                 srcAddr, srcPacking);      if (!convImage)         return NULL;      /* the convolved image is our new source image */      srcAddr = convImage;      srcFormat = logicalBaseFormat;      srcType = GL_FLOAT;      srcPacking = &ctx->DefaultPacking;      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);      transferOps = 0;      freeSrcImage = GL_TRUE;   }   /* unpack and transfer the source image */   tempImage = (GLchan *) _mesa_malloc(srcWidth * srcHeight * srcDepth                                       * components * sizeof(GLchan));   if (!tempImage)      return NULL;   dst = tempImage;   for (img = 0; img < srcDepth; img++) {      const GLint srcStride = _mesa_image_row_stride(srcPacking,                                                     srcWidth, srcFormat,                                                     srcType);      const GLubyte *src         = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,                                                 srcWidth, srcHeight,                                                 srcFormat, srcType,                                                 img, 0, 0);      for (row = 0; row < srcHeight; row++) {         _mesa_unpack_color_span_chan(ctx, srcWidth, logicalBaseFormat, dst,                                      srcFormat, srcType, src, srcPacking,                                      transferOps);         dst += srcWidth * components;         src += srcStride;      }   }   /* If we made a temporary image for convolution, free it here */   if (freeSrcImage) {      _mesa_free((void *) srcAddr);   }   if (logicalBaseFormat != textureBaseFormat) {      /* one more conversion step */      GLint texComponents = _mesa_components_in_format(textureBaseFormat);      GLint logComponents = _mesa_components_in_format(logicalBaseFormat);      GLchan *newImage;      GLint i, n;      GLubyte map[6];      /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */      ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||             textureBaseFormat == GL_LUMINANCE_ALPHA);      /* The actual texture format should have at least as many components       * as the logical texture format.       */      ASSERT(texComponents >= logComponents);      newImage = (GLchan *) _mesa_malloc(srcWidth * srcHeight * srcDepth                                         * texComponents * sizeof(GLchan));      if (!newImage) {         _mesa_free(tempImage);         return NULL;      }      compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);      n = srcWidth * srcHeight * srcDepth;      for (i = 0; i < n; i++) {         GLint k;         for (k = 0; k < texComponents; k++) {            GLint j = map[k];            if (j == ZERO)               newImage[i * texComponents + k] = 0;            else if (j == ONE)               newImage[i * texComponents + k] = CHAN_MAX;            else               newImage[i * texComponents + k] = tempImage[i * logComponents + j];         }      }      _mesa_free(tempImage);      tempImage = newImage;   }   return tempImage;}/** * Copy GLubyte pixels from <src> to <dst> with swizzling. * \param dst  destination pixels * \param dstComponents  number of color components in destination pixels * \param src  source pixels * \param srcComponents  number of color components in source pixels * \param map  the swizzle mapping.  map[X] says where to find the X component *             in the source image's pixels.  For example, if the source image *             is GL_BGRA and X = red, map[0] yields 2. * \param count  number of pixels to copy/swizzle. */static voidswizzle_copy(GLubyte *dst, GLuint dstComponents, const GLubyte *src,              GLuint srcComponents, const GLubyte *map, GLuint count){#define SWZ_CPY(dst, src, count, dstComps, srcComps) \   do {                                              \      GLuint i;                                      \      for (i = 0; i < count; i++) {                  \         GLuint j;                                   \         if (srcComps == 4) {                        \            COPY_4UBV(tmp, src);                     \         }                                           \         else {                                      \            for (j = 0; j < srcComps; j++) {         \               tmp[j] = src[j];                      \            }                                        \         }                                           \         src += srcComps;                            \         for (j = 0; j < dstComps; j++) {            \            dst[j] = tmp[map[j]];                    \         }                                           \         dst += dstComps;                            \      }                                              \   } while (0)   GLubyte tmp[6];   tmp[ZERO] = 0x0;   tmp[ONE] = 0xff;   ASSERT(srcComponents <= 4);   ASSERT(dstComponents <= 4);   switch (dstComponents) {   case 4:      switch (srcComponents) {      case 4:         SWZ_CPY(dst, src, count, 4, 4);         break;      case 3:         SWZ_CPY(dst, src, count, 4, 3);         break;      case 2:         SWZ_CPY(dst, src, count, 4, 2);         break;      case 1:         SWZ_CPY(dst, src, count, 4, 1);         break;      default:         ;      }      break;   case 3:      switch (srcComponents) {      case 4:         SWZ_CPY(dst, src, count, 3, 4);         break;      case 3:         SWZ_CPY(dst, src, count, 3, 3);         break;      case 2:         SWZ_CPY(dst, src, count, 3, 2);         break;      case 1:         SWZ_CPY(dst, src, count, 3, 1);         break;      default:         ;      }      break;   case 2:      switch (srcComponents) {      case 4:         SWZ_CPY(dst, src, count, 2, 4);         break;      case 3:         SWZ_CPY(dst, src, count, 2, 3);         break;      case 2:         SWZ_CPY(dst, src, count, 2, 2);         break;      case 1:         SWZ_CPY(dst, src, count, 2, 1);         break;      default:         ;      }      break;   case 1:      switch (srcComponents) {      case 4:         SWZ_CPY(dst, src, count, 1, 4);         break;      case 3:         SWZ_CPY(dst, src, count, 1, 3);

⌨️ 快捷键说明

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