c-如何在帧缓冲区中正确显示TGA图像



我一直在开发自己的业余操作系统。我想显示图标。为了简单起见,我选择了tga格式。但要有一个正确的形象是不可能的:它是完全扭曲的。这是我的代码:

struct tga_header {
uint8_t magic1;             // must be zero
uint8_t colormap;           // must be zero
uint8_t encoding;           // must be 2
uint16_t cmaporig, cmaplen; // must be zero
uint8_t cmapent;            // must be zero
uint16_t x;                 // must be zero
uint16_t y;                 // image's height
uint16_t h;                 // image's height
uint16_t w;                 // image's width
uint8_t bpp;                // must be 32
uint8_t pixeltype;          // must be 40
} __attribute__((packed));

void display_tga(struct tga_header *base)
{
if (base->magic1 != 0 || base->colormap != 0 || base->encoding != 2
|| base->cmaporig != 0 || base->cmapent != 0 || base->x != 0
|| base->bpp != 32 || base->pixeltype != 40)
return;
uint32_t *img = (u32*)(sizeof(struct tga_header)+(uint64_t)base);
draw_icon(700, 50, base->w, base->h, img);
}

draw_icon函数:

static void draw_icon(int x, int y, int w, int h, u32 *img) {
int j, l, i;
for (l = j = 0; l < h; l++) {
for (i = 0; i < w; i++, j++) {
putpixel(x + i, y + l, img[j]);
}
}
}

图像显示如下

只要我搜索,就应该交换tga_headerhw;(

相关内容

  • 没有找到相关文章

最新更新