{"id":20220654,"url":"https://github.com/andrewevstyukhin/nebc7","last_synced_at":"2025-04-10T16:04:39.268Z","repository":{"id":201748516,"uuid":"207038291","full_name":"andrewevstyukhin/nebc7","owner":"andrewevstyukhin","description":"Nearly Exhaustive BC7 compressor","archived":false,"fork":false,"pushed_at":"2022-11-20T16:54:35.000Z","size":340,"stargazers_count":24,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T13:50:29.694Z","etag":null,"topics":["bc7","texture-compression"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrewevstyukhin.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}},"created_at":"2019-09-07T23:46:35.000Z","updated_at":"2024-05-23T13:15:02.000Z","dependencies_parsed_at":"2024-03-12T00:46:16.812Z","dependency_job_id":null,"html_url":"https://github.com/andrewevstyukhin/nebc7","commit_stats":null,"previous_names":["andrewevstyukhin/nebc7"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewevstyukhin%2Fnebc7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewevstyukhin%2Fnebc7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewevstyukhin%2Fnebc7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewevstyukhin%2Fnebc7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewevstyukhin","download_url":"https://codeload.github.com/andrewevstyukhin/nebc7/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248250105,"owners_count":21072532,"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":["bc7","texture-compression"],"created_at":"2024-11-14T06:47:11.395Z","updated_at":"2025-04-10T16:04:39.254Z","avatar_url":"https://github.com/andrewevstyukhin.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nebc7 - Nearly Exhaustive BC7 compressor\n\nNebc7 is an open-source software published as is.\n\nNebc7 converts specified RGBA image to BC7 format. It focuses on image quality and uses weighted PSNR metric with some assistance of SSIM.\n\nNebc7 always preserves opaque alpha for opaque blocks.\n\n## Details\n\nNebc7 computes bounding box for each partition to choose the most suitable mode. Trivial min \u0026 max bounds swap to conform channel's covariations. Such mode is very fast and can be enabled by \"/draft\" command-line switch. Usually only -3dB below of an ideal encoding.\n\nHi-quality BC7 encodings can waste space for noise contained in source images. Error calculation function shifts away least bit of |delta| to allow simple denoising (of rounded pixels). While indices selection function treats full 8-bit values preserving gradients. Unseen random delta with magnitude 1 gives 48.13dB cap. Shifting trick forces unusual naming for metrics: qMSE and qPSNR.\n\nIt is suitable to use low entropy modes for opaque blocks. Mode 6 has excellent block structure, while modes 4\u00265 can discard single index. Nebc7 tries modes in special order and uses error stepping for only valuable switching. Random deltas with magnitude 3 are usually invisible in non-gradient areas and give 38.58dB cap. An interesting fact: many monitors can show only 6-bit true color. It is possible to render modes map specifying \"/map ...\" command-line parameter. Mode 6 is painted gray, 4\u00265 - yellow, other modes use green, red, blue for partitions 0, 1, 2 accordingly.\n\nNebc7 sorts nearly all possible endpoint values of each single channel and chooses some good of them. Then exhaustive search tries all selected combinations and reveals the best solution. Sorting provides a surprisingly fast convergence for such slow process.\n\nModes 7, 1, 3 are memory-bound because of large tables, so they are partially limited in default working mode. Slow modes can be fully activated by impractical \"/slow\" command-line switch.\n\nFor premultiplied alpha it is necessary to specify \"/nomask\" command-line option. While extruded RGBA images can highly benefit from masking. Switch \"/retina\" allows future artifact-free scaling by 0.5. Masking gives smaller compressed images and better borders, because masked pixels can have any value.\n\nMany encoders use single metric (RMSE / MSE / PSNR) insensitive to a direction. While SSIM is unhandy for direct compression, it enhances correlation when encoding produces equal deltas and so SSIM overcomes dithering.\n\n## Special features\n\n1. The additional mode 6 with a 2-bit index instead of a 4-bit one gives a significant reduction in size.\n\n2. For non-production purposes, the fastest encoder can be used by the \"/draft\" command-line option. Of course, loading png files will remain a significant bottleneck.\n\n## Usage\n\nThe solution was tested on SSSE3, SSE4.1, AVX, AVX2, AVX-512BW - capable CPUs for Win64 API only. It was then successfully expanded onto Linux and macOS with `OPTION_LIBRARY` and `OPTION_PCA` definitions.\n\n* `Bc7Compress /nomask /noflip source.png destination.ktx [/debug result.png]`\n* `Bc7Compress /nomask /noflip source.png destination.ktx [/debug result.png] /draft`\n* `Bc7Compress /data /noflip source.png destination.ktx [/debug result.png]`\n\nI would recommend using AVX2 or AVX-512 for the best performance. See [Bc7Mode.h](src/Bc7Mode.h) about advanced settings.\n\n## Customization\n\nThe kDenoise and kDenoiseStep constants in [Bc7Mode.h](src/Bc7Mode.h) define RDO capabilities:\n\n1. The most performant and compact mode is defined by kDenoise = 1, kDenoiseStep = 3 \\* 3.\n2. Generally precise but much slower mode is defined by kDenoise = 0, kDenoiseStep = 0.\n3. Especially for Moon shots (black backround with low light amplitude) I recommend kDenoise = 0, kDenoiseStep = 3 \\* 3.\n\nThe parameters gWeightAlpha, gWeightGreen, gWeightRed, gWeightBlue set weights for channels and depend on the nature of the data.\n\n## Examples\n\nLet's try the soup from https://cbloomrants.blogspot.com/2020/06/oodle-texture-sample-run.html on an i7-7800X CPU with AVX-512 enabled:\n\n  A precise compression with kDenoise = 0, kDenoiseStep = 0\n\n    Bc7Compress.exe /nomask /noflip mysoup1024.png mysoup1024-precise.ktx /debug mysoup1024-precise.png\n      Image 1024x1024, Texture 1024x1024\n        Compressed 65536 blocks, elapsed 1396 ms, throughput 0.751 Mpx/s\n          Whole A\n          SubTexture RGB qMSE = 1.6, qPSNR = 46.144434, wSSIM_4x4 = 0.99468383\n\n    dssim-1.13.exe mysoup1024.png mysoup1024-precise.png\n      0.00011307      mysoup1024-precise.png\n\n    mysoup1024-precise.7z  973 652\n\n  Standard BC7 modes separated by error stepping kDenoise = 1, kDenoiseStep = 3 \\* 3:\n\n    Bc7Compress.exe /nomask /noflip mysoup1024.png mysoup1024-stepping.ktx /debug mysoup1024-stepping.png\n      Image 1024x1024, Texture 1024x1024\n        Compressed 65536 blocks, elapsed 345 ms, throughput 3.039 Mpx/s\n          Whole A\n          SubTexture RGB qMSE = 1.6, qPSNR = 46.097026, wSSIM_4x4 = 0.99034363\n\n    dssim-1.13.exe mysoup1024.png mysoup1024-stepping.png\n      0.00023433      mysoup1024-stepping.png\n\n    mysoup1024-stepping.7z  840 465\n\n  Using additional RDO Mode6Index2 (Bc7Core.cpp, Mode6Index2::CompressBlockFast(input)):\n\n    Bc7Compress.exe /nomask /noflip mysoup1024.png mysoup1024-mode6index2.ktx /debug mysoup1024-mode6index2.png\n      Image 1024x1024, Texture 1024x1024\n        Compressed 65536 blocks, elapsed 350 ms, throughput 2.995 Mpx/s\n          Whole A\n          SubTexture RGB qMSE = 2.1, qPSNR = 44.949510, wSSIM_4x4 = 0.98476649\n\n    dssim-1.13.exe mysoup1024.png mysoup1024-mode6index2.png\n      0.00045838      mysoup1024-mode6index2.png\n\n    mysoup1024-mode6index2.7z  651 851\n\nThen check all modes with BC7Ltest.png from https://code.google.com/archive/p/nvidia-texture-tools/downloads bc7_export.zip:\n\n    Bc7Compress.exe /nomask /noflip BC7Ltest.png BC7Ltest.ktx /debug output.png\n      Image 152x152, Texture 152x152\n        Compressed 1444 blocks, elapsed 17 ms, throughput 1.359 Mpx/s\n          SubTexture A qMSE = 0.0, qPSNR = 69.026097, SSIM_4x4 = 0.99997865\n          SubTexture RGB qMSE = 0.6, qPSNR = 50.687018, wSSIM_4x4 = 0.99964438\n\n    dssim-1.13.exe BC7Ltest.png output.png\n      0.00003303      output.png\n\nAnd finally compress an interesting image https://github.com/castano/image-datasets/blob/master/waterloo/frymire.png:\n\n    Bc7Compress.exe /nomask /noflip frymire.png frymire.ktx /debug output.png\n      Image 1118x1105, Texture 1120x1108\n        Compressed 77560 blocks, elapsed 69 ms, throughput 17.984 Mpx/s\n          Whole A\n          SubTexture RGB qMSE = 0.6, qPSNR = 50.594453, wSSIM_4x4 = 0.97119160\n\n    frymire.7z  313 550\n\nFor non-production purposes, we can use the fastest encoder for the previously saved https://bitbucket.org/wolfpld/etcpak/downloads/8192.png:\n\n    Bc7Compress.exe /draft /nomask /noflip 8192.png 8192.ktx /debug output.png\n      Image 8192x8192, Texture 8192x8192\n        Compressed 4194304 blocks, elapsed 282 ms, throughput 237.974 Mpx/s\n          Whole A\n          SubTexture RGB qMSE = 0.9, qPSNR = 48.734921, wSSIM_4x4 = 0.98443459\n\n    dssim-1.13.exe 8192.png output.png\n      0.00085877      output.png\n\n    8192.7z  31 309 975\n\nand the \"Cosmic Cliffs\" https://webbtelescope.org/contents/media/images/2022/031/01G77PKB8NKR7S8Z6HBXMYATGJ:\n\n    Bc7Compress.exe /draft /nomask /noflip CosmicCliffs.png CosmicCliffs.ktx /debug output.png\n      Image 14575x8441, Texture 14576x8444\n        Compressed 7692484 blocks, elapsed 710 ms, throughput 173.351 Mpx/s\n          Whole A\n          SubTexture RGB qMSE = 0.6, qPSNR = 50.035373, wSSIM_4x4 = 0.99143002\n\n    CosmicCliffs.7z  50 304 354\n\n## Copyright\n\nCopyright (c) 2019-2022 Andrew Evstyukhin\n\nLicensed under the MIT License.\n\nAll other trademarks are property of their respective owners.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewevstyukhin%2Fnebc7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewevstyukhin%2Fnebc7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewevstyukhin%2Fnebc7/lists"}