A method for in-loop converting image data between an input bit depth and a target bit depth in an encoder, the method comprising: accessing an input image in the input bit depth; dividing the input image into coding regions; for each coding region of the input image in the input bit depth: generating or selecting a forward reshaping function and a backward reshaping function for the coding region, wherein the forward reshaping function is configured to convert image data in the input bit depth to the target bit depth, wherein the backward reshaping function is configured to convert image data in the target bit depth to the input bit depth, and wherein the target bit depth is lower or equal to the input bit depth; accessing reference data in the input bit depth, the reference data being pixel data from a related previously coded region; applying the forward reshaping function to the reference data and to pixel data of the coding region to generate second reference data and second coding region pixel data in the target bit depth; encoding with an encoder the second reference data and the second coding region pixel data to generate a coded bit stream in the target bit depth; generating, using the encoder, reconstructed data based on an in-loop decoding of the coded bit stream; and applying the backward reshaping function to the reconstructed data to generate future reference data in the input bit depth, the future reference data being stored in a frame buffer to be used as reference data in the coding of future coding regions, wherein for each coding region of the input image in the input bit depth, multiplexing the coded bit stream with metadata characterizing the forward reshaping function and/or the backward reshaping function. accessing an input image in the input bit depth; dividing the input image into coding regions; for each coding region of the input image in the input bit depth: generating or selecting a forward reshaping function and a backward reshaping function for the coding region, wherein the forward reshaping function is configured to convert image data in the input bit depth to the target bit depth, wherein the backward reshaping function is configured to convert image data in the target bit depth to the input bit depth, and wherein the target bit depth is lower or equal to the input bit depth; accessing reference data in the input bit depth, the reference data being pixel data from a related previously coded region; applying the forward reshaping function to the reference data and to pixel data of the coding region to generate second reference data and second coding region pixel data in the target bit depth; encoding with an encoder the second reference data and the second coding region pixel data to generate a coded bit stream in the target bit depth; generating, using the encoder, reconstructed data based on an in-loop decoding of the coded bit stream; and applying the backward reshaping function to the reconstructed data to generate future reference data in the input bit depth, the future reference data being stored in a frame buffer to be used as reference data in the coding of future coding regions, wherein for each coding region of the input image in the input bit depth, multiplexing the coded bit stream with metadata characterizing the forward reshaping function and/or the backward reshaping function. generating or selecting a forward reshaping function and a backward reshaping function for the coding region, wherein the forward reshaping function is configured to convert image data in the input bit depth to the target bit depth, wherein the backward reshaping function is configured to convert image data in the target bit depth to the input bit depth, and wherein the target bit depth is lower or equal to the input bit depth; accessing reference data in the input bit depth, the reference data being pixel data from a related previously coded region; applying the forward reshaping function to the reference data and to pixel data of the coding region to generate second reference data and second coding region pixel data in the target bit depth; encoding with an encoder the second reference data and the second coding region pixel data to generate a coded bit stream in the target bit depth; generating, using the encoder, reconstructed data based on an in-loop decoding of the coded bit stream; and applying the backward reshaping function to the reconstructed data to generate future reference data in the input bit depth, the future reference data being stored in a frame buffer to be used as reference data in the coding of future coding regions, wherein for each coding region of the input image in the input bit depth, multiplexing the coded bit stream with metadata characterizing the forward reshaping function and/or the backward reshaping function.