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

📄 mipmap.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 4 页
字号:
            const GLint rowBb1 = (rowB[k] >> 5) & 0x7;            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;            dst[i] = (blue << 5) | (green << 2) | red;         }      }      return;   case MESA_FORMAT_A8:   case MESA_FORMAT_L8:   case MESA_FORMAT_I8:   case MESA_FORMAT_CI8:#if FEATURE_EXT_texture_sRGB   case MESA_FORMAT_SL8:#endif      {         GLuint i, j, k;         const GLubyte *rowA = (const GLubyte *) srcRowA;         const GLubyte *rowB = (const GLubyte *) srcRowB;         GLubyte *dst = (GLubyte *) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) >> 2;         }      }      return;   case MESA_FORMAT_RGBA_FLOAT32:      {         GLuint i, j, k;         const GLfloat (*rowA)[4] = (const GLfloat (*)[4]) srcRowA;         const GLfloat (*rowB)[4] = (const GLfloat (*)[4]) srcRowB;         GLfloat (*dst)[4] = (GLfloat (*)[4]) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            dst[i][0] = (rowA[j][0] + rowA[k][0] +                         rowB[j][0] + rowB[k][0]) * 0.25F;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) * 0.25F;            dst[i][2] = (rowA[j][2] + rowA[k][2] +                         rowB[j][2] + rowB[k][2]) * 0.25F;            dst[i][3] = (rowA[j][3] + rowA[k][3] +                         rowB[j][3] + rowB[k][3]) * 0.25F;         }      }      return;   case MESA_FORMAT_RGBA_FLOAT16:      {         GLuint i, j, k, comp;         const GLhalfARB (*rowA)[4] = (const GLhalfARB (*)[4]) srcRowA;         const GLhalfARB (*rowB)[4] = (const GLhalfARB (*)[4]) srcRowB;         GLhalfARB (*dst)[4] = (GLhalfARB (*)[4]) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            for (comp = 0; comp < 4; comp++) {               GLfloat aj, ak, bj, bk;               aj = _mesa_half_to_float(rowA[j][comp]);               ak = _mesa_half_to_float(rowA[k][comp]);               bj = _mesa_half_to_float(rowB[j][comp]);               bk = _mesa_half_to_float(rowB[k][comp]);               dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);            }         }      }      return;   case MESA_FORMAT_RGB_FLOAT32:      {         GLuint i, j, k;         const GLfloat (*rowA)[3] = (const GLfloat (*)[3]) srcRowA;         const GLfloat (*rowB)[3] = (const GLfloat (*)[3]) srcRowB;         GLfloat (*dst)[3] = (GLfloat (*)[3]) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            dst[i][0] = (rowA[j][0] + rowA[k][0] +                         rowB[j][0] + rowB[k][0]) * 0.25F;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) * 0.25F;            dst[i][2] = (rowA[j][2] + rowA[k][2] +                         rowB[j][2] + rowB[k][2]) * 0.25F;         }      }      return;   case MESA_FORMAT_RGB_FLOAT16:      {         GLuint i, j, k, comp;         const GLhalfARB (*rowA)[3] = (const GLhalfARB (*)[3]) srcRowA;         const GLhalfARB (*rowB)[3] = (const GLhalfARB (*)[3]) srcRowB;         GLhalfARB (*dst)[3] = (GLhalfARB (*)[3]) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            for (comp = 0; comp < 3; comp++) {               GLfloat aj, ak, bj, bk;               aj = _mesa_half_to_float(rowA[j][comp]);               ak = _mesa_half_to_float(rowA[k][comp]);               bj = _mesa_half_to_float(rowB[j][comp]);               bk = _mesa_half_to_float(rowB[k][comp]);               dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);            }         }      }      return;   case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:      {         GLuint i, j, k;         const GLfloat (*rowA)[2] = (const GLfloat (*)[2]) srcRowA;         const GLfloat (*rowB)[2] = (const GLfloat (*)[2]) srcRowB;         GLfloat (*dst)[2] = (GLfloat (*)[2]) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            dst[i][0] = (rowA[j][0] + rowA[k][0] +                         rowB[j][0] + rowB[k][0]) * 0.25F;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) * 0.25F;         }      }      return;   case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:      {         GLuint i, j, k, comp;         const GLhalfARB (*rowA)[2] = (const GLhalfARB (*)[2]) srcRowA;         const GLhalfARB (*rowB)[2] = (const GLhalfARB (*)[2]) srcRowB;         GLhalfARB (*dst)[2] = (GLhalfARB (*)[2]) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            for (comp = 0; comp < 2; comp++) {               GLfloat aj, ak, bj, bk;               aj = _mesa_half_to_float(rowA[j][comp]);               ak = _mesa_half_to_float(rowA[k][comp]);               bj = _mesa_half_to_float(rowB[j][comp]);               bk = _mesa_half_to_float(rowB[k][comp]);               dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);            }         }      }      return;   case MESA_FORMAT_ALPHA_FLOAT32:   case MESA_FORMAT_LUMINANCE_FLOAT32:   case MESA_FORMAT_INTENSITY_FLOAT32:      {         GLuint i, j, k;         const GLfloat *rowA = (const GLfloat *) srcRowA;         const GLfloat *rowB = (const GLfloat *) srcRowB;         GLfloat *dst = (GLfloat *) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) * 0.25F;         }      }      return;   case MESA_FORMAT_ALPHA_FLOAT16:   case MESA_FORMAT_LUMINANCE_FLOAT16:   case MESA_FORMAT_INTENSITY_FLOAT16:      {         GLuint i, j, k;         const GLhalfARB *rowA = (const GLhalfARB *) srcRowA;         const GLhalfARB *rowB = (const GLhalfARB *) srcRowB;         GLhalfARB *dst = (GLhalfARB *) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            GLfloat aj, ak, bj, bk;            aj = _mesa_half_to_float(rowA[j]);            ak = _mesa_half_to_float(rowA[k]);            bj = _mesa_half_to_float(rowB[j]);            bk = _mesa_half_to_float(rowB[k]);            dst[i] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);         }      }      return;   default:      _mesa_problem(NULL, "bad format in do_row()");   }}/* * These functions generate a 1/2-size mipmap image from a source image. * Texture borders are handled by copying or averaging the source image's * border texels, depending on the scale-down factor. */static voidmake_1d_mipmap(const struct gl_texture_format *format, GLint border,               GLint srcWidth, const GLubyte *srcPtr,               GLint dstWidth, GLubyte *dstPtr){   const GLint bpt = format->TexelBytes;   const GLubyte *src;   GLubyte *dst;   /* skip the border pixel, if any */   src = srcPtr + border * bpt;   dst = dstPtr + border * bpt;   /* we just duplicate the input row, kind of hack, saves code */   do_row(format, srcWidth - 2 * border, src, src,          dstWidth - 2 * border, dst);   if (border) {      /* copy left-most pixel from source */      MEMCPY(dstPtr, srcPtr, bpt);      /* copy right-most pixel from source */      MEMCPY(dstPtr + (dstWidth - 1) * bpt,             srcPtr + (srcWidth - 1) * bpt,             bpt);   }}static voidmake_2d_mipmap(const struct gl_texture_format *format, GLint border,               GLint srcWidth, GLint srcHeight,	       const GLubyte *srcPtr, GLint srcRowStride,               GLint dstWidth, GLint dstHeight,	       GLubyte *dstPtr, GLint dstRowStride){   const GLint bpt = format->TexelBytes;   const GLint srcWidthNB = srcWidth - 2 * border;  /* sizes w/out border */   const GLint dstWidthNB = dstWidth - 2 * border;   const GLint dstHeightNB = dstHeight - 2 * border;   const GLint srcRowBytes = bpt * srcRowStride;   const GLint dstRowBytes = bpt * dstRowStride;   const GLubyte *srcA, *srcB;   GLubyte *dst;   GLint row;   /* Compute src and dst pointers, skipping any border */   srcA = srcPtr + border * ((srcWidth + 1) * bpt);   if (srcHeight > 1)       srcB = srcA + srcRowBytes;   else      srcB = srcA;   dst = dstPtr + border * ((dstWidth + 1) * bpt);   for (row = 0; row < dstHeightNB; row++) {      do_row(format, srcWidthNB, srcA, srcB,             dstWidthNB, dst);      srcA += 2 * srcRowBytes;      srcB += 2 * srcRowBytes;      dst += dstRowBytes;   }   /* This is ugly but probably won't be used much */   if (border > 0) {      /* fill in dest border */      /* lower-left border pixel */      MEMCPY(dstPtr, srcPtr, bpt);      /* lower-right border pixel */      MEMCPY(dstPtr + (dstWidth - 1) * bpt,             srcPtr + (srcWidth - 1) * bpt, bpt);      /* upper-left border pixel */      MEMCPY(dstPtr + dstWidth * (dstHeight - 1) * bpt,             srcPtr + srcWidth * (srcHeight - 1) * bpt, bpt);      /* upper-right border pixel */      MEMCPY(dstPtr + (dstWidth * dstHeight - 1) * bpt,             srcPtr + (srcWidth * srcHeight - 1) * bpt, bpt);      /* lower border */      do_row(format, srcWidthNB,             srcPtr + bpt,             srcPtr + bpt,             dstWidthNB, dstPtr + bpt);      /* upper border */      do_row(format, srcWidthNB,             srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,             srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,             dstWidthNB,             dstPtr + (dstWidth * (dstHeight - 1) + 1) * bpt);      /* left and right borders */      if (srcHeight == dstHeight) {         /* copy border pixel from src to dst */         for (row = 1; row < srcHeight; row++) {            MEMCPY(dstPtr + dstWidth * row * bpt,                   srcPtr + srcWidth * row * bpt, bpt);            MEMCPY(dstPtr + (dstWidth * row + dstWidth - 1) * bpt,                   srcPtr + (srcWidth * row + srcWidth - 1) * bpt, bpt);         }      }      else {         /* average two src pixels each dest pixel */         for (row = 0; row < dstHeightNB; row += 2) {            do_row(format, 1,                   srcPtr + (srcWidth * (row * 2 + 1)) * bpt,                   srcPtr + (srcWidth * (row * 2 + 2)) * bpt,                   1, dstPtr + (dstWidth * row + 1) * bpt);            do_row(format, 1,                   srcPtr + (srcWidth * (row * 2 + 1) + srcWidth - 1) * bpt,                   srcPtr + (srcWidth * (row * 2 + 2) + srcWidth - 1) * bpt,                   1, dstPtr + (dstWidth * row + 1 + dstWidth - 1) * bpt);         }      }   }}static voidmake_3d_mipmap(const struct gl_texture_format *format, GLint border,               GLint srcWidth, GLint srcHeight, GLint srcDepth,               const GLubyte *srcPtr, GLint srcRowStride,               GLint dstWidth, GLint dstHeight, GLint dstDepth,               GLubyte *dstPtr, GLint dstRowStride){   const GLint bpt = format->TexelBytes;   const GLint srcWidthNB = srcWidth - 2 * border;  /* sizes w/out border */   const GLint srcDepthNB = srcDepth - 2 * border;   const GLint dstWidthNB = dstWidth - 2 * border;   const GLint dstHeightNB = dstHeight - 2 * border;   const GLint dstDepthNB = dstDepth - 2 * border;   GLvoid *tmpRowA, *tmpRowB;   GLint img, row;   GLint bytesPerSrcImage, bytesPerDstImage;   GLint bytesPerSrcRow, bytesPerDstRow;   GLint srcImageOffset, srcRowOffset;   (void) srcDepthNB; /* silence warnings */   /* Need two temporary row buffers */   tmpRowA = _mesa_malloc(srcWidth * bpt);   if (!tmpRowA)      return;   tmpRowB = _mesa_malloc(srcWidth * bpt);   if (!tmpRowB) {      _mesa_free(tmpRowA);      return;   }   bytesPerSrcImage = srcWidth * srcHeight * bpt;

⌨️ 快捷键说明

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