├── android ├── sample │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── drawable-nodpi │ │ │ │ ├── tcr.jpg │ │ │ │ └── bilibili.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ └── com │ │ │ └── bilibili │ │ │ └── burstlinker │ │ │ └── sample │ │ │ └── MainActivity.java │ ├── proguard-rules.pro │ └── build.gradle ├── settings.gradle ├── lib │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── cpp │ │ │ ├── DithererWithRs.cpp │ │ │ ├── DisableDithererWithRs.h │ │ │ ├── BayerDithererWithRs.h │ │ │ ├── NoDithererWithRs.h │ │ │ ├── DithererWithRs.h │ │ │ ├── DisableDithererWithRs.cpp │ │ │ ├── NoDithererWithRs.cpp │ │ │ ├── BayerDithererWithRs.cpp │ │ │ └── BurstLinker.cpp │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ └── com │ │ │ └── bilibili │ │ │ └── burstlinker │ │ │ ├── GifEncodeException.java │ │ │ └── BurstLinker.java │ ├── proguard-rules.pro │ ├── build.gradle │ └── CMakeLists.txt ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradle.properties ├── .gitignore ├── upload.gradle ├── build.gradle ├── gradlew.bat └── gradlew ├── .gitattributes ├── screenshot ├── octree.gif ├── random.gif ├── bilibili.png ├── k-means.gif ├── uniform.gif ├── media-cut.gif ├── neu-quant-1.gif ├── octree-m2.gif ├── neu-quant-10.gif ├── octree-bayer.gif ├── lenna-original.png ├── bilibili-octree-default.gif ├── bilibili-octree-ignore.gif └── octree-floyd-steinberg.gif ├── .gitignore ├── src ├── GifAnalyzer.h ├── M2Ditherer.h ├── NoDitherer.h ├── BayerDitherer.h ├── KMeansQuantizer.h ├── UniformQuantizer.h ├── RandomQuantizer.h ├── NeuQuantQuantizer.h ├── FloydSteinbergDitherer.h ├── MedianCutQuantizer.h ├── Logger.h ├── ColorQuantizer.h ├── NeuQuantQuantizer.cpp ├── KDTree.h ├── Ditherer.h ├── LzwEncoder.h ├── RandomQuantizer.cpp ├── BurstLinker.h ├── OctreeQuantizer.h ├── UniformQuantizer.cpp ├── Logger.cpp ├── M2Ditherer.cpp ├── BayerDitherer.cpp ├── BurstLinker.cpp ├── GifBlockWriter.h ├── NoDitherer.cpp ├── GifEncoder.h ├── ThreadPool.h ├── FloydSteinbergDitherer.cpp ├── LzwEncoder.cpp ├── KDTree.cpp ├── MedianCutQuantizer.cpp ├── KMeansQuantizer.cpp ├── OctreeQuantizer.cpp ├── NeuQuant.h ├── Main.cpp ├── GifBlockWriter.cpp ├── GifAnalyzer.cpp ├── NeuQuant.cpp └── GifEncoder.cpp ├── CMakeLists.txt ├── README.md ├── example └── Main.cpp └── LICENSE /android/sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':lib', ':sample' 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.c linguist-language=C++ 2 | *.h linguist-language=C++ -------------------------------------------------------------------------------- /screenshot/octree.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/octree.gif -------------------------------------------------------------------------------- /screenshot/random.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/random.gif -------------------------------------------------------------------------------- /screenshot/bilibili.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/bilibili.png -------------------------------------------------------------------------------- /screenshot/k-means.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/k-means.gif -------------------------------------------------------------------------------- /screenshot/uniform.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/uniform.gif -------------------------------------------------------------------------------- /screenshot/media-cut.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/media-cut.gif -------------------------------------------------------------------------------- /screenshot/neu-quant-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/neu-quant-1.gif -------------------------------------------------------------------------------- /screenshot/octree-m2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/octree-m2.gif -------------------------------------------------------------------------------- /screenshot/neu-quant-10.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/neu-quant-10.gif -------------------------------------------------------------------------------- /screenshot/octree-bayer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/octree-bayer.gif -------------------------------------------------------------------------------- /screenshot/lenna-original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/lenna-original.png -------------------------------------------------------------------------------- /android/lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | .externalNativeBuild/ 3 | /src/main/cpp/cmake-build-debug/ 4 | /src/main/cpp/.idea/ 5 | -------------------------------------------------------------------------------- /android/sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BurstLinker 3 | 4 | -------------------------------------------------------------------------------- /screenshot/bilibili-octree-default.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/bilibili-octree-default.gif -------------------------------------------------------------------------------- /screenshot/bilibili-octree-ignore.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/bilibili-octree-ignore.gif -------------------------------------------------------------------------------- /screenshot/octree-floyd-steinberg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/screenshot/octree-floyd-steinberg.gif -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/lib/src/main/cpp/DithererWithRs.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/10. 3 | // 4 | 5 | #include "DithererWithRs.h" 6 | -------------------------------------------------------------------------------- /android/sample/src/main/res/drawable-nodpi/tcr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/android/sample/src/main/res/drawable-nodpi/tcr.jpg -------------------------------------------------------------------------------- /android/sample/src/main/res/drawable-nodpi/bilibili.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/android/sample/src/main/res/drawable-nodpi/bilibili.png -------------------------------------------------------------------------------- /android/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/BurstLinker/HEAD/android/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | org.gradle.jvmargs=-Xmx5120m -XX:MaxPermSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 3 | org.gradle.daemon=true 4 | org.gradle.parallel=true 5 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | /Android/local.properties 3 | .idea/ 4 | .DS_Store 5 | build/ 6 | /Android/build 7 | /.idea 8 | /.gradle 9 | captures/ 10 | *.class 11 | *.iml 12 | .externalNativeBuild/ 13 | CMakeFiles/ 14 | .vs/ -------------------------------------------------------------------------------- /android/sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | /local.properties 3 | local.properties 4 | .idea/ 5 | .DS_Store 6 | build/ 7 | /Android/build 8 | /.idea 9 | /.gradle 10 | captures/ 11 | *.class 12 | *.iml 13 | .externalNativeBuild/ 14 | CMakeFiles/ 15 | .vs/ 16 | cmake-build-debug/ 17 | CMakeSettings.json -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Aug 07 14:39:55 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /android/upload.gradle: -------------------------------------------------------------------------------- 1 | publish { 2 | userOrg = 'succlz123' 3 | groupId = 'com.bilibili' 4 | artifactId = 'burst-linker' 5 | publishVersion = rootProject.ext.burstLinkerVer 6 | desc = 'BurstLinker is a simple C++ GIF encode library.' 7 | website = 'https://github.com/Bilibili/BurstLinker' 8 | } 9 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/bilibili/burstlinker/GifEncodeException.java: -------------------------------------------------------------------------------- 1 | package com.bilibili.burstlinker; 2 | 3 | /** 4 | * Created by succlz123 on 2017/9/7. 5 | */ 6 | public class GifEncodeException extends Exception { 7 | 8 | public GifEncodeException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/GifAnalyzer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/4. 3 | // 4 | 5 | #ifndef BURSTLINKER_GIFANALYZER_H 6 | #define BURSTLINKER_GIFANALYZER_H 7 | 8 | namespace blk { 9 | 10 | class GifAnalyzer { 11 | 12 | public: 13 | 14 | void showGifInfo(const char *path); 15 | 16 | }; 17 | 18 | } 19 | 20 | #endif //BURSTLINKER_GIFANALYZER_H 21 | -------------------------------------------------------------------------------- /android/sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/M2Ditherer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 17-9-19. 3 | // 4 | 5 | #ifndef BURSTLINKER_M2DITHERER_H 6 | #define BURSTLINKER_M2DITHERER_H 7 | 8 | #include "Ditherer.h" 9 | 10 | namespace blk { 11 | 12 | class M2Ditherer : public Ditherer { 13 | 14 | public: 15 | 16 | void dither(std::vector &origin, std::vector &quantize, uint8_t *colorIndices) override; 17 | 18 | }; 19 | 20 | } 21 | 22 | #endif //BURSTLINKER_M2DITHERER_H 23 | -------------------------------------------------------------------------------- /src/NoDitherer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/15. 3 | // 4 | 5 | #ifndef BURSTLINKER_NODITHERER_H 6 | #define BURSTLINKER_NODITHERER_H 7 | 8 | #include "Ditherer.h" 9 | 10 | namespace blk { 11 | 12 | class NoDitherer : public Ditherer { 13 | 14 | public: 15 | 16 | void dither(std::vector &origin, std::vector &quantize, uint8_t *colorIndices) override; 17 | 18 | }; 19 | 20 | } 21 | 22 | #endif //BURSTLINKER_NODITHERER_H 23 | -------------------------------------------------------------------------------- /src/BayerDitherer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/10/26. 3 | // 4 | 5 | #ifndef BURSTLINKER_BAYERDITHERER_H 6 | #define BURSTLINKER_BAYERDITHERER_H 7 | 8 | #include "Ditherer.h" 9 | 10 | namespace blk { 11 | 12 | class BayerDitherer : public Ditherer { 13 | 14 | public: 15 | 16 | void dither(std::vector &origin, std::vector &quantize, uint8_t *colorIndices) override; 17 | }; 18 | 19 | } 20 | 21 | #endif //BURSTLINKER_BAYERDITHERER_H 22 | -------------------------------------------------------------------------------- /src/KMeansQuantizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 17-10-9. 3 | // 4 | 5 | #ifndef BURSTLINKER_KMEANSQUANTIZER_H 6 | #define BURSTLINKER_KMEANSQUANTIZER_H 7 | 8 | #include "ColorQuantizer.h" 9 | 10 | namespace blk { 11 | 12 | class KMeansQuantizer : public ColorQuantizer { 13 | 14 | public: 15 | 16 | int32_t quantize(const std::vector &in, uint32_t maxColorCount, std::vector &out) override; 17 | 18 | }; 19 | 20 | } 21 | 22 | #endif //BURSTLINKER_KMEANSQUANTIZER_H 23 | -------------------------------------------------------------------------------- /src/UniformQuantizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 17-9-12. 3 | // 4 | 5 | #ifndef BURSTLINKER_UNIFORMQUANTIZER_H 6 | #define BURSTLINKER_UNIFORMQUANTIZER_H 7 | 8 | #include "ColorQuantizer.h" 9 | 10 | namespace blk { 11 | 12 | class UniformQuantizer : public ColorQuantizer { 13 | 14 | public: 15 | 16 | int32_t quantize(const std::vector &in, uint32_t maxColorCount, std::vector &out) override; 17 | }; 18 | 19 | } 20 | 21 | #endif //BURSTLINKER_UNIFORMQUANTIZER_H 22 | -------------------------------------------------------------------------------- /src/RandomQuantizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/5. 3 | // 4 | 5 | #ifndef BURSTLINKER_RANDOMQUANTIZER_H 6 | #define BURSTLINKER_RANDOMQUANTIZER_H 7 | 8 | #include "ColorQuantizer.h" 9 | 10 | namespace blk { 11 | 12 | class RandomQuantizer : public ColorQuantizer { 13 | 14 | public: 15 | 16 | int32_t quantize(const std::vector &in, uint32_t maxColorCount, std::vector &out) override; 17 | 18 | }; 19 | 20 | } 21 | 22 | #endif //BURSTLINKER_RANDOMQUANTIZER_H 23 | -------------------------------------------------------------------------------- /src/NeuQuantQuantizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/5. 3 | // 4 | 5 | #ifndef BURSTLINKER_NEUQUANTQUANTIZER_H 6 | #define BURSTLINKER_NEUQUANTQUANTIZER_H 7 | 8 | #include "ColorQuantizer.h" 9 | 10 | namespace blk { 11 | 12 | class NeuQuantQuantizer : public ColorQuantizer { 13 | 14 | public: 15 | 16 | int32_t quantize(const std::vector &in, uint32_t maxColorCount, std::vector &out) override; 17 | 18 | }; 19 | 20 | } 21 | 22 | #endif //BURSTLINKER_NEUQUANTQUANTIZER_H 23 | -------------------------------------------------------------------------------- /src/FloydSteinbergDitherer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 17-9-19. 3 | // 4 | 5 | #ifndef BURSTLINKER_FLOYDSTEINBERGDITHERER_H 6 | #define BURSTLINKER_FLOYDSTEINBERGDITHERER_H 7 | 8 | #include "Ditherer.h" 9 | 10 | namespace blk { 11 | 12 | class FloydSteinbergDitherer : public Ditherer { 13 | 14 | public: 15 | 16 | void dither(std::vector &origin, std::vector &quantize, uint8_t *colorIndices) override; 17 | 18 | }; 19 | 20 | } 21 | 22 | #endif //BURSTLINKER_FLOYDSTEINBERGDITHERER_H 23 | -------------------------------------------------------------------------------- /src/MedianCutQuantizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/10/14. 3 | // 4 | 5 | #ifndef BURSTLINKER_MEDIANCUTQUANTIZER_H 6 | #define BURSTLINKER_MEDIANCUTQUANTIZER_H 7 | 8 | #include "ColorQuantizer.h" 9 | 10 | namespace blk { 11 | 12 | class MedianCutQuantizer : public ColorQuantizer { 13 | 14 | public: 15 | 16 | int32_t quantize(const std::vector &in, uint32_t maxColorCount, std::vector &out) override; 17 | 18 | }; 19 | 20 | } 21 | 22 | #endif //BURSTLINKER_MEDIANCUTQUANTIZER_H 23 | -------------------------------------------------------------------------------- /src/Logger.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 17-9-30. 3 | // 4 | 5 | #ifndef BURSTLINKER_GIFLOGGER_H 6 | #define BURSTLINKER_GIFLOGGER_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace blk { 13 | 14 | class Logger { 15 | 16 | public: 17 | 18 | static void log(bool show, std::string str); 19 | 20 | template 21 | static std::string toString(T value) { 22 | std::ostringstream os; 23 | os << value; 24 | return os.str(); 25 | } 26 | }; 27 | 28 | } 29 | 30 | #endif //BURSTLINKER_GIFLOGGER_H 31 | -------------------------------------------------------------------------------- /src/ColorQuantizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 17-9-11. 3 | // 4 | 5 | #ifndef BURSTLINKER_COLORQUANTIZER_H 6 | #define BURSTLINKER_COLORQUANTIZER_H 7 | 8 | #include 9 | #include 10 | #include "GifEncoder.h" 11 | 12 | namespace blk { 13 | 14 | class ColorQuantizer { 15 | 16 | public: 17 | 18 | int32_t resultSize = 0; 19 | 20 | virtual ~ColorQuantizer() = default;; 21 | 22 | virtual int32_t quantize(const std::vector &in, uint32_t maxColorCount, std::vector &out)= 0; 23 | 24 | protected: 25 | 26 | int sample = 10; // for NeuQuant 27 | 28 | }; 29 | 30 | } 31 | 32 | #endif //BURSTLINKER_COLORQUANTIZER_H 33 | -------------------------------------------------------------------------------- /android/lib/src/main/cpp/DisableDithererWithRs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/10/5. 3 | // 4 | 5 | #ifndef BURSTLINKER_DISABLEDITHERERWITHRS_H 6 | #define BURSTLINKER_DISABLEDITHERERWITHRS_H 7 | 8 | #include "../../../../../src/Ditherer.h" 9 | #include "DithererWithRs.h" 10 | #include 11 | #include 12 | 13 | using namespace android::RSC; 14 | 15 | class DisableDithererWithRs : public DithererWithRs { 16 | 17 | public: 18 | 19 | void dither(uint32_t *originalColors, int width, int height, unsigned char *quantizerColors, 20 | int quantizerSize, sp rs) override; 21 | 22 | }; 23 | 24 | 25 | #endif //BURSTLINKER_DISABLEDITHERERWITHRS_H 26 | -------------------------------------------------------------------------------- /android/lib/src/main/cpp/BayerDithererWithRs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/15. 3 | // 4 | 5 | #ifndef BURSTLINKER_BAYERDITHERERWITHRS_H 6 | #define BURSTLINKER_BAYERDITHERERWITHRS_H 7 | 8 | #include "../../../../../src/Ditherer.h" 9 | #include "DithererWithRs.h" 10 | #include 11 | 12 | using namespace android::RSC; 13 | 14 | class BayerDithererWithRs : public DithererWithRs { 15 | 16 | public: 17 | 18 | void dither(blk::RGB *originPixels, uint16_t width, uint16_t height, 19 | blk::RGB quantizerPixels[], int32_t quantizerSize, 20 | uint8_t *colorIndices, sp rs) override; 21 | 22 | }; 23 | 24 | 25 | #endif //BURSTLINKER_BAYERDITHERERWITHRS_H 26 | -------------------------------------------------------------------------------- /android/lib/src/main/cpp/NoDithererWithRs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/10/5. 3 | // 4 | 5 | #ifndef BURSTLINKER_DISABLEDITHERERWITHRS_H 6 | #define BURSTLINKER_DISABLEDITHERERWITHRS_H 7 | 8 | #include "../../../../../src/Ditherer.h" 9 | #include "DithererWithRs.h" 10 | #include 11 | #include 12 | 13 | using namespace android::RSC; 14 | 15 | class NoDithererWithRs : public DithererWithRs { 16 | 17 | public: 18 | 19 | void dither(blk::RGB *originPixels, uint16_t width, uint16_t height, 20 | blk::RGB quantizerPixels[], int32_t quantizerSize, 21 | uint8_t *colorIndices, sp rs) override; 22 | 23 | }; 24 | 25 | 26 | #endif //BURSTLINKER_DISABLEDITHERERWITHRS_H 27 | -------------------------------------------------------------------------------- /android/lib/src/main/cpp/DithererWithRs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/10. 3 | // 4 | 5 | #ifndef BURSTLINKER_DITHERERWITHRS_H 6 | #define BURSTLINKER_DITHERERWITHRS_H 7 | 8 | #include "../../../../../src/Ditherer.h" 9 | #include 10 | 11 | class DithererWithRs : public blk::Ditherer { 12 | 13 | public: 14 | 15 | void 16 | dither(blk::RGB *originPixels, uint16_t width, uint16_t height, 17 | blk::RGB quantizerPixels[], int32_t quantizerSize, 18 | uint8_t *colorIndices) {}; 19 | 20 | virtual void 21 | dither(blk::RGB *originPixels, uint16_t width, uint16_t height, 22 | blk::RGB quantizerPixels[], int32_t quantizerSize, 23 | uint8_t *colorIndices, android::RSC::sp rs)=0; 24 | 25 | }; 26 | 27 | 28 | #endif //BURSTLINKER_DITHERERWITHRS_H 29 | -------------------------------------------------------------------------------- /src/NeuQuantQuantizer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/5. 3 | // 4 | 5 | #include "NeuQuantQuantizer.h" 6 | #include "NeuQuant.h" 7 | 8 | using namespace blk; 9 | 10 | int32_t NeuQuantQuantizer::quantize(const std::vector &in, uint32_t maxColorCount, std::vector &out) { 11 | NeuQuant neuQuant; 12 | size_t size = in.size(); 13 | auto pixels = new uint8_t[size * 3]; 14 | int index = 0; 15 | for (int i = 0; i < size; ++i) { 16 | auto inColor = in[i]; 17 | pixels[index++] = inColor.r; 18 | pixels[index++] = inColor.g; 19 | pixels[index++] = inColor.b; 20 | } 21 | neuQuant.initnet(pixels, size * 3, sample); 22 | neuQuant.learn(); 23 | neuQuant.unbiasnet(); 24 | resultSize = neuQuant.getColourMap(out, maxColorCount); 25 | delete[] pixels; 26 | return resultSize; 27 | } 28 | -------------------------------------------------------------------------------- /src/KDTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/12/28. 3 | // 4 | 5 | #ifndef BURSTLINKER_KDTREE_H 6 | #define BURSTLINKER_KDTREE_H 7 | 8 | #include "GifEncoder.h" 9 | 10 | namespace blk { 11 | 12 | class KDTree { 13 | 14 | public: 15 | 16 | struct Node { 17 | uint8_t r = 0; 18 | uint8_t g = 0; 19 | uint8_t b = 0; 20 | uint8_t index = 0; 21 | uint8_t split = 0; 22 | Node *left = nullptr; 23 | Node *right = nullptr; 24 | }; 25 | 26 | Node nearest; 27 | 28 | void *createKDTree(Node *node, std::vector &quantize, int32_t start, int32_t end, uint8_t split); 29 | 30 | int searchNoBacktracking(Node *node, uint8_t r, uint8_t g, uint8_t b, int32_t dis); 31 | 32 | void freeKDTree(Node *tree); 33 | 34 | }; 35 | 36 | } 37 | 38 | #endif //BURSTLINKER_KDTREE_H 39 | -------------------------------------------------------------------------------- /src/Ditherer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 17-9-19. 3 | // 4 | 5 | #ifndef BURSTLINKER_DITHERER_H 6 | #define BURSTLINKER_DITHERER_H 7 | 8 | #include 9 | #include "ColorQuantizer.h" 10 | 11 | namespace blk { 12 | 13 | class Ditherer { 14 | 15 | public: 16 | 17 | // ffmpeg vf_paletteuse.c 18 | static int bayerDitherValue(int p) { 19 | const int q = p ^(p >> 3); 20 | return (p & 4) >> 2 | (q & 4) >> 1 \ 21 | | (p & 2) << 1 | (q & 2) << 2 \ 22 | | (p & 1) << 4 | (q & 1) << 5; 23 | } 24 | 25 | // only for bayer 26 | int bayerScale = 1; 27 | 28 | uint16_t width = 0; 29 | 30 | uint16_t height = 0; 31 | 32 | virtual ~Ditherer() = default; 33 | 34 | virtual void dither(std::vector &origin, std::vector &quantize, uint8_t *colorIndices) = 0; 35 | 36 | }; 37 | 38 | } 39 | 40 | #endif //BURSTLINKER_DITHERER_H 41 | -------------------------------------------------------------------------------- /src/LzwEncoder.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 17-9-9. 3 | // 4 | 5 | #ifndef BURSTLINKER_LZWENCODER_H 6 | #define BURSTLINKER_LZWENCODER_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace blk { 14 | 15 | class LzwEncoder { 16 | 17 | public: 18 | 19 | explicit LzwEncoder(int32_t paddedColorCount); 20 | 21 | ~LzwEncoder(); 22 | 23 | void encode(uint8_t indices[], uint16_t width, uint16_t height, std::vector &content); 24 | 25 | private: 26 | 27 | std::list datas; 28 | 29 | uint8_t *current; 30 | 31 | int pos; 32 | 33 | int remain; 34 | 35 | int32_t numColors; 36 | 37 | void writeBits(uint32_t src, int32_t bit); 38 | 39 | int write(std::vector &content, uint8_t minimumCodeSize); 40 | }; 41 | 42 | } 43 | 44 | #endif //BURSTLINKER_LZWENCODER_H 45 | -------------------------------------------------------------------------------- /android/sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /android/lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/succlz123/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /android/sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/succlz123/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /src/RandomQuantizer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/5. 3 | // 4 | 5 | #include 6 | #include "RandomQuantizer.h" 7 | 8 | using namespace blk; 9 | 10 | int32_t RandomQuantizer::quantize(const std::vector &in, uint32_t maxColorCount, std::vector &out) { 11 | size_t pixelCount = in.size(); 12 | std::mt19937 generator((uint32_t) time(nullptr)); 13 | std::uniform_int_distribution dis(0, pixelCount); 14 | std::set randomColor; 15 | uint32_t index = 0; 16 | size_t maxCount = pixelCount / 4; 17 | while (randomColor.size() < maxColorCount && index < maxCount) { 18 | index++; 19 | auto rColor = in[dis(generator)]; 20 | randomColor.emplace(rColor.r, rColor.g, rColor.b); 21 | } 22 | resultSize = static_cast(randomColor.size()); 23 | uint8_t colorPaletteIndex = 0; 24 | for (ARGB color:randomColor) { 25 | out.emplace_back(color.r, color.g, color.b, colorPaletteIndex); 26 | colorPaletteIndex++; 27 | } 28 | return resultSize; 29 | } 30 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | import com.android.build.gradle.BaseExtension 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.4.1' 10 | classpath 'com.novoda:bintray-release:0.9.1' 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | jcenter() 17 | google() 18 | } 19 | afterEvaluate { 20 | def android = project.extensions.findByName('android') as BaseExtension 21 | android?.compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | } 26 | tasks.withType(Javadoc) { 27 | options.addStringOption('Xdoclint:none', '-quiet') 28 | options.addStringOption('encoding', 'UTF-8') 29 | } 30 | } 31 | 32 | task clean(type: Delete) { 33 | delete rootProject.buildDir 34 | } 35 | 36 | ext { 37 | burstLinkerVer = '0.0.12' 38 | libs = ['burstLinkerVer': "com.bilibili:$burstLinkerVer"] 39 | } 40 | -------------------------------------------------------------------------------- /src/BurstLinker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by succlz123 on 2017/11/30. 3 | // 4 | 5 | #ifndef BURSTLINKER_BURSTLINKER_H 6 | #define BURSTLINKER_BURSTLINKER_H 7 | 8 | #include 9 | #include "GifEncoder.h" 10 | 11 | namespace blk { 12 | 13 | class BurstLinker { 14 | 15 | public: 16 | 17 | bool init(const char *path, uint16_t width, uint16_t height, uint32_t loopCount, 18 | uint32_t threadNum); 19 | 20 | bool connect(std::vector &image, uint32_t delay, 21 | QuantizerType quantizerType, DitherType ditherType, int32_t transparencyOption, 22 | uint16_t left, uint16_t top); 23 | 24 | bool connect(std::vector> &images, uint32_t delay, 25 | QuantizerType quantizerType, DitherType ditherType, int32_t transparencyOption, 26 | uint16_t left, uint16_t top); 27 | 28 | void release(); 29 | 30 | void analyzerGifInfo(const char *path); 31 | 32 | private: 33 | 34 | std::unique_ptr gifEncoder; 35 | 36 | }; 37 | 38 | } 39 | 40 | #endif //BURSTLINKER_BURSTLINKER_H 41 | -------------------------------------------------------------------------------- /android/sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 23 | 24 |