当前位置:网站首页>Gif Development Notes (1): gif introduction, compilation and engineering template

Gif Development Notes (1): gif introduction, compilation and engineering template

2020-12-08 08:45:18 Red Imitation_ Red fat man

If the article is original , Reprint please indicate the source of the original
This article blog address :https://blog.csdn.net/qq21497936/article/details/110530966
Long term sustainability brings more projects and technology sharing , Please add QQ:21497936、 WeChat :yangsir198808
Red fat man ( Red Imitation ) The complete blog of : Development technology collection ( contain Qt Practical technology 、 Raspberry pie 、 The three dimensional 、OpenCV、OpenGL、ffmpeg、OSG、 Single chip microcomputer 、 The combination of software and hardware and so on ) Ongoing update …( Click on the portal )

Qt Development column : Third party Library Development Technology


Preface

   Realization gif Image decoding and generation .


Gif

brief introduction

  GIF The name of the format is Graphics Interchange Format Abbreviation , Is in 1987 Year by year Compu Serve In order to fill the gap of cross platform image format, the company has developed .GIF Can be PC and Mactiontosh It is supported on a variety of platforms .
  GIF It's a bitmap . The general principle of bitmap is : The picture is made up of many pixels , Each pixel is assigned a color , These pixels together make up the picture .GIF It's using Lempel-Zev-Welch(LZW) Compression algorithm , The highest support 256 Color . Because of this characteristic ,GIF More suitable for less color pictures , For example, cartoon modeling 、 Company logo and so on . If you need to use true color , that GIF It's limited .GIF It usually comes with a palette , It contains all kinds of colors that need to be used . stay Web In use , The size of the image file size will significantly affect the download speed , So we can base on GIF Features with a palette to optimize the palette , Reduce the number of colors used in images ( Some of the colors you don't use can be discarded ), It doesn't affect the quality of the picture .
  GIF The biggest difference between format and other image formats is , It was designed entirely as a common standard , because Compu Serve The popularity of the Internet , Many platforms support GIF Format .Compu Serve Promote... By distributing free format sheets GIF, But it requires the use of GIF The software in file format should contain the description of its copyright information .

edition

  GIF have GIF87a and GIF89a Two versions .

  • GIF87a The version is 1987 , launched in , A file stores an image , Transparent pixels are strictly not supported ;GIF87a use LZW Compression algorithm , It can compress image size by 20 to 25 percent while maintaining image quality .
  • GIF89a The version is 1989 It's a very distinctive version of , This version allows one file to store multiple images , Can realize animation function , Allow some pixels to be transparent . In this version , by GIF The document expands the graphic control block 、 remarks 、 explain 、 Application programming interface 4 Block , It also provides support for transparent colors and multi frame animation .

   among GIF89a In transparency 、 Interlacing and animation GIF A major improvement has been made in . The first is to support transparency ,GIF89a Some parts of the picture that are not allowed to be seen in . This feature is very important , In some cases, we can make use of such a feature to make the edge of the image no longer present a rectangular border , And become whatever shape we want . These transparent areas , It's very convenient to be in Photoshop、Fireworks Generated and exported to GIF89a Format GIF Picture to achieve . Of course , Transparency doesn't mean that borders no longer exist. In fact , It exists , It's just not shown , This will make the inserted images more in harmony with the overall web page .

characteristic

  GIF The image file format has the following characteristics :

  • GIF Format image file extension is “.gif”.
  • Best for grayscale images .
  • have GIF87a and GIF89a Two versions .
  • Adopt improved LZW Compression algorithms process image data .
  • Palette data can be divided into general palette and local palette , There are different color values .
  • I won't support it 24bit Color mode , Maximum storage 256 color .


GifLib

brief introduction

   Graphics exchange format (c) yes CompuServe Incorporated All rights reserved .GIF(sm) yes CompuServe Incorporated Service tag properties of .
   The library can be used for any need to read / Write GIF File format applications .
  CSDN:QQ Group :1047134658( Click on “ file ” Search for “giflib”, Update within the group and blog posts simultaneously )


GifLib Library compilation

Step one : decompression

   Insert picture description here

   View the directory structure of the project , It's actually linux Of , So we should use linux compile , First msys.

Step two : Use mysy Re deploy the directory structure

   Insert picture description here

Step three : introduce Qt Of mingw32

export PATH=$PATH:/mingw530_32/bin

Step four : Catalog make, Lack of mistakes cc

   Insert picture description here
  make There is an error
   Insert picture description here
   introduce CC

export CC=gcc

   Insert picture description here
   Continue compiling .

Step five : There is an error “GifErrorString”

   Insert picture description here

   I was going to solve , As soon as it turns out , There has been a libgif.a 了 , So in fact, the compilation that reported an error may be the other demo Examples need to rely on ( Wise remark of an experienced person ).
   Insert picture description here


modularization

   Insert picture description here

gifManager.pri

INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD

HEADERS += \
    $$PWD/GifManager.h

SOURCES += \
    $$PWD/GifManager.cpp


# mingw32  edition 
INCLUDEPATH += \
        $$PWD/giflib-5.2.1-mingw32/include

LIBS += $$PWD/giflib-5.2.1-mingw32/lib/libgif.a


Demo

void GifManager::testRunEnv()
{
    qDebug() << __FILE__ << __LINE__ <<  QString(GifErrorString(D_GIF_SUCCEEDED));
    qDebug() << __FILE__ << __LINE__ <<  QString(GifErrorString(D_GIF_ERR_OPEN_FAILED));
    qDebug() << __FILE__ << __LINE__ <<  QString(GifErrorString(D_GIF_ERR_READ_FAILED));
    qDebug() << __FILE__ << __LINE__ <<  QString(GifErrorString(D_GIF_ERR_NOT_GIF_FILE));
    qDebug() << __FILE__ << __LINE__ <<  QString(GifErrorString(D_GIF_ERR_NO_IMAG_DSCR));
}

   Insert picture description here

Running results

   Insert picture description here

Engineering formwork v1.0.0

   Corresponding template “gifDemo_v1.0.0_ Basic template _ Test whether the library is loaded successfully .rar”.


If the article is original , Reprint please indicate the source of the original
This article blog address :https://blog.csdn.net/qq21497936/article/details/110530966

版权声明
本文为[Red Imitation_ Red fat man]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012080844456177.html