A method for coding an image comprising the steps of: - receiving an input high dynamic range image comprising pixels having linear luminances; - constructing a code allocation function to map a luminance of a pixel to a luma code value; - mapping the pixel luminances to pixel luma code values which encode these luminances using the code allocation function by generating the pixel luma code values corresponding to the luminances of pixels in the input high dynamic range image by applying the code allocation function, and storing for the pixels the luma code values in an image signal for transmission or storage; wherein the code allocation function mapping a linear luminance of a pixel to a luma code value is constructed from at least two partial functions (111, 113): - a first partial function of the at least two partial functions (111, 113), the first partial function defining a non-linear invertible mapping of an entire luminance range of a linear luminance input value to an entire luma range of a first output luma code value, and - a second partial function of the at least two partial functions (111, 113), the second partial function mapping a first output luma code value from the first partial function of the at least two partial functions (111,113) to a second output luma code value, and the second partial function defining a non-linear invertible mapping of an entire luma range of an input luma code value being the first output luma code value to an entire luma range of the second output luma code value, wherein the code allocation function defines a non-linear mapping of linear luminances to luma code values wherein the method comprises storing in the image signal for transmission or storage control data defining the first partial function and the second partial function, and wherein the method uses as one of the at least two partial functions (111,113): - a non-linear gamma curve in accordance with the sRGB specification; - a non-linear gamma curve in accordance with the ITU-R BT.709-5 specification; - a Dolby perceptual quantizer function; or - a function defined as: Y = L V 1 m − c 1 c 2 − c 3 ⋅ V 1 m 1 n where Y is a luma value, V is a linear luminance input value in the range of [0;1], L is a constant reflecting a white point, and m, n, c1, c2, and c3 are design parameters; or - a function defined as: x = 10 v − d c − b a where x is the output value in the range of [0;1], v is the input value in the range of [0;1], and the values a, b, c and d are design parameters. - receiving an input high dynamic range image comprising pixels having linear luminances; - constructing a code allocation function to map a luminance of a pixel to a luma code value; - mapping the pixel luminances to pixel luma code values which encode these luminances using the code allocation function by generating the pixel luma code values corresponding to the luminances of pixels in the input high dynamic range image by applying the code allocation function, and storing for the pixels the luma code values in an image signal for transmission or storage; wherein the code allocation function mapping a linear luminance of a pixel to a luma code value is constructed from at least two partial functions (111, 113): - a first partial function of the at least two partial functions (111, 113), the first partial function defining a non-linear invertible mapping of an entire luminance range of a linear luminance input value to an entire luma range of a first output luma code value, and - a second partial function of the at least two partial functions (111, 113), the second partial function mapping a first output luma code value from the first partial function of the at least two partial functions (111,113) to a second output luma code value, and the second partial function defining a non-linear invertible mapping of an entire luma range of an input luma code value being the first output luma code value to an entire luma range of the second output luma code value, wherein the code allocation function defines a non-linear mapping of linear luminances to luma code values wherein the method comprises storing in the image signal for transmission or storage control data defining the first partial function and the second partial function, and wherein the method uses as one of the at least two partial functions (111,113): - a non-linear gamma curve in accordance with the sRGB specification; - a non-linear gamma curve in accordance with the ITU-R BT.709-5 specification; - a Dolby perceptual quantizer function; or - a function defined as: Y = L V 1 m − c 1 c 2 − c 3 ⋅ V 1 m 1 n where Y is a luma value, V is a linear luminance input value in the range of [0;1], L is a constant reflecting a white point, and m, n, c1, c2, and c3 are design parameters; or - a function defined as: x = 10 v − d c − b a where x is the output value in the range of [0;1], v is the input value in the range of [0;1], and the values a, b, c and d are design parameters. - a non-linear gamma curve in accordance with the sRGB specification; - a non-linear gamma curve in accordance with the ITU-R BT.709-5 specification; - a Dolby perceptual quantizer function; or - a function defined as: Y = L V 1 m − c 1 c 2 − c 3 ⋅ V 1 m 1 n where Y is a luma value, V is a linear luminance input value in the range of [0;1], L is a constant reflecting a white point, and m, n, c1, c2, and c3 are design parameters; or - a function defined as: x = 10 v − d c − b a where x is the output value in the range of [0;1], v is the input value in the range of [0;1], and the values a, b, c and d are design parameters.