像素在 SDL2 中的排列方式
How are pixels arranged in SDL2?
我有 2x2 图像
像素不应该这样排列吗?
1 2 // each number is a pixel
3 4
我在访问带有 x 和 y 的像素时遇到问题,因为当 x = 1 且 y = 0 时,我得到索引 2,但打印像素 4 的 RGB 值
所以它是像什么?
1 2 // each number is a pixel
4 3
这是我使用的代码
index = y + x * s->w;
c = s->format->palette->colors[index]; // c is an SDL_Color and s is an SDL_Surface*
我也使用它进行循环,并且仍然打印相同的
for (Uint8 i = *(Uint8 *)s->pixels; i < s->w*s->h; i++) {
c = s->format->palette->colors[i];
printf("%u %u %u %u n", i, c.r , c.g , c.b);
}
SDL_Surface SDL 文档中的结构定义
typedef struct SDL_Surface {
Uint32 flags; /* Read-only */
SDL_PixelFormat *format; /* Read-only */
int w, h; /* Read-only */
Uint16 pitch; /* Read-only */
void *pixels; /* Read-write */
/* clipping information */
SDL_Rect clip_rect; /* Read-only */
/* Reference count -- used when freeing surface */
int refcount; /* Read-mostly */
/* This structure also contains private fields not shown here */
} SDL_Surface;
Uint8 *pixel = (Uint8 *)s->pixels,*index;
index = &pixel[y + x * s->pitch];
c = s->format->palette->colors[*index];
使用@holyblackcat的建议让它做。
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 如何在c++中为模板函数实例创建快捷方式
- 为什么不;名字在地图上是按顺序排列的吗
- C++优先级队列,按对象的唯一指针的特定方法升序排列
- 在c代码之间共享数据的最佳方式
- 在C++中将函数压缩为两种方式
- 按对象的特定方法按升序排列的C++优先级队列
- 以螺旋方式打印矩阵的程序.(工作不好)
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- 创建引用向量的优雅方式
- Constexpr替代了新的放置方式,可以让内存中的对象保持未初始化状态
- 使用QQuickFramebufferObject时同步数据的最佳方式是什么
- 不同/较旧的处理器运行c++代码的方式是否不同
- 从嵌套在std::映射中的std::列表中删除元素的最佳方式
- 如果条件为TRUE(最佳方式?),则在do while循环中后置增量
- 在数组中输入 n 个整数的列表,并以类似于钟摆来回移动的方式排列它们. 输入-1 3 2 5 4,输出5 3 1 2 4
- 像素在 SDL2 中的排列方式
- C++结构来定义数据的排列和访问方式
- iomanip有问题,专栏没有按我预期的方式排列
- LLVM clang编译器优化器以一种非常奇怪的方式重新排列代码,该怎么做