Confusion on YUV NV21 conversion to RGB

后端 未结 2 1706
忘了有多久
忘了有多久 2020-11-27 13:56

According to http://developer.android.com/reference/android/graphics/ImageFormat.html#NV21, NV21 is the default used format.

There are quite a number of code on web

2条回答
  •  星月不相逢
    2020-11-27 14:08

    Terms like "most significant position" are ambiguous, because it depends on the endian of the machine.

    When all data types are 8 bits, there is an easy unambiguous specification: byte order. For example, unsigned char rgba[4]; would have the data stored as rgba[0] = r; rgba[1] = g; rgba[2] = b; rgba[3] = a;

    or {r, g, b, a } regardless of the endianness of the processor.

    If instead you did

    int32 color = (r << 24) | (g << 16) | (b << 8) | (a << 0);

    you would get { r, g, b, a } on a big-endian system, and { a, r, g, b } on a little-endian system. Do you work on systems that have heterogeneous processors? Like maybe you have a CPU and a GPU? How do they know which endian the other is using? You are much better off defining the byte ordering.

提交回复
热议问题