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实现一个图片拆分工具

《基于Python实现一个图片拆分工具》这篇文章主要为大家详细介绍了如何基于Python实现一个图片拆分工具,可以根据需要的行数和列数进行拆分,感兴趣的小伙伴可以跟随小编一起学习一下... 简单介绍先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过

使用Python绘制3D堆叠条形图全解析

《使用Python绘制3D堆叠条形图全解析》在数据可视化的工具箱里,3D图表总能带来眼前一亮的效果,本文就来和大家聊聊如何使用Python实现绘制3D堆叠条形图,感兴趣的小伙伴可以了解下... 目录为什么选择 3D 堆叠条形图代码实现:从数据到 3D 世界的搭建核心代码逐行解析细节优化应用场景:3D 堆叠图

利用Python脚本实现批量将图片转换为WebP格式

《利用Python脚本实现批量将图片转换为WebP格式》Python语言的简洁语法和库支持使其成为图像处理的理想选择,本文将介绍如何利用Python实现批量将图片转换为WebP格式的脚本,WebP作为... 目录简介1. python在图像处理中的应用2. WebP格式的原理和优势2.1 WebP格式与传统

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

Python如何去除图片干扰代码示例

《Python如何去除图片干扰代码示例》图片降噪是一个广泛应用于图像处理的技术,可以提高图像质量和相关应用的效果,:本文主要介绍Python如何去除图片干扰的相关资料,文中通过代码介绍的非常详细,... 目录一、噪声去除1. 高斯噪声(像素值正态分布扰动)2. 椒盐噪声(随机黑白像素点)3. 复杂噪声(如伪

Python中图片与PDF识别文本(OCR)的全面指南

《Python中图片与PDF识别文本(OCR)的全面指南》在数据爆炸时代,80%的企业数据以非结构化形式存在,其中PDF和图像是最主要的载体,本文将深入探索Python中OCR技术如何将这些数字纸张转... 目录一、OCR技术核心原理二、python图像识别四大工具库1. Pytesseract - 经典O

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

Go语言如何判断两张图片的相似度

《Go语言如何判断两张图片的相似度》这篇文章主要为大家详细介绍了Go语言如何中实现判断两张图片的相似度的两种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 在介绍技术细节前,我们先来看看图片对比在哪些场景下可以用得到:图片去重:自动删除重复图片,为存储空间"瘦身"。想象你是一个

使用Python实现base64字符串与图片互转的详细步骤

《使用Python实现base64字符串与图片互转的详细步骤》要将一个Base64编码的字符串转换为图片文件并保存下来,可以使用Python的base64模块来实现,这一过程包括解码Base64字符串... 目录1. 图片编码为 Base64 字符串2. Base64 字符串解码为图片文件3. 示例使用注意