Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A lightweight image converter which supports PNG, PNM, BMP, QOI, JPEG-LS, and H.265 intra-frame.

License

NotificationsYou must be signed in to change notification settings

WangXuan95/ImCvt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

languagebuildbuild

ImCvt

ImCvt is aimage format converter which supports several image formats.ImCvt contains the simplest, standalone implementation of the encoders/decoders of some image formats, the purpose is to help you understand these image compression formats and algorithms swiftly.

formatfile suffixsupported colorconvert from (decode)convert to (encode)source code
PNM.pnmgray8rgb24✅ fully support✅ fully support150 lines of C
PNG.pnggray8rgb24☑️ partially support☑️ partially supportuPNG library
BMP.bmpgray8rgb24☑️ partially support☑️ partially support180 lines of C
QOI.qoirgb24✅ fully support✅ fully support240 lines of C
JPEG-LS.jlsgray8rgb24❎ unsupport☑️ partially support480 lines of C
H.265.h265gray8❎ unsupport☑️ partially support1650 lines of C

Illustration of these image formats:

  • PNM (Portable Any Map),PGM (Portable Gray Map), andPPM (Portable Pix Map) are simple uncompressed image formats which store raw pixels.

  • PNG (Portable Network Graph) is the most popular lossless image compression format. This repo usesuPNG library to decode PNG.

  • BMP (Bitmap Image File) is a popular uncompressed image formats which store raw pixels.

  • QOI (Quite OK Image) is a simple, fast lossless RGB image compression format. This repo implements a simple QOI encoder/decoder in only 240 lines of C.

  • JPEG-LS is a lossless/lossy image compression standard which can get better grayscale compression ratio compared to PNG and Lossless-WEBP. JPEG-LS uses the maximum difference between the pixels before and after compression (NEAR value) to control distortion,NEAR=0 is the lossless mode;NEAR>0 is the lossy mode. The specification of JPEG-LS isITU-T T.87 [1].ImCvt implements a simple JPEG-LS encoder in only 480 lines of C. However,ImCvt do not support JPEG-LS decoder yet. Here are two ways to decompress a .jls file:

  • H.265/HEVC is a video coding standard. This repo implements a lightweight grayscale 8-bit H.265/HEVC intra-frame image compressor in only 1650 lines of C, which may be the simplest H.265 implementation.

 

 

Compile

compile in Windows (MinGW)

If you installed MinGW, run following compiling command in CMD:

gcc src\*.c src\HEVCe\HEVCe.c src\uPNG\uPNG.c-static-O3-Wall-Wno-array-bounds-oImCvt.exe

which will get executable fileImCvt.exe

compile in Windows (MSVC)

Also, you can use MSVC to compile. If you added MSVC (cl.exe) to your environment, run following compiling command in CMD:

cl src\*.c src\HEVCe\HEVCe.c src\uPNG\uPNG.c/MT/Ox/FeImCvt.exe

which will get executable fileImCvt.exe

compile in Linux (gcc)

gcc src/*.c src/HEVCe/HEVCe.c src/uPNG/uPNG.c -static -O3 -Wall -Wno-array-bounds -o ImCvt

which will get Linux binary fileImCvt

 

 

Usage

Run the program without any parameters to display usage:

> .\ImCvt.exe|------------------------------------------------------------------------------------|| ImageConverter (v0.5)  by https://github.com/WangXuan95/                           ||------------------------------------------------------------------------------------|| Usage:                                                                             ||   ImCvt [-switches]  <in1> -o <out1>  [<in2> -o <out2]  ...                        ||                                                                                    || Where <in> and <out> can be:                                                       ||   .pnm (Portable Any Map)          : gray 8-bit or RGB 24-bit                      ||   .pgm (Portable Gray Map)         : gray 8-bit                                    ||   .ppm (Portable Pix Map)          : RGB 24-bit                                    ||   .png (Portable Network Graphics) : gray 8-bit or RGB 24-bit                      ||   .bmp (Bitmap Image File)         : gray 8-bit or RGB 24-bit                      ||   .qoi (Quite OK Image)            : RGB 24-bit                                    ||   .jls (JPEG-LS Image)             : gray 8-bit or RGB 24-bit, can be <out> only!  ||   .h265 (H.265/HEVC Image)         : gray 8-bit              , can be <out> only!  ||                                                                                    || switches:    -f                    : force overwrite of output file                ||              -0, -1, -2, -3, -4    : JPEG-LS near value or H.265 (qp-4)/6 value    ||------------------------------------------------------------------------------------|

Example Usage

convert a PNG to a PNM:

ImCvt.exe image\1.png-o image\1.pnm

convert a PNM to a QOI:

ImCvt.exe image\1.pnm-o image\1.qoi

convert a QOI to a BMP:

ImCvt.exe image\1.qoi-o image\1.bmp

convert a BMP to a JPEG-LS, with near=1 (lossy):

ImCvt.exe image\1.bmp-o image\1.jls-1

convert a BMP to a H.265 image file, with (qp-4)/6=2 (lossy):

ImCvt.exe image\1.bmp-o image\1.h265

convert multiple files by a single command:

ImCvt.exe-f image\1.png-o image\1.qoi image\2.png-o image\2.jls image\3.png-o image\3.bmp

 

 

About H.265

This repo implementsa lightweight grayscale 8-bit H.265/HEVC intra-frame image compressor in only 1650 lines of C, which may be the simplest H.265 implementation.

  • This code (HEVCe.c) is highly portable:
    • Only use two data types:unsigned char andint;
    • Do not include any headers;
    • Do not use dynamic memory.
  • Supported H.265/HEVC features:
    • Quality parameter can be 0~4, corresponds to Quantize Parameter (QP) = 4, 10, 16, 22, 28.
    • CTU : 32x32
    • CU : 32x32, 16x16, 8x8
    • TU : 32x32, 16x16, 8x8, 4x4
    • The maximum depth of CU splitting into TUs is 1 (each CU is treated as a TU, or divided into 4 small TUs, while the small TUs are not divided into smaller TUs).
    • part_mode: The 8x8 CU is treated as a PU (PART_2Nx2N), or divided into 4 PUs (PART_NxN)
    • Supports all 35 prediction modes
    • Simplified RDOQ (Rate Distortion Optimized Quantize)

For more knowledge about H.265, seeH.265/HEVC 帧内编码详解:CU层次结构、预测、变换、量化、编码 [10]

Source code of H.265

The source code is insrc/HEVCe/ , includes two files:

  • HEVCe.c : implements a H.265/HEVC gray 8-bit encoder.
  • HEVCe.h : header for users.

The users can call theHEVCImageEncoder function inHEVCe.h :

intHEVCImageEncoder (// return the length of encoded stream (unit: bytes)unsignedchar*pbuffer,// encoded stream will be stored hereconstunsignedchar*img,// The original grayscale pixels of the image need to be input here, with each pixel occupying 8-bit (i.e. an unsigned char), in the order of left to right and top to bottom.unsignedchar*img_rcon,// The pixel buffer of the reconstructed image, with each pixel occupying 8-bit (i.e. an unsigned char), in the order of left to right and top to bottom. Note: Even if you don't care about the reconstructed image, you must pass in an array space of the same size as the input image here, otherwise the image encoder will not work.int*ysz,// Enter the height of the image here. For values that are not multiples of 32, they will be supplemented with multiples of 32, so this is a pointer and the function will modify the value internally.int*xsz,// Enter the width of the image here. For values that are not multiples of 32, they will be supplemented with multiples of 32, so this is a pointer and the function will modify the value internally.constintqpd6// Quality parameter, can be 0~4, corresponds to Quantize Parameter (QP) = 4, 10, 16, 22, 28.);

To decode H265

This repo only offers H.265/HEVC compressor instead of decompressor. You can useFile Viewer Plus orElecard HEVC Analyzer to view the compressed .h265 image file.

 

 

Related links

[1] Official website of QOI :https://qoiformat.org/

[2] ITU-T T.87 : JPEG-LS baseline specification :https://www.itu.int/rec/T-REC-T.87/en

[3] UBC's JPEG-LS baseline Public Domain Code :http://www.stat.columbia.edu/~jakulin/jpeg-ls/mirror.htm

[4] pillow-jpls library for Python :https://pypi.org/project/pillow-jpls

[5] PNM Image File Specification :https://netpbm.sourceforge.net/doc/pnm.html

[6] uPNG: a simple PNG decoder:https://github.com/elanthis/upng

[7] FPGA-based Verilog QOI compressor/decompressor:https://github.com/WangXuan95/FPGA-QOI

[8] FPGA-based Verilog JPEG-LS encoder (basic version which support 8-bit gray lossless and lossy compression) :https://github.com/WangXuan95/FPGA-JPEG-LS-encoder

[9] FPGA-based Verilog JPEG-LS encoder (ultra high performance version which support 8-bit gray lossless compression) :https://github.com/WangXuan95/UH-JLS

[10] H.265/HEVC 帧内编码详解:CU层次结构、预测、变换、量化、编码:https://zhuanlan.zhihu.com/p/607679114

[11] The H.265/HEVC reference software HM:https://github.com/listenlink/HM

About

A lightweight image converter which supports PNG, PNM, BMP, QOI, JPEG-LS, and H.265 intra-frame.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp