initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled

This commit is contained in:
2025-09-16 20:46:46 -04:00
commit 9d30169a8d
13378 changed files with 7050105 additions and 0 deletions

112
modules/jpg/SCsub Normal file
View File

@@ -0,0 +1,112 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *
Import("env")
Import("env_modules")
env_jpg = env_modules.Clone()
thirdparty_obj = []
thirdparty_dir = "#thirdparty/libjpeg-turbo"
thirdparty_sources_common = [
"jaricom.c",
"jcapimin.c",
"jcarith.c",
"jchuff.c",
"jcicc.c",
"jcinit.c",
"jcmarker.c",
"jcmaster.c",
"jcomapi.c",
"jcparam.c",
"jcphuff.c",
"jctrans.c",
"jdapimin.c",
"jdarith.c",
"jdatadst.c",
"jdatadst-tj.c",
"jdatasrc.c",
"jdatasrc-tj.c",
"jdhuff.c",
"jdicc.c",
"jdinput.c",
"jdmarker.c",
"jdmaster.c",
"jdphuff.c",
"jdtrans.c",
"jerror.c",
"jfdctflt.c",
"jmemmgr.c",
"jmemnobs.c",
"jpeg_nbits.c",
"transupp.c",
"turbojpeg.c",
]
thirdparty_sources_bit_dependent = [
"jcapistd.c",
"jccoefct.c",
"jccolor.c",
"jcdctmgr.c",
"jcmainct.c",
"jcprepct.c",
"jcsample.c",
"jdcoefct.c",
"jdcolor.c",
"jdapistd.c",
"jddctmgr.c",
"jdmainct.c",
"jdmerge.c",
"jdpostct.c",
"jdsample.c",
"jfdctfst.c",
"jfdctint.c",
"jidctflt.c",
"jidctfst.c",
"jidctint.c",
"jidctred.c",
"jutils.c",
"jquant1.c",
"jquant2.c",
]
thirdparty_sources_by_bits = {
8: list(thirdparty_sources_bit_dependent),
12: list(thirdparty_sources_bit_dependent),
}
def source_paths(files):
return [thirdparty_dir + "/src/" + f for f in files]
env_jpg.Prepend(CPPEXTPATH=[thirdparty_dir + "/src"])
def add_bit_depth(bit_depth: int):
env_bit_depth = env_jpg.Clone()
env_bit_depth.disable_warnings()
env_bit_depth["OBJSUFFIX"] = f"_{bit_depth}{env_bit_depth['OBJSUFFIX']}"
env_bit_depth.Append(CPPDEFINES=[f"BITS_IN_JSAMPLE={bit_depth}"])
env_bit_depth.add_source_files(thirdparty_obj, source_paths(thirdparty_sources_by_bits[bit_depth]))
add_bit_depth(8)
add_bit_depth(12)
env_thirdparty = env_jpg.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, source_paths(thirdparty_sources_common))
env.modules_sources += thirdparty_obj
# Godot source files
module_obj = []
env_jpg.add_source_files(module_obj, "*.cpp")
env.modules_sources += module_obj
# Needed to force rebuilding the module files when the thirdparty library is updated.
env.Depends(module_obj, thirdparty_obj)

6
modules/jpg/config.py Normal file
View File

@@ -0,0 +1,6 @@
def can_build(env, platform):
return True
def configure(env):
pass

View File

@@ -0,0 +1,189 @@
/**************************************************************************/
/* image_loader_libjpeg_turbo.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "image_loader_libjpeg_turbo.h"
#include <turbojpeg.h>
Error jpeg_turbo_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p_buffer_len) {
tjhandle tj_instance = tj3Init(TJINIT_DECOMPRESS);
if (tj_instance == NULL) {
return FAILED;
}
if (tj3DecompressHeader(tj_instance, p_buffer, p_buffer_len) < 0) {
tj3Destroy(tj_instance);
return ERR_FILE_CORRUPT;
}
const unsigned int width = tj3Get(tj_instance, TJPARAM_JPEGWIDTH);
const unsigned int height = tj3Get(tj_instance, TJPARAM_JPEGHEIGHT);
const TJCS colorspace = (TJCS)tj3Get(tj_instance, TJPARAM_COLORSPACE);
if (tj3Get(tj_instance, TJPARAM_PRECISION) > 8) {
// Proceed anyway and convert to rgb8?
tj3Destroy(tj_instance);
return ERR_UNAVAILABLE;
}
TJPF tj_pixel_format;
Image::Format gd_pixel_format;
if (colorspace == TJCS_GRAY) {
tj_pixel_format = TJPF_GRAY;
gd_pixel_format = Image::FORMAT_L8;
} else {
// Force everything else (RGB, CMYK etc) into RGB8.
tj_pixel_format = TJPF_RGB;
gd_pixel_format = Image::FORMAT_RGB8;
}
Vector<uint8_t> data;
data.resize(width * height * tjPixelSize[tj_pixel_format]);
if (tj3Decompress8(tj_instance, p_buffer, p_buffer_len, data.ptrw(), 0, tj_pixel_format) < 0) {
tj3Destroy(tj_instance);
return ERR_FILE_CORRUPT;
}
tj3Destroy(tj_instance);
p_image->set_data(width, height, false, gd_pixel_format, data);
return OK;
}
Error ImageLoaderLibJPEGTurbo::load_image(Ref<Image> p_image, Ref<FileAccess> f, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) {
Vector<uint8_t> src_image;
uint64_t src_image_len = f->get_length();
ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT);
src_image.resize(src_image_len);
uint8_t *w = src_image.ptrw();
f->get_buffer(&w[0], src_image_len);
Error err = jpeg_turbo_load_image_from_buffer(p_image.ptr(), w, src_image_len);
return err;
}
void ImageLoaderLibJPEGTurbo::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("jpg");
p_extensions->push_back("jpeg");
}
static Ref<Image> _jpeg_turbo_mem_loader_func(const uint8_t *p_data, int p_size) {
Ref<Image> img;
img.instantiate();
Error err = jpeg_turbo_load_image_from_buffer(img.ptr(), p_data, p_size);
ERR_FAIL_COND_V(err, Ref<Image>());
return img;
}
static Vector<uint8_t> _jpeg_turbo_buffer_save_func(const Ref<Image> &p_img, float p_quality) {
Vector<uint8_t> output;
ERR_FAIL_COND_V(p_img.is_null() || p_img->is_empty(), output);
Ref<Image> image = p_img->duplicate();
if (image->is_compressed()) {
Error error = image->decompress();
ERR_FAIL_COND_V_MSG(error != OK, output, "Couldn't decompress image.");
}
if (image->get_format() != Image::FORMAT_RGB8) {
// Allow grayscale L8?
image = image->duplicate();
image->convert(Image::FORMAT_RGB8);
}
tjhandle tj_instance = tj3Init(TJINIT_COMPRESS);
ERR_FAIL_COND_V_MSG(tj_instance == NULL, output, "Couldn't create tjhandle");
if (tj3Set(tj_instance, TJPARAM_QUALITY, (int)(p_quality * 100)) < 0) {
tj3Destroy(tj_instance);
ERR_FAIL_V_MSG(output, "Couldn't set jpg quality");
}
if (tj3Set(tj_instance, TJPARAM_PRECISION, 8) < 0) {
tj3Destroy(tj_instance);
ERR_FAIL_V_MSG(output, "Couldn't set jpg precision");
}
if (tj3Set(tj_instance, TJPARAM_SUBSAMP, TJSAMP_420) < 0) {
tj3Destroy(tj_instance);
ERR_FAIL_V_MSG(output, "Couldn't set jpg subsamples");
}
// If the godot image format is `Image::FORMAT_L8` we could set the appropriate
// color space here rather than defaulting to RGB.
unsigned char *jpeg_buff = NULL;
size_t jpeg_size = 0;
int code = tj3Compress8(
tj_instance,
image->get_data().ptr(),
image->get_width(),
0,
image->get_height(),
TJPF_RGB,
&jpeg_buff,
&jpeg_size);
if (code < 0) {
tj3Destroy(tj_instance);
tj3Free(jpeg_buff);
ERR_FAIL_V_MSG(output, "Couldn't compress jpg");
}
output.resize(jpeg_size);
memcpy(output.ptrw(), jpeg_buff, jpeg_size);
tj3Destroy(tj_instance);
tj3Free(jpeg_buff);
return output;
}
static Error _jpeg_turbo_save_func(const String &p_path, const Ref<Image> &p_img, float p_quality) {
Error err;
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err, err, vformat("Can't save JPG at path: '%s'.", p_path));
Vector<uint8_t> data = _jpeg_turbo_buffer_save_func(p_img, p_quality);
ERR_FAIL_COND_V(data.size() == 0, FAILED);
ERR_FAIL_COND_V_MSG(!file->store_buffer(data.ptr(), data.size()), FAILED, "Failed writing jpg to file");
return OK;
}
ImageLoaderLibJPEGTurbo::ImageLoaderLibJPEGTurbo() {
Image::_jpg_mem_loader_func = _jpeg_turbo_mem_loader_func;
Image::save_jpg_func = _jpeg_turbo_save_func;
Image::save_jpg_buffer_func = _jpeg_turbo_buffer_save_func;
}

View File

@@ -0,0 +1,40 @@
/**************************************************************************/
/* image_loader_libjpeg_turbo.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "core/io/image_loader.h"
class ImageLoaderLibJPEGTurbo : public ImageFormatLoader {
public:
virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> f, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
ImageLoaderLibJPEGTurbo();
};

View File

@@ -0,0 +1,263 @@
/**************************************************************************/
/* movie_writer_mjpeg.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "movie_writer_mjpeg.h"
#include "core/config/project_settings.h"
uint32_t MovieWriterMJPEG::get_audio_mix_rate() const {
return mix_rate;
}
AudioServer::SpeakerMode MovieWriterMJPEG::get_audio_speaker_mode() const {
return speaker_mode;
}
bool MovieWriterMJPEG::handles_file(const String &p_path) const {
return p_path.get_extension().to_lower() == "avi";
}
void MovieWriterMJPEG::get_supported_extensions(List<String> *r_extensions) const {
r_extensions->push_back("avi");
}
Error MovieWriterMJPEG::write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path) {
// Quick & Dirty MJPEG Code based on - https://docs.microsoft.com/en-us/windows/win32/directshow/avi-riff-file-reference
base_path = p_base_path.get_basename();
if (base_path.is_relative_path()) {
base_path = "res://" + base_path;
}
base_path += ".avi";
f = FileAccess::open(base_path, FileAccess::WRITE_READ);
fps = p_fps;
ERR_FAIL_COND_V(f.is_null(), ERR_CANT_OPEN);
f->store_buffer((const uint8_t *)"RIFF", 4);
f->store_32(0); // Total length (update later)
f->store_buffer((const uint8_t *)"AVI ", 4);
f->store_buffer((const uint8_t *)"LIST", 4);
f->store_32(300); // 4 + 4 + 4 + 56 + 4 + 4 + 132 + 4 + 4 + 84
f->store_buffer((const uint8_t *)"hdrl", 4);
f->store_buffer((const uint8_t *)"avih", 4);
f->store_32(56);
f->store_32(1000000 / p_fps); // Microsecs per frame.
f->store_32(7000); // Max bytes per second
f->store_32(0); // Padding Granularity
f->store_32(16);
total_frames_ofs = f->get_position();
f->store_32(0); // Total frames (update later)
f->store_32(0); // Initial frames
f->store_32(1); // Streams
f->store_32(0); // Suggested buffer size
f->store_32(p_movie_size.width); // Movie Width
f->store_32(p_movie_size.height); // Movie Height
for (uint32_t i = 0; i < 4; i++) {
f->store_32(0); // Reserved.
}
f->store_buffer((const uint8_t *)"LIST", 4);
f->store_32(132); // 4 + 4 + 4 + 48 + 4 + 4 + 40 + 4 + 4 + 16
f->store_buffer((const uint8_t *)"strl", 4);
f->store_buffer((const uint8_t *)"strh", 4);
f->store_32(48);
f->store_buffer((const uint8_t *)"vids", 4);
f->store_buffer((const uint8_t *)"MJPG", 4);
f->store_32(0); // Flags
f->store_16(0); // Priority
f->store_16(0); // Language
f->store_32(0); // Initial Frames
f->store_32(1); // Scale
f->store_32(p_fps); // FPS
f->store_32(0); // Start
total_frames_ofs2 = f->get_position();
f->store_32(0); // Number of frames (to be updated later)
f->store_32(0); // Suggested Buffer Size
f->store_32(0); // Quality
f->store_32(0); // Sample Size
f->store_buffer((const uint8_t *)"strf", 4);
f->store_32(40); // Size.
f->store_32(40); // Size.
f->store_32(p_movie_size.width); // Width
f->store_32(p_movie_size.height); // Width
f->store_16(1); // Planes
f->store_16(24); // Bitcount
f->store_buffer((const uint8_t *)"MJPG", 4); // Compression
f->store_32(((p_movie_size.width * 24 / 8 + 3) & 0xFFFFFFFC) * p_movie_size.height); // SizeImage
f->store_32(0); // XPelsXMeter
f->store_32(0); // YPelsXMeter
f->store_32(0); // ClrUsed
f->store_32(0); // ClrImportant
f->store_buffer((const uint8_t *)"LIST", 4);
f->store_32(16);
f->store_buffer((const uint8_t *)"odml", 4);
f->store_buffer((const uint8_t *)"dmlh", 4);
f->store_32(4); // sizes
total_frames_ofs3 = f->get_position();
f->store_32(0); // Number of frames (to be updated later)
// Audio //
const uint32_t bit_depth = 32;
uint32_t channels = 2;
switch (speaker_mode) {
case AudioServer::SPEAKER_MODE_STEREO:
channels = 2;
break;
case AudioServer::SPEAKER_SURROUND_31:
channels = 4;
break;
case AudioServer::SPEAKER_SURROUND_51:
channels = 6;
break;
case AudioServer::SPEAKER_SURROUND_71:
channels = 8;
break;
}
uint32_t blockalign = bit_depth / 8 * channels;
f->store_buffer((const uint8_t *)"LIST", 4);
f->store_32(84); // 4 + 4 + 4 + 48 + 4 + 4 + 16
f->store_buffer((const uint8_t *)"strl", 4);
f->store_buffer((const uint8_t *)"strh", 4);
f->store_32(48);
f->store_buffer((const uint8_t *)"auds", 4);
f->store_32(0); // Handler
f->store_32(0); // Flags
f->store_16(0); // Priority
f->store_16(0); // Language
f->store_32(0); // Initial Frames
f->store_32(blockalign); // Scale
f->store_32(mix_rate * blockalign); // mix rate
f->store_32(0); // Start
total_audio_frames_ofs4 = f->get_position();
f->store_32(0); // Number of frames (to be updated later)
f->store_32(12288); // Suggested Buffer Size
f->store_32(0xFFFFFFFF); // Quality
f->store_32(blockalign); // Block Align to 32 bits
audio_block_size = (mix_rate / fps) * blockalign;
f->store_buffer((const uint8_t *)"strf", 4);
f->store_32(16); // Standard format, no extra fields
f->store_16(1); // Compression code, standard PCM
f->store_16(channels);
f->store_32(mix_rate); // Samples (frames) / Sec
f->store_32(mix_rate * blockalign); // Bytes / sec
f->store_16(blockalign); // Bytes / sec
f->store_16(bit_depth); // Bytes / sec
f->store_buffer((const uint8_t *)"LIST", 4);
movi_data_ofs = f->get_position();
f->store_32(0); // Number of frames (to be updated later)
f->store_buffer((const uint8_t *)"movi", 4);
return OK;
}
Error MovieWriterMJPEG::write_frame(const Ref<Image> &p_image, const int32_t *p_audio_data) {
ERR_FAIL_COND_V(f.is_null(), ERR_UNCONFIGURED);
Vector<uint8_t> jpg_buffer = p_image->save_jpg_to_buffer(quality);
uint32_t s = jpg_buffer.size();
f->store_buffer((const uint8_t *)"00db", 4); // Stream 0, Video
f->store_32(jpg_buffer.size()); // sizes
f->store_buffer(jpg_buffer.ptr(), jpg_buffer.size());
if (jpg_buffer.size() & 1) {
f->store_8(0);
s++;
}
jpg_frame_sizes.push_back(s);
f->store_buffer((const uint8_t *)"01wb", 4); // Stream 1, Audio.
f->store_32(audio_block_size);
f->store_buffer((const uint8_t *)p_audio_data, audio_block_size);
frame_count++;
return OK;
}
void MovieWriterMJPEG::write_end() {
if (f.is_valid()) {
// Finalize the file (frame indices)
f->store_buffer((const uint8_t *)"idx1", 4);
f->store_32(8 * 4 * frame_count);
uint32_t ofs = 4;
uint32_t all_data_size = 0;
for (uint32_t i = 0; i < frame_count; i++) {
f->store_buffer((const uint8_t *)"00db", 4);
f->store_32(16); // AVI_KEYFRAME
f->store_32(ofs);
f->store_32(jpg_frame_sizes[i]);
ofs += jpg_frame_sizes[i] + 8;
f->store_buffer((const uint8_t *)"01wb", 4);
f->store_32(16); // AVI_KEYFRAME
f->store_32(ofs);
f->store_32(audio_block_size);
ofs += audio_block_size + 8;
all_data_size += jpg_frame_sizes[i] + audio_block_size;
}
uint32_t file_size = f->get_position();
f->seek(4);
f->store_32(file_size - 78);
f->seek(total_frames_ofs);
f->store_32(frame_count);
f->seek(total_frames_ofs2);
f->store_32(frame_count);
f->seek(total_frames_ofs3);
f->store_32(frame_count);
f->seek(total_audio_frames_ofs4);
f->store_32(frame_count * mix_rate / fps);
f->seek(movi_data_ofs);
f->store_32(all_data_size + 4 + 16 * frame_count);
f.unref();
}
}
MovieWriterMJPEG::MovieWriterMJPEG() {
mix_rate = GLOBAL_GET("editor/movie_writer/mix_rate");
speaker_mode = AudioServer::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));
quality = GLOBAL_GET("editor/movie_writer/video_quality");
}

View File

@@ -0,0 +1,70 @@
/**************************************************************************/
/* movie_writer_mjpeg.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "servers/movie_writer/movie_writer.h"
class MovieWriterMJPEG : public MovieWriter {
GDCLASS(MovieWriterMJPEG, MovieWriter)
uint32_t mix_rate = 48000;
AudioServer::SpeakerMode speaker_mode = AudioServer::SPEAKER_MODE_STEREO;
String base_path;
uint32_t frame_count = 0;
uint32_t fps = 0;
float quality = 0.75;
uint32_t audio_block_size = 0;
Vector<uint32_t> jpg_frame_sizes;
uint64_t total_frames_ofs = 0;
uint64_t total_frames_ofs2 = 0;
uint64_t total_frames_ofs3 = 0;
uint64_t total_audio_frames_ofs4 = 0;
uint64_t movi_data_ofs = 0;
Ref<FileAccess> f;
protected:
virtual uint32_t get_audio_mix_rate() const override;
virtual AudioServer::SpeakerMode get_audio_speaker_mode() const override;
virtual void get_supported_extensions(List<String> *r_extensions) const override;
virtual Error write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path) override;
virtual Error write_frame(const Ref<Image> &p_image, const int32_t *p_audio_data) override;
virtual void write_end() override;
virtual bool handles_file(const String &p_path) const override;
public:
MovieWriterMJPEG();
};

View File

@@ -0,0 +1,74 @@
/**************************************************************************/
/* register_types.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "register_types.h"
#include "image_loader_libjpeg_turbo.h"
#include "movie_writer_mjpeg.h"
static Ref<ImageLoaderLibJPEGTurbo> image_loader_libjpeg_turbo;
static MovieWriterMJPEG *writer_mjpeg = nullptr;
void initialize_jpg_module(ModuleInitializationLevel p_level) {
switch (p_level) {
case MODULE_INITIALIZATION_LEVEL_SERVERS: {
if (GD_IS_CLASS_ENABLED(MovieWriterMJPEG)) {
writer_mjpeg = memnew(MovieWriterMJPEG);
MovieWriter::add_writer(writer_mjpeg);
}
} break;
case MODULE_INITIALIZATION_LEVEL_SCENE: {
image_loader_libjpeg_turbo.instantiate();
ImageLoader::add_image_format_loader(image_loader_libjpeg_turbo);
} break;
default:
break;
}
}
void uninitialize_jpg_module(ModuleInitializationLevel p_level) {
switch (p_level) {
case MODULE_INITIALIZATION_LEVEL_SCENE: {
ImageLoader::remove_image_format_loader(image_loader_libjpeg_turbo);
image_loader_libjpeg_turbo.unref();
} break;
case MODULE_INITIALIZATION_LEVEL_SERVERS: {
if (GD_IS_CLASS_ENABLED(MovieWriterMJPEG)) {
memdelete(writer_mjpeg);
}
} break;
default:
break;
}
}

View File

@@ -0,0 +1,36 @@
/**************************************************************************/
/* register_types.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "modules/register_module_types.h"
void initialize_jpg_module(ModuleInitializationLevel p_level);
void uninitialize_jpg_module(ModuleInitializationLevel p_level);