Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / bitmap_decoded_image_data.lucb

#==============================================================================================
#
#   bitmap_decoded_image_data - HTML::BitmapDecodedImageData: an image's decoded frames
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp (lines 17-70) with the inline
#       overrides of BitmapDecodedImageData.h (lines 30-32). Its frames come from the
#       ImageCodecPlugin (platform/image_codec_plugin_luce.lucb decodes through luce-png and
#       luce-jpeg).
#
#       Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:19 Web::HTML::BitmapDecodedImageData::create.
pub func html_bitmap_decoded_image_data_create(realm: Realm*, frames: ak.Vector[HtmlBitmapDecodedImageDataFrame], loop_count: usize, animated: bool) -> HtmlDecodedImageData*!:
    return realm_create_html_bitmap_decoded_image_data(realm, frames, loop_count, animated).html_decoded_image_data()

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:24 Web::HTML::BitmapDecodedImageData::BitmapDecodedImageData.
func html_bitmap_decoded_image_data_construct(this: HtmlBitmapDecodedImageData*, frames: ak.Vector[HtmlBitmapDecodedImageDataFrame], loop_count: usize, animated: bool):
    html_decoded_image_data_construct(this.html_decoded_image_data())
    this.m_frames = frames
    this.m_loop_count = loop_count
    this.m_animated = animated

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.h:30 Web::HTML::BitmapDecodedImageData::frame_count (override).
pub func html_bitmap_decoded_image_data_frame_count_impl(base: HtmlDecodedImageData*) -> usize:
    return ak.vector_size(&((HtmlBitmapDecodedImageData*)base).m_frames)

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.h:31 Web::HTML::BitmapDecodedImageData::loop_count (override).
pub func html_bitmap_decoded_image_data_loop_count_impl(base: HtmlDecodedImageData*) -> usize:
    return ((HtmlBitmapDecodedImageData*)base).m_loop_count

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.h:32 Web::HTML::BitmapDecodedImageData::is_animated (override).
pub func html_bitmap_decoded_image_data_is_animated_impl(base: HtmlDecodedImageData*) -> bool:
    return ((HtmlBitmapDecodedImageData*)base).m_animated

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:33 Web::HTML::BitmapDecodedImageData::bitmap (override).
pub func html_bitmap_decoded_image_data_bitmap_impl(base: HtmlDecodedImageData*, frame_index: usize, arg1: gfx.IntSize) -> gfx.ImmutableBitmap*?:
    let this = (HtmlBitmapDecodedImageData*)base
    if frame_index >= ak.vector_size(&this.m_frames):
        return none
    return ak.vector_at(&this.m_frames, frame_index).bitmap

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:40 Web::HTML::BitmapDecodedImageData::frame_duration (override).
pub func html_bitmap_decoded_image_data_frame_duration_impl(base: HtmlDecodedImageData*, frame_index: usize) -> i32:
    let this = (HtmlBitmapDecodedImageData*)base
    if frame_index >= ak.vector_size(&this.m_frames):
        return 0
    return ak.vector_at(&this.m_frames, frame_index).duration

## `m_frames.first().bitmap`.
func html_bitmap_decoded_image_data_first_bitmap(this: HtmlBitmapDecodedImageData*) -> gfx.ImmutableBitmap*:
    return ak.vector_first(&this.m_frames).bitmap else trap("VERIFY: a decoded frame has a bitmap")

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:47 Web::HTML::BitmapDecodedImageData::intrinsic_width (override).
pub func html_bitmap_decoded_image_data_intrinsic_width_impl(base: HtmlDecodedImageData*) -> gfx.CssPixels?:
    let this = (HtmlBitmapDecodedImageData*)base
    return gfx.CssPixels.from_int(gfx.immutable_bitmap_width(html_bitmap_decoded_image_data_first_bitmap(this)))

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:52 Web::HTML::BitmapDecodedImageData::intrinsic_height (override).
pub func html_bitmap_decoded_image_data_intrinsic_height_impl(base: HtmlDecodedImageData*) -> gfx.CssPixels?:
    let this = (HtmlBitmapDecodedImageData*)base
    return gfx.CssPixels.from_int(gfx.immutable_bitmap_height(html_bitmap_decoded_image_data_first_bitmap(this)))

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:57 Web::HTML::BitmapDecodedImageData::intrinsic_aspect_ratio (override).
pub func html_bitmap_decoded_image_data_intrinsic_aspect_ratio_impl(base: HtmlDecodedImageData*) -> gfx.CssPixelFraction?:
    let this = (HtmlBitmapDecodedImageData*)base
    let bitmap = html_bitmap_decoded_image_data_first_bitmap(this)
    return gfx.CssPixels.from_int(gfx.immutable_bitmap_width(bitmap)).div(gfx.CssPixels.from_int(gfx.immutable_bitmap_height(bitmap)))

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:62 Web::HTML::BitmapDecodedImageData::frame_rect (override).
pub func html_bitmap_decoded_image_data_frame_rect_impl(base: HtmlDecodedImageData*, frame_index: usize) -> gfx.DevicePixelRect?:
    let this = (HtmlBitmapDecodedImageData*)base
    let bitmap = ak.vector_at(&this.m_frames, frame_index).bitmap else trap("VERIFY: a decoded frame has a bitmap")
    return gfx.immutable_bitmap_rect(bitmap)

## Ported from Libraries/LibWeb/HTML/BitmapDecodedImageData.cpp:67 Web::HTML::BitmapDecodedImageData::paint (override).
pub func html_bitmap_decoded_image_data_paint_impl(base: HtmlDecodedImageData*, context: DisplayListRecordingContext*, frame_index: usize, dst_rect: gfx.DevicePixelRect, clip_rect: gfx.DevicePixelRect, scaling_mode: gfx.ScalingMode):
    let this = (HtmlBitmapDecodedImageData*)base
    let bitmap = ak.vector_at(&this.m_frames, frame_index).bitmap else trap("VERIFY: a decoded frame has a bitmap")
    display_list.display_list_recorder_draw_scaled_immutable_bitmap(display_list_recording_context_display_list_recorder(context), dst_rect, clip_rect, bitmap, scaling_mode)