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

📄 pixel.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:  6.5.3 * * 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 "colormac.h"#include "context.h"#include "image.h"#include "macros.h"#include "pixel.h"#include "mtypes.h"/**********************************************************************//*****                    glPixelZoom                             *****//**********************************************************************/void GLAPIENTRY_mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor ){   GET_CURRENT_CONTEXT(ctx);   if (ctx->Pixel.ZoomX == xfactor &&       ctx->Pixel.ZoomY == yfactor)      return;   FLUSH_VERTICES(ctx, _NEW_PIXEL);   ctx->Pixel.ZoomX = xfactor;   ctx->Pixel.ZoomY = yfactor;}/**********************************************************************//*****                    glPixelStore                            *****//**********************************************************************/void GLAPIENTRY_mesa_PixelStorei( GLenum pname, GLint param ){   /* NOTE: this call can't be compiled into the display list */   GET_CURRENT_CONTEXT(ctx);   ASSERT_OUTSIDE_BEGIN_END(ctx);   switch (pname) {      case GL_PACK_SWAP_BYTES:	 if (param == (GLint)ctx->Pack.SwapBytes)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);         ctx->Pack.SwapBytes = param ? GL_TRUE : GL_FALSE;	 break;      case GL_PACK_LSB_FIRST:	 if (param == (GLint)ctx->Pack.LsbFirst)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);         ctx->Pack.LsbFirst = param ? GL_TRUE : GL_FALSE;	 break;      case GL_PACK_ROW_LENGTH:	 if (param<0) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Pack.RowLength == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Pack.RowLength = param;	 break;      case GL_PACK_IMAGE_HEIGHT:         if (param<0) {            _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Pack.ImageHeight == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Pack.ImageHeight = param;         break;      case GL_PACK_SKIP_PIXELS:	 if (param<0) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Pack.SkipPixels == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Pack.SkipPixels = param;	 break;      case GL_PACK_SKIP_ROWS:	 if (param<0) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Pack.SkipRows == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Pack.SkipRows = param;	 break;      case GL_PACK_SKIP_IMAGES:	 if (param<0) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Pack.SkipImages == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Pack.SkipImages = param;	 break;      case GL_PACK_ALIGNMENT:         if (param!=1 && param!=2 && param!=4 && param!=8) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Pack.Alignment == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Pack.Alignment = param;	 break;      case GL_PACK_INVERT_MESA:         if (!ctx->Extensions.MESA_pack_invert) {            _mesa_error( ctx, GL_INVALID_ENUM, "glPixelstore(pname)" );            return;         }         if (ctx->Pack.Invert == param)            return;         FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);         ctx->Pack.Invert = param;         break;      case GL_UNPACK_SWAP_BYTES:	 if (param == (GLint)ctx->Unpack.SwapBytes)	    return;	 if ((GLint)ctx->Unpack.SwapBytes == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Unpack.SwapBytes = param ? GL_TRUE : GL_FALSE;         break;      case GL_UNPACK_LSB_FIRST:	 if (param == (GLint)ctx->Unpack.LsbFirst)	    return;	 if ((GLint)ctx->Unpack.LsbFirst == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Unpack.LsbFirst = param ? GL_TRUE : GL_FALSE;	 break;      case GL_UNPACK_ROW_LENGTH:	 if (param<0) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Unpack.RowLength == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Unpack.RowLength = param;	 break;      case GL_UNPACK_IMAGE_HEIGHT:         if (param<0) {            _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Unpack.ImageHeight == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Unpack.ImageHeight = param;         break;      case GL_UNPACK_SKIP_PIXELS:	 if (param<0) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Unpack.SkipPixels == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Unpack.SkipPixels = param;	 break;      case GL_UNPACK_SKIP_ROWS:	 if (param<0) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Unpack.SkipRows == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Unpack.SkipRows = param;	 break;      case GL_UNPACK_SKIP_IMAGES:	 if (param < 0) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );	    return;	 }	 if (ctx->Unpack.SkipImages == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Unpack.SkipImages = param;	 break;      case GL_UNPACK_ALIGNMENT:         if (param!=1 && param!=2 && param!=4 && param!=8) {	    _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore" );	    return;	 }	 if (ctx->Unpack.Alignment == param)	    return;	 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);	 ctx->Unpack.Alignment = param;	 break;      case GL_UNPACK_CLIENT_STORAGE_APPLE:         if (param == (GLint)ctx->Unpack.ClientStorage)            return;         FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);         ctx->Unpack.ClientStorage = param ? GL_TRUE : GL_FALSE;         break;      default:	 _mesa_error( ctx, GL_INVALID_ENUM, "glPixelStore" );	 return;   }}void GLAPIENTRY_mesa_PixelStoref( GLenum pname, GLfloat param ){   _mesa_PixelStorei( pname, (GLint) param );}/**********************************************************************//*****                         glPixelMap                         *****//**********************************************************************//** * Return pointer to a pixelmap by name. */static struct gl_pixelmap *get_pixelmap(GLcontext *ctx, GLenum map){   switch (map) {   case GL_PIXEL_MAP_I_TO_I:      return &ctx->PixelMaps.ItoI;   case GL_PIXEL_MAP_S_TO_S:      return &ctx->PixelMaps.StoS;   case GL_PIXEL_MAP_I_TO_R:      return &ctx->PixelMaps.ItoR;   case GL_PIXEL_MAP_I_TO_G:      return &ctx->PixelMaps.ItoG;   case GL_PIXEL_MAP_I_TO_B:      return &ctx->PixelMaps.ItoB;   case GL_PIXEL_MAP_I_TO_A:      return &ctx->PixelMaps.ItoA;   case GL_PIXEL_MAP_R_TO_R:      return &ctx->PixelMaps.RtoR;   case GL_PIXEL_MAP_G_TO_G:      return &ctx->PixelMaps.GtoG;   case GL_PIXEL_MAP_B_TO_B:      return &ctx->PixelMaps.BtoB;   case GL_PIXEL_MAP_A_TO_A:      return &ctx->PixelMaps.AtoA;   default:      return NULL;   }}/** * Helper routine used by the other _mesa_PixelMap() functions. */static voidstore_pixelmap(GLcontext *ctx, GLenum map, GLsizei mapsize,               const GLfloat *values){   GLint i;   struct gl_pixelmap *pm = get_pixelmap(ctx, map);   if (!pm) {      _mesa_error(ctx, GL_INVALID_ENUM, "glPixelMap(map)");      return;   }   switch (map) {   case GL_PIXEL_MAP_S_TO_S:      /* special case */      ctx->PixelMaps.StoS.Size = mapsize;      for (i = 0; i < mapsize; i++) {         ctx->PixelMaps.StoS.Map[i] = IROUND(values[i]);      }      break;   case GL_PIXEL_MAP_I_TO_I:      /* special case */      ctx->PixelMaps.ItoI.Size = mapsize;      for (i = 0; i < mapsize; i++) {         ctx->PixelMaps.ItoI.Map[i] = values[i];      }      break;   default:      /* general case */      pm->Size = mapsize;      for (i = 0; i < mapsize; i++) {         GLfloat val = CLAMP(values[i], 0.0F, 1.0F);         pm->Map[i] = val;         pm->Map8[i] = (GLint) (val * 255.0F);      }   }}void GLAPIENTRY_mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values ){   GET_CURRENT_CONTEXT(ctx);   ASSERT_OUTSIDE_BEGIN_END(ctx);   /* XXX someday, test against ctx->Const.MaxPixelMapTableSize */   if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {      _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );      return;   }   if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {      /* test that mapsize is a power of two */      if (_mesa_bitcount((GLuint) mapsize) != 1) {	 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );         return;      }   }   FLUSH_VERTICES(ctx, _NEW_PIXEL);   if (ctx->Unpack.BufferObj->Name) {      /* unpack pixelmap from PBO */      GLubyte *buf;      /* Note, need to use DefaultPacking and Unpack's buffer object */      ctx->DefaultPacking.BufferObj = ctx->Unpack.BufferObj;      if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,                                     GL_INTENSITY, GL_FLOAT, values)) {         _mesa_error(ctx, GL_INVALID_OPERATION,                     "glPixelMapfv(invalid PBO access)");         return;      }      /* restore */      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,                                              GL_READ_ONLY_ARB,                                              ctx->Unpack.BufferObj);      if (!buf) {         /* buffer is already mapped - that's an error */         _mesa_error(ctx, GL_INVALID_OPERATION,                     "glPixelMapfv(PBO is mapped)");         return;      }      values = (const GLfloat *) ADD_POINTERS(buf, values);   }   else if (!values) {      return;   }   store_pixelmap(ctx, map, mapsize, values);   if (ctx->Unpack.BufferObj->Name) {      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,                              ctx->Unpack.BufferObj);   }}void GLAPIENTRY_mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values ){   GLfloat fvalues[MAX_PIXEL_MAP_TABLE];

⌨️ 快捷键说明

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