Exemplo n.º 1
0
    def draw_8bit_10bit_checker(self, bit_depth='8bit', pos_v_coef=0.5):
        """
        256~768 の 8bit/10bitのRampパターンを描く
        """
        # パラメータ計算
        width = self.get_bit_depth_checker_grad_width()
        height = int(self.img_height * self.ramp_height_coef)
        grad_st_pos_h, grad_ed_pos_h = self.get_bit_depth_checker_grad_st_ed()
        width_after_trim = grad_ed_pos_h - grad_st_pos_h
        ramp_st_pos_h = self.get_ramp_st_pos_h(width_after_trim)
        ramp_st_pos_v = int(self.img_height * pos_v_coef)
        ramp_pos = (ramp_st_pos_h, ramp_st_pos_v)
        text_height, font_size = self.get_each_spec_text_height_and_size()
        text_8 = "8bit gray ramp (256, 260, 264, ..., 756, 760, 764 level)."
        text_10 = "10bit gray ramp (256, 257, 258, ..., 765, 766, 767 level)."
        text_sub = text_8 if bit_depth == '8bit' else text_10
        text = "▼ " + text_sub
        text_pos = self.get_text_st_pos_for_over_info(ramp_pos, text_height)

        # ramp パターン作成
        step_num = 257 if bit_depth == '8bit' else 1025
        ramp = tpg.gen_step_gradation(width=width,
                                      height=height,
                                      step_num=step_num,
                                      bit_depth=self.bit_depth,
                                      color=(1.0, 1.0, 1.0),
                                      direction='h')
        tpg.merge(self.img, ramp[:, grad_st_pos_h:grad_ed_pos_h], pos=ramp_pos)
        self.merge_each_spec_text(text_pos, font_size,
                                  (width_after_trim, text_height), text)
Exemplo n.º 2
0
    def draw_10bit_ramp(self):
        """
        10bitのRampパターンを描く
        """
        global g_cuurent_pos_v

        # パラメータ計算
        width = (self.img_height // 1080) * 1024
        height = int(self.img_height * self.ramp_height_coef)
        ramp_st_pos_h = self.get_ramp_st_pos_h(width)
        ramp_st_pos_v = int(self.img_height * self.ramp_st_pos_v_coef)
        ramp_pos = (ramp_st_pos_h, ramp_st_pos_v)
        text_height, font_size = self.get_each_spec_text_height_and_size()
        text_sub = " 10bit gray ramp (0, 1, 2, ..., 1021, 1022, 1023 level)."
        text = "▼" + text_sub
        text_pos = self.get_text_st_pos_for_over_info(ramp_pos, text_height)

        # ramp パターン作成
        ramp_10bit = tpg.gen_step_gradation(width=width,
                                            height=height,
                                            step_num=1025,
                                            bit_depth=self.bit_depth,
                                            color=(1.0, 1.0, 1.0),
                                            direction='h')
        tpg.merge(self.img, ramp_10bit, pos=ramp_pos)
        self.merge_each_spec_text(text_pos, font_size, (width, text_height),
                                  text)
Exemplo n.º 3
0
def _test_save_various_format(width=1024, height=768):
    grad_10 = tpg.gen_step_gradation(width=width, height=height,
                                     step_num=1025, bit_depth=10,
                                     color=(1.0, 1.0, 1.0), direction='h')
    grad_10 = grad_10 / np.max(grad_10)

    # attr_dpx = {"oiio:BitsPerSample": 12}
    # save_img_using_oiio(grad_10, 'test_dpx_12bit.dpx',
    #                     out_img_type_desc=oiio.UINT16, attr=attr_dpx)

    # timecode = '01:23:45:12'
    # attr_dpx = {"oiio:BitsPerSample": 10,
    #             'dpx:TimeCode': timecode,
    #             'dpx:UserBits': 0,
    #             'dpx:FrameRate': 24.0,
    #             'dpx:TemporalFrameRate': 24.0,
    #             'dpx:TimeOffset': 0.0,
    #             'dpx:BlackLevel': 64,
    #             'dpx:BlackGain': 0.0,
    #             'dpx:BreakPoint': 0.0,
    #             'dpx:WhiteLevel': 940}
    # save_img_using_oiio(grad_10, 'test_dpx_10bit.dpx',
    #                     out_img_type_desc=oiio.UINT16, attr=attr_dpx)

    # OpenEXR へのタイムコード埋め込みは失敗。どうすればいいの?
    timecode = '02:31:59:19'
    timecode_bcd = timecode_str_to_bcd(timecode)
    attr_openexr = {'smpte:TimeCode': [oiio.TypeDesc.TypeTimeCode, timecode_bcd]}
    save_img_using_oiio(grad_10, 'test_dpx_10bit.exr',
                        out_img_type_desc=oiio.UINT16, attr=attr_openexr)
Exemplo n.º 4
0
    def draw_wrgbmyc_color_bar_type2(self):
        """
        階段状のカラーバーをプロットする
        """
        scale_step = 257
        color_list = [(1, 1, 1)]
        width = int(self.img_width * self.step_bar_width_coef_type2) * 4
        height = int(self.img_height * self.step_bar_height_coef_type2)
        vspace = int(self.img_height * self.step_bar_v_space_coef_type2)
        color_bar_st_pos_h = int(self.img_width *
                                 self.step_bar_st_pos_h_coef_type2)
        color_bar_st_pos_v = int(self.img_height *
                                 self.step_bar_st_pos_v_coef_type2)
        st_pos = (color_bar_st_pos_h, color_bar_st_pos_v)

        bar_height_list = tpg.equal_devision(height, len(color_list))
        bar_img_list = []
        for color, bar_height in zip(color_list, bar_height_list):
            color_bar = tpg.gen_step_gradation(width=width,
                                               height=bar_height,
                                               step_num=scale_step,
                                               bit_depth=self.bit_depth,
                                               color=color,
                                               direction='h')
            bar_img_list.append(color_bar)
        color_bar = np.vstack(bar_img_list)

        # テキストデータ作成
        txt_img = self.get_video_level_text_img(scale_step, width, type=2)

        # 最終データだけ削除(後で4分割できるように)
        width = int(round(width / 257 * 256))
        color_bar = color_bar[:, :width, :]
        txt_img = txt_img[:, :width, :]

        for idx in range(4):
            img_pos_h = (width // 4) * idx
            img_merge_width = (width // 4)
            color_bar_temp = color_bar[:,
                                       img_pos_h:img_pos_h + img_merge_width]
            txt_img_temp = txt_img[:, img_pos_h:img_pos_h + img_merge_width]
            tpg.merge(self.img, color_bar_temp, st_pos)
            text_pos = self.get_text_st_pos_for_over_info(
                st_pos, txt_img.shape[0])
            self.merge_text(txt_img_temp, text_pos)
            st_pos = (st_pos[0], st_pos[1] + vspace)
Exemplo n.º 5
0
    def draw_wrgbmyc_color_bar(self):
        """
        階段状のカラーバーをプロットする
        """
        scale_step = 65
        color_list = [(1, 1, 1), (1, 1, 1), (1, 0, 0), (0, 1, 0), (0, 0, 1),
                      (1, 0, 1), (1, 1, 0), (0, 1, 1)]
        width = int(self.img_width * self.step_bar_width_coef)
        height = int(self.img_height * self.step_bar_height_coef)
        color_bar_st_pos_h = self.get_color_bar_st_pos_h(width)
        color_bar_st_pos_v = int(self.img_height * self.step_bar_st_pos_v_coef)
        st_pos = (color_bar_st_pos_h, color_bar_st_pos_v)

        bar_height_list = tpg.equal_devision(height, len(color_list))
        bar_img_list = []
        for color, bar_height in zip(color_list, bar_height_list):
            color_bar = tpg.gen_step_gradation(width=width,
                                               height=bar_height,
                                               step_num=scale_step,
                                               bit_depth=self.bit_depth,
                                               color=color,
                                               direction='h')
            bar_img_list.append(color_bar)
        color_bar = np.vstack(bar_img_list)
        tpg.merge(self.img, color_bar, st_pos)

        # ここからテキスト。あらかじめV方向で作っておき、最後に回転させる
        txt_img = self.get_video_level_text_img(scale_step, width)
        text_pos = self.get_text_st_pos_for_over_info(st_pos, txt_img.shape[0])
        self.merge_text(txt_img, text_pos)

        # 説明文を下に追加する
        text_pos_v = st_pos[1] + color_bar.shape[0]
        text_pos = (st_pos[0], text_pos_v)
        text_height, font_size = self.get_each_spec_text_height_and_size()
        level_text = " (0, 16, 32, ..., 992, 1008, 1023 Level)"
        text = "▲ WRGBMYC Color Gradation" + level_text
        self.merge_each_spec_text(text_pos, font_size, (width, text_height),
                                  text)
Exemplo n.º 6
0
def composite_color_bar_ramp(img, resolution, eotf):
    """
    Rampパターンを合成するよん
    """
    # 左端に0% Black
    h_st_pos = 0
    h_ed_pos = h_st_pos + Cc[resolution]
    v_st_pos = Bb[resolution] // 12 + Bb[
        resolution] // 2 + +Bb[resolution] // 12
    v_ed_pos = v_st_pos + Bb[resolution] // 12
    _composite_color_img(img, h_st_pos, h_ed_pos, v_st_pos, v_ed_pos, K0[eotf])
    # Ramp の左端黒ベタ
    h_st_pos, h_ed_pos =\
        _update_param_horizontal_cb(h_st_pos, h_ed_pos, BB[eotf][resolution])
    _composite_color_img(img, h_st_pos, h_ed_pos, v_st_pos, v_ed_pos,
                         Ramp[eotf]['min'])

    # とりあえずRamp作る
    rate = _get_pixel_rate(resolution)
    width = 1024 * rate
    height = v_ed_pos - v_st_pos
    ramp = tpg.gen_step_gradation(width=width,
                                  height=height,
                                  step_num=1025,
                                  bit_depth=10,
                                  color=(1.0, 1.0, 1.0),
                                  direction='h')
    h_st_pos = h_ed_pos
    h_ed_pos = h_st_pos + CC[eotf][resolution]
    ramp_st_offset = Ramp[eotf]['min'][0] * rate
    ramp_ed = (Ramp[eotf]['max'][0]) * rate
    img[v_st_pos:v_ed_pos, h_st_pos:h_ed_pos] = ramp[:, ramp_st_offset:ramp_ed]

    # 右端のフラットな領域
    h_st_pos = h_ed_pos
    h_ed_pos = h_st_pos + DD[eotf][resolution]
    temp_img = np.ones((height, h_ed_pos - h_st_pos, 3), dtype=np.uint16)
    temp_img *= bit_shift_10_to_16(Ramp[eotf]['max'][0])
    img[v_st_pos:v_ed_pos, h_st_pos:h_ed_pos] = temp_img