• YCbCr to RGB and RGB toYCbCr


    RGB => YCbCr:

    Y = 0.299R + 0.587G + 0.114B
    Cb = -0.1726R - 0.3388G + 0.5114B + 128
    Cr = 0.5114R - 0.4282G – 0.0832B + 128

    Then we get YCbCr => RGB:

    R = Y + 1.371(Cr – 128)
    G = Y – 0.6982(Cr – 128) – 0.3365(Cb – 128)
    B = Y + 1.732(Cb – 128)

    8bit conversion equation
    Y = (77R + 150G + 29B)>>8
    Cb = (-44R – 87G + 131B)>>8 + 128
    Cr = (131R – 110G – 21B)>>8 + 128

    R = Y + (351(Cr – 128))>>8
    G = Y – (179(Cr – 128) + 86(Cb - 128))>>8
    = Y – (179Cr + 86Cb)>>8 + ((179 + 86) * 128)>>8
    = Y + 133 – (128 + 179Cr + 86Cb)>>8
    B = Y + (443(Cb - 128))>>8

    To use look-up table, we can change to following format:

    RGB => YCbCr:
    We adjust a little of the factors to avoid saturation operation to improve performance
    Y = (77R + 150G + 29B)>>8
    Cb = (128B – 43R – 85G)>>8 + 128 = (32768 + 128B – 43R – 85G)>>8
    Cr = (128R – 107G – 21B)>>8 + 128 = (32768 + 128R – 107G – 21B)>>8

    It needs 8 look-up tables:
    T_77 [256], T_150 [256], T_29 [256], T_128 [256],
    T_43 [256], T_85 [256], T_107 [256], T_21 [256]

    YCbCr => RGB
    R = SATURATION (Y + 1.371(Cr – 128))  
    G = SATURATION (Y – 0.6982(Cr – 128) – 0.3365(Cb – 128))
    B = SATURATION (Y + 1.732(Cb – 128))
    Here, “SATURATION (A)” means:
    If (A > 255)
    A = 255
    Else if (A < 0)
    A = 0

    It needs 4 tables:
    Cr_1371 [256], Cr_06982 [256], Cb_03365 [256], Cb_1732 [256]

  • 相关阅读:
    Toolbar设置回退箭头的方法
    Android进程绝杀技--forceStop
    线程池的经典使用
    Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
    adb pull apk
    工厂模式_工厂方法模式
    工厂模式_简单工厂模式
    spring_aop
    代理模式_动态代理
    代理模式_静态代理
  • 原文地址:https://www.cnblogs.com/wenrenhua08/p/3934828.html
Copyright © 2020-2023  润新知