Skip to content

Commit b255374

Browse files
committed
Crop frames in VideoStreamTheora, fixes godotengine#62752
1 parent 4ead2c2 commit b255374

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

modules/theora/video_stream_theora.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ void VideoStreamPlaybackTheora::video_write(th_ycbcr_buffer yuv) {
8181
}
8282

8383
Ref<Image> img = memnew(Image(size.x, size.y, false, Image::FORMAT_RGBA8, frame_data)); //zero copy image creation
84+
if (region.size.x != size.x || region.size.y != size.y) {
85+
img = img->get_region(region);
86+
}
8487

8588
texture->update(img); //zero copy send to rendering server
8689

@@ -286,14 +289,14 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {
286289
th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level, sizeof(pp_level));
287290
pp_inc = 0;
288291

289-
int w;
290-
int h;
291-
w = ((ti.pic_x + ti.frame_width + 1) & ~1) - (ti.pic_x & ~1);
292-
h = ((ti.pic_y + ti.frame_height + 1) & ~1) - (ti.pic_y & ~1);
293-
size.x = w;
294-
size.y = h;
292+
size.x = ti.frame_width;
293+
size.y = ti.frame_height;
294+
region.position.x = ti.pic_x;
295+
region.position.y = ti.pic_y;
296+
region.size.x = ti.pic_width;
297+
region.size.y = ti.pic_height;
295298

296-
Ref<Image> img = Image::create_empty(w, h, false, Image::FORMAT_RGBA8);
299+
Ref<Image> img = Image::create_empty(region.size.x, region.size.y, false, Image::FORMAT_RGBA8);
297300
texture->set_image(img);
298301

299302
} else {

modules/theora/video_stream_theora.h

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback {
5050
Ref<FileAccess> file;
5151
String file_name;
5252
Point2i size;
53+
Rect2i region;
5354

5455
int buffer_data();
5556
int queue_page(ogg_page *page);

0 commit comments

Comments
 (0)