Login| Sign Up| Help| Contact|

Patent Searching and Data


Title:
METADATA SIGNALING AND CONVERSION FOR FILM GRAIN ENCODING
Document Type and Number:
WIPO Patent Application WO/2022/212792
Kind Code:
A1
Abstract:
Methods, systems, and bitstream syntax are described for metadata signaling and conversion for film grain encoding and synthesis. Given a bitstream with MPEG film-grain SEI messaging, for each picture, a processor: detects if the film grain model is suitable for film-grain synthesis using the AV1 autoregressive with additive blending noise model, and then: transcodes the MPEG film grain SEI parameters to corresponding AV1 film grain parameters, synthesizes the film grain, and adds it to the decoded video pictures according to the AV1 specification. An example process for translating AV1 parameters to MPEG film-grain SEI messaging is also provided.

Inventors:
MCCARTHY SEAN THOMAS (US)
YIN PENG (US)
RAMAKRISHNA VIJAYAKUMAR GAYATHRI (US)
CHAMARTHI KISHORE (US)
SHRIPAD PATANKAR KAUSTUBH (US)
Application Number:
PCT/US2022/022958
Publication Date:
October 06, 2022
Filing Date:
March 31, 2022
Export Citation:
Click for automatic bibliography generation   Help
Assignee:
DOLBY LABORATORIES LICENSING CORP (US)
International Classes:
H04N19/70; G06T5/00; H04N19/80; H04N19/85
Foreign References:
US20060133686A12006-06-22
US200162632494P
US198962632107P
IN202141015755A2021-04-02
IN202141029381A2021-06-30
Other References:
TOURAPIS (APPLE) A M ET AL: "Film Grain Synthesis Support in AVC and HEVC", no. JCTVC-AL0022 ; m52579, 7 January 2020 (2020-01-07), XP030224361, Retrieved from the Internet [retrieved on 20200107]
LLACH JOAN, 6 March 2006 (2006-03-06), pages 1 - 18, XP055783627, Retrieved from the Internet [retrieved on 20210309]
"Text of ISO/IEC FDIS 23002-7 Versatile supplemental enhancement information messages for coded video bitstreams", no. n19472, 24 September 2020 (2020-09-24), XP030292977, Retrieved from the Internet [retrieved on 20200924]
HUSAK (DOLBY) W ET AL: "AHG13: Proposed Draft Film Grain Technical Report Text", no. JVET-Y0158, 17 January 2022 (2022-01-17), XP030300536, Retrieved from the Internet [retrieved on 20220117]
Attorney, Agent or Firm:
KONSTANTINIDES, Konstantinos et al. (US)
Download PDF:
Claims:
CLAIMS

What is claimed is:

1. A method to process film grain metadata, the method comprising: receiving an input video bitstream and associated input film grain information according to a first coding format; parsing the input film grain information to generate input film grain parameters for film grain synthesis in the first coding format; generating output film grain parameters for noise synthesis in a second coding format based on the input film grain parameters, wherein the second coding format is different than the first coding format; generating output film noise according to the output film grain parameters; decoding the input video bitstream according to the first coding format to generate decoded video pictures; and adding the output film noise to the decoded video pictures to generate output video pictures.

2. The method of claim 1, wherein the first coding format comprises an MPEG video format, and the second coding format comprises an AVI video format.

3. The method of claim 1, wherein the first coding format comprises an AVI coding format and the second coding format comprises an MPEG video coding format.

4. The method of claim 2, wherein the input film grain information comprises film grain supplemental enhancement information (SEI) and the output film grain parameters are generated only when the input film grain parameters indicate that noise synthesis is generated using an autoregressive model with an additive blending mode.

5. The method of claim 4, wherein the input film grain parameters indicate that the input video bitstream is progressive video in monochrome or 4:2:0 YUV format.

6. The method of claim 4, wherein if first film grain parameters indicate that fg_intensity_interval_upper_bound[ 0 ] [ i ] = fg_intensity_interval_lower_bound[ 0 ] [ i + 1 ] - 1, and fg_intensity_interval_lower_bound[ 0 ][ i + 1 ] = fg_intensity_interval_upper_bound[ 0 ][ i ] + 1, then film_grain_params_present =1, apph grain =1, and update grain = 0, wherein fg intensity interval upper bound and fg intensity interval lower bound denote first film grain parameters, and nim grain params present. apply grain, and update grain denote output film grain parameters.

7. The method of claim 4, further comprising: for a current picture in the input video bitstream, if there is no input film grain information, then: if a fg_characteristics_persistence_flag was set previously to 1, then film_grain_params_present is set to 1, apply grain is set to 1, and update rain is set equal to 0, else film_grain_params_present is set to 0, wherein fg_characteristics_persistence_flag denotes an input film grain parameter and film_grain_params_present , apply _grain, and update grain, denote output film grain parameters.

8. The method of claim 7, further comprising: for a current picture in the input video bitstream, if there is input film grain information, then: if fg_characteristics_cancel_flag is equal to 0, then apply _grain is set to 1 and update_grain is set to 1, else nim grain params present is set to 0 and apply grain is set to 0.

9. The method of claim 3, wherein the input film grain information comprises AVI film grain parameters and the output film grain parameters are generated only if apply grain =1, and update grain = 1, wherein apph grain and update grain denote input film grain parameters.

10. The method of claim 9, wherein if apply _grain =1 and update grain = 1, then fg_characteristics_cancel_flag = 0, fg_model_id = 1, fg sepearate colour description present riag =0, and fg_blending_mode_id = 0, wherein fg_characteristics_cancel_flag, fg_model_id, fg sepearate colour description present riag. and fg blending mode id denote output film grain parameters.

11. A method to synthesize film grain according to the SMPTE RDD-5 specification, wherein the specification is extended to support video coding beyond the AVC (H.264) video coding standard, the method comprising: adding support for one or more of these features:

• applying film grain only to luma pixel values;

• allowing processing at both 8x8 blocks, 16x16 blocks, and 32x32 blocks;

• disabling deblocking filtering; or

• forcing a scale factor of film grain values to be an integer power of two.

12. The method of claim 11, wherein processing an NxN block, wherein N > 8, further comprises: a. calculating an NxN block average of a current block in a decoded frame; b. selecting film-grain parameters for the current block using the NxN block average; and c. selecting a NxN grain block from a database using an offset of the top-left comer of the current block.

13. The method of claim 11, wherein forcing a scale factor of film grain values to be an integer power of two further comprises: replacing calculating g = scale_factor * database[ h ][ v ][ k + k_offset ][ 1 + l_offset ]; fg_block[ k ][ 1 ] = g >> (log2_scale_factor + 6); with fg_block[ k ][ 1 ] = database[ h ][ v ][ k + k_offset ][ 1 + l_offset ] >>

(log2_scale_factor + 6 - x ); wherein x is determined so that the scale factor (scale_factor) = 2X.

14. A non-transitory computer-readable storage medium having stored thereon computer- executable instructions for executing with one or more processors a method in accordance with any one of the claims 1-10.

15. An apparatus comprising a processor and configured to perform any one of the methods recited in claims 1-10.

Description:
METADATA SIGNALING AND CONVERSION FOR FILM GRAIN ENCODING

CROSS-REFERENCE TO RELATED APPLICATIONS

[0001] This application claims priority to US Provisional Application No. 63/249,401, filed September 28, 2021, US Provisional Application No. 63/210,789, filed June 15, 2021, Indian Application No. 202141015755, filed April 02, 2021, and Indian Application No. 202141029381, filed June 30, 2021 all of which are incorporated herein by reference in their entirety

TECHNOLOGY

[0002] The present document relates generally to images. More particularly, an embodiment of the present invention relates to metadata signaling and conversion for film grain encoding and synthesis in images and video sequences.

BACKGROUND

[0003] Film grain is typically defined as a random optical texture in processed photographic film due to the presence of small particles of a metallic silver, or dye clouds, developed from silver halide that have received enough photons. In the entertainment industry, and especially in motion pictures, film grain is considered part of the creative process and intent. Thus, while digital cameras do not generate film grain, it is not uncommon for simulated film grain to be added to captured material from digital video cameras to emulate a “film look.“

[0004] Because of its random nature, film grain poses a challenge to image and video compression algorithms, since a) like random noise, it may reduce the compression efficiency of a coding algorithm used for the coding and distribution of motion pictures, and b) original film grain may be filtered and/or altered due to the lossy compression characteristics of coding algorithms, thus altering the director’s creative intent. Thus, it is important when encoding motion pictures to maintain the director’s intent on the film-look of a movie, but also maintain coding efficiency during compression.

[0005] To handle the film grain more efficiently, coding standards like AVC, HEVC, VVC, AVI, and the like (see Refs. [1-4]) have adopted Film Grain Technology (FGT). FGT in media workflow consists of two major components, film grain modelling and film grain synthesis. At an encoder, film grain is removed from the content, it is modelled according to a film-grain model, and the film grain model parameters are sent in the bitstream as metadata. This part allows for more efficient coding. At a decoder, film grain is simulated according to the model parameters and re-inserted back to the decoded images prior to display, thus preserving creative intent.

[0006] The term “metadata” herein relates to any auxiliary information transmitted as part of the coded bitstream and assists a decoder to render a decoded image. Such metadata may include, but are not limited to, color space or gamut information, reference display parameters, and film grain modeling parameters, as those described herein.

[0007] Film grain technology is not limited to the content which contains the true film grain. By adding artificial film grain, FGT can also be used to hide compression artifact at a decoder, which is very useful for very low bitrate applications, especially for mobile media. As appreciated by the inventors here, improved techniques for metadata signaling for film grain encoding and synthesis are described herein.

[0008] The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in this section. Similarly, issues identified with respect to one or more approaches should not assume to have been recognized in any prior art on the basis of this section, unless otherwise indicated.

BRIEF DESCRIPTION OF THE DRAWINGS

[0009] An embodiment of the present invention is illustrated by way of example, and not in way by limitation, in the figures of the accompanying drawings and in which like reference numerals refer to similar elements and in which:

[00010] FIG. 1A depicts an example end-to-end flow of film grain technology when film grain may be part of the original input video;

[00011] FIG. IB depicts an example end-to-end flow of film grain technology when film grain may not be part of the original input video but is added in a decoder;

[00012] FIG. 2 depicts an example of a process flow to determine if syntax values contained in an MPEG film-grain SEI message may be applied in an AVI film grain synthesis process.

[00013] FIG. 3 depicts an example of a process flow to determine if an MPEG film-grain SEI message should be ignored or transcoded for use in an AVI film grain synthesis process; [00014] FIG. 4 depicts an example of a process flow to transcode an MPEG SEI message for use in an AVI film grain process; [00015] FIG. 5 A and FIG. 5B depict example processes for film grain synthesis using MPEG SEI messaging and AVI film grain synthesis;

[00016] FIG. 6A depicts an example of transcoding MPEG SEI message model values to AVI AR coefficients when AR lag is equal to 1;

[00017] FIG. 6B depicts an example of transcoding MPEG SEI message model values to AVI AR coefficients when AR lag is equal to 2; and

[00018] FIG. 7A and FIG. 7B each depict an example of transcoding AVI AR coefficients to MPEG SEI message model values when AR lag is equal to 1.

DESCRIPTION OF EXAMPLE EMBODIMENTS

[00019] Example embodiments that relate to metadata signaling and conversion for film grain encoding are described herein. In the following description, for the purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the various embodiments of present invention. It will be apparent, however, that the various embodiments of the present invention may be practiced without these specific details. In other instances, well-known structures and devices are not described in exhaustive detail, in order to avoid unnecessarily occluding, obscuring, or obfuscating embodiments of the present invention.

SUMMARY

[00020] Example embodiments described herein relate to metadata signaling and conversion for film grain technology. In an embodiment, a processor receives an input video bitstream and associated input film grain information according to a first coding format. The processor parses the input film grain information to generate input film grain parameters for film grain synthesis in the first coding format. Next, it generates output film grain parameters for noise synthesis in a second coding format based on the input film grain parameters, wherein the second coding format is different than the first coding format. The processor generates output film noise according to the output film grain parameters and decodes the input video bitstream according to the first coding format to generate decoded video pictures. Finally, the processor adds the output film noise to the decoded video pictures to generate output video pictures.

FILM GRAIN DATA FLOW PROCESS [00021] In reference to existing coding standards, in AVC, HEVC and VVC (Refs. [1-3] and Ref. [6]) (collectively to be referred to as MPEG or MPEG video standards), film-grain model parameters are carried in a film-grain specific supplemental enhancement information (SEI) message. SEI messaging, including film-grain SEI messaging, is not normative. In SMPTE-RDD-5-2006 (Ref. [5]), the Film Grain Technology Decoder Specification, specifies bit-accurate film grain simulation. In AVI (Ref. [4]), film-grain model parameters are carried as part of the “Film grain params syntax” section in the bitstream. Unlike the MPEG standards, film grain synthesis in AVI is normative.

[00022] FIG. 1A depicts an example end-to-end flow (100 A) of film grain technology when film grain may be part of the original input video. As depicted in FIG. 1A, during the encoding process (80), given an input video sequence (102), a film-grain-removal step (105) analyzes the video and applies denoising or other filtering techniques known in the art to reduce or remove film grain and generate a film-grain-free video (107). Subsequently, the film-grain-free video is encoded by encoder 110 (e.g., using AVC, HEVC, AVI, and the like). In parallel, an estimate of the film grain noise (109) (e.g., as extracted by the input video 102) is processed by film grain modeling process 120 to generate parameters which according to a film-grain model can be used by the decoding process (90) to reproduce a close approximation of the original film grain. These parameters are embedded as metadata (122) in the encoded bitstream (112). The metadata can be part of the bitstream syntax or part of supplemental information (e.g., SEI messaging and the like).

[00023] During the decoding process (90), a video decoder (130) (e.g., an AVC, HEVC, AVI, and the like decoder) receives the coded bitstream (112) and the corresponding film- grain metadata (122), to generate a decoded video bitstream (132) and FG parameters (134), typically the same as the parameters generated in step 120 in the encoding process. A film- grain synthesis process 140 applies those FG parameters to generate synthetic film grain (142), which, when added to the decoded video film-grain-free video (132), generates the output video (152), which is a close approximation of the input video (102).

[00024] FIG. IB depicts an example end-to-end flow (100B) of film grain technology when film grain may not be part of the original input video, but it may be added during the decoding process. As depicted in FIG. IB, during encoding (95), given an input video sequence (102), which may be free of film grain, a content analysis step (160) may take into consideration the input characteristics and the encoder (110) coding characteristics to decide on what type of synthetic film-grain noise, when added on the decoded video, may improve video quality or emulate a “film look.” The output of this analysis is a set of film-grain model parameters which can be embedded into the coding bitstream (112) as metadata (122). These metadata can be part of the bitstream syntax or part of supplemental information (e.g., SEI messaging and the like).

[00025] The decoding process (90) in process 100B is identical to the one as in process 100A. After decoding the coded bitstream (112), a film-grain synthesis process (140) applies the extracted FG parameters to generate synthetic film grain (142), which, when added to the decoded film-grain-free video (132) generates the output video 152, which is a close approximation of the input video (102).

MPEG Film Grain Metadata

[00026] In AVC, HEVC, and VVC (Refs. [1-3] and Ref. [6]), collectively, for ease of discussion, to be referred to as MPEG or as MPEG video, the film grain model parameters are part of the syntax related to film grain characteristics (FGC) or film-grain (FG) SEI messaging. Film Grain Synthesis (FGS) is primarily characterized by the following set of parameters:

- A film grain model: comprising a frequency filtering model or an auto-regression (AR) model

- Blending mode: comprising an additive mode or a multiplicative mode

- Intensity intervals: comprising lower and upper bounds for each of the intervals

- Component model values: syntax parameters which define the characteristics of the method used in a particular grain model.

As an example, Table 1 captures some of the key parameters supported in FGC SEI for AVC. In VVC SEI (Ref. [6]), these parameters may be referred to with slightly different names, e.g., fg_model_id, fg_separate_colour_description_present_flag, fg_blending_mode_id, and the like.

Table 1 Film Grain Characteristic in MPEG SEI parameters where

Range_0: [0,limit_model_0] for nim_grain_model_id=():

Range l: [-limit model l, limit model l -1 ] for nim_grain_model_id=l : Note: for HEVC and VVC, film_grain_characteristics_repetition_period is replaced by fg_characteristics_persistence_flag which uses u(l) encoding (unsigned integer of 1 bit).

[00027] MPEG video SEI messaging supports two models: a frequency filtering model and an auto-regression (AR) model. No bit-accurate FG synthesis process has been specified in the AVC, HEVC and VVC specifications. For the frequency filtering model, the SMPTE- RDD-5-2006 document (to also be referred as RDD-5) “Film Grain Technology - Specifications for H.264 | MPEG-4 AVC Bit streams” (Ref. [5]) specifies a bit-accurate process for film grain simulation. Table 2 depicts the FGC parameters being used in Ref. [5] and their supported range.

[00028]

Table 2: Film grain characteristic constraints in SMPTE RDD-5

[00029] FGC parameters are additionally constrained when used in Ref. [5], as follows:

• intensity _interval_lower_bound[ c ][ i ] and intensity _interval_upper_bound[ c ][ i ]. For all c and for any intensity value v, there shall be at most one intensity interval i that verifies intensity _interval_lower_bound[ c ][ i ] <= v and intensity _interval_upper_bound[ c ][ i ] >= v

• Combining all the color components c and intensity intervals i in an SEI message, the number of different pairs (comp_model_value[ c ][ i ][ 1 ], comp_model_value[ c ][ i ][ 2 ]) shall be equal or smaller than 10.

• The film grain simulation method shall only be used on progressive content

[00030] These constraints are interpreted as follows:

The film synthesis method is applied only on progressive content. The film grain model uses frequency filtering with additive blending mode

The process restricts the value num model values minusl [ c ] to a max of 2, which does not allow band-pass filtering and cross-color correlation.

Multi-generational film grain is not supported. The intensity intervals do not overlap thus only one intensity interval is allowed for each sample (the interval is determined from the average at 8x8 block level).

For all color components c and intensity intervals i in an SEI message, the number of different pairs (comp_model_value[ c ][ i ][ 1 ], comp_model_value[ c ][ i ][ 2 ]) should be less than or equal to 10.

Successive IDR frames shall not have the same idr _picjd and any two IDR frames which are 32 or fewer frames apart (in decoding order) shall not have the same idr _picjd.

Film grain simulation shall be performed on the decoded frame, before applying cropping.

The simulation process is defined for 4:2:0 chroma format, 8-bit depth.

Note: recent updates to AVC, HEVC, and VVC specifications extended FGC to support bit depth larger than 8 bits. In principle, the same procedure could be applied to RDD-5 as well.

[00031] The film grain synthesis in RDD-5 contains two major steps: o Creation of a film grain pattern data base o Film grain simulation

A database for all combinations of horizontal and vertical cut frequencies h and v in range 0 to 12 (total of 169 patterns) is created using a look up table and pseudo random values.

For all 8x8 blocks in each color component, the block average is computed and compared with intensity intervals to select the film grain component values to be used for the 8x8 block. If the average does not fall into any bounds, then no simulation will be performed.

A 3 -tap deblocking filter is applied to the vertical boundaries of 8x8 blocks to reduce the degree of visible blocks.

AVI Film Grain Technology [00032] Film grain synthesis in AVI is a normative process and uses an auto regression (AR) model for the simulation of noise and an additive blend mode for adding the noise to the decoded source samples. The synthesis process is primarily controlled by grain pattern and grain intensity.

[00033] AVI determines the FG process in the following steps: a) a random number generation process, b) a grain generation process, c) a scaling lookup initialization process, and d) an adding noise synthesis process.

[00034] Comparing the two film grain synthesis models, MPEG video SEI supports the AR film model by setting film grain model id to 1 and supports additive blend mode by setting blending mode id to 0. The major FGS differences between the MPEG video SEI AR model and the AVI AR model are as follows:

• The MPEG video SEI AR model works at the frame level with dependencies on previous synthesized grains. The AVI AR model use stripes, which are 32xW size which are formed from Luma grain of size 82x73.

• The MPEG video SEI AR model can use higher number of neighbours compared to AVI

• For chroma grain dependency on Luma, a. For the MPEG video SEI AR model, chroma grain synthesis can be dependent on luma and chroma, which are controlled by component model value b. For the AVI FGS model, grain synthesis is independent. Blending of noise on chroma can have dependency on the intensity of decoded luminance

Transcoding of film-grain metadata

[00035] Given that decoding devices may have already hardware accelerators to enable film-grain synthesis for either AVI or MPEG video content (e.g., AVC, HEVC, and VVC), and given that film grain metadata may be generated regardless of the video coding technology, as appreciated by the inventors, transcoding between MPEG and AVI film-grain metadata may allow users a richer user experience, using existing content. Furthermore, proposed embodiments allow the existing MPEG film-grain (FG) SEI messaging syntax to be used as is to allow decoders to apply the AVI film-grain synthesis on MPEG-decoded video. MPEG to AV 1 conversion of film grain parameters

[00036] FIG. 2 depicts an example of a process flow (200) to determine if syntax values contained in an MPEG SEI message may be applied in an AVI film grain synthesis process. In an embodiment, when all of the following constraints apply, the variable FGC2AVlenableFlag shall be set equal to 1, indicating that MPEG SEI messaging can be used to generate film grain noise according to the AVI specification, otherwise FGC2AVlenableFlag shall be set to 0: fg_model_id shall equal 1 (autoregressive). fg blending mode id shall equal 0 (additive). fg_separate_colour_description_present_flag shall equal 0.

- ChromaFormatldc shall be less than 2 (monochrome or YUV 4:2:0 only).

The value of fg_intensity_interval_upper_bound[ 0 ] [ i ] shall be equal to fg_intensity_interval_lower_bound[ 0 ][ i + 1 ] - 1 and the value of fg_intensity_interval_lower_bound[ 0 ][ i + 1 ] shall be equal to fg_intensity_interval_upper_bound[ 0 ][ i ] + 1, which is consistent with representation of intensity intervals using a piecewise continuous model. (Note that this constraint also disallows multi-generational film grain synthesis) fg_characteristics_cancel_flag = 0; assuming there is no persistence from prior FG messaging, the flag indicates that new FG parameters are present

The content for which the MPEG SEI applies is progressive.

When FGC2AVlenableFlag is equal to 1, the syntax values contained in the MPEG SEI message may be used in an AVI film grain synthesis process. When FGC2AVlenableFlag is equal to 0 the syntax values contained in the MPEG SEI message should not be used in an AVI film grain synthesis process.

[00037] FIG. 3 depicts an example of a process flow to determine if an MPEG SEI message related to film grain should be ignored or transcoded for use in an AVI film grain process.

If, as depicted in FIG. 2, it is determined that FGC2AVlenableFlag = 0, then (step 305), the decoder will not apply any AVI film synthesis and may apply film-grain according to the MPEG video specification. When FGC2AVlenableFlag is equal to 1 and the MPEG SEI message is intended to be used in an AVI film grain synthesis process, in an embodiment, the following constraints may apply for the values of the AVI film grain params syntax elements:

1) if MPEG FG SEI for the current picture is not present ( path 310),

(step 320) if fg_characteristics_persistence_flag in previous MPEG SEI is equal to 1, then (step 325): film_grain_params_present shall be equal to 1, apply _grain shall be equal to 1, update grain shall be equal to 0, grain_seed shall be set to the same value of the previous MPEG FG SEI .

Otherwise (330) (if fg_characteristics_persistence_flag in a previous MPEG SEI is equal to 0), film_grain_params_present shall be equal to 0

2) otherwise (if MPEG FG SEI for current picture is present), then, in step 400, the MPEF

FG SEI parameters may be transcoded to AVI FG parameters as follows (see also FIG.

4):

When fg_characteristics_cancel_flag is equal to 1, then (405): the film_grain_params_present flag shall be equal to 0 and apply grain shall be equal to 0 else (402), if fg_characteristics_cancel_flag is equal to 0, then

(407) apply grain shall be equal to 1 and update grain shall be equal to 1.

(407) num_y joints shall be equal to a value consistent with fg_num_intensity_intervals_minusl[ 0 ]+l (i.e., the number of points in the piecewise continuous model shall be sufficient to support fg_intensity_interval_lower_bound[ 0 ][ i ] and fg_intensity_interval_upper_bound[ 0 ][ i ])

(407) chroma scaling from luma shall be equal to 0 and ar_coeff_lag = ceil(fg_num_model_values_minusl[0] ÷ 4 )

_ (410) grain seed shall be set to an unsigned 16-bit value. In one embodiment, grain_seed value can be set as in the section “1.5.2.1 Seed initialization” in SMPTE RDD-5 for the luma component. (415) grain_scaling_minus_8 shall be equal to a value consistent with fg_log2_scale_factor. For example, in an embodiment, fg_log2_scale_factor = grain_scaling_minus_8 + 8.

[00038] Thus, given the two MPEG SEI flags: fg_characteristics_cancel_flag and fg_characteristics_persistence_flag, the following data flow in pseudo code summarizes the proposed actions according to an embodiment: if film-grain SEI messaging is present { if (fg_characteristics_cancel_flag = = 0), then proceed with FG process; else { fg_characteristics_persistence_flag = 0; there is no film-grain process;

}

} else { if (fg_characteristics_persistence_flag = =1), then proceed with FG process; else there is no film-grain process;

}

[00039] In addition, one can set the overlap_flag equal to 0 or 1, to either disallow or allow spatial overlapping between film grain blocks. Because this value is signaled in the bitstream in AVI, unless it can also be signaled through the MPEG FG SEI messaging, for improved video quality, a default value of 1 is suggested. The AR model parameters can be mapped in a variety of ways. In one embodiment, the mapping may be indicated as follows: a) Using ar_coeff_lag = ceil(fg_num_model_values_minusl[0] ÷ 4 ), the value of ar coeff lag parameter may be as indicated as in Table 3.

Table 3: ar coeff lag values derived from fg num model values minus 1 [01 b) (430) The value of ar_coeff_y_plus_128[ pos ] shall be as indicated in Table 4, when ar_coeff_lag is equal to 1, and Table 5, when ar_coeff_lag is equal to 2. Table 4 - ar_coeff_y_plus_128[ pos ] derived from fg_comp_model_value[ 0 ][ i ][ j ] when ar coeff lag is equal to 1

Table 5 - ar_coeff_y_plus_128[ pos ] derived from fg_comp_model_value[ 0 ][ i ][ j ] when ar coeff lag is equal to 2 c) (425) ar_coeff_shift_minus_6 shall be equal to a value consistent with the range for auto regressive coefficients indicated by fg_comp_model_value[ 0 ][ i ][ j ] and fg_log2_scale_factor. d) (420) grain_scale_shift shall be equal to a value consistent with fg_comp_model_value[ 0 ][ i ][ 0 ] e) set overlap_flag to 0 or 1 (1 should provide better quality)

1) (435) when film grain is applied to narrow range content, clip_to_restricted_range should be equal to 1, otherwise it to should be set to 0.

[00040] FIG. 5A depicts an alternative example process (500A) for film grain synthesis using MPEG SEI messaging and AVI film grain synthesis. Given a sequence of pictures (502), in step 504, a decoder may check whether the current picture has associated film-gram (FG) SEI messaging. If there is no such messaging, then (path 505), ignoring for now the status of any persistence flags, there is no film grain to be added and the decoder moves to the next picture. Otherwise, the decoder moves to step 510 to parse the MPEG SEI messaging.

[00041] In step 515, the decoder needs to decide whether the provided SEI messaging can be used to perform FG synthesis using AVI film synthesis, and in particular, using the AR, additive, model. For example, process 200 (in FIG. 2) may be used to detect whether the value of FGC2AVlenableFlag = 1. If the model being used is different, then parsing and transcoding of the MPEG FG SEI parameters is done through “other process” (520) which is outside the scope of the current disclosure. For example, in one embodiment, process 520 may simply be “do nothing” or “apply the MPEG film-grain synthesis” process.

[00042] Next, in step 525, one needs to set up the parameters for the AVI AR model, such as the value of shifts, the AR coefficients, and the like. For the shift operation, AVI has three related parameters: grain_scaling_minus_8 , ar_coeff_shift_minus_6 and grain_scale_shift.

In MPEG FG, there is only one parameter fg_log2_scale_factor (in AVC, also referred to as log2_scale_factor). In an embodiment, fg_log2_scale_factor is set equal to grain_scaling_minus_8 + 8, grain_scale_shift is set equal to 0, and ar_coeff_shift_minus_6 is set to a constant value among (0, 1, 2, 3). For example, one can set ar_coeff_shift_minus_6 equal to 2.

[00043] For the MPEG AR model parameters, fg_comp_model_value[ c ][ i ][ 0 ] models the variance or standard deviation of film grain noise. In an embodiment, one can use it to generate the ScalingLUT table or map to point_y/cb/cr values, described in step 540. The ScalingLUT is generated by having the constant value within an intensity interval instead of linear interpolation. ScalingLUT is generated as follows:

The variable NumPointsfcIdx] for cldx=0..2 is set as following: if fg_comp_model_present_flag[ cldx ] is equal to 0, NumPointsfcIdx] is set to 0.

Otherwise (fg_comp_model_present_flag [ cldx ] is not equal to 0),

NumPointsl cldx ] is set to equal to fg_num_intensity_intervals_minusl[ cldx ] + 1.

AVI syntax num_y joints is set equal to NumPoints[0], AVI syntax num_cb_points is set equal to NumPointsfl], and AVI syntax num_cr_points is set equal to NumPoints[2]. if ( NumPointsl cldx ] == 0 ) { for ( x = 0; x < 256; x++ ) ScalingLut[cIdx][ x ] = 0

} else { for ( x = 0; x < fg_intensity_interval_lower_bound[ c ][ 0 ] [ 0 ]; x++ ) ScalingLut[cIdx][ x ] = 0 for ( i = 0; i < = fg num intensity intervals minusl [ c ]; i++ ) { dX = fg_intensity_interval_upper_bound[ cldx ] [ i ] - fg_intensity_interval_lower_bound[ cldx ][ i ] for ( x = 0; x < dX; x++ )

ScalingLut[cIdx][ fg_intensity_interval_lower_bound[ cldx ] [ i ] + x ] = fg_comp_model_value[ c ][ i ][ 0 ]

} for ( x = fg_intensity_interval_upper_bound[ cldx ][ fg num intensity intervals minus 1 [ c ] ]; x < 256; x++ )

ScalingLut[cIdx][ x ] = 0

}

[00044] To obtain values of the scaling function, the following procedure is invoked with the color plane index cldx and the input value pointVal as inputs. The output is the value of the scaling function pointScal. scaleLut(ddx, pointVal) { if ( BitDepth == 8) pointScal = ScalingLut[cIdx][ pointVal ] else x = Clip3( 0, 255,

( pointVal + ( 1 « ( BitDepth - 9 ) ) ) » ( BitDepth | c ] - 8 ) ) pointScal = ScalingLut[cIdx][x]

[00045] When ar_coeff_lag is set equal to 2, fg_comp_model_value[ c ][ i ][ j ], j=l, 2, 3, 4, 5, are set as follows: fg_comp_model_value[ c ] [ i ] [ 2 ] shall be equal to 0 for c = 0...2 and i =

0... fg num intensity intervals minusl [ c ] fg_comp_model_value[ c ][ i ][ 1 ] shall be equal to an ar (AR) value, denoted as ar valuel [c], for c = 0...2 and i = 0... fg num intensity intervals minusl [ c ] fg_comp_model_value[ c ][ i ][ 3 ] shall be equal to an ar value, denoted as ar_value3[c], for c = 0...2 and i = 0... fg num intensity intervals minusl [ c ] fg_comp_model_value[ c ] [ i ] [ 4 ] shall be equal to an ar value, denoted as ar_value4[c], for c = 0...2 and i = 0... fg num intensity intervals minusl [ c ] fg_comp_model_value[ c ][ i ][ 5 ] shall be equal to an ar value, denoted as ar_value5[c], for c = 0...2 and i = 0... fg num intensity intervals minusl [ c ]

The variable numPos[cIdx] is set as the follows:

If cldx = 0, numPos[cIdx] = 2 * ar coeff lag * (ar_coeff_lag+l)

Otherwise (cldx != 0), numPosfcIdx] = numPos[0] + 1

[00046] The array aRCoeffs[cIdx] [ pos ], for pos = 0... numPos[cIdx] - 1 is set equal to 0, except the following. aRCoeffs[cIdx] [ 2 ] is set equal to ( ((ar_value5[cldx] * ar_value4[cldx] * ar_value4[cldx])« aRCoeffShift) + (l«(ScalingShift+l)) » (3*ScalingShift) aRCoeffs[cIdx] [ 6 ] is set equal to (((ar_value3[cldx] * ar_value4[cldx])« aRCoeffShift) + (1 « ScalingShift)) » (2*ScalingShift) aRCoeffs[cIdx] [ 7 ] is set equal to (((ar_valuel[cldx] * ar_value4[cldx])« aRCoeffShift) + (1 « ScalingShift)) » (2*ScalingShift) aRCoeffs[cIdx] [ 8 ] is set equal to ((ar_value3[cldx]« aRCoeffShift) + (1 « (ScalingShift- 1))) » ScalingShift aRCoeffs[cIdx] [ 10 ] is set equal to ((ar_value5[cldx]« aRCoeffShift) + (1 « (ScalingShift- 1))) » ScalingShift aRCoeffs[cIdx] [ 11 ] is set equal to ((ar_valuel[cldx]« aRCoeffShift) + (1 « (ScalingShift- 1))) » ScalingShift

The aRCoeffs are used to generate grain template in step 535.

[00047] In AVI, the variable grain_seed (also to be referred to as GrainSeed) specifies the starting value for the pseudo-random number generator used in film grain synthesis. In particular, GrainSeed contains the value used to initialize a 16-bit variable RandomRegister. Without limitation, the GrainSeed generation step (530) may follows section “1.5.2.1 Seed initialization” in SMPTE RDD-5 for the luma component. An example implementation is also provided in “Section 8.5.3.2” in Appendix 1.

[00048] In SMPTE RDD-5, the seed is generated based on the variables PicOrderCnt and idr_pic_id for IDR frame (frames that can be decoded without reference to other frames). In AVC, idr_pic_id can be read from the slice header, and successive IDR frames should not have the same idr_pic_id. Additionally, any two IDR frames that are 32 or fewer frames apart (in decoding order) should not have the same idr_pic_id. This is to avoid film grain repetition in temporally -adjacent frames. However, this syntax does not exist in HEVC or VVC. In an embodiment, one may define a new “idr_pic_id”-like variable (herein named for convenience and with no limitation idr_pic_id), which can be updated by setting idr_pic_id=0 initially and increasing idr_pic_id by 1 for every IRAP picture. A potential shortcoming of this approach is that for trick modes (e.g., fast forwarding and the like) such an idr_pic_id variable will lose proper synchronization and may have invalid values. In another embodiment, it is proposed not to use the idr_pic_id information. For example, it is suggested to put constraints to the PicOrderCnt value. For example, PicOrderCnt value can have the following constraints: 1) successive IRAP frames shall not have the same PicOrderCnt value, and 2) any two IRAP frames which are 32 or fewer frames apart (in decoding order) shall not have the same PicOrderCnt value. This approach could be applied to future revisions of SMPTE-RDD-5 to support HEVC and VVC.

[00049] The film grain synthesis process can be described as follows. Given AR coefficients and a Gaussian sequence, a film grain template is generated first (530). With a pseudo-random generator, the decoder generates offsets for a 32x32 block (or +2 additional row/columns when overlap is used) inside the film grain template. The pseudo-random generator is initialized in the beginning of each row of 32x32 blocks to allow parallel row processing. The generator is initialized based on a GrainSeed element. The 32x32 block of the film grain is scaled, and added to the reconstructed samples, and then clipping is applied (545). For 4:2:0, the block size for chroma components is half of the luma block size horizontally and vertically. For more details, one is referred to the proposed example operations provided in Appendix 1 in “Section 8.5.3.3.”

[00050] Following step 535, as in AVI, the process continues with initializing a scaling look-up table (LUT) in step 540 and adding the noise to the current decoded picture (step 545).

[00051] In summary, the process of applying AVI FGS process using the MPEG SEI AR model is as follows: • At the encoder, develop the model and appropriate syntax to transmit using the MPEG video SEI messaging for film grain synthesis.

• At the decoder, map the MPEG FG SEI parameters to corresponding AVI FG parameters, and follow the proposed film-grain synthesis process (500)

[00052] FIG. 5B depicts an alternative example process (500B) for film grain synthesis using MPEG SEI messaging and AVI film grain synthesis. Compared to process 500 A, both have identical film-noise synthesis and film-noise addition steps 525, 530, 535, 540, and 545, as described earlier. Assuming AR modeling with additive blending is enabled, process 500B provides some additional processing details on how the computed AR parameters can be updated as needed. For example, after step 504, if there is no FG SEI messaging, process 500B includes two additional steps: 560 and 565. In step 560, a decoder may check whether film-grain processing was previously available (e.g., by checking the FG persistence flag). If no such processing was available, process follows path 505 as before. If yes, then in step 565 the decoder may retrieve the previously generated AVI film-grain parameters and move to step 525.

[00053] Process 500B includes also the additional steps 570 and 575. In step 570, the decoder checks the value of fg_characteristics_cancel_flag. If it is set to zero, then the remaining FG SEI message is parsed and new film-synthesis parameters are generated to proceed with step 525. Otherwise, in step 575, the stored AR parameters are cleared and the film-grain synthesis and addition process is skipped.

[00054] FIG. 6A depicts an example of transcoding MPEG SEI message model values to AVI AR coefficients when AR lag is equal to 1.

[00055] FIG. 6B depicts an example of transcoding MPEG SEI message model values to AVI AR coefficients when AR lag is equal to 2.

AV 1 to MPEG conversion of film grain parameters

[00056] For greater interoperability, in some embodiments, it may be desirable to translate AVI film-grain parameter to MPEG FG SEI parameters. For example, a content creator may want to take advantage of existing film-grain synthesis hardware or they may want to allow users to experience a similar film look regardless of whether they view MPEG- or AV1- compressed content. As before, one may establish a flag (e.g., denoted as AV12FGCenableFlag), which when all of the following constraints apply, the flag AV12FGCenableFlag shall be set equal to 1, otherwise AV12FGCenableFlag shall be set to 0. When AV12FGCenableFlag is equal to 1, the AVI film grain model parameter values may be signaled in an MPEG FG SEI message. When AV12FGCenableFlag is equal to 0, the AVI film grain model parameter values should not be signaled in an MPEG SEI message chroma scaling from luma shall equal 0 ar_coeff_lag shall be less than 3 fg_separate_colour_description_present_flag shall equal 0

- ChromaFormatldc shall be less than 2 (monochrome or YUV 4:2:0 only)

The content for which the MPEG SEI applies is progressive

[00057] When AV12FGCenableFlag is equal to 1 and the AVI film grain model parameters are signaled in an MPEG SEI message, the following constraints apply for the values of the MPEG SEI syntax elements:

When apply grain is equal to 1 and update grain is equal to 1, the value of fg characteristics cancel flag shall be equal to 0. Otherwise, when apply _grain is equal to 0, fg_characteristics_cancel_flag shall be equal to 0 fg model id shall equal 1 fg_sepearate_colour_description_present_flag shall equal 0 fg blending mode id shall equal 0 fg_log2_scale_factor shall be equal to a value consistent with grain_scaling_minus_8 fg num intensity intervals minusl shall be equal to num_y joints [ 0 ] - 1

When ar_coeff_lag is equal to 0, fg_num_model_values_minusl[ 0 ] shall equal 0. Otherwise, when ar coeff lag is equal to 2, fg_num_model_values_minusl[ 0 ] shall equal 5. Otherwise, ar coeff lag is equal to 1, fg_num_model_values_minusl[ 0 ] shall be greater than 0 and less than 5

[00058] By way of example, the value of fg_comp_model_value[ 0 ][ i ][ j ] may be determined from ar_coeff_y_plus_128[ pos ], when present, as indicated in Table 6 for the case in which ar_coeff_lag is equal to 1, and Table 7 for the case in which ar_coeff_lag is equal to 2. Table 6 - fg comp model value[ 0 ][ i ][ j ] derived from ar_coeff_y_plus_128[ pos ] when ar coeff lag is equal to 1

Table 7 - fg comp model value[ 0 ][ i ][ j ] derived from ar_coeff_y_plus_128[ pos ] when ar coeff lag is equal to 2

[00059] FIG. 7A and FIG. 7B each depict an example of transcoding AVI AR coefficients to MPEG SEI message model values when AR lag is equal to 1.

Extending RDD-5 to HEVC and VVC

[00060] As discussed earlier, RDD-5 (Ref. [5]) provides a bit-accurate technology implementation of film-grain technology for AVC (H.264). This section provides some recommendations for an updated version of RDD-5 as it may apply to HEVC and VVC.

Some of the recommendations have already been discussed earlier, thus their details may be omitted from this section. Appendix 2 of this document provides an example of proposed amendments to the RDD-5 frequency model in MPEG film-grain synthesis for HEVC and VVC.

[00061] As appreciated by the inventors, future versions of RDD-5 should consider at least the following: a) In addition to supporting the frequency filtering model, also to support the autoregressive film grain model, as described earlier b) Apply film grain only to luma pixels. This helps reduce complexity and improves visual quality c) Extend grain simulation and deblocking to 16 x 16 blocks or higher, depending on the input resolution. This assists in reducing complexity for high-resolution content.

For example, modifying the process to support 16x16 blocks may include: a. Calculating an average value of the pixels of a current 16x16 block in a decoded frame b. Using the average value to select grain model parameters for the current block c. Selecting a 16x16 grain block from a database using an offset of the top-left comer of the current 16x16 block in the decoded frame d) Force the scale factor, now defined as any integer value in [0, 255], to be a power of 2, and limit its maximum value to 128.

Equation (1.6) in RDD-5 now reads for( k = 0; k < 8; k++) for( 1 = 0; 1 < 8; 1++) { g = scale_factor * database[ h ][ v ][ k + k_offset ][ 1 + l_offset ] fg_block[ k ][ 1 ] = g >> (log2_scale_factor + 6)

}

In an embodiment, a power of two scale factor, e.g., scale_factor = 2 X , can be determined by rounding the value of comp_model_value[ c ][ s ][ 0 ], as illustrated below g = comp_model_value[ c ][ s ][ 0] * database[ h ][ v ][ k + k_offset ][ 1 + l_offset] fg_block[ k ][ 1 ] = g >> (log2_scale_factor + 6)

If 2 X is closest to comp_model_value[ c ][ s ][ 0] , then the above set of equations reduce to fg_block[ k ][ 1 ] = database[ h ][ v ][ k + k_offset ][ 1 + l_offset ] >>

(log2_scale_factor + 6 - x ) e) Disable deblocking. The deblocking process can introduce dependencies, hence it may not be friendly in multi -processing architectures (e.g., SIMD). Experimental results have demonstrated that disabling deblocking has minimal effect on perceived visual quality. In an embodiment, deblocking may be enabled only for very low or very high cut-off frequencies

[00062] As appreciated by the inventors, among the places where SMPTE RDD-5 needs to be generalized to support blockAvgSize greater than 8x8 include the routines for:

1) Refinement of the grain pattern database

2) Selection of intensity interval

3) Determination of grain block offsets

4) Determination of grain pattern from grain blocks; and

5) Deblocking of grain pattern at vertical boundaries of grain blocks

Example code of those modifications, without limitation, is listed in Appendix 3. While Appendix 3 discusses an example implementation using a 13x13x64x64 film grain database, it is appreciated that people skilled in the art may use smaller or larger databases, depending on memory limitations.

References

Each one of the references listed herein is incorporated by reference in its entirety.

[1] Advanced Video Coding , Rec. ITU-T H.264, May 2019, ITU.

[2] High Efficiency Video Coding, Rec. ITU-T H.265, November 2019, ITU.

[3] Versatile Video Coding, Rec. ITU-T H.266, August 2020, ITU.

[4] AVI Bitstream and Decoding Process Specification, by P. de Rivaz et ak, Version 1.0.0 with Errata, 2019-01-08.

[5] RDD 5-2006 - SMPTE Registered Disclosure Doc - Film Grain Technology Specifications for H.264 \ MPEG-4 AVC Bitstreams, Mar. 2006, SMPTE.

[6] Versatile supplemental enhancement information messages for coded video bitstreams,

Rec. ITU-T H.274, Aug. 2020, ITU.

EXAMPLE COMPUTER SYSTEM IMPLEMENTATION [00063] Embodiments of the present invention may be implemented with a computer system, systems configured in electronic circuitry and components, an integrated circuit (IC) device such as a microcontroller, a field programmable gate array (FPGA), or another configurable or programmable logic device (PLD), a discrete time or digital signal processor (DSP), an application specific IC (ASIC), and/or apparatus that includes one or more of such systems, devices or components. The computer and/or IC may perform, control, or execute instructions relating to film-grain metadata signaling and conversion in image and video coding, such as those described herein. The computer and/or IC may compute any of a variety of parameters or values that relate to film-grain metadata signaling and conversion in image and video coding described herein. The image and video embodiments may be implemented in hardware, software, firmware and various combinations thereof.

[00064] Certain implementations of the invention comprise computer processors which execute software instructions which cause the processors to perform a method of the invention. For example, one or more processors in a display, an encoder, a set top box, a transcoder, or the like may implement methods related to film-grain metadata signaling and conversion in image and video coding as described above by executing software instructions in a program memory accessible to the processors. Embodiments of the invention may also be provided in the form of a program product. The program product may comprise any non- transitory and tangible medium which carries a set of computer-readable signals comprising instructions which, when executed by a data processor, cause the data processor to execute a method of the invention. Program products according to the invention may be in any of a wide variety of non-transitory and tangible forms. The program product may comprise, for example, physical media such as magnetic data storage media including floppy diskettes, hard disk drives, optical data storage media including CD ROMs, DVDs, electronic data storage media including ROMs, flash RAM, or the like. The computer-readable signals on the program product may optionally be compressed or encrypted.

Where a component (e.g. a software module, processor, assembly, device, circuit, etc.) is referred to above, unless otherwise indicated, reference to that component (including a reference to a "means") should be interpreted as including as equivalents of that component any component which performs the function of the described component (e.g., that is functionally equivalent), including components which are not structurally equivalent to the disclosed structure which performs the function in the illustrated example embodiments of the invention.

EQUIVALENTS, EXTENSIONS, ALTERNATIVES AND MISCELLANEOUS [00065] Example embodiments that relate to film-grain metadata signaling and conversion in image and video coding are thus described. In the foregoing specification, embodiments of the present invention have been described with reference to numerous specific details that may vary from implementation to implementation. Thus, the sole and exclusive indicator of what is the invention, and what is intended by the applicants to be the invention, is the set of claims that issue from this application, in the specific form in which such claims issue, including any subsequent correction. Any definitions expressly set forth herein for terms contained in such claims shall govern the meaning of such terms as used in the claims. Hence, no limitation, element, property, feature, advantage or attribute that is not expressly recited in a claim should limit the scope of such claim in any way. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.

Appendix 1

Example addendum to Section 8.5, Film grain characteristics SEI message, of VVC SEI messaging (Ref. [6]) to support film grain synthesis during MPEG decoding according to the AVI specification.

8.5.3 Film grain synthesis process for AR model with additive blending mode

The process requires the definition of the following variables:

A picture width and picture height in units of luma samples, denoted herein by PicWidthlnLumaSamples and PicHeightlnLumaSamples, respectively.

A chroma format indicator, denoted herein by ChromaFormatldc, as described in clause Error! Reference source not found..

A bit depth for the samples of the luma component, denoted herein by BitDepthY, and when ChromaFormatldc is not equal to 0, a bit depth for the samples of the two associated chroma components, denoted herein by BitDepthC. BitDepthY is set equal to BitDepthC, and is denoted as BitDepth.

The process requires the further constraint of the following variables: fg_model_id shall be equal to 1 (autoregressive) fg blending mode id shall equal to 0 (additive). fg_separate_colour_description_present_flag shall be equal to 0.

ChromaFormatldc shall be less than 2 (monochrome when ChromaFormatldc is equal to 0 or YUV 4:2:0 when ChromaFormatldc is equal to 1).

The value of fg_intensity_interval_upper_bound[ 0 ] [ i ] shall be equal to fg_intensity_interval_lower_bound[ 0 ][ i + 1 ] - 1 and the value of fg_intensity_interval_lower_bound[ 0 ][ i + 1 ] shall be equal to fg_intensity_interval_upper_bound[ 0 ][ i ] + 1, which is consistent with representation of intensity intervals using a piecewise continuous model. (Note that this constraint also disallows multi-generational film grain synthesis). fg_comp_model_value[ c ][ i ][ 2 ] shall be equal to 0 fg_comp_model_value[ c ][ i ][ 1 ] shall be equal to an ar value, denoted as ar valuel [c], for c = 0...2 and i = 0... fg num intensity intervals minusl [ c ] fg_comp_model_value[ c ][ i ][ 3 ] shall be equal to an ar, denoted as ar_value3[c], for c = 0...2 and i = 0... fg_num_intensity_intervals_minus 1 [ c ] fg_comp_model_value[ c ] [ i ] [ 4 ] shall be equal to an ar value, denoted as ar_value4[c], for c = 0...2 and i = 0... fg num intensity intervals minusl [ c ] fg_comp_model_value[ c ][ i ][ 5 ] shall be equal to an ar value, denoted as ar_value5[c], for c = 0...2 and i = 0... fg num intensity intervals minusl [ c ]

The input to this process are the decoded picture sample array IdecodedY and, when ChromaFormatldc is equal to 1, the arrays IdecodedU and IdecodedV.

Outputs of this process are the modified picture sample array IgrainY and, when ChromaFormatldc is equal to 1, the arrays IgrainU and IgrainV.

The variable GrainCenter is set equal to 128 « (BitDepth - 8).

The variable GrainMin is set equal to = - GrainCenter.

The variable GrainMax is set equal to (256 « (BitDepth - 8)) - 1 - GrainCenter.

The variable ScalinShift is set equal to fg_log2_scale_factor

The film grain synthesis process can be described as follows. Given AR coefficients and a Gaussian sequence, a film grain template (64x64, implementation wise, using 82x73) is first generated. With a pseudo-random generator, the decoder generates offsets for a 32x32 block (or +2 additional row/columns when overlap is used) inside the film grain template. The pseudo-random generator is initialized in the beginning of each row of 32x32 blocks to allow parallel row processing. The generator is initialized based on a GrainSeed element. The 32x32 block of the film grain is scaled, and added to the reconstructed samples, and the clipping is applied. For 4:2:0, the block size for chroma components are twice smaller for 4:2:0.

The grain seed (GrainSeed) generation process is invoked as specified in clause 8.5.3.1.

The pseudo-random number generation process is invoked as specified in clause 8.5.3.2.

The grain template generation process is invoked as specified in clause 8.5.3.3.

The scaling lookup initialization process is invoked as specified in clause 8.5.3.4.

The add noise process is invoked as specified in clause 8.5.3.5.

8.5.3.1 Grain seed generation process

The variable GrainSeed (or grain seed) specifies the starting value for the pseudo-random number generator used in film grain synthesis. In particular, GrainSeed contains the value used to initialize a 16-bit variable RandRegister (or RandomRegister).

GrainSeed generation follows cause 1.5.2.1 Seed initialization in SMPTE RDD-5 for luma component. 8.5.3.2 Random number generation process

The input of the process is the variable nBits. The output of the process is the variable randResult.

The random number generation process is specified with the function randResult = getRandNum(nBits). function randResult = getRandNum(nBits) rVal = RandRegister newBit = ((rVal » 0) L (rVal » 1) L (rVal » 3) L (rVal » 12)) & 1 rVal = (rVal » 1) | (newBit « 15) randResult = (rVal » (16 - nBits)) & ((1 « nBits) - 1)

RandRegister = rVal

8.5.3.3 Grain template generation process

The output of this process is the film grain template GrainTemplate[cIdx][y][x], where the variable cldx is the color component index, y =0... nCurrSh, and x=0... nCurrSw. When cldx is equal to 0 (luma component), nCurrSw = 82, nCurrSh = 73. When ChromaFormatldc = 1, nCurrSw = 44, nCurrSh = 38 for cldx is equal to 1 or 2 (chroma component).

The array gaussianSequence contains random samples from a Gaussian distribution with zero mean and standard deviation of about 512 clipped to the range of [-2048, 2047] and rounded to the nearest multiple of 4. gaussianSequence[2048] = {

56, 568, -180, 172, 124, -84, 172, -64, -900, 24, 820, 224, 1248, 996, 272, -8, -916, -388, -732, -104, -188, 800, 112, -652, -320, -376, 140, -252, 492, -168, 44, -788, 588, -584, 500, -228, 12, 680, 272,

-476, 972, -100, 652, 368, 432, -196, -720, -192, 1000, -332, 652, -136, -552, -604, -4, 192, -220, -136, 1000, -52, 372, -96, -624, 124, -24,

396, 540, -12, -104, 640, 464, 244, -208, -84, 368, -528, -740, 248,

-968, -848, 608, 376, -60, -292, -40, -156, 252, -292, 248, 224, -280,

400, -244, 244, -60, 76, -80, 212, 532, 340, 128, -36, 824, -352, -60, -264, -96, -612, 416, -704, 220, -204, 640, -160, 1220, -408, 900,

336, 20, -336, -96, -792, 304, 48, -28, -1232, -1172, -448, 104, -292,

-520, 244, 60, -948, 0, -708, 268, 108, 356, -548, 488, -344, -136,

488, -196, -224, 656, -236, -1128, 60, 4, 140, 276, -676, -376, 168,

-108, 464, 8, 564, 64, 240, 308, -300, -400, -456, -136, 56, 120,

-408, -116, 436, 504, -232, 328, 844, -164, -84, 784, -168, 232, -224,

348, -376, 128, 568, 96, -1244, -288, 276, 848, 832, -360, 656, 464, -384, -332, -356, 728, -388, 160, -192, 468, 296, 224, 140, -776, -100, 280, 4, 196, 44, -36, -648, 932, 16, 1428, 28, 528, 808, 772,

20, 268, 88, -332, -284, 124, -384, -448, 208, -228, -1044, -328, 660,

380, -148, -300, 588, 240, 540, 28, 136, -88, -436, 256, 296, -1000,

1400, 0, -48, 1056, -136, 264, -528, -1108, 632, -484, -592, -344, 796,

124, -668, -768, 388, 1296, -232, -188, -200, -288, -4, 308, 100, -168,

256, -500, 204, -508, 648, -136, 372, -272, -120, -1004, -552, -548, -384, 548, -296, 428, -108, -8, -912, -324, -224, -88, -112, -220, -100, 996,

-796, 548, 360, -216, 180, 428, -200, -212, 148, 96, 148, 284, 216,

-412, -320, 120, -300, -384, -604, -572, -332, -8, -180, -176, 696, 116,

-88, 628, 76, 44, -516, 240, -208, -40, 100, -592, 344, -308, -452, -228, 20, 916, -1752, -136, -340, -804, 140, 40, 512, 340, 248, 184,

-492, 896, -156, 932, -628, 328, -688, -448, -616, -752, -100, 560, -1020 180, -800, -64, 76, 576, 1068, 396, 660, 552, -108, -28, 320, -628,

312, -92, -92, -472, 268, 16, 560, 516, -672, -52, 492, -100, 260,

384, 284, 292, 304, -148, 88, -152, 1012, 1064, -228, 164, -376, -684,

592, -392, 156, 196, -524, -64, -884, 160, -176, 636, 648, 404, -396,

-436, 864, 424, -728, 988, -604, 904, -592, 296, -224, 536, -176, -920,

436, -48, 1176, -884, 416, -776, -824, -884, 524, -548, -564, -68, -164,

-96, 692, 364, -692, -1012, -68, 260, -480, 876, -1116, 452, -332, -352,

892, -1088, 1220, -676, 12, -292, 244, 496, 372, -32, 280, 200, 112,

-440, -96, 24, -644, -184, 56, -432, 224, -980, 272, -260, 144, -436,

420, 356, 364, -528, 76, 172, -744, -368, 404, -752, -416, 684, -688,

72, 540, 416, 92, 444, 480, -72, -1416, 164, -1172, -68, 24, 424,

264, 1040, 128, -912, -524, -356, 64, 876, -12, 4, -88, 532, 272,

-524, 320, 276, -508, 940, 24, -400, -120, 756, 60, 236, -412, 100, 376, -484, 400, -100, -740, -108, -260, 328, -268, 224, -200, -416, 184, -604, -564, -20, 296, 60, 892, -888, 60, 164, 68, -760, 216, -296,

904, -336, -28, 404, -356, -568, -208, -1480, -512, 296, 328, -360, -164, -1560, -776, 1156, -428, 164, -504, -112, 120, -216, -148, -264, 308, 32, 64, -72, 72, 116, 176, -64, -272, 460, -536, -784, -280, 348, 108,

-752, -132, 524, -540, -776, 116, -296, -1196, -288, -560, 1040, -472, 116

-848, -1116, 116, 636, 696, 284, -176, 1016, 204, -864, -648, -248, 356,

972, -584, -204, 264, 880, 528, -24, -184, 116, 448, -144, 828, 524, 212, -212, 52, 12, 200, 268, -488, -404, -880, 824, -672, -40, 908,

-248, 500, 716, -576, 492, -576, 16, 720, -108, 384, 124, 344, 280,

576, -500, 252, 104, -308, 196, -188, -8, 1268, 296, 1032, -1196, 436,

316, 372, -432, -200, -660, 704, -224, 596, -132, 268, 32, -452, 884,

104, -1008, 424, -1348, -280, 4, -1168, 368, 476, 696, 300, -8, 24,

180, -592, -196, 388, 304, 500, 724, -160, 244, -84, 272, -256, -420,

320, 208, -144, -156, 156, 364, 452, 28, 540, 316, 220, -644, -248,

464, 72, 360, 32, -388, 496, -680, -48, 208, -116, -408, 60, -604,

-392, 548, -840, 784, -460, 656, -544, -388, -264, 908, -800, -628, -612, -568, 572, -220, 164, 288, -16, -308, 308, -112, -636, -760, 280, -668, 432, 364, 240, -196, 604, 340, 384, 196, 592, -44, -500, 432, -580,

-132, 636, -76, 392, 4, -412, 540, 508, 328, -356, -36, 16, -220,

-64, -248, -60, 24, -192, 368, 1040, 92, -24, -1044, -32, 40, 104,

148, 192, -136, -520, 56, -816, -224, 732, 392, 356, 212, -80, -424,

-1008, -324, 588, -1496, 576, 460, -816, -848, 56, -580, -92, -1372, -112

-496, 200, 364, 52, -140, 48, -48, -60, 84, 72, 40, 132, -356, -268, -104, -284, -404, 732, -520, 164, -304, -540, 120, 328, -76, -460,

756, 388, 588, 236, -436, -72, -176, -404, -316, -148, 716, -604, 404,

-72, -88, -888, -68, 944, 88, -220, -344, 960, 472, 460, -232, 704,

120, 832, -228, 692, -508, 132, -476, 844, -748, -364, -44, 1116, -1104, -1056, 76, 428, 552, -692, 60, 356, 96, -384, -188, -612, -576, 736,

508, 892, 352, -1132, 504, -24, -352, 324, 332, -600, -312, 292, 508, -144, -8, 484, 48, 284, -260, -240, 256, -100, -292, -204, -44, 472,

-204, 908, -188, -1000, -256, 92, 1164, -392, 564, 356, 652, -28, -884, 256, 484, -192, 760, -176, 376, -524, -452, -436, 860, -736, 212, 124, 504, -476, 468, 76, -472, 552, -692, -944, -620, 740, -240, 400, 132,

20, 192, -196, 264, -668, -1012, -60, 296, -316, -828, 76, -156, 284,

-768, -448, -832, 148, 248, 652, 616, 1236, 288, -328, -400, -124, 588,

220, 520, -696, 1032, 768, -740, -92, -272, 296, 448, -464, 412, -200,

392, 440, -200, 264, -152, -260, 320, 1032, 216, 320, -8, -64, 156,

-1016, 1084, 1172, 536, 484, -432, 132, 372, -52, -256, 84, 116, -352,

48, 116, 304, -384, 412, 924, -300, 528, 628, 180, 648, 44, -980,

-220, 1320, 48, 332, 748, 524, -268, -720, 540, -276, 564, -344, -208,

-196, 436, 896, 88, -392, 132, 80, -964, -288, 568, 56, -48, -456,

888, 8, 552, -156, -292, 948, 288, 128, -716, -292, 1192, -152, 876,

352, -600, -260, -812, -468, -28, -120, -32, -44, 1284, 496, 192, 464,

312, -76, -516, -380, -456, -1012, -48, 308, -156, 36, 492, -156, -808,

188, 1652, 68, -120, -116, 316, 160, -140, 352, 808, -416, 592, 316,

-480, 56, 528, -204, -568, 372, -232, 752, -344, 744, -4, 324, -416,

-600, 768, 268, -248, -88, -132, -420, -432, 80, -288, 404, -316, -1216,

-588, 520, -108, 92, -320, 368, -480, -216, -92, 1688, -300, 180, 1020,

-176, 820, -68, -228, -260, 436, -904, 20, 40, -508, 440, -736, 312,

332, 204, 760, -372, 728, 96, -20, -632, -520, -560, 336, 1076, -64,

-532, 776, 584, 192, 396, -728, -520, 276, -188, 80, -52, -612, -252,

-48, 648, 212, -688, 228, -52, -260, 428, -412, -272, -404, 180, 816,

-796, 48, 152, 484, -88, -216, 988, 696, 188, -528, 648, -116, -180,

316, 476, 12, -564, 96, 476, -252, -364, -376, -392, 556, -256, -576,

260, -352, 120, -16, -136, -260, -492, 72, 556, 660, 580, 616, 772,

436, 424, -32, -324, -1268, 416, -324, -80, 920, 160, 228, 724, 32,

-516, 64, 384, 68, -128, 136, 240, 248, -204, -68, 252, -932, -120, -480, -628, -84, 192, 852, -404, -288, -132, 204, 100, 168, -68, -196,

-868, 460, 1080, 380, -80, 244, 0, 484, -888, 64, 184, 352, 600,

460, 164, 604, -196, 320, -64, 588, -184, 228, 12, 372, 48, -848,

-344, 224, 208, -200, 484, 128, -20, 272, -468, -840, 384, 256, -720,

-520, -464, -580, 112, -120, 644, -356, -208, -608, -528, 704, 560, -424, 392, 828, 40, 84, 200, -152, 0, -144, 584, 280, -120, 80, -556,

-972, -196, -472, 724, 80, 168, -32, 88, 160, -688, 0, 160, 356,

372, -776, 740, -128, 676, -248, -480, 4, -364, 96, 544, 232, -1032,

956, 236, 356, 20, -40, 300, 24, -676, -596, 132, 1120, -104, 532, -1096, 568, 648, 444, 508, 380, 188, -376, -604, 1488, 424, 24, 756,

-220, -192, 716, 120, 920, 688, 168, 44, -460, 568, 284, 1144, 1160,

600, 424, 888, 656, -356, -320, 220, 316, -176, -724, -188, -816, -628,

-348, -228, -380, 1012, -452, -660, 736, 928, 404, -696, -72, -268, -892, 128, 184, -344, -780, 360, 336, 400, 344, 428, 548, -112, 136, -228,

-216, -820, -516, 340, 92, -136, 116, -300, 376, -244, 100, -316, -520,

-284, -12, 824, 164, -548, -180, -128, 116, -924, -828, 268, -368, -580, 620, 192, 160, 0, -1676, 1068, 424, -56, -360, 468, -156, 720, 288,

-528, 556, -364, 548, -148, 504, 316, 152, -648, -620, -684, -24, -376, -384, -108, -920, -1032, 768, 180, -264, -508, -1268, -260, -60, 300, -240, 988, 724, -376, -576, -212, -736, 556, 192, 1092, -620, -880, 376, -56, -4, -216, -32, 836, 268, 396, 1332, 864, -600, 100, 56, -412, -92,

356, 180, 884, -468, -436, 292, -388, -804, -704, -840, 368, -348, 140,

-724, 1536, 940, 372, 112, -372, 436, -480, 1136, 296, -32, -228, 132,

-48, -220, 868, -1016, -60, -1044, -464, 328, 916, 244, 12, -736, -296,

360, 468, -376, -108, -92, 788, 368, -56, 544, 400, -672, -420, 728,

16, 320, 44, -284, -380, -796, 488, 132, 204, -596, -372, 88, -152,

-908, -636, -572, -624, -116, -692, -200, -56, 276, -88, 484, -324, 948,

864, 1000, -456, -184, -276, 292, -296, 156, 676, 320, 160, 908, -84,

-1236, -288, -116, 260, -372, -644, 732, -756, -96, 84, 344, -520, 348,

-688, 240, -84, 216, -1044, -136, -676, -396, -1500, 960, -40, 176, 168, 1516, 420, -504, -344, -364, -360, 1216, -940, -380, -212, 252, -660, -708 ; 484, -444, -152, 928, -120, 1112, 476, -260, 560, -148, -344, 108, -196, 228, -288, 504, 560, -328, -88, 288, -1008, 460, -228, 468, -836, -196, 76, 388, 232, 412, -1168, -716, -644, 756, -172, -356, -504, 116, 432,

528, 48, 476, -168, -608, 448, 160, -532, -272, 28, -676, -12, 828,

980, 456, 520, 104, -104, 256, -344, -4, -28, -368, -52, -524, -572,

-556, -200, 768, 1124, -208, -512, 176, 232, 248, -148, -888, 604, -600,

-304, 804, -156, -212, 488, -192, -804, -256, 368, -360, -916, -328, 228,

-240, -448, -472, 856, -556, -364, 572, -12, -156, -368, -340, 432, 252,

-752, -152, 288, 268, -580, -848, -592, 108, -76, 244, 312, -716, 592,

-80, 436, 360, 4, -248, 160, 516, 584, 732, 44, -468, -280, -292,

-156, -588, 28, 308, 912, 24, 124, 156, 180, -252, 944, -924, -772,

-520, -428, -624, 300, -212, -1144, 32, -724, 800, -1128, -212, -1288, -848

180, -416, 440, 192, -576, -792, -76, -1080, 80, -532, -352, -132, 380, -820, 148, 1112, 128, 164, 456, 700, -924, 144, -668, -384, 648, -832, 508, 552, -52, -100, -656, 208, -568, 748, -88, 680, 232, 300, 192, -408, -1012, -152, -252, -268, 272, -876, -664, -648, -332, -136, 16, 12,

1152, -28, 332, -536, 320, -672, -460, -316, 532, -260, 228, -40, 1052,

-816, 180, 88, -496, -556, -672, -368, 428, 92, 356, 404, -408, 252,

196, -176, -556, 792, 268, 32, 372, 40, 96, -332, 328, 120, 372,

-900, -40, 472, -264, -592, 952, 128, 656, 112, 664, -232, 420, 4,

-344, -464, 556, 244, -416, -32, 252, 0, -412, 188, -696, 508, -476,

324, -1096, 656, -312, 560, 264, -136, 304, 160, -64, -580, 248, 336,

-720, 560, -348, -288, -276, -196, -500, 852, -544, -236, -1128, -992, -776,

116, 56, 52, 860, 884, 212, -12, 168, 1020, 512, -552, 924, -148,

716, 188, 164, -340, -520, -184, 880, -152, -680, -208, -1156, -300, -528,

-472, 364, 100, -744, -1056, -32, 540, 280, 144, -676, -32, -232, -280,

-224, 96, 568, -76, 172, 148, 148, 104, 32, -296, -32, 788, -80,

32, -16, 280, 288, 944, 428, -484};

The variable scaleShift is set to 12 - BitDepth

The film grain templates are generated as follows.

If cldx is equal to 1, RandRegister is set to GrainSeed L 0xb524 If cldx is equal to 2, RandRegister is set to GrainSeed L 0x49d8 for ( y = 0; y < nCurrSh; y++ ) { for ( x = 0; x < nCurrSw; x++ ) { if ( fg_comp_model_present_flag [ cldx ] > 0 )

GrainTemplate[cIdx][y][x]=( gaussianSequence[getRandNum(ll)]+2scaleShift-l)» scaleShift

The variable ar_coeff_lag is set equal to 2.

The variable aRCoeffShift is set equal to 8 The variable numPos[cIdx] is set as the follows:

If cldx = 0, numPos[cIdx] = 2 * ar coeff lag * (ar_coeff_lag+l)

Otherwise (cldx != 0), numPosfcIdx] = numPos|()| + 1 The array aRCoeffsfcIdx] [ pos ], for pos = 0... numPosfcIdx] - 1 is set equal to 0, except the following. aRCoeffsfcIdx] [ 2 ] is set equal to ( ((ar_value5[cldx] * ar_value4[cldx] * ar_value4[cldx])« aRCoeffShift) + (l«(ScalingShift+l)) » (3*ScalingShift) aRCoeffsfcIdx] [ 6 ] is set equal to (((ar_value3[cldx] * ar_value4[cldx])« aRCoeffShift) + (1 « ScalingShift)) » (2*ScalingShift) aRCoeffsfcIdx] [ 7 ] is set equal to (((ar_valuel[cldx] * ar_value4[cldx])« aRCoeffShift) + (1 « ScalingShift)) » (2*ScalingShift) aRCoeffsfcIdx] [ 8 ] is set equal to ((ar_value3[cldx]« aRCoeffShift) + (1 « (ScalingShift- 1))) » ScalingShift aRCoeffsfcIdx] [ 10 ] is set equal to ((ar_value5[cldx]« aRCoeffShift) + (1 « (ScalingShift- 1))) » ScalingShift aRCoeffs aRCoeffsfcIdx] [ 11 ] is set equal to ((ar_valuel[cldx]« aRCoeffShift) +

(1 « (ScalingShift- 1))) » ScalingShift

The grain template for each cldx is generated as follows: for ( y = 3; y < nCurrSh; y++ ) { for ( x = 3; x < nCurrSw - 3; x++ ) { pos = 0, s = 0 for ( idxY = -ar_coeff_lag; idxY <= 0; idxY ++ ) for (idxX = -ar_coeff_lag; idxX <= ar_coeff_lag && (idxY!=0 || idxX != 0); idxX ++ ) s += grainTemplate[ddx][ [ y + idxY][ x + idxX] * aRCoeffs[cIdx] [ pos++ ]

GrainTemplate [cldx][y][x] = Clip3(-2BitDepth-l, 2BitDepth-l-l, GrainTemplate[[Idx][y][x] + (( s + 2aRCoeffShift-l) » aRCoeffShift )))

}

}

8.S.3.4 scalingLut initialization

For a color plane cldx, the following initialization procedure is envoked to initialize the ScalingLut[ cldx ][ 256 ].

The variable NumPoints[cIdx] for cldx=0..2 is set as following: if fg_comp_model_present_flag[ cldx ] is equal to 0, NumPoints[cIdx] is set to 0. Otherwise (fg_comp_model_present_flag [ cldx ] is not equal to 0),

NumPoints[ cldx ] is set to equal to fg_num_intensity_intervals_minusl[ cldx ] + 1, . if ( NumPoints[ cldx ] == 0 ) { for ( x = 0; x < 256; x++ )

ScalingLut[cIdx][ x ] = 0

} else { for ( x = 0; x < fg_intensity_interval_lower_bound[ c ][ 0 ] [ 0 ]; x++ ) ScalingLut[cIdx][ x ] = 0 for ( i = 0; i < = fg num intensity intervals minusl [ c ]; i++ ) { dX = fg_intensity_interval_upper_bound[ cldx ] [ i + 1 ] - fg_intensity_interval_lower_bound[ cldx ][ i ] for ( x = 0; x < dX; x++ )

ScalingLut[cIdx][ fg_intensity_interval_lower_bound[ cldx ] [ i ] + x ] = fg_comp_model_value[ c ] [ i ] [ 0 ]

} for ( x = fg_intensity_interval_upper_bound[ cldx ][ fg num intensity intervals minus 1 [ c ] ]; x < 256; x++ )

ScalingLut[cIdx][ x ] = 0

} To obtain values of the scaling function, the following procedure is invoked with the color plane index cldx and the input value pointVal as inputs. The output is the value of the scaling function pointScal. scaleLut(ddx, pointVal) { if ( BitDepth == 8) pointScal = ScalingLut[cIdx][ pointVal ] else x = Clip3( 0, 255,

( pointVal + ( 1 « ( BitDepth - 9 ) ) ) » ( BitDepth) c ] - 8 ) ) pointScal = ScalingLut[cIdx][x]

8.5.3.5 Add noise process

Inputs to this process are the reconstructed picture prior to adding film grain, i.e., the array recPictureL and, when ChromaFomatldc is not equal to 0, the arrays recPictureCb and recPictureCr.

Outputs of this process are the modified reconstructed picture after adding film grain, i.e., the array recPictureL and, when ChromaFomatldc is not equal to 0, the arrays recPictureCb and recPictureCr.

The pseudo-random generator is initialized in the beginning of each row of 32x32 blocks to allow parallel row processing ((denoted as variable rowNum). The generator is initialized based on a GrainSeed element. For every 32x32 block, with a pseudo-random generator getRandNum(8), a 34x34 array grSCur[ddx] is generated from GrainTemplate[cIdx] grSCur[ddx] is then assigned to the picture array grPlanes[cIdx] The variable cldx specfies the color component index. rowNum = 0 for ( y = 0; y < (picHeightlnLumaSamples + 1) » 1; y += 16 ) {

RandRegister = GrainSeed

RandRegister L = ((rowNum * 37 + 178) & 255) « 8 RandRegister L = ((rowNum * 173 + 105) & 255) for ( x = 0; x < (picWidthlnLumaSamples + l) » l; x += 16 ) { rand = getRandNum( 8 ) offsetX = rand » 4 offsetY = rand & 15 for ( cldx = 0; cldx < 3; cldx ++ ) { cSubsX = (cldx > 0) ? subsX : 0 cSubsY = (cldx > 0) ? subsY : 0 planeOffsetX = cSubsX? 6 + offsetX : 9 + offsetX * 2 planeOffsetY = cSubsY? 6 + offsetY : 9 + offsetY * 2 for ( i = 0; i < 34 » cSubsY ; i++ ) for (j = 0; j < 34 » cSubsX; j++ ) { grSCur[ddx][ i ][ j ] = GrainTemplate [cldx]

[ planeOffsetY + i ][ planeOffsetX + j ] if (overlap_flag) blendingOperation(grSCur[ddx]) grPlanes[ddx][y+i][x+j] = grSCur[ddx][ i ][ j ]

}

}

} rowNum++

}

When NumPoints[0] is larger than 0, the film grain is added to the luma ccomponent recPictureL. for ( y = 0; y < PicHeightlnLumaSamples ; y++ ) { for ( x = 0; x < PicWidthlnLumaSamples ; x++ ) { grSamp = ( scaleLut( 0, recPictureL[y][x]) * grPlanes[ 0 ][ y ][ x ] + 2ScalingShift-l) » ScalingShift recPictureL[ y ][ x ] = Clip3(minVal[0], maxVal[0], recPictureL [y][x]+ grSamp)

}

}

When ChromaFormatldc is larger than 0 and NumPoints[cIdx] is larger than 0 where cldx is equal to 1 or 2, the film grain is added to the chroma components recPictureC chroma samples. recPictureC refers to recPictureCb when cldx is equal to 1 and refers to recPictureCr when cldx is equal to 2 for ( y = 0; y < PicHeightlnLumaSamples / SubHeightC ; y++ ) { for ( x = 0; x < PicWidthlnLumaSamples/ SubWidthC ; x++ ) { grSamp = ( scaleLut( cldx, recPictureC [y][x]) * grPlanes[ cldx ][ y ][ x ] + 2scalingShift-l) » ScalingShift recPictureC'l y ][ x ] = Clip3(minVal[cIdx], maxValfcIdx], recPictureC[y][x]+ grSamp)

}

}

The variable minValfcIdx] and maxValfcIdx] is specified as follows:

If fg full range flag is equal to 1, minValfcIdx] is equal to 0, and maxValfcIdx] is equal to 2BitDepth - 1 when cldx is equal to 0, 1 or 2.

Otherwise if fg_full_range_flagis is equal to 0, minVal| 1 1 and minVal[2] is equal to 16*2BitDepth-8 and maxVal[0] is equal to 235*2BitDepth-8 .

- If fg matrix coeffs is equal to 0, maxValfl] and maxVal[2] are equal to 235*2BitDepth-8

- otherwise, maxValfl] and maxVal[2] are equal to 240*2BitDepth-8

Appendix 2

Example addendum to Section 8.5, Film grain characteristics SEI message, of VVC SEI messaging (Ref. [6]) to support film grain synthesis during MPEG decoding for different picture sizes and the frequency filtering model. Proposed amendments are shown in an Italic font.

Modify the location and text of Note 3 in the following text:

“NOTE 1 - SMPTE RDD 5 specifies a film grain simulator based on the information provided in the film grain characteristics SEI message.

Use of this SEI message requires the definition of the following variables:

- A picture width and picture height in units of luma samples, denoted herein by PicWidthlnLumaSamples and PicHeightlnLumaSamples, respectively.

- When the syntax element fg_separate_colour_description_present_flag of the film grain characteristics SEI message is equal to 0, the following additional variables:

- A chroma format indicator, denoted herein by ChromaFormatldc, as described in clause Error! Reference source not found..

- A bit depth for the samples of the luma component, denoted herein by BitDepthy, and when ChromaFormatldc is not equal to 0, a bit depth for the samples of the two associated chroma components, denoted herein by BitDepthc.” As follows:

“Use of this SEI message requires the definition of the following variables:

- A picture width and picture height in units of luma samples, denoted herein by PicWidthlnLumaSamples and PicHeightlnLumaSamples, respectively.

- When the syntax element fg_separate_colour_description_present_flag of the film grain characteristics SEI message is equal to 0, the following additional variables:

- A chroma format indicator, denoted herein by ChromaFormatldc, as described in clause Error! Reference source not found..

- A bit depth for the samples of the luma component, denoted herein by BitDepthy, and when ChromaFormatldc is not equal to 0, a bit depth for the samples of the two associated chroma components, denoted herein by BitDepthc.

NOTE 2 - SMPTE RDD 5 specifies a film grain simulator based on the information provided in the film grain characteristics SEI message when PicWidthlnLumaSamples is less than or equal to 1920 and PicHeightlnLumaSamples is less than or equal to 1080.”

Modify the following:

“Depending on the value of fg model id, the selection of the one or more intensity intervals for the sample value I decoded [ c ][ x ][ y ] is specified as follows:

- The variable numApplicableIntensityIntervals[ c ] [ x ] [ y ] is initially set equal to 0.

- If fg model id is equal to 0, the following applies:

- The top-left sample location ( xB, yB ) of the current 8x8 block b that contains the sample value I decoded t c ][ x ][ y ] is derived as ( xB, yB ) = ( x / 8, y / 8 ).

- The average value b il g of the current 8x8 block b is derived as follows: sum8x8 = 0 for( i = 0; i < 8; i++ ) for(j = 0;j < 8;j++ ) sum8x8 += I decoded [ c ] [ xB * 8 + i ] [yB * 8 + j ] (1) b avg = Clip3( 0, 255,

( sum8x8 + ( 1 « ( fgBitDepth[ c ] — 3 ) ) ) » ( fgBitDepth[ c ] - 2 ) )” As follows:

“Depending on the value of fg model id, the selection of the one or more intensity intervals for the sample value D ecoded [ c ][ x ][ y ] is specified as follows:

- The variable numApplicableIntensityIntervals[ c ] [ x ] [ y ] is initially set equal to 0.

- The variable blockAvgSize is derived as blockAvgSize = (1 « (3 + Log2 ( Max ( Ceil( PicHeightlnLumaSamples / 1080) , Ceil(PicHeightInLumaSamples / 1920 ) ) ) ) )

- If fg model id is equal to 0, the following applies:

- The top-left sample location ( xB, yB ) of the current blockAvgSize x blockAvgSize block b that contains the sample value D ecoded [ c ] [ x ] [ y ] is derived as

( xB, yB ) = ( x / blockAvgSize, y / blockAvgSize ).

- The average value b avg of the current blockAvgSize x blockAvgSize block b is derived as follows: sum Block = 0 avgRatio = Log2 (blockAvgSize / 8) for( i = 0; i < blockAvgSize; i++ ) for( j = 0; j < blockAvgSize ; j++ ) sum Block += D ecoded [ c ][ xB * blockAvgSize + i ][yB * blockAvgSize + j ] (2) b avg = Clip3( 0, 255,

( sumBlock + ( 1 « ( fgBitDepth[ c ] + 2*avgRatio - 3 ) ) ) » ( fgBitDepth[ c ] + 2*avgRatio - 2 ) )

- The value of intensity Intervalldx[ c ] [ x ] [ y ] [ j ] is derived as follows: for( i = 0, j = 0; i <= fg_num_intensity_intervals_minusl[ c ]; i++ ) if( b avg >= fg_intensity_interval_lower_bound[ c ][ i ] && b avg <= fg_intensity_interval_upper_bound[ c ][ i ] ) { intensity Intervalldx[ c ] [ x ] [ y ] [ j ] = i (3) j++

} numApplicableIntensityIntervals[ c ] [ x ] [ y ] = j “ Appendix 3

1.1.3 Example Embodiment for a bit-accurate process for grain blending

The bit-accurate grain blending process and constraints are specified such that all decoders that conform to this version of this Specification will produce numerically identical cropped decoded output pictures.

Bitstreams conforming to the bit-accurate grain generation process shall obey the following constraints:

- ChromaFormatldc shall equal 1

- FGC SEI message shall have fg model id equal to 0.

- FGC SEI message shall have fg_separate_colour_description_present flag equal to 0.

- FGC SEI message shall have fg blending mode id equal to 0.

- FGC SEI message shall have fg_log2_scale_factor in the range 2 to 7, inclusive.

- FGC SEI message shall have fg_intensity_interval_upper_bound[ c ][ i ] less than fg_intensity_interval_lower_bound[ c ][ i + 1 ].

- FGC SEI message shall have fg num model values minusl [ c ] in the range 0..2, inclusive.

- FGC SEI message shall have fg_comp_model_value[ c ][ i ][ 0 ] in the range 0..255, inclusive.

- FGC SEI message shall have fg_comp_model_value[ c ][ i ][ 1 ] in the range 2..14, inclusive.

- FGC SEI message shall have fg_comp_model_value[ c ][ i ][ 2 ] in the range 2..14, inclusive.

Inputs to the process are the decoded picture sample arrays before grain blending decPicture L, decPicturecb, and decPicturecr.

Outputs of this process are modified decoded picture sample array after grain blending blendPicture L, blendPicturecb, and blendPicturecr.

The variable BlockSize is derived as follows:

BlockSize = Min(l « (3 + Ceil( Log2 (Max( Ceil( PicHeightlnLumaSamples ÷ 1080 ),

Ceil( PicWidthlnLumaSamples ÷ 1920 ) ) ) ), 32)

The grain blending process is derived as the following ordered steps:

- The grain pattern database generation is invoked in clause 1.1.3.1. The output is a 13x13x64x64 array GrainDb.

- The grain blending process as specified in clause 1.1.3.2 is invoked with decPicture L, decPicturecb, and decPicturecr. as the input, and the output is blendPictureL, blendPicturecb, and blendPicturecr. 1.1.3.1 Grain patern database generation

Output of this process is a 13x13x64x64 grain pattern database array GrainDb. The function Pmg(x), with x = 0..2 L (32)-1, is defined as follows:

Pmg(x) = (x « 1) + (1 + ((x & (1«2)) > 0) + ((x & (1«30)) > 0)) % 2 The pseudo-random number generator array SeedLUT[i] with i=0..255 is specified as follows: SeedLUT[i] =

{

7475384602023850500 1115949072 135274561 541098240 1669598224 67112961 809550080

1088979410 76561770 1631803309 355958469 1468005469 1337918685 1005669825 991480851

1744950180 1226763489 98284748 248291472 456510673 1219264706 903663673 1816248997

1767011913 80325252 2874338562127839491 1578687785 1799741108 1771104465 1561503561

1403382928 19925814422119719977 146920100 1838217424 1834116681 1277749632 329575568

521866116 502705249 988742797 5859826122010752065 683417731 1229754427 780651196

1060417601 740409860 1827432592 16117023372089828354 1120274457 950632997 1659144592

2110622736 516219202 579378475 696506029 1362717428 1073098457 1979371465 1910793616

1557184770 557974537 1017745956 1386498192 970073673 1648396544 2074373264 604016641

105289385 1883843076 1309377032 1258072451 854129835 176642749 305357524 1665084765

585624216 720112066 1316535465 1212240548 714793201 31171789 1049387408 1530186961

1827676546 16401377372074315269 1043171860 1266069081 718317889 1171033360 1870928913

1191843873 1820967556 1923385360 1217404993 1047060864 1266977808 1686114305 809550081

1018104344 40667586 209722667 1090770605 1991471829 1400892508 2147468765 2079346113 1123590530 155354121 1546228260 1386498193 1098097741 549749008 1941195985 71307521

663361569 1820967557 168102420 169093201 913883585 1808010512 117709841 876663040

2023850500 1115949072 135274561 541098240 1669598224 67112961 809550080 1073807360

76561770 1631803309 355958469 1468005469 1337918685 1005669825 991480851 832356664

1226763489 98284748 248291472 456510673 1219264706 903663673 1816248997 1573927377

80325252 2874338562127839491 1578687785 1799741108 1771104465 1561503561 204073344

19925814422119719977 146920100 1838217424 1834116681 1277749632 3295755682026918147

502705249 988742797 5859826122010752065 683417731 1229754427 780651196 1702476788

740409860 1827432592 16117023372089828354 1120274457 950632997 16591445922043881033

516219202 579378475 696506029 1362717428 1073098457 1979371465 1910793616 57949587

557974537 1017745956 1386498192 970073673 16483965442074373264 604016641 2001393952

1883843076 1309377032 1258072451 854129835 176642749 305357524 1665084765 1197426649

720112066 1316535465 1212240548 714793201 31171789 1049387408 1530186961 1186508931

16401377372074315269 1043171860 1266069081 718317889 1171033360 1870928913 332056865

1820967556 1923385360 1217404993 1047060864 1266977808 1686114305 809550081 950043140

40667586 209722667 1090770605 1991471829 14008925082147468765 2079346113 890043474

155354121 1546228260 1386498193 1098097741 549749008 1941195985 71307521 349099312

1820967557 168102420 169093201 913883585 1808010512 117709841 876663040 148914948

The Gaussian pseudo-random array gaussianLUT[m], with m=0..2047 is specified as follows: gaussianLUT[ m ] =

{

-11 -51 -38 -1 30 12 -105 127 99 51 -36 60 -38 74 68 93

12 21 42 120 12 112 50 127 -7 -16 19 101 14 -54 5 17

103 13 2 -127 77 67 16 -2 88 107 55 -12 127 -2 -74 -51 -11 -11 75 -108 112 79 -24 41 125 -8 17 -73 16 32 -61 -59

42 -20 -67 -49 82 -3 -35 87 -26 53 -51 17 -127 -45 93 71

-35 -19 52 9 -61 -114 -14 -65 91 38 40 -52 -31 17 -43 77

12 33 -90 14 -127 -87 -15 -16 0 -34 33 98 -86 -92 14 81

59 -127 33 127 111 -6 -127 55 63 17 -37 3 -39 59 -26 127 77 17 -47 122 -52 -5 -55 19 60 -7 126 3 -56 -64 -38 127

98 -6 21 109 -29 40 -22 91 -14 4 -39 60 46 67 -126 61 87 -105 -3 52 2 58 -55 -81 -23 -91 -118 33 -41 56 -17 33

3 18 -56 127 -49 -81 -127 -65 113 6 17 -3 75 -102 16 -106

65 19 49 2 -24 49 -112 -64 -33 63 -30 -2 23 29 -127 -93 -78 71 1 7 58 -27 5 35 116 63 0 10 -19 -87 64 0 45 48 -57 114 -29 -31 -26 -7 14 -15 19 -42 -22 -34 34 0

56 -10 -42 19 -73 -34 -72 -54 26 39 98 -106 -70 -92 31 75

-51 -38 -1 30 12 -105 127 99 51 -36 60 -38 74 68 93 -69

21 42 120 12 112 50 127 -7 -16 19 101 14 -54 5 17 71

13 2 -127 77 67 16 -2 88 107 55 -12 127 -2 -74 -51 127

-11 75 -108 112 79 -24 41 125 -8 17 -73 16 32 -61 -59 -19 -20 -67 -49 82 -3 -35 87 -26 53 -51 17 -127 -45 93 71 -111

-19 52 9 -61 -114 -14 -65 91 38 40 -52 -31 17 -43 77 30

33 -90 14 -127 -87 -15 -16 0 -34 33 98 -86 -92 14 81 23

-127 33 127 111 -6 -127 55 63 17 -37 3 -39 59 -26 127 15

17 -47 122 -52 -5 -55 19 60 -7 126 3 -56 -64 -38 127 2

-6 21 109 -29 40 -22 91 -14 4 -39 60 46 67 -126 61 39

-105 -3 52 2 58 -55 -81 -23 -91 -118 33 -41 56 -17 33 92

18 -56 127 -49 -81 -127 -65 113 6 17 -3 75 -102 16 -106 5

19 49 2 -24 49 -112 -64 -33 63 -30 -2 23 29 -127 -93 42 71 1 7 58 -27 5 35 116 63 0 10 -19 -87 64 0 2

48 -57 114 -29 -31 -26 -7 14 -15 19 -42 -22 -34 34 0 -6 -10 -42 19 -73 -34 -72 -54 26 39 98 -106 -70 -92 31 75 38

-38 -1 30 12 -105 127 99 51 -36 60 -38 74 68 93 -69 15

42 120 12 112 50 127 -7 -16 19 101 14 -54 5 17 71 114

-2 -127 77 67 16 -2 88 107 55 -12 127 -2 -74 -51 127 -30 75 -108 112 79 -24 41 125 -8 17 -73 16 32 -61 -59 -19 -37

-67 -49 82 -3 -35 87 -26 53 -51 17 -127 -45 93 71 -111 50

52 9 -61 -114 -14 -65 91 38 40 -52 -31 17 -43 77 30 44

-90 14 -127 -87 -15 -16 0 -34 33 98 -86 -92 14 81 23 106

33 127 111 -6 -127 55 63 17 -37 3 -39 59 -26 127 15 27 -47 122 -52 -5 -55 19 60 -7 126 3 -56 -64 -38 127 2 119

21 109 -29 40 -22 91 -14 4 -39 60 46 67 -126 61 39 7

-3 52 2 58 -55 -81 -23 -91 -118 33 -41 56 -17 33 92 -80 -56 127 -49 -81 -127 -65 113 6 17 -3 75 -102 16 -106 5 25

49 2 -24 49 -112 -64 -33 63 -30 -2 23 29 -127 -93 42 -68

1 7 58 -27 5 35 116 63 0 10 -19 -87 64 0 2 -21

-57 114 -29 -31 -26 -7 14 -15 19 -42 -22 -34 34 0 -6 92 -42 19 -73 -34 -72 -54 26 39 98 -106 -70 -92 31 75 38 -11

-1 30 12 -105 127 99 51 -36 60 -38 74 68 93 -69 15 -1

120 12 112 50 127 -7 -16 19 101 14 -54 5 17 71 114 18

-127 77 67 16 -2 88 107 55 -12 127 -2 -74 -51 127 -30 41

-108 112 79 -24 41 125 -8 17 -73 16 32 -61 -59 -19 -37 -50 -49 82 -3 -35 87 -26 53 -51 17 -127 -45 93 71 -111 50 79

9 -61 -114 -14 -65 91 38 40 -52 -31 17 -43 77 30 44 -127

14 -127 -87 -15 -16 0 -34 33 98 -86 -92 14 81 23 106 -43

127 111 6 -127 55 63 17 -37 3 -39 59 -26 127 15 27 127

122 -52 -5 -55 19 60 -7 126 3 -56 -64 -38 127 2 119 18

109 -29 40 -22 91 -14 4 -39 60 46 67 -126 61 39 7 11

52 2 58 -55 -81 -23 -91 -118 33 -41 56 -17 33 92 -80 -21 127 -49 -81 -127 -65 113 6 17 -3 75 -102 16 -106 5 25 32

2 -24 49 -112 -64 -33 63 -30 -2 23 29 -127 -93 42 -68 -52 7 58 -27 5 35 116 63 0 10 -19 -87 64 0 2 -21 27

114 -29 -31 -26 -7 14 -15 19 -42 -22 -34 34 0 -6 92 -88 19 -73 -34 -72 -54 26 39 98 -106 -70 -92 31 75 38 -11 -90

30 12 -105 127 99 51 -36 60 -38 74 68 93 -69 15 -1 -39

12 112 50 127 -7 -16 19 101 14 -54 5 17 71 114 18 -19

77 67 16 -2 88 107 55 -12 127 -2 -74 -51 127 -30 41 -10

112 79 -24 41 125 -8 17 -73 16 32 -61 -59 -19 -37 -50 24

82 -3 -35 87 -26 53 -51 17 -127 -45 93 71 -111 50 79 -118 -61 -114 -14 -65 91 38 40 -52 -31 17 -43 77 30 44 -127 72

-127 -87 -15 -16 0 -34 33 98 -86 -92 14 81 23 106 -43 -24

111 6 -127 55 63 17 -37 3 -39 59 -26 127 15 27 127 -44 -52 -5 -55 19 60 -7 126 3 -56 -64 -38 127 2 119 18 2

-29 40 -22 91 -14 4 -39 60 46 67 -126 61 39 7 11 12

2 58 -55 -81 -23 -91 -118 33 -41 56 -17 33 92 -80 -21 86 -49 -81 -127 -65 113 6 17 -3 75 -102 16 -106 5 25 32 -107

-24 49 -112 -64 -33 63 -30 -2 23 29 -127 -93 42 -68 -52 39 58 -27 5 35 116 63 0 10 -19 -87 64 0 2 -21 27 -33 -29 -31 -26 -7 14 -15 19 -42 -22 -34 34 0 -6 92 -88 -127 -73 -34 -72 -54 26 39 98 -106 -70 -92 31 75 38 -11 -90 47 12 -105 127 99 51 -36 60 -38 74 68 93 -69 15 -1 -39 51

112 50 127 -7 -16 19 101 14 -54 5 17 71 114 18 -19 -24

67 16 -2 88 107 55 -12 127 -2 -74 -51 127 -30 41 -10 -22

79 -24 41 125 -8 17 -73 16 32 -61 -59 -19 -37 -50 24 46

-3 -35 87 -26 53 -51 17 -127 -45 93 71 -111 50 79 -118 0 -114 -14 -65 91 38 40 -52 -31 17 -43 77 30 44 -127 72 15 -87 -15 -16 0 -34 33 98 -86 -92 14 81 23 106 -43 -24 -35

-6 -127 55 63 17 -37 3 -39 59 -26 127 15 27 127 -44 -69

-5 -55 19 60 -7 126 3 -56 -64 -38 127 2 119 18 2 -2

40 -22 91 -14 4 -39 60 46 67 -126 61 39 7 11 12 -74

58 -55 -81 -23 -91 -118 33 -41 56 -17 33 92 -80 -21 86 24

-81 -127 -65 113 6 17 -3 75 -102 16 -106 5 25 32 -107 -6

49 -112 -64 -33 63 -30 -2 23 -29 -127 -93 42 -68 -52 39 0

-27 5 35 116 63 0 10 -19 -87 64 0 2 -21 27 -33 29

-31 -26 -7 14 -15 19 -42 -22 -34 34 0 -6 92 88 -127 -3

-34 -72 -54 26 39 98 -106 -70 -92 31 75 38 -11 -90 47 45 -105 127 99 51 -36 60 -38 74 68 93 -69 15 -1 -39 51 32

50 127 -7 -16 19 101 14 -54 5 17 71 114 18 -19 -24 -32

16 -2 88 107 55 -12 127 -2 -74 -51 127 -30 41 -10 -22 117

-24 41 125 -8 17 -73 16 32 -61 -59 -19 -37 -50 24 46 -45

-35 87 -26 53 -51 17 -127 -45 93 71 -111 50 79 -118 0 79 -14 -65 91 38 40 -52 -31 17 -43 77 30 44 -127 72 15 -24

-15 -16 0 -34 33 98 -86 -92 14 81 23 106 -43 -24 -35 -17

-127 55 63 17 -37 3 -39 59 -26 127 15 27 127 -44 -69 -109 -55 19 60 -7 126 3 -56 -64 -38 127 2 119 18 2 -2 -10

-22 91 -14 4 -39 60 46 67 -126 61 39 7 11 12 -74 -70

-55 -81 -23 -91 -118 33 -41 56 -17 33 92 -80 -21 86 24 88

-127 -65 113 6 17 -3 75 -102 16 -106 5 25 32 -107 -6 -48

-112 -64 -33 63 -30 -2 23 29 -127 -93 42 -68 -52 39 0 24 5 35 116 63 0 10 -19 -87 64 0 2 -21 27 -33 29 -91

-26 -7 14 -15 19 -42 -22 -34 34 0 -6 92 -88 -127 -3 120

-72 -54 26 39 98-106 -70 -92 31 75 38 -11 -90 47 45 -37

127 99 51 -36 60 -38 74 68 93 -69 15 -1 -39 51 32 50

127 -7 -16 19 101 14 -54 5 17 71 114 18 -19 -24 -32-127

-2 88 107 55 -12 127 -2 -74 -51 127 -30 41 -10 -22 117 58

41 125 -8 17 -73 16 32 -61 -59 -19 -37 -50 24 46 -45 32

87 -26 53 -51 -17-127 -45 93 71 -111 50 79-118 0 79 -82 -65 91 38 40 -52 -31 17 -43 77 30 44-127 72 15 -24 -10

-16 0 -34 33 98 -86 -92 14 81 23 106 -43 -24 -35 -17 -17

55 63 17 -37 3 -39 59 -26 127 15 27 127 -44 -69-109 -7

19 60 -7 126 3 -56 -64 -38 127 2 119 18 2 -2 -10 46

91 -14 4 -39 60 46 -67-126 61 39 7 11 12 -74 -70-127 -81 -23 -91 -118 33 -41 56 -17 33 92 -80 -21 86 24 88 -15 -65 113 6 17 -3 75 -102 16 -106 5 25 32-107 -6 -48 89

-64 -33 63 -30 -2 23 -29 -127 -93 42 -68 -52 39 0 24 127

35 116 63 0 10 -19 -87 64 0 2 -21 27 -33 29 -91 17

-7 14 -15 19 -42 -22 -34 34 0 -6 92 -88 -127 -3 120 98

-54 26 39 98 -106 -70 -92 31 75 38 -11 -90 47 45 -37 -39

The variable fgCutFreqH[ h]=((h + 3)«2)-l, with h = 0..12.

The variable fgCutFreqV[ v]=((v + 3)«2)-l, with v = 0..12.

The variable fgCoeffs[ h ][ v ][ i ][ j ] is initially set equal to 0, with h = 0..12, v = 0..12, i = 0..63, j = 0..63, and is derived as follows: for(h = 0; h < 13 , h++ ) { for(v = 0; v < 13 , v++ ) { pmgVal = SeedLUT( h + 13 * v ) for( i = 0; i <= fgCutFreqH[ h ] ; i++ ) { for( j = 0; j <= fgCutFreqV[ v ] ; j++ ) { for( k = 0; k < 4; k++ ) fgCoeffs[ h][v][i][j+k] = gaussianLUT[ ( prngVal + k ) % 2048 ] pmgVal = Pmg( pmgVal )

}

} }

}

For given h, and v, with h = 0..12, v = 0..12, the array GrainDb[ h ][ v ][ i ][ j ] is derived from fgCoeffs [ h ][ v ][ i ][j ] with i = 0..63 J = 0..63 , by invoking the transformation process as specified in Rec. ITU-T H.266 | ISO/IEC 23090-3, clause 8.7.4.4, with trType inferred to equal 0.

The grain pattern database GrainDb is further refined as follows:

GrainDb[ h ][ v ][ i ][ j ] = Clip3( -127, 127 , GrainDb[ h ][ v ][ i ][ j ] ) (xx) deblockFactor[ v ] = { 64, 71, 77, 84, 90, 96, 103, 109, 116, 122, 128, 128, 128 } (xx) for( i = 0; i < 64 ; i += BlockSize ) { for(j = 0;j < 64 ;j++ ) {

GrainDb[ h ][ v ][ i ][j ] = ( GrainDb[ h ][ v ][ i ][j ] * deblockFactor[ v ] ) » 7(xx) GrainDb[ h ] [ v ] [ i + BlockSize - 1 ] [ j ] =

( GrainDb[ h ] [ v ] [ i + BlockSize - 1] [ j ] * deblockFactor[ v ] ) » 7

}

}

}

1.1.3.2 Grain blending process

Inputs to this process are the decoded picture prior to grain blending, i.e., the arrays decPicture L , decPicturecb and decPicturecr.

Outputs of this process are the modified decoded picture after grain blending, i.e., the array blendPicture L , blendPicturea, and blendPicturecr.

Depending on the value of the colour component cldx, the following assignment is made:

- If cldx is equal to 0, decSamples corresponds to the decoded picture sample array decPicture L and blendSamples corresponds to the blended sample array blendPicture L .

- else if cldx is equal to 1, decSamples corresponds to the decoded picture sample array decPicturec b and blendSamples corresponds to the blended sample array blendPicturea, ·

- otherwise (cldx is equal to 2), decSamples corresponds to the decoded picture sample array decPicturec r and blendSamples corresponds to the blended sample array blendPicturec r .

For given cldx,

- If fg_comp_model_present_flag[ cldx ] is equal to 0, blendSamples[i]|j] = decSamples[i]|j], with i=0.. (cIdx==0):PicWidthInLumaSamples: PicWidthInLumaSamples/2, j =0.. (cldx==0) : Pic W idthlnLumaSample s : PicHeightInLumaSamples/2 - Otherwise (fg_comp_model_present_flag[ cldx ] is not equal to 0), the following applies:

- The variable PicWidthlnBlockY and PicHeightlnBlockY are derived as follows: PicWidthlnBlockY = Ceil( PicWidthlnLumaSamples ÷ BlockSize )

PicHeightlnBlockY = Ceil( PicHeightlnLumaSamples ÷ BlockSize )

- The variable PicWidthlnBlockC and PicHeightlnBlockC are derived as follows: PicWidthlnBlockC = Ceil( PicWidthlnLumaSamples ÷ 2 ÷ BlockSize ) PicHeightlnBlockC = Ceil( PicHeightlnLumaSamples ÷ 2 ÷ BlockSize )

- For color component index cldx, with cldx=0..2, the variable PicWidthlnBlock ad PicHeightlnBlock are derived as follows:

PicWidthlnBlock = ( cldx == 0) ? PicWidthlnBlockY : PicWidthlnBlockC PicHeightlnBlock = ( cldx == 0) ? PicHeightlnBlockY : PicHeightlnBlockC

- The seed initialization for current picture is invoked in clause 1.1.3.2.1 with cldx as inputs, and outputs are array prngArray.

- The grain blending process is performed on a block basis. For every block with block location ( rx, ry), where rx = 0.. PicWidthlnBlock - 1 and ry = O..PicHeightIn Block - 1, the grain block blending process is invoked as specified in clause 1.1.3.2.2, with the location (xCurr, yCurr) set equal to (rx*BlockSize, ry*BlockSize), cldx assigned to cldx, (xldx, yldx) set equal to (rx, ry), the array prngArray and decSamples as inputs, and the outputs are blendSamples.

1.1.3.2.1 Seed initialization for current picture

Input to this process is a variable cldx specifying the colour component.

The output of this process are picture seed array prngArray.

The function MSB16(x) with x = 0..2 L (32) - 1, is defined as follows:

MSB16(x) = ((x&OxFFFFOOOO)» 16)

The function LSB16(x) with x = 0..2 L (32) - 1, is defined as follows:

LSB16(x) = (x&OxOOOOFFFF)

The function BIT0(x) with x = 0..2 L (32) - 1, is defined as follows:

BIT0(x) = (x&Oxl)

The variable picOffset = PicOrderCnt (e.g., PicOrderCnt = PicOrderCntVal)

The variable cOffset = (cldx==0)? 0: (cldx==l) ? 85:170)

The variable pmglnit = SeedLUT[ picOffset + cOffset) % 256]

The array prngArray [i] [j] with i=0.. PicHeightlnBlock — 1, j=0.. PicWidthlnBlock -1 is derived as follows:

The variable pmgVal = pmglnit bide = ((BlockSize == 8) ? 2 : 1 for( i = 0; i < PicHeightlnBlock/bldc ; i ++ ) { for( j = 0; j < PicWidthlnBlock/bldc; j ++ ) { if (bide == 2) { pmgArray[2*i][2*j] = pmgVal pmgArray[2*i][2*j+l] = pmgVal prngArray[2*i+l][2*j] = pmgVal prngArray[2*i+l][2*j+l] = prngVal

}else prngArray[i][j] = prngVal prngVal = Pmg(prngVal)

}

1.1.3.2.2 Grain block blending process Inputs to this process are:

- a location ( xCurr, yCurr ) specifying the top-left sample of the current block relative to the top-left sample of the current picture component,

- a variable cldx specifying the colour component of the current block,

- a block index ( xldx, yldx ) specifying the block index of the current block,

- a picture seed array pmgArray,

- a decoded sample array decSamples

Outputs to this process are blended sample array blendSamples.

The variable picWidth = (cldx==0)? PicWidthlnLumaSamples : PicWidthInLumaSamples/2 The variable picHeight = (cldx==0)? PicHeightlnLumaSamples : PicHeightInLumaSamples/2 The variable intensity Intevalldx for the current block is initialized to be - 1 and is derivded as follows:

sumBlock = 0 avgRatio = Log2(BlockSize / 8) for( i = 0; i < BlockSize ; i++ ) for( j = 0; j < BlockSize ; j++ ) sumBlock += decSamples [Min(picWidth - 1, xCurr + i )][Min( picHeight - 1, yCurr +j )] (xx) b avg = Clip3( 0, 255,

( sumBlock + ( 1 « ( fgBitDepth[ cldx ] + 2 * avgRatio - 3 ) ) ) » ( fgBitDepth[ cldx ] + 2 * avgRatio - 2 ) ) for( i = 0; i <= fg_num_intensity_intervals_minusl[ cldx ]; i++ ) if( b avg >= fg_intensity_interval_lower_bound[ cldx ][ i ] && b avg <= fg_intensity_interval_upper_boimd[ cldx ][ i ] ) { intensitylntervalldx = i (xx) break

}

The derivation of decSamples for the current block is as follows:

- If intensitylntervalldx == - 1, blendSamples[ xCurr+ i ][ yCurr+j ] = decSamples[ xCurr+ i ][ yCurr+j ], with i=0..Min(pic Width - xCurr - 1, BlockSize -1), j=0.. Min(picHeight - yCurr - 1, BlockSize -1;

- Otherwise (intensitylntervalldx != - 1), the following applies:

- The variable scaleFactor = fg_comp_model_value[ cldx ][ intensitylntervalldx ][ 0 ] *

( 1 - 2 * BIT0(pmgArray[yIdx][xIdx])

- The variable hFreq is derived as follows: hFreq = fg_comp_model_value[ cldx ][ intensitylntervalldx] [ 1 ] hFeq = (cldx == 0) ? hFreq : Clip3(2, 14, (hFreq « 1)) hFeq = hFreq - 2

- The variable vFreq is derived as follows: vFreq = fg_comp_model_value[ cldx ][ intensitylntervalldx] [ 2 ] vFeq = (cldx == 0) ? vFreq : Clip3(2, 14, (vFreq « 1)) vFeq = vFreq - 2

- The variable horzDenom = (BlockSize==32)? 36: 52

- The variable vertDenom = (BlockSize==32)? 40: 56 - The variable horzOffset is derived as follows: horzOffset = MSB16(pmgArray[yIdx][xIdx]% horzDenom) horzOffset &= OxFFFC horzOffset += ( BlockSize == 8 )? (xldx & 0x0008) : 0

- The variable vertOffset is derived as follows: vertOffset = LSB16(pmgArray[yIdx][xIdx]% vertDenom) vertOffset &= 0xFFF8 vertOffset += ( BlockSize == 8 )? (yldx & 0x0008) : 0

- The array grainSamples is derived as follows: grainSamples[xCurr + i ][ yCurr + j ] =

( scaleFactor * grainDb[hFreq ][ vFreq ][ i + horzOffset] [ j + vertOffset] ) » ( fg_log2_sc ale factor + 6 ) with i=0..Min(picWidth - xCurr - 1, BlockSize -1), j=0.. Min(picHeight - yCurr - 1, BlockSize -1)

The grainSample is further refined as follows:

- if xCurr > 0, the following applies: for( k = 0; k < BlockSize; k++ ) {

11 = grainSamples [xCurr - 2][k]

10 = grainSamples [xCurr - l][k] rO = grainSample [xCurr] [k] rl = grainSample [xCurr+l][k] grainSamples [xCurr] [k] = ( (10 + (rO « 1 ) + rl ) » 2) grainSamples [xCurr - l][k] = ( (11 + (10 « 1 ) + rO ) » 2)

- The array blendSamples is derived as follows: blendSample[xCurr+i][yCurr+j] = Clip3( 0, ( 1 « fgBitDepth[ cldx ] ) - 1, decodedSamples[xCurr+i][yCurr+j] + grainSamples[xCurr+i][yCurr+j] ) with i=0..Min(pic Width - xCurr - 1, BlockSize -1), j=0.. Min(picHeight - yCurr - 1, BlockSize -1)