I need to overlay an image that has an auxiliary alpha mask over another image. HEIF specification allows me to do this, as is showcased [in the "Alpha Mask" example](https://nokiatech.github.io/heif/examples.html#alpha-1). I tried to reconstruct this sample HEIF image. The original file `alpha_1440x960.heic` can be found [here](https://github.com/nokiatech/heif/blob/gh-pages/content/overlay_grid_alpha/alpha_1440x960.heic).

Running `mp4box -info alpha_1440x960.heic`:
```
# File Meta type: "pict" - 5 resource item(s)
Primary Item - ID 1009
Item #1: ID 1002 type hvc1 Name "HEVC Image" size 1440x960
Item #2: ID 1005 type hvc1 Name "HEVC Image" size 1440x960
Item #3: ID 1008 type hvc1 Name "HEVC Image" size 1440x960 Hidden
Item #4: ID 1009 type iovl Name "Derived image" size 1440x960

File has no movie (moov) - static data container
```

Extract the raw streams from the original `alpha_1440x960.heic`:
```
$ mp4box -dump-item 1002:path=1002.hvc alpha_1440x960.heic
$ mp4box -dump-item 1005:path=1005.hvc alpha_1440x960.heic
$ mp4box -dump-item 1008:path=1008.hvc alpha_1440x960.heic
```

Reconstruct the HEIF image:
```
$ mp4box \
    -add-image \
        "1002.hvc":id=1002 \
    -add-image \
        "1005.hvc":id=1005 \
    -add-image \
        "1008.hvc":id=1008:alpha:hidden:ref=auxl,1005 \
    -add-derived-image \
        :type=iovl:id=1009:primary:image-size=1440x960:ref=dimg,1002:ref=dimg,1005:image-overlay-offsets=0,0,0,0 \
    -new \
        "reconstruct.heic"

>>>>>> OUTPUT <<<<<<
Track Importing HEVC - Width 1440 Height 960 FPS 25000/1000
HEVC Import results: 1 samples (4 NALUs) - Slices: 1 I 0 P 0 B - 0 SEI - 1 IDR - 0 CRA
Adding sample at time 0.000 as item 1002
Track Importing HEVC - Width 1440 Height 960 FPS 25000/1000
HEVC Import results: 1 samples (4 NALUs) - Slices: 1 I 0 P 0 B - 0 SEI - 1 IDR - 0 CRA
Adding sample at time 0.000 as item 1005
Track Importing HEVC - Width 1440 Height 960 FPS 25000/1000
HEVC Import results: 1 samples (4 NALUs) - Slices: 1 I 0 P 0 B - 0 SEI - 1 IDR - 0 CRA
HEVC Max NALU size is 396 - stream could be optimized by setting nal_length=2
Adding sample at time 0.000 as item 1008
0.500 secs Interleaving
```

The derived image, `ID=1009`, does not render properly on my Mac. Instead of correctly rendering an overlayed alpha image, it just shows all black. The original image, however, renders correctly.

By the way, running `mp4box -info reconstruct.heic` shows
```
# File Meta type: "pict" - 5 resource item(s)
Primary Item - ID 1009
Item #1: ID 1002 type hvc1 size 1440x960 SAR 1/1 3 channels (8 bpc)
Item #2: ID 1005 type hvc1 size 1440x960 SAR 1/1 3 channels (8 bpc)
Item #3: ID 1008 type hvc1 size 1440x960 SAR 1/1 3 channels (8 bpc) Hidden
Item #4: ID 1009 type iovl size 1440x960

File has no movie (moov) - static data container
```
It contains `SAR 1/1 3 channels (8 bpc)` lines the original file info does not have.

Environment:
```
Image viewed on macOS 12.4 Monterey
MP4Box: GPAC version 2.1-DEV-rev232-gfcaa01eb-master
Image extracted and reconstructed on Windows 10 21H2 19044.1766 but I don't think this matters
```
MP4Box: HEIF overlay images with alpha mask does not produce correct file
This is a GitHub Issue
repo:gpac
owner:gpac
Title : MP4Box: HEIF overlay images with alpha mask does not produce correct file
Issue date:

--- start body ---
I need to overlay an image that has an auxiliary alpha mask over another image. HEIF specification allows me to do this, as is showcased [in the "Alpha Mask" example](https://nokiatech.github.io/heif/examples.html#alpha-1). I tried to reconstruct this sample HEIF image. The original file `alpha_1440x960.heic` can be found [here](https://github.com/nokiatech/heif/blob/gh-pages/content/overlay_grid_alpha/alpha_1440x960.heic).

Running `mp4box -info alpha_1440x960.heic`:
```
# File Meta type: "pict" - 5 resource item(s)
Primary Item - ID 1009
Item #1: ID 1002 type hvc1 Name "HEVC Image" size 1440x960
Item #2: ID 1005 type hvc1 Name "HEVC Image" size 1440x960
Item #3: ID 1008 type hvc1 Name "HEVC Image" size 1440x960 Hidden
Item #4: ID 1009 type iovl Name "Derived image" size 1440x960

File has no movie (moov) - static data container
```

Extract the raw streams from the original `alpha_1440x960.heic`:
```
$ mp4box -dump-item 1002:path=1002.hvc alpha_1440x960.heic
$ mp4box -dump-item 1005:path=1005.hvc alpha_1440x960.heic
$ mp4box -dump-item 1008:path=1008.hvc alpha_1440x960.heic
```

Reconstruct the HEIF image:
```
$ mp4box \
    -add-image \
        "1002.hvc":id=1002 \
    -add-image \
        "1005.hvc":id=1005 \
    -add-image \
        "1008.hvc":id=1008:alpha:hidden:ref=auxl,1005 \
    -add-derived-image \
        :type=iovl:id=1009:primary:image-size=1440x960:ref=dimg,1002:ref=dimg,1005:image-overlay-offsets=0,0,0,0 \
    -new \
        "reconstruct.heic"

>>>>>> OUTPUT <<<<<<
Track Importing HEVC - Width 1440 Height 960 FPS 25000/1000
HEVC Import results: 1 samples (4 NALUs) - Slices: 1 I 0 P 0 B - 0 SEI - 1 IDR - 0 CRA
Adding sample at time 0.000 as item 1002
Track Importing HEVC - Width 1440 Height 960 FPS 25000/1000
HEVC Import results: 1 samples (4 NALUs) - Slices: 1 I 0 P 0 B - 0 SEI - 1 IDR - 0 CRA
Adding sample at time 0.000 as item 1005
Track Importing HEVC - Width 1440 Height 960 FPS 25000/1000
HEVC Import results: 1 samples (4 NALUs) - Slices: 1 I 0 P 0 B - 0 SEI - 1 IDR - 0 CRA
HEVC Max NALU size is 396 - stream could be optimized by setting nal_length=2
Adding sample at time 0.000 as item 1008
0.500 secs Interleaving
```

The derived image, `ID=1009`, does not render properly on my Mac. Instead of correctly rendering an overlayed alpha image, it just shows all black. The original image, however, renders correctly.

By the way, running `mp4box -info reconstruct.heic` shows
```
# File Meta type: "pict" - 5 resource item(s)
Primary Item - ID 1009
Item #1: ID 1002 type hvc1 size 1440x960 SAR 1/1 3 channels (8 bpc)
Item #2: ID 1005 type hvc1 size 1440x960 SAR 1/1 3 channels (8 bpc)
Item #3: ID 1008 type hvc1 size 1440x960 SAR 1/1 3 channels (8 bpc) Hidden
Item #4: ID 1009 type iovl size 1440x960

File has no movie (moov) - static data container
```
It contains `SAR 1/1 3 channels (8 bpc)` lines the original file info does not have.

Environment:
```
Image viewed on macOS 12.4 Monterey
MP4Box: GPAC version 2.1-DEV-rev232-gfcaa01eb-master
Image extracted and reconstructed on Windows 10 21H2 19044.1766 but I don't think this matters
```
--- end body ---

None