{"id":18022995,"url":"https://github.com/kanryu/lodepng-turbo","last_synced_at":"2025-03-26T23:30:57.088Z","repository":{"id":140593442,"uuid":"165181315","full_name":"kanryu/lodepng-turbo","owner":"kanryu","description":"lodepng-turbo is a fast PNG image codec that uses SIMD instructions (MMX, SSE2, AVX2, NEON) to accelerate baseline PNG decompression on x86, x86-64, ARM systems.","archived":false,"fork":false,"pushed_at":"2019-01-22T03:17:48.000Z","size":523,"stargazers_count":20,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-22T17:13:28.095Z","etag":null,"topics":["image-processing","png","simd-library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kanryu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-01-11T04:52:47.000Z","updated_at":"2024-08-05T16:44:02.000Z","dependencies_parsed_at":"2023-05-03T19:33:40.859Z","dependency_job_id":null,"html_url":"https://github.com/kanryu/lodepng-turbo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Flodepng-turbo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Flodepng-turbo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Flodepng-turbo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Flodepng-turbo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanryu","download_url":"https://codeload.github.com/kanryu/lodepng-turbo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245753858,"owners_count":20666823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image-processing","png","simd-library"],"created_at":"2024-10-30T07:06:35.579Z","updated_at":"2025-03-26T23:30:56.620Z","avatar_url":"https://github.com/kanryu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lodepng-turbo\nlodepng-turbo is a PNG image codec that uses SIMD instructions (MMX, SSE2, AVX2, NEON) to accelerate baseline PNG decompression on x86, x86-64, ARM systems.\n\n## Background\nlodepng-turbo is a PNG image codec that uses SIMD instructions (MMX, SSE2, AVX2, NEON) \nto accelerate baseline PNG decompression on x86, x86-64, ARM systems. \nOn x86 and x86-64 or ARM systems, lodepng-turbo is twice as fast as libpng, but it may be slower elsewhere. \nWith lodepng-turbo, its highly optimized libdeflate and depng prediction routines perform significantly better than lodepng(origin) and libpng.\n\nlodepng-turbo implements both the traditional lodepng API and the less powerful but more direct TurboPNG API.\n\n## How to build\n\nBuild lodepng-turbo with gcc/clang and GNU make.\nFor Windows, the built library can also be used under msvc.\n\n```shell\n$ git submodule init\n$ git submodule update\n$ make\n```\nWhen it is built, static libraries and shared libraries are created.\n\nliblodepngturbo.dll(so) is a shared library and can be used alone. For Windows, use the import library (liblodepngturbo.lib).\n\nliblodepngturbostatic.a (lib) is a static library and can be statically linked to your library. In this case libdeflatestatic.a also needs to be linked.\n\n### for MSVC\n\nAttention: When using libpng-turbo with msvc, lodepng(-turbo)  of C++ API built with msys2 (g++) can not be used because of different naming conventions. (However, it is set not to be generated by default.)\n\ng++ of msys2 is necessary for building this library by msvc.\nTo build libdeflatestatic.lib in the msys2 environment first.\n\nOpen the solution file in the vstudio folder and build it on msvc. The setting of the project file is set to build the static library of libpng - turbo, so change the setting if you want dll.\n\n## Loading sample\n\n```C++\n#include \u003cQtGui\u003e\n#include \"lodepng.h\"\n\nint main(int argc, char *argv[])\n{\n    QCoreApplication a(argc, argv);\n    QString infilename(\"in.png\");\n    QString outfilename(\"out.png\");\n\n    if(argc \u003c= 1) {\n        qDebug() \u003c\u003c \"Usage: qt_lodepng_test [in.png] [out.png]\";\n        return 0;\n    }\n    if(argc \u003e 1)\n        infilename = QString(argv[1]);\n    if(argc \u003e 2)\n        outfilename = QString(argv[2]);\n\n    QByteArray bytes;\n    {\n        QFile fl(infilename);\n        fl.open(QFile::ReadOnly);\n        bytes = fl.readAll();\n        fl.close();\n    }\n    unsigned char* out = nullptr; // lodepng decodes a dynamically allocated bitmap into a buffer\n    unsigned width,height;\n    unsigned result;\n    LodePNGState state; // png state\n\n    state.inspected = 3; // dummy initialize value\n    qDebug() \u003c\u003c \"before init:\" \u003c\u003c state.inspected; // will be 3\n    lodepng_state_init(\u0026state);\n    qDebug() \u003c\u003c \"after init:\" \u003c\u003c state.inspected; // will be 0\n\n    // check png header and get basical metadata\n    result = lodepng_inspect(\u0026width, \u0026height, \u0026state, (unsigned char*)bytes.data(), bytes.size());\n    qDebug() \u003c\u003c \"inspect:\" \u003c\u003c result \u003c\u003c width \u003c\u003c height \u003c\u003c state.info_png.color.colortype \u003c\u003c state.info_raw.colortype \u003c\u003c state.inspected; // will be 1\n    state.decoder.color_convert = 0; // skip color converting\n\n    QImage::Format fmt = QImage::Format_Indexed8;\n    switch(state.info_png.color.colortype) {\n        case LodePNGColorType::LCT_GREY: fmt = QImage::Format_Grayscale8; break;\n        case LodePNGColorType::LCT_RGB: fmt = QImage::Format_RGB888; break;\n        case LodePNGColorType::LCT_PALETTE: fmt = QImage::Format_Indexed8; break;\n        case LodePNGColorType::LCT_RGBA: fmt = QImage::Format_RGBA8888; break;\n        case LodePNGColorType::LCT_GREY_ALPHA: fmt = QImage::Format_RGBA8888; break;\n    }\n    qDebug() \u003c\u003c \"colortype\" \u003c\u003c state.info_png.color.colortype \u003c\u003c \"format\" \u003c\u003c fmt;\n    if(state.info_png.color.colortype == LodePNGColorType::LCT_GREY_ALPHA) {\n        // LCT_GREY_ALPHA -\u003e LCT_RGBA\n        result = lodepng_decode32(\u0026out, \u0026width, \u0026height, (unsigned char*)bytes.data(), bytes.size());\n    } else {\n        result = lodepng_decode(\u0026out, \u0026width, \u0026height, \u0026state, (unsigned char*)bytes.data(), bytes.size());\n        qDebug() \u003c\u003c \"decode:\" \u003c\u003c result \u003c\u003c width \u003c\u003c height \u003c\u003c state.info_png.color.colortype \u003c\u003c state.info_raw.colortype \u003c\u003c fmt;\n    }\n\n    QImage img(QSize(width, height), fmt);\n    // LodePNGColorType::LCT_PALETTE has palette\n    if(state.info_png.color.palettesize \u003e 0) {\n        QVector\u003cQRgb\u003e palettes(state.info_png.color.palettesize);\n        unsigned char* pal = state.info_png.color.palette;\n        for(int i = 0; i \u003c state.info_png.color.palettesize; i++) {\n            // on x86 or x64 CPUs, must be swapped between R and B.\n            palettes[i] = (pal[4*i+3] \u003c\u003c 24) | (pal[4*i+0] \u003c\u003c 16) | (pal[4*i+1] \u003c\u003c8) | pal[4*i+2];\n        }\n        img.setColorTable(palettes);\n        qDebug() \u003c\u003c \"palette set completed:\" \u003c\u003c state.info_png.color.palettesize;\n    }\n    // Since Bitmap pads each scanline with 4 bytes, there is a case that there is a gap in the byte stream.\n    int bytewidth = width*img.depth()/8;\n    if(bytewidth == img.bytesPerLine())\n    {\n        memcpy(img.bits(), out, img.byteCount());\n    } else {\n        qDebug() \u003c\u003c \"bytesPerLine\" \u003c\u003c img.bytesPerLine() \u003c\u003c \"bytewidth\" \u003c\u003c bytewidth;\n        for(int y = 0; y \u003c img.height(); y++)\n            memcpy(img.scanLine(y), \u0026out[y*bytewidth], bytewidth);\n    }\n    // Some PNG images may use transparent colors\n    // instead of using alpha values to describe transparency,\n    // but lodepng does not take this into consideration.\n    // (When Convert is Disabled)\n    if(state.info_png.color.key_defined) {\n        QRgb mask = QRgb(((state.info_png.color.key_r \u0026 0xff) \u003c\u003c 16)\n                         | ((state.info_png.color.key_g \u0026 0xff) \u003c\u003c 8)\n                         | (state.info_png.color.key_b \u0026 0xff));\n        qDebug() \u003c\u003c \"MaskOutColor:\" \u003c\u003c mask;\n        qDebug() \u003c\u003c \"depth\" \u003c\u003c img.depth();\n        img = img.convertToFormat(QImage::Format_ARGB32);\n        for(QRgb* pix = (QRgb*)img.bits(); (uchar*)pix \u003c img.bits()+img.byteCount(); pix++) {\n            if(((*pix - mask) \u0026 0x00ffffff) == 0x0)\n                    *pix = 0x0;\n        }\n    }\n    img.save(outfilename);\n    free(out);\n\n    a.exit();\n    return 0;\n}\n```\n\n## Acknowledgments\n\nlodepng is a very easy-to-understand png library, which is the foundation of this library.\n\nlibdeflate is a very fast zlib compatible codec, and substantial decode processing is realized with this library.\n\nSimdTests is a public domain to test SIMD optimized functions related mostly to 2D computer graphics.\n\n## License\n\nzlib\n\n## Copyright\n\nCopyright 2019 KATO Kanryu\u003ck.kanryu@gmail.com\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanryu%2Flodepng-turbo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanryu%2Flodepng-turbo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanryu%2Flodepng-turbo/lists"}