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

📄 colortab.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * 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. */#include "glheader.h"#include "bufferobj.h"#include "colortab.h"#include "context.h"#include "image.h"#include "macros.h"#include "state.h"#include "teximage.h"/** * Given an internalFormat token passed to glColorTable, * return the corresponding base format. * Return -1 if invalid token. */static GLintbase_colortab_format( GLenum format ){   switch (format) {      case GL_ALPHA:      case GL_ALPHA4:      case GL_ALPHA8:      case GL_ALPHA12:      case GL_ALPHA16:         return GL_ALPHA;      case GL_LUMINANCE:      case GL_LUMINANCE4:      case GL_LUMINANCE8:      case GL_LUMINANCE12:      case GL_LUMINANCE16:         return GL_LUMINANCE;      case GL_LUMINANCE_ALPHA:      case GL_LUMINANCE4_ALPHA4:      case GL_LUMINANCE6_ALPHA2:      case GL_LUMINANCE8_ALPHA8:      case GL_LUMINANCE12_ALPHA4:      case GL_LUMINANCE12_ALPHA12:      case GL_LUMINANCE16_ALPHA16:         return GL_LUMINANCE_ALPHA;      case GL_INTENSITY:      case GL_INTENSITY4:      case GL_INTENSITY8:      case GL_INTENSITY12:      case GL_INTENSITY16:         return GL_INTENSITY;      case GL_RGB:      case GL_R3_G3_B2:      case GL_RGB4:      case GL_RGB5:      case GL_RGB8:      case GL_RGB10:      case GL_RGB12:      case GL_RGB16:         return GL_RGB;      case GL_RGBA:      case GL_RGBA2:      case GL_RGBA4:      case GL_RGB5_A1:      case GL_RGBA8:      case GL_RGB10_A2:      case GL_RGBA12:      case GL_RGBA16:         return GL_RGBA;      default:         return -1;  /* error */   }}/** * Examine table's format and set the component sizes accordingly. */static voidset_component_sizes( struct gl_color_table *table ){   /* assuming the ubyte table */   const GLubyte sz = 8;   switch (table->_BaseFormat) {      case GL_ALPHA:         table->RedSize = 0;         table->GreenSize = 0;         table->BlueSize = 0;         table->AlphaSize = sz;         table->IntensitySize = 0;         table->LuminanceSize = 0;         break;      case GL_LUMINANCE:         table->RedSize = 0;         table->GreenSize = 0;         table->BlueSize = 0;         table->AlphaSize = 0;         table->IntensitySize = 0;         table->LuminanceSize = sz;         break;      case GL_LUMINANCE_ALPHA:         table->RedSize = 0;         table->GreenSize = 0;         table->BlueSize = 0;         table->AlphaSize = sz;         table->IntensitySize = 0;         table->LuminanceSize = sz;         break;      case GL_INTENSITY:         table->RedSize = 0;         table->GreenSize = 0;         table->BlueSize = 0;         table->AlphaSize = 0;         table->IntensitySize = sz;         table->LuminanceSize = 0;         break;      case GL_RGB:         table->RedSize = sz;         table->GreenSize = sz;         table->BlueSize = sz;         table->AlphaSize = 0;         table->IntensitySize = 0;         table->LuminanceSize = 0;         break;      case GL_RGBA:         table->RedSize = sz;         table->GreenSize = sz;         table->BlueSize = sz;         table->AlphaSize = sz;         table->IntensitySize = 0;         table->LuminanceSize = 0;         break;      default:         _mesa_problem(NULL, "unexpected format in set_component_sizes");   }}/** * Update/replace all or part of a color table.  Helper function * used by _mesa_ColorTable() and _mesa_ColorSubTable(). * The table->Table buffer should already be allocated. * \param start first entry to update * \param count number of entries to update * \param format format of user-provided table data * \param type datatype of user-provided table data * \param data user-provided table data * \param [rgba]Scale - RGBA scale factors * \param [rgba]Bias - RGBA bias factors */static voidstore_colortable_entries(GLcontext *ctx, struct gl_color_table *table,			 GLsizei start, GLsizei count,			 GLenum format, GLenum type, const GLvoid *data,			 GLfloat rScale, GLfloat rBias,			 GLfloat gScale, GLfloat gBias,			 GLfloat bScale, GLfloat bBias,			 GLfloat aScale, GLfloat aBias){   if (ctx->Unpack.BufferObj->Name) {      /* Get/unpack the color table data from a PBO */      GLubyte *buf;      if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1,                                     format, type, data)) {         _mesa_error(ctx, GL_INVALID_OPERATION,                     "glColor[Sub]Table(bad PBO access)");         return;      }      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,                                              GL_READ_ONLY_ARB,                                              ctx->Unpack.BufferObj);      if (!buf) {         _mesa_error(ctx, GL_INVALID_OPERATION,                     "glColor[Sub]Table(PBO mapped)");         return;      }      data = ADD_POINTERS(buf, data);   }   {      /* convert user-provided data to GLfloat values */      GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];      GLfloat *tableF;      GLint i;      _mesa_unpack_color_span_float(ctx,                                    count,         /* number of pixels */                                    table->_BaseFormat, /* dest format */                                    tempTab,       /* dest address */                                    format, type,  /* src format/type */                                    data,          /* src data */                                    &ctx->Unpack,                                    IMAGE_CLAMP_BIT); /* transfer ops */      /* the destination */      tableF = table->TableF;      /* Apply scale & bias & clamp now */      switch (table->_BaseFormat) {         case GL_INTENSITY:            for (i = 0; i < count; i++) {               GLuint j = start + i;               tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);            }            break;         case GL_LUMINANCE:            for (i = 0; i < count; i++) {               GLuint j = start + i;               tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);            }            break;         case GL_ALPHA:            for (i = 0; i < count; i++) {               GLuint j = start + i;               tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);            }            break;         case GL_LUMINANCE_ALPHA:            for (i = 0; i < count; i++) {               GLuint j = start + i;               tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);               tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);            }            break;         case GL_RGB:            for (i = 0; i < count; i++) {               GLuint j = start + i;               tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);               tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);               tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);            }            break;         case GL_RGBA:            for (i = 0; i < count; i++) {               GLuint j = start + i;               tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);               tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);               tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);               tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);            }            break;         default:            _mesa_problem(ctx, "Bad format in store_colortable_entries");            return;         }   }   /* update the ubyte table */   {      const GLint comps = _mesa_components_in_format(table->_BaseFormat);      const GLfloat *tableF = table->TableF + start * comps;      GLubyte *tableUB = table->TableUB + start * comps;      GLint i;      for (i = 0; i < count * comps; i++) {         CLAMPED_FLOAT_TO_UBYTE(tableUB[i], tableF[i]);      }   }   if (ctx->Unpack.BufferObj->Name) {      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,                              ctx->Unpack.BufferObj);   }}void GLAPIENTRY_mesa_ColorTable( GLenum target, GLenum internalFormat,                  GLsizei width, GLenum format, GLenum type,                  const GLvoid *data ){   static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };   static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };   GET_CURRENT_CONTEXT(ctx);   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];   struct gl_texture_object *texObj = NULL;   struct gl_color_table *table = NULL;   GLboolean proxy = GL_FALSE;   GLint baseFormat;   const GLfloat *scale = one, *bias = zero;   GLint comps;   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */   switch (target) {      case GL_SHARED_TEXTURE_PALETTE_EXT:         table = &ctx->Texture.Palette;         break;      case GL_COLOR_TABLE:         table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION];         scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION];         bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION];         break;      case GL_PROXY_COLOR_TABLE:         table = &ctx->ProxyColorTable[COLORTABLE_PRECONVOLUTION];         proxy = GL_TRUE;         break;      case GL_TEXTURE_COLOR_TABLE_SGI:         if (!ctx->Extensions.SGI_texture_color_table) {            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");            return;         }         table = &(texUnit->ColorTable);         scale = ctx->Pixel.TextureColorTableScale;         bias = ctx->Pixel.TextureColorTableBias;         break;      case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:         if (!ctx->Extensions.SGI_texture_color_table) {            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");            return;         }         table = &(texUnit->ProxyColorTable);         proxy = GL_TRUE;         break;      case GL_POST_CONVOLUTION_COLOR_TABLE:         table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION];         scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION];         bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION];         break;      case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:         table = &ctx->ProxyColorTable[COLORTABLE_POSTCONVOLUTION];         proxy = GL_TRUE;         break;      case GL_POST_COLOR_MATRIX_COLOR_TABLE:         table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX];         scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX];         bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX];         break;      case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:         table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX];         proxy = GL_TRUE;         break;      default:         /* try texture targets */         {            struct gl_texture_object *texobj               = _mesa_select_tex_object(ctx, texUnit, target);            if (texobj) {               table = &texobj->Palette;               proxy = _mesa_is_proxy_texture(target);            }            else {               _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");               return;            }         }   }   assert(table);   if (!_mesa_is_legal_format_and_type(ctx, format, type) ||       format == GL_INTENSITY) {      _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");      return;   }

⌨️ 快捷键说明

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