<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p></p>
<div>Hi,<br>
<br>
I have a problem when I try to load a TGA picture.<br>
<br>
My Code :<br>
[code]<br>
AVStream*    MainWindow::openTgaImage(std::string path)<br>
{<br>
    ctx = avformat_alloc_context();<br>
    av_register_all();<br>
    AVDictionary* options = NULL;<br>
<br>
    int read = avformat_open_input(&ctx, path.c_str(), NULL, &options);<br>
<br>
    if (read >= 0 && avformat_find_stream_info(ctx, &options) >= 0)<br>
    {<br>
        AVStream* stream = NULL;<br>
<br>
        for (size_t i = 0; i < ctx->nb_streams; ++i)<br>
        {<br>
            AVStream*    currentStream = ctx->streams[i];<br>
<br>
            if (currentStream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && currentStream->codecpar->codec_id == AV_CODEC_ID_TARGA)<br>
                return currentStream;<br>
        }<br>
    }<br>
<br>
    return NULL;<br>
}<br>
<br>
QImage    MainWindow::parseTgaImage(std::string path)<br>
{<br>
    QImage        ret;<br>
    AVStream*    stream = openTgaImage(path);<br>
<br>
    if (stream)<br>
    {<br>
        AVPacket packet;<br>
<br>
        av_init_packet(&packet);<br>
        packet.data = NULL;<br>
        packet.size = 0;<br>
<br>
        while (av_read_frame(ctx, &packet) >= 0)<br>
        {<br>
            if (packet.stream_index == stream->index)<br>
            {<br>
<br>
                  AVPicture frame;<br>
<br>
                //  avpicture_alloc(&frame, stream->codec->pix_fmt, stream->codec->width, stream->codec->height);<br>
                //  avpicture_fill(&frame, packet.data, stream->codec->pix_fmt, stream->codec->width, stream->codec->height);<br>
<br>
                  QImage    img(stream->codec->width, stream->codec->height, QImage::Format_ARGB32);<br>
                  int        offset = 18; // I need to set offset to 18 because the buffer is shifted.<br>
<br>
                  for (size_t y = 0; y < stream->codec->height; ++y)<br>
                  {<br>
                    for (size_t x = 0; x < stream->codec->width; ++x)<br>
                    {<br>
                        QColor color;<br>
<br>
                        color.setBlue(packet.data[offset + 0]);<br>
                        color.setGreen(packet.data[offset + 1]);<br>
                        color.setRed(packet.data[offset + 2]);<br>
                        color.setAlpha(packet.data[offset + 3]);<br>
                        img.setPixel(x, y, color.rgba());<br>
                        offset += 4;<br>
                    }<br>
                  }<br>
<br>
                  if (!img.isNull())<br>
                      ret = img;<br>
<br>
                  avpicture_free(&frame);<br>
            }<br>
        }<br>
<br>
        av_free_packet(&packet);<br>
    }<br>
<br>
    avformat_close_input(&ctx);<br>
<br>
    return ret;<br>
}<br>
[/code]<br>
<br>
My problem:<br>
I set the offset to 18, because without this offset, my picture have bad colors.<br>
The packet->size is not good (packet->size == (width * height * 4 (4 for RGBA) + 44)<br>
Why my packet->size has 44 bytes at the end?<br>
Why my picture is shifted and have the bad colors?<br>
If I set my offset to 18, so I start to read to packet->buffer[18], my picture isn't shifted and have the good colors. Why?<br>
<br>
Thanks you for you help,</div>
<br>
<p></p>
</div>
</body>
</html>