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

📄 mipmap.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * Mesa 3-D graphics library * Version:  7.1 * * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//** * \file mipmap.c  mipmap generation and teximage resizing functions. */#include "imports.h"#include "mipmap.h"#include "texcompress.h"#include "texformat.h"#include "teximage.h"#include "image.h"/** * Average together two rows of a source image to produce a single new * row in the dest image.  It's legal for the two source rows to point * to the same data.  The source width must be equal to either the * dest width or two times the dest width. */static voiddo_row(const struct gl_texture_format *format, GLint srcWidth,       const GLvoid *srcRowA, const GLvoid *srcRowB,       GLint dstWidth, GLvoid *dstRow){   const GLuint k0 = (srcWidth == dstWidth) ? 0 : 1;   const GLuint colStride = (srcWidth == dstWidth) ? 1 : 2;   /* This assertion is no longer valid with non-power-of-2 textures   assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth);   */   switch (format->MesaFormat) {   case MESA_FORMAT_RGBA:      {         GLuint i, j, k;         const GLchan (*rowA)[4] = (const GLchan (*)[4]) srcRowA;         const GLchan (*rowB)[4] = (const GLchan (*)[4]) srcRowB;         GLchan (*dst)[4] = (GLchan (*)[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]) / 4;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) / 4;            dst[i][2] = (rowA[j][2] + rowA[k][2] +                         rowB[j][2] + rowB[k][2]) / 4;            dst[i][3] = (rowA[j][3] + rowA[k][3] +                         rowB[j][3] + rowB[k][3]) / 4;         }      }      return;   case MESA_FORMAT_RGB:      {         GLuint i, j, k;         const GLchan (*rowA)[3] = (const GLchan (*)[3]) srcRowA;         const GLchan (*rowB)[3] = (const GLchan (*)[3]) srcRowB;         GLchan (*dst)[3] = (GLchan (*)[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]) / 4;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) / 4;            dst[i][2] = (rowA[j][2] + rowA[k][2] +                         rowB[j][2] + rowB[k][2]) / 4;         }      }      return;   case MESA_FORMAT_ALPHA:   case MESA_FORMAT_LUMINANCE:   case MESA_FORMAT_INTENSITY:      {         GLuint i, j, k;         const GLchan *rowA = (const GLchan *) srcRowA;         const GLchan *rowB = (const GLchan *) srcRowB;         GLchan *dst = (GLchan *) 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]) / 4;         }      }      return;   case MESA_FORMAT_LUMINANCE_ALPHA:      {         GLuint i, j, k;         const GLchan (*rowA)[2] = (const GLchan (*)[2]) srcRowA;         const GLchan (*rowB)[2] = (const GLchan (*)[2]) srcRowB;         GLchan (*dst)[2] = (GLchan (*)[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]) / 4;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) / 4;         }      }      return;   case MESA_FORMAT_Z32:      {         GLuint i, j, k;         const GLuint *rowA = (const GLuint *) srcRowA;         const GLuint *rowB = (const GLuint *) srcRowB;         GLfloat *dst = (GLfloat *) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            dst[i] = rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4;         }      }      return;   case MESA_FORMAT_Z16:      {         GLuint i, j, k;         const GLushort *rowA = (const GLushort *) srcRowA;         const GLushort *rowB = (const GLushort *) srcRowB;         GLushort *dst = (GLushort *) 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]) / 4;         }      }      return;   /* Begin hardware formats */   case MESA_FORMAT_RGBA8888:   case MESA_FORMAT_RGBA8888_REV:   case MESA_FORMAT_ARGB8888:   case MESA_FORMAT_ARGB8888_REV:#if FEATURE_EXT_texture_sRGB   case MESA_FORMAT_SRGBA8:#endif      {         GLuint i, j, k;         const GLubyte (*rowA)[4] = (const GLubyte (*)[4]) srcRowA;         const GLubyte (*rowB)[4] = (const GLubyte (*)[4]) srcRowB;         GLubyte (*dst)[4] = (GLubyte (*)[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]) / 4;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) / 4;            dst[i][2] = (rowA[j][2] + rowA[k][2] +                         rowB[j][2] + rowB[k][2]) / 4;            dst[i][3] = (rowA[j][3] + rowA[k][3] +                         rowB[j][3] + rowB[k][3]) / 4;         }      }      return;   case MESA_FORMAT_RGB888:   case MESA_FORMAT_BGR888:#if FEATURE_EXT_texture_sRGB   case MESA_FORMAT_SRGB8:#endif      {         GLuint i, j, k;         const GLubyte (*rowA)[3] = (const GLubyte (*)[3]) srcRowA;         const GLubyte (*rowB)[3] = (const GLubyte (*)[3]) srcRowB;         GLubyte (*dst)[3] = (GLubyte (*)[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]) / 4;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) / 4;            dst[i][2] = (rowA[j][2] + rowA[k][2] +                         rowB[j][2] + rowB[k][2]) / 4;         }      }      return;   case MESA_FORMAT_RGB565:   case MESA_FORMAT_RGB565_REV:      {         GLuint i, j, k;         const GLushort *rowA = (const GLushort *) srcRowA;         const GLushort *rowB = (const GLushort *) srcRowB;         GLushort *dst = (GLushort *) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            const GLint rowAr0 = rowA[j] & 0x1f;            const GLint rowAr1 = rowA[k] & 0x1f;            const GLint rowBr0 = rowB[j] & 0x1f;            const GLint rowBr1 = rowB[k] & 0x1f;            const GLint rowAg0 = (rowA[j] >> 5) & 0x3f;            const GLint rowAg1 = (rowA[k] >> 5) & 0x3f;            const GLint rowBg0 = (rowB[j] >> 5) & 0x3f;            const GLint rowBg1 = (rowB[k] >> 5) & 0x3f;            const GLint rowAb0 = (rowA[j] >> 11) & 0x1f;            const GLint rowAb1 = (rowA[k] >> 11) & 0x1f;            const GLint rowBb0 = (rowB[j] >> 11) & 0x1f;            const GLint rowBb1 = (rowB[k] >> 11) & 0x1f;            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 << 11) | (green << 5) | red;         }      }      return;   case MESA_FORMAT_ARGB4444:   case MESA_FORMAT_ARGB4444_REV:      {         GLuint i, j, k;         const GLushort *rowA = (const GLushort *) srcRowA;         const GLushort *rowB = (const GLushort *) srcRowB;         GLushort *dst = (GLushort *) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            const GLint rowAr0 = rowA[j] & 0xf;            const GLint rowAr1 = rowA[k] & 0xf;            const GLint rowBr0 = rowB[j] & 0xf;            const GLint rowBr1 = rowB[k] & 0xf;            const GLint rowAg0 = (rowA[j] >> 4) & 0xf;            const GLint rowAg1 = (rowA[k] >> 4) & 0xf;            const GLint rowBg0 = (rowB[j] >> 4) & 0xf;            const GLint rowBg1 = (rowB[k] >> 4) & 0xf;            const GLint rowAb0 = (rowA[j] >> 8) & 0xf;            const GLint rowAb1 = (rowA[k] >> 8) & 0xf;            const GLint rowBb0 = (rowB[j] >> 8) & 0xf;            const GLint rowBb1 = (rowB[k] >> 8) & 0xf;            const GLint rowAa0 = (rowA[j] >> 12) & 0xf;            const GLint rowAa1 = (rowA[k] >> 12) & 0xf;            const GLint rowBa0 = (rowB[j] >> 12) & 0xf;            const GLint rowBa1 = (rowB[k] >> 12) & 0xf;            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;            const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;            dst[i] = (alpha << 12) | (blue << 8) | (green << 4) | red;         }      }      return;   case MESA_FORMAT_ARGB1555:   case MESA_FORMAT_ARGB1555_REV: /* XXX broken? */      {         GLuint i, j, k;         const GLushort *rowA = (const GLushort *) srcRowA;         const GLushort *rowB = (const GLushort *) srcRowB;         GLushort *dst = (GLushort *) dstRow;         for (i = j = 0, k = k0; i < (GLuint) dstWidth;              i++, j += colStride, k += colStride) {            const GLint rowAr0 = rowA[j] & 0x1f;            const GLint rowAr1 = rowA[k] & 0x1f;            const GLint rowBr0 = rowB[j] & 0x1f;            const GLint rowBr1 = rowB[k] & 0xf;            const GLint rowAg0 = (rowA[j] >> 5) & 0x1f;            const GLint rowAg1 = (rowA[k] >> 5) & 0x1f;            const GLint rowBg0 = (rowB[j] >> 5) & 0x1f;            const GLint rowBg1 = (rowB[k] >> 5) & 0x1f;            const GLint rowAb0 = (rowA[j] >> 10) & 0x1f;            const GLint rowAb1 = (rowA[k] >> 10) & 0x1f;            const GLint rowBb0 = (rowB[j] >> 10) & 0x1f;            const GLint rowBb1 = (rowB[k] >> 10) & 0x1f;            const GLint rowAa0 = (rowA[j] >> 15) & 0x1;            const GLint rowAa1 = (rowA[k] >> 15) & 0x1;            const GLint rowBa0 = (rowB[j] >> 15) & 0x1;            const GLint rowBa1 = (rowB[k] >> 15) & 0x1;            const GLint red   = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;            const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;            const GLint blue  = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;            const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;            dst[i] = (alpha << 15) | (blue << 10) | (green << 5) | red;         }      }      return;   case MESA_FORMAT_AL88:   case MESA_FORMAT_AL88_REV:#if FEATURE_EXT_texture_sRGB   case MESA_FORMAT_SLA8:#endif      {         GLuint i, j, k;         const GLubyte (*rowA)[2] = (const GLubyte (*)[2]) srcRowA;         const GLubyte (*rowB)[2] = (const GLubyte (*)[2]) srcRowB;         GLubyte (*dst)[2] = (GLubyte (*)[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]) >> 2;            dst[i][1] = (rowA[j][1] + rowA[k][1] +                         rowB[j][1] + rowB[k][1]) >> 2;         }      }      return;   case MESA_FORMAT_RGB332:      {         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) {            const GLint rowAr0 = rowA[j] & 0x3;            const GLint rowAr1 = rowA[k] & 0x3;            const GLint rowBr0 = rowB[j] & 0x3;            const GLint rowBr1 = rowB[k] & 0x3;            const GLint rowAg0 = (rowA[j] >> 2) & 0x7;            const GLint rowAg1 = (rowA[k] >> 2) & 0x7;            const GLint rowBg0 = (rowB[j] >> 2) & 0x7;            const GLint rowBg1 = (rowB[k] >> 2) & 0x7;            const GLint rowAb0 = (rowA[j] >> 5) & 0x7;            const GLint rowAb1 = (rowA[k] >> 5) & 0x7;            const GLint rowBb0 = (rowB[j] >> 5) & 0x7;

⌨️ 快捷键说明

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