convrtr
Start converting

15 September 2026

Converting Better Portable Graphics (BPG) to PNG: HEVC-Derived Image Decoding

Converting Better Portable Graphics (BPG) to PNG: HEVC-Derived Image Decoding

In 2014, legendary programmer Fabrice Bellard (creator of FFmpeg, QEMU, and QuickJS) announced BPG (Better Portable Graphics), an image format engineered to replace JPEG. By utilizing the intra-frame prediction algorithms of the HEVC (H.265) video standard, BPG achieved unprecedented image quality at half the file size of comparable JPEG images.

While WebP and AVIF eventually became native web standards, millions of high-efficiency graphics, scientific imagery, and photography archives were produced in .bpg format. Because mainstream browsers do not support BPG natively, converting them into standard 32-bit RGBA PNG files is essential for viewing and sharing.


1. The BPG File Architecture

A valid BPG file begins with a 4-byte magic signature followed by variable-length quantity headers:

| Offset | Length | Description | |---|---|---| | 0x00 | 4 bytes | Magic signature: 0x79 0x71 0x73 0xFB (ASCII yqs\xFB) | | 0x04 | 1 byte | Pixel format (4:2:0, 4:2:2, 4:4:4, RGB) and bit depth (8 to 14 bits) | | 0x05 | 1 byte | Color space (YCbCr BT.601, BT.709, BT.2020, RGB), alpha, and animation flags | | 0x06 | Variable (LEB128) | Picture width in pixels | | Next | Variable (LEB128) | Picture height in pixels | | Next | Variable (LEB128) | Picture data byte length | | Next | Variable | Optional extension tags (EXIF metadata, ICC color profile, XMP) | | Next | Variable | Intra-frame bitstream and image payload |


2. Variable-Length LEB128 Integer Decoding

BPG encodes dimensions and chunk lengths using unsigned LEB128 (Little-Endian Base 128) variable-length integers to conserve header bytes:

function readUleb128(bytes: Uint8Array, offset: { val: number }): number {
  let result = 0;
  let shift = 0;
  while (offset.val < bytes.length) {
    const b = bytes[offset.val++] ?? 0;
    result |= (b & 0x7f) << shift;
    if ((b & 0x80) === 0) break;
    shift += 7;
  }
  return result;
}

This encoding allows a 4K image (3840x2160) to be represented in just two bytes per dimension instead of four fixed bytes.


3. Color Space Transformation: YCbCr to 32-Bit RGBA

Most photographic BPG images store pixel data in the YCbCr color space. To render a standard PNG image, convrtr performs color space transformation from luma (Y) and chroma difference (Cb, Cr) channels into RGB:

R = Y + 1.402 * (Cr - 128)
G = Y - 0.344136 * (Cb - 128) - 0.714136 * (Cr - 128)
B = Y + 1.772 * (Cb - 128)

The resulting 32-bit RGBA pixel buffer is passed directly into convrtr's browser PNG encoder, yielding an uncompressed, lossless PNG image.


4. How to Convert BPG to PNG in Your Browser

  1. Navigate to BPG to PNG on convrtr.
  2. Drag and drop your .bpg image file.
  3. convrtr parses the BPG header, transforms YCbCr coordinates into linear RGB, and outputs a standard 32-bit RGBA PNG ready for instant download or web use.
  4. All processing is 100% private and happens locally on your computer with zero server uploads.
[ ARCHIVE & GUIDES ]

Related reading

All guides