1.8. 绘制图片 Drawing Images

2024-01-08 22:08
文章标签 图片 绘制 1.8 images drawing

本文主要是介绍1.8. 绘制图片 Drawing Images,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.8. 绘制图片 Drawing Images


As mentioned previously, OpenGL has a great deal of support for drawing images in addition to

its support for drawing 3D geometry. In OpenGL parlance, images are called PIXEL RECTANGLES.

The values that define a pixel rectangle start out in application-controlled memory as shown in

Figure 1.1 (11). Color or grayscale pixel rectangles are rendered into the frame buffer with

glDrawPixels, and bitmaps are rendered into the frame buffer with glBitmap. Images that are

destined for texture memory are specified with glTexImage or glTexSubImage. Up to a point, the

same basic processing is applied to the image data supplied with each of these commands.

1.8.1. Pixel Unpacking

OpenGL reads image data provided by the application in a variety of formats. Parameters that

define how the image data is stored in memory (length of each pixel row, number of rows to

skip before the first one, number of pixels to skip before the first one in each row, etc.) can be

specified with glPixelStore. So that operations on pixel data can be defined more precisely, pixels

read from application memory are converted into a coherent stream of pixels by an operation

referred to as PIXEL UNPACKING (12). When a pixel rectangle is transferred to OpenGL by a call like

glDrawPixels, this operation applies the current set of pixel unpacking parameters to determine

how the image data should be read and interpreted. As each pixel is read from memory, it is

converted to a PIXEL GROUP that contains either a color, a depth, or a stencil value. If the pixel

group consists of a color, the image data is destined for the color buffer in the frame buffer. If

the pixel group consists of a depth value, the image data is destined for the depth buffer. If the

pixel group consists of a stencil value, the image data is destined for the stencil buffer. Color

values are made up of a red, a green, a blue, and an alpha component (i.e., RGBA) and are

constructed from the input image data according to a set of rules defined by OpenGL. The result

is a stream of RGBA values that are sent to OpenGL for further processing.

1.8.2. Pixel Transfer

After a coherent stream of image pixels is created, pixel rectangles undergo a series of

operations called PIXEL TRANSFER (13). These operations are applied whenever pixel rectangles are

transferred from the application to OpenGL (glDrawPixels, glTexImage, glTexSubImage), from OpenGL

back to the application (glReadPixels), or when they are copied within OpenGL (glCopyPixels,

glCopyTexImage, glCopyTexSubImage).

The behavior of the pixel transfer stage is modified with glPixelTransfer. This command sets state

that controls whether red, green, blue, alpha, and depth values are scaled and biased. It can

also set state that determines whether incoming color or stencil values are mapped to different

color or stencil values through the use of a lookup table. The lookup tables used for these

operations are specified with the glPixelMap command.

Some additional operations that occur at this stage are part of the OpenGL IMAGING SUBSET, which

is an optional part of OpenGL. Hardware vendors that find it important to support advanced

imaging capabilities will support the imaging subset in their OpenGL implementations, and other

vendors will not support it. To determine whether the imaging subset is supported, applications

need to call glGetString with the symbolic constant GL_EXTENSIONS. This returns a list of

extensions supported by the implementation; the application should check for the presence of

the string "ARB_imaging" within the returned extension string.

The pixel transfer operations that are defined to be part of the imaging subset are convolution,

color matrix, histogram, min/max, and additional color lookup tables. Together, they provide

powerful image processing and color correction operations on image data as it is being

transferred to, from, or within OpenGL.

1.8.3. Rasterization and Back-End Processing

Following the pixel transfer stage, fragments are generated through rasterization of pixel

rectangles in much the same way as they are generated from 3D geometry (14). This process,

along with the current OpenGL state, determines where the image will be drawn in the frame

buffer. Rasterization takes into account the current RASTER POSITION, which can be set with

glRasterPos or glWindowPos, and the current zoom factor, which can be set with glPixelZoom and

which causes an image to be magnified or reduced in size as it is drawn.

After fragments have been generated from pixel rectangles, they undergo the same set of

fragment processing operations as geometric primitives (6) and then go on to the remainder of

the OpenGL pipeline in exactly the same manner as geometric primitives, all the way until

pixels are deposited in the frame buffer (8, 9, 10).

Pixel values provided through a call to glTexImage or glTexSubImage do not go through rasterization

or the subsequent fragment processing but directly update the appropriate portion of texture

memory (15).

1.8.4. Read Control

Pixel rectangles are read from the frame buffer and returned to application memory with

glReadPixels. They can also be read from the frame buffer and written to another portion of the

frame buffer with glCopyPixels, or they can be read from the frame buffer and written into texture

memory with glCopyTexImage or glCopyTexSubImage. In all of these cases, the portion of the frame

buffer that is to be read is controlled by the READ CONTROL stage of OpenGL and set with the

glReadBuffer command (16).

The values read from the frame buffer are sent through the pixel transfer stage (13) in which

various image processing operations can be performed. For copy operations, the resulting pixels

are sent to texture memory or back into the frame buffer, depending on the command that

initiated the transfer. For read operations, the pixels are formatted for storage in application

memory under the control of the PIXEL PACKING stage (17). This stage is the mirror of the pixel

unpacking stage (12), in that parameters that define how the image data is to be stored in

memory (length of each pixel row, number of rows to skip before the first one, number of pixels

to skip before the first one in each row, etc.) can be specified with glPixelStore. Thus, application

developers enjoy a lot of flexibility in determining how the image data is returned from OpenGL

into application memory.

这篇关于1.8. 绘制图片 Drawing Images的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/584977

相关文章

Python利用PIL进行图片压缩

《Python利用PIL进行图片压缩》有时在发送一些文件如PPT、Word时,由于文件中的图片太大,导致文件也太大,无法发送,所以本文为大家介绍了Python中图片压缩的方法,需要的可以参考下... 有时在发送一些文件如PPT、Word时,由于文件中的图片太大,导致文件也太大,无法发送,所有可以对文件中的图

java获取图片的大小、宽度、高度方式

《java获取图片的大小、宽度、高度方式》文章介绍了如何将File对象转换为MultipartFile对象的过程,并分享了个人经验,希望能为读者提供参考... 目China编程录Java获取图片的大小、宽度、高度File对象(该对象里面是图片)MultipartFile对象(该对象里面是图片)总结java获取图片

Java实战之自助进行多张图片合成拼接

《Java实战之自助进行多张图片合成拼接》在当今数字化时代,图像处理技术在各个领域都发挥着至关重要的作用,本文为大家详细介绍了如何使用Java实现多张图片合成拼接,需要的可以了解下... 目录前言一、图片合成需求描述二、图片合成设计与实现1、编程语言2、基础数据准备3、图片合成流程4、图片合成实现三、总结前

使用Python实现图片和base64转换工具

《使用Python实现图片和base64转换工具》这篇文章主要为大家详细介绍了如何使用Python中的base64模块编写一个工具,可以实现图片和Base64编码之间的转换,感兴趣的小伙伴可以了解下... 简介使用python的base64模块来实现图片和Base64编码之间的转换。可以将图片转换为Bas

css实现图片旋转功能

《css实现图片旋转功能》:本文主要介绍了四种CSS变换效果:图片旋转90度、水平翻转、垂直翻转,并附带了相应的代码示例,详细内容请阅读本文,希望能对你有所帮助... 一 css实现图片旋转90度.icon{ -moz-transform:rotate(-90deg); -webkit-transfo

C#实现添加/替换/提取或删除Excel中的图片

《C#实现添加/替换/提取或删除Excel中的图片》在Excel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更加美观,下面我们来看看如何在C#中实现添加/替换/提取或删除E... 在Excandroidel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更

C#中图片如何自适应pictureBox大小

《C#中图片如何自适应pictureBox大小》文章描述了如何在C#中实现图片自适应pictureBox大小,并展示修改前后的效果,修改步骤包括两步,作者分享了个人经验,希望对大家有所帮助... 目录C#图片自适应pictureBox大小编程修改步骤总结C#图片自适应pictureBox大小上图中“z轴

使用Python将长图片分割为若干张小图片

《使用Python将长图片分割为若干张小图片》这篇文章主要为大家详细介绍了如何使用Python将长图片分割为若干张小图片,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. python需求的任务2. Python代码的实现3. 代码修改的位置4. 运行结果1. Python需求

使用Python绘制蛇年春节祝福艺术图

《使用Python绘制蛇年春节祝福艺术图》:本文主要介绍如何使用Python的Matplotlib库绘制一幅富有创意的“蛇年有福”艺术图,这幅图结合了数字,蛇形,花朵等装饰,需要的可以参考下... 目录1. 绘图的基本概念2. 准备工作3. 实现代码解析3.1 设置绘图画布3.2 绘制数字“2025”3.3

使用Python绘制可爱的招财猫

《使用Python绘制可爱的招财猫》招财猫,也被称为“幸运猫”,是一种象征财富和好运的吉祥物,经常出现在亚洲文化的商店、餐厅和家庭中,今天,我将带你用Python和matplotlib库从零开始绘制一... 目录1. 为什么选择用 python 绘制?2. 绘图的基本概念3. 实现代码解析3.1 设置绘图画