示例#1
0
    def _fill_rect(self, window_line_buf, window, y, block_x):
        width = window.width if self._width == -1 else self._width
        height = window.height if self._height == -1 else self._height

        bg_color_start = self.color(window, self._bgcolor_start)
        bg_color_end = self.color(window, self._bgcolor_end)

        steps = 1
        if self._gradient_mode == GradientMode.LEFT_TO_RIGHT:
            steps = width - self._border_weight * 2
        elif self._gradient_mode == GradientMode.TOP_TO_BOTTOM:
            steps = height - self._border_weight * 2
        elif self._gradient_mode == GradientMode.TOP_LEFT_TO_BOTTOM_RIGHT or \
                self._gradient_mode == GradientMode.BOTTOM_LEFT_TO_TOP_RIGHT:
            steps = (width - self._border_weight * 2) * (
                height - self._border_weight * 2)

        R_delta = ((bg_color_end >> 16 & 0xFF) -
                   (bg_color_start >> 16 & 0xFF)) / steps
        G_delta = ((bg_color_end >> 8 & 0xFF) -
                   (bg_color_start >> 8 & 0xFF)) / steps
        B_delta = ((bg_color_end >> 0 & 0xFF) -
                   (bg_color_start >> 0 & 0xFF)) / steps

        color = bg_color_start
        step = 0

        for x in range(block_x + self._border_weight,
                       block_x + width - self._border_weight):
            if self._gradient_mode == GradientMode.NONE:
                factor = 0
            elif self._gradient_mode == GradientMode.LEFT_TO_RIGHT:
                factor = x - block_x + self._border_weight
            elif self._gradient_mode == GradientMode.TOP_TO_BOTTOM:
                factor = y
            elif self._gradient_mode == GradientMode.TOP_LEFT_TO_BOTTOM_RIGHT:
                factor = (x - block_x + self._border_weight) * y
            elif self._gradient_mode == GradientMode.BOTTOM_LEFT_TO_TOP_RIGHT:
                factor = (x - block_x + self._border_weight) * (
                    height - self._border_weight - y)
            else:
                raise Exception('Unknown gradient mode <%s>' %
                                self._gradient_mode.name)
            color = ImageUtil.color_add(bg_color_start, R_delta * factor,
                                        G_delta * factor, B_delta * factor)

            window_line_buf[x] = color
示例#2
0
    def _fill_rect(self, window_line_buf, window, y, block_x):

        if self._gradient_mode == GradientMode.NONE:
            return

        width = window.width if self._width == 0 else self._width
        height = window.height if self._height == 0 else self._height

        bg_color_start = self.get_color(self._bgcolor_start)
        bg_color_end = self.get_color(self._bgcolor_end)

        color_steps = 1
        fill_width = width - self._border_weight * 2
        fill_height = height - self._border_weight * 2
        if self._gradient_mode == GradientMode.LEFT_TO_RIGHT:
            color_steps = fill_width
        elif self._gradient_mode == GradientMode.TOP_TO_BOTTOM:
            color_steps = fill_height
        elif self._gradient_mode == GradientMode.TOP_LEFT_TO_BOTTOM_RIGHT or \
                self._gradient_mode == GradientMode.BOTTOM_LEFT_TO_TOP_RIGHT:
            color_steps = fill_width * fill_height
        elif self._gradient_mode == GradientMode.CORNER_TO_CENTER:
            color_steps = (fill_width * fill_height) >> 2

        r_start, g_start, b_start = ImageUtil.rgb(bg_color_start)
        r_end, g_end, b_end = ImageUtil.rgb(bg_color_end)

        r_delta = (r_end - r_start) / color_steps
        g_delta = (g_end - g_start) / color_steps
        b_delta = (b_end - b_start) / color_steps

        for x in range(block_x + self._border_weight,
                       block_x + width - self._border_weight):
            fill_x = x - (block_x + self._border_weight)
            fill_y = y - self._border_weight
            if self._gradient_mode == GradientMode.SOLID:
                factor = 0
            elif self._gradient_mode == GradientMode.LEFT_TO_RIGHT:
                factor = fill_x
            elif self._gradient_mode == GradientMode.TOP_TO_BOTTOM:
                factor = y
            elif self._gradient_mode == GradientMode.TOP_LEFT_TO_BOTTOM_RIGHT:
                factor = fill_x * fill_y
            elif self._gradient_mode == GradientMode.BOTTOM_LEFT_TO_TOP_RIGHT:
                factor = fill_x * (fill_height - fill_y)
            elif self._gradient_mode == GradientMode.CORNER_TO_CENTER:
                if fill_x <= (fill_width >> 1):
                    factor_x = fill_x
                else:
                    factor_x = fill_width - fill_x

                if fill_y <= (fill_height >> 1):
                    factor_y = fill_y
                else:
                    factor_y = (fill_height - fill_y)
                factor = factor_x * factor_y
            else:
                raise Exception('Unknown gradient mode <%s>' %
                                self._gradient_mode.name)
            color = ImageUtil.color_add(bg_color_start, r_delta * factor,
                                        g_delta * factor, b_delta * factor)
            if 0 <= x < window.width:
                window_line_buf[x] = color