读取 Targa 文件。缺少深色?

发布于 2024-11-18 11:16:02 字数 1265 浏览 2 评论 0原文

由于是新人,我只能有两个链接,无法发布我的图片。抱歉,复制+粘贴地址给您带来不便

我正在解析 Targa (.tga) 图像文件,其代码类似于 steinsoft.net/index.php?site=Programming/Code% 中找到的代码20Snippets/Cpp/no8

将数据检索到 unsigned char 数组后,我将其打印到日志中以进行手动检查。似乎无论出于何种原因,深色颜色都没有被解析。


简单打印代码

file.open( save );

//using while( tga.data[ i ] != NULL ) resulted in ~400,000 lines of garbage being appended
for( unsigned i = 1; i <= ( tga.width * tga.height * tga.byteCount ); i++ )
{
    if( tga.data[ i ] == NULL )
        break;

    file << ( int )tga.data[ i ] << ",";

    if( ( i % 3 ) == 0 )
        file << "\n";
}

file.close( );

示例

Dark : https://i.sstatic.net/qefIA.png : http://pastebin.com/8JeJwP2w

浅色:https://i.sstatic.net/XNTIK.pnghttp://pastebin.com/s2sW0XfM

如您所见,图像顶部的线不是当它是深色(在本例中为黑色)时包括在内,但当它是浅色(粉红色[255,53,204])时它就存在。

有谁知道为什么会发生这种情况?


规格

Windows Vista

Microsoft Visual C++ 2010 Professional

Targa 保存为 24 位未压缩。

Due to being new, I can only have two links and can not post my images. Sorry for the inconvenience of having to copy+paste addresses

I am parsing a Targa (.tga) image file with code similar to that found at steinsoft.net/index.php?site=Programming/Code%20Snippets/Cpp/no8

After retrieving the data into the unsigned char array, I print it out into a log to check manually. It seems that darker colors are not being parsed for whatever reason.


The Simple Print Code

file.open( save );

//using while( tga.data[ i ] != NULL ) resulted in ~400,000 lines of garbage being appended
for( unsigned i = 1; i <= ( tga.width * tga.height * tga.byteCount ); i++ )
{
    if( tga.data[ i ] == NULL )
        break;

    file << ( int )tga.data[ i ] << ",";

    if( ( i % 3 ) == 0 )
        file << "\n";
}

file.close( );

Example

Dark : https://i.sstatic.net/qefIA.png : http://pastebin.com/8JeJwP2w

Light : https://i.sstatic.net/XNTIK.png : http://pastebin.com/s2sW0XfM

As you can see, the line at the top of the image is not included when it is a dark color (black in this instance), but it is there when it is light (a pink [255,53,204]).

Does anyone have any information on why this may be happening?


Specs

Windows Vista

Microsoft Visual C++ 2010 Professional

Targa is saved as 24-bit NOT compressed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尹雨沫 2024-11-25 11:16:02

首先,为什么要检查data[i]==NULL?可能有 0 像素(黑色),所以将它们全部保留。您基本上检查颜色是否为 0,然后退出循环。无论值如何,只需读取所有像素即可。

First of all, why do you check if the data[i]==NULL? There might be 0-pixels (black), so keep them all in. You basically check if the color is 0 and then you exit your loop. Just read all pixels no matter the value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文