feat: add Fibo 2.0 Dev and Edit Turbo support (#2180)

This commit is contained in:
leejet authored and GitHub committed 2026-10-21 23:32:19 +08:00
1 parent 939895f00e
commit 2e2ba3faec
22 files changed
+931 -69

No files matched your search

+36
View File
@@ -6,6 +6,42 @@
namespace sd {
std::pair<int, int> select_image_size_bucket(int source_width, int source_height, int area, int factor, int fallback_width, int fallback_height) {
int width = fallback_width;
int height = fallback_height;
double ratio = static_cast<double>(source_width) / source_height;
double best_crop = INFINITY;
int64_t best_area_error = INT64_MAX;
int min_size = 4 * factor;
for (int w = min_size; w < 2LL * area / min_size; w += factor) {
for (int h = min_size; h < 2LL * area / w; h += factor) {
int64_t pixels = int64_t(w) * h;
if (pixels < 0.9 * area || pixels > 1.1 * area) {
continue;
}
double candidate_ratio = static_cast<double>(w) / h;
double crop = std::round((1.0 - std::min(candidate_ratio / ratio, ratio / candidate_ratio)) * 1e9);
int64_t area_error = std::abs(pixels - area);
if (crop < best_crop || (crop == best_crop && (area_error < best_area_error || (area_error == best_area_error && w > width)))) {
width = w;
height = h;
best_crop = crop;
best_area_error = area_error;
}
}
}
return {width, height};
}
Tensor<float> resize_and_center_crop(const Tensor<float>& image, int width, int height, ops::InterpolateMode filter) {
double scale = std::max(static_cast<double>(width) / image.shape()[0], static_cast<double>(height) / image.shape()[1]);
int w = static_cast<int>(std::ceil(image.shape()[0] * scale));
int h = static_cast<int>(std::ceil(image.shape()[1] * scale));
auto resized = ops::interpolate(image, {w, h, image.shape()[2], image.shape()[3]}, filter);
resized = ops::slice(resized, 0, (w - width) / 2, (w - width) / 2 + width);
return ops::slice(resized, 1, (h - height) / 2, (h - height) / 2 + height);
}
static constexpr std::pair<const char*, ImageTarget> image_targets[] = {
{"init", ImageTarget::Init},
{"end", ImageTarget::End},
+4
View File
@@ -3,6 +3,7 @@
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "core/tensor.hpp"
@@ -10,6 +11,9 @@
namespace sd {
std::pair<int, int> select_image_size_bucket(int source_width, int source_height, int area, int factor, int fallback_width, int fallback_height);
Tensor<float> resize_and_center_crop(const Tensor<float>& image, int width, int height, ops::InterpolateMode filter = ops::InterpolateMode::Lanczos);
enum class ImageTarget {
Init,
End,