Add source to get_dimensions.

This commit is contained in:
levlam 2021-01-23 22:04:35 +03:00
parent ae59f017e7
commit 6e20aaa428
7 changed files with 37 additions and 33 deletions

View File

@ -78,7 +78,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
switch (attribute->get_id()) {
case telegram_api::documentAttributeImageSize::ID: {
auto image_size = move_tl_object_as<telegram_api::documentAttributeImageSize>(attribute);
dimensions = get_dimensions(image_size->w_, image_size->h_);
dimensions = get_dimensions(image_size->w_, image_size->h_, "documentAttributeImageSize");
break;
}
case telegram_api::documentAttributeAnimated::ID:
@ -111,7 +111,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
if (video != nullptr) {
video_duration = video->duration_;
if (dimensions.width == 0) {
dimensions = get_dimensions(video->w_, video->h_);
dimensions = get_dimensions(video->w_, video->h_, "documentAttributeVideo");
}
if (animated != nullptr) {

View File

@ -1621,7 +1621,7 @@ static Result<InputMessageContent> create_input_message_content(
td->animations_manager_->create_animation(
file_id, string(), thumbnail, AnimationSize(), has_stickers, std::move(sticker_file_ids),
std::move(file_name), std::move(mime_type), input_animation->duration_,
get_dimensions(input_animation->width_, input_animation->height_), false);
get_dimensions(input_animation->width_, input_animation->height_, "inputMessageAnimation"), false);
content = make_unique<MessageAnimation>(file_id, std::move(caption));
break;
@ -1690,7 +1690,7 @@ static Result<InputMessageContent> create_input_message_content(
PhotoSize s;
s.type = type;
s.dimensions = get_dimensions(input_photo->width_, input_photo->height_);
s.dimensions = get_dimensions(input_photo->width_, input_photo->height_, "inputMessagePhoto");
s.size = static_cast<int32>(file_view.size());
s.file_id = file_id;
@ -1713,9 +1713,10 @@ static Result<InputMessageContent> create_input_message_content(
emoji = std::move(input_sticker->emoji_);
td->stickers_manager_->create_sticker(file_id, string(), thumbnail,
get_dimensions(input_sticker->width_, input_sticker->height_), nullptr,
false, nullptr);
td->stickers_manager_->create_sticker(
file_id, string(), thumbnail,
get_dimensions(input_sticker->width_, input_sticker->height_, "inputMessageSticker"), nullptr, false,
nullptr);
content = make_unique<MessageSticker>(file_id);
break;
@ -1726,10 +1727,11 @@ static Result<InputMessageContent> create_input_message_content(
ttl = input_video->ttl_;
bool has_stickers = !sticker_file_ids.empty();
td->videos_manager_->create_video(
file_id, string(), thumbnail, AnimationSize(), has_stickers, std::move(sticker_file_ids),
std::move(file_name), std::move(mime_type), input_video->duration_,
get_dimensions(input_video->width_, input_video->height_), input_video->supports_streaming_, false);
td->videos_manager_->create_video(file_id, string(), thumbnail, AnimationSize(), has_stickers,
std::move(sticker_file_ids), std::move(file_name), std::move(mime_type),
input_video->duration_,
get_dimensions(input_video->width_, input_video->height_, "inputMessageVideo"),
input_video->supports_streaming_, false);
content = make_unique<MessageVideo>(file_id, std::move(caption));
break;
@ -1743,7 +1745,7 @@ static Result<InputMessageContent> create_input_message_content(
}
td->video_notes_manager_->create_video_note(file_id, string(), thumbnail, input_video_note->duration_,
get_dimensions(length, length), false);
get_dimensions(length, length, "inputMessageVideoNote"), false);
content = make_unique<MessageVideoNote>(file_id, false);
break;
@ -1834,7 +1836,8 @@ static Result<InputMessageContent> create_input_message_content(
PhotoSize s;
s.type = 'n';
s.dimensions = get_dimensions(input_invoice->photo_width_, input_invoice->photo_height_);
s.dimensions =
get_dimensions(input_invoice->photo_width_, input_invoice->photo_height_, "inputMessageInvoice");
s.size = input_invoice->photo_size_; // TODO use invoice_file_id size
s.file_id = invoice_file_id;
@ -2075,7 +2078,7 @@ Result<InputMessageContent> get_input_message_content(
LOG(WARNING) << "Ignore thumbnail file: " << r_thumbnail_file_id.error().message();
} else {
thumbnail.type = 't';
thumbnail.dimensions = get_dimensions(input_thumbnail->width_, input_thumbnail->height_);
thumbnail.dimensions = get_dimensions(input_thumbnail->width_, input_thumbnail->height_, "inputThumbnail");
thumbnail.file_id = r_thumbnail_file_id.ok();
CHECK(thumbnail.file_id.is_valid());

View File

@ -29,18 +29,18 @@
namespace td {
static uint16 get_dimension(int32 size) {
static uint16 get_dimension(int32 size, const char *source) {
if (size < 0 || size > 65535) {
LOG(ERROR) << "Wrong image dimension = " << size;
LOG(ERROR) << "Wrong image dimension = " << size << " from " << source;
return 0;
}
return narrow_cast<uint16>(size);
}
Dimensions get_dimensions(int32 width, int32 height) {
Dimensions get_dimensions(int32 width, int32 height, const char *source) {
Dimensions result;
result.width = get_dimension(width);
result.height = get_dimension(height);
result.width = get_dimension(width, source);
result.height = get_dimension(height, source);
if (result.width == 0 || result.height == 0) {
result.width = 0;
result.height = 0;
@ -338,7 +338,7 @@ PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice
}
PhotoSize res;
res.type = 't';
res.dimensions = get_dimensions(width, height);
res.dimensions = get_dimensions(width, height, "get_secret_thumbnail_photo_size");
res.size = narrow_cast<int32>(bytes.size());
// generate some random remote location to save
@ -374,7 +374,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
type = std::move(size->type_);
location = std::move(size->location_);
res.dimensions = get_dimensions(size->w_, size->h_);
res.dimensions = get_dimensions(size->w_, size->h_, "photoSize");
res.size = size->size_;
break;
@ -385,7 +385,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
type = std::move(size->type_);
location = std::move(size->location_);
CHECK(size->bytes_.size() <= static_cast<size_t>(std::numeric_limits<int32>::max()));
res.dimensions = get_dimensions(size->w_, size->h_);
res.dimensions = get_dimensions(size->w_, size->h_, "photoCachedSize");
res.size = static_cast<int32>(size->bytes_.size());
content = std::move(size->bytes_);
@ -411,7 +411,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
type = std::move(size->type_);
location = std::move(size->location_);
res.dimensions = get_dimensions(size->w_, size->h_);
res.dimensions = get_dimensions(size->w_, size->h_, "photoSizeProgressive");
res.size = size->sizes_.back();
size->sizes_.pop_back();
res.progressive_sizes = std::move(size->sizes_);
@ -460,7 +460,7 @@ AnimationSize get_animation_size(FileManager *file_manager, PhotoSizeSource sour
LOG(ERROR) << "Wrong videoSize \"" << size->type_ << "\" in " << to_string(size);
}
res.type = static_cast<uint8>(size->type_[0]);
res.dimensions = get_dimensions(size->w_, size->h_);
res.dimensions = get_dimensions(size->w_, size->h_, "get_animation_size");
res.size = size->size_;
if ((size->flags_ & telegram_api::videoSize::VIDEO_START_TS_MASK) != 0) {
res.main_frame_timestamp = size->video_start_ts_;
@ -534,7 +534,7 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t
switch (attribute->get_id()) {
case telegram_api::documentAttributeImageSize::ID: {
auto image_size = move_tl_object_as<telegram_api::documentAttributeImageSize>(attribute);
dimensions = get_dimensions(image_size->w_, image_size->h_);
dimensions = get_dimensions(image_size->w_, image_size->h_, "web documentAttributeImageSize");
break;
}
case telegram_api::documentAttributeAnimated::ID:
@ -684,7 +684,7 @@ Photo get_encrypted_file_photo(FileManager *file_manager, tl_object_ptr<telegram
PhotoSize s;
s.type = 'i';
s.dimensions = get_dimensions(photo->w_, photo->h_);
s.dimensions = get_dimensions(photo->w_, photo->h_, "get_encrypted_file_photo");
s.size = photo->size_;
s.file_id = file_id;
res.photos.push_back(s);

View File

@ -71,7 +71,7 @@ struct Photo {
}
};
Dimensions get_dimensions(int32 width, int32 height);
Dimensions get_dimensions(int32 width, int32 height, const char *source);
bool operator==(const Dimensions &lhs, const Dimensions &rhs);
bool operator!=(const Dimensions &lhs, const Dimensions &rhs);

View File

@ -1855,7 +1855,7 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(
switch (attribute->get_id()) {
case telegram_api::documentAttributeImageSize::ID: {
auto image_size = move_tl_object_as<telegram_api::documentAttributeImageSize>(attribute);
dimensions = get_dimensions(image_size->w_, image_size->h_);
dimensions = get_dimensions(image_size->w_, image_size->h_, "sticker documentAttributeImageSize");
break;
}
case telegram_api::documentAttributeSticker::ID:
@ -4573,7 +4573,8 @@ Result<std::tuple<FileId, bool, bool, bool>> StickersManager::prepare_input_file
if (is_animated) {
int32 width = for_thumbnail ? 100 : 512;
create_sticker(file_id, string(), PhotoSize(), get_dimensions(width, width), nullptr, true, nullptr);
create_sticker(file_id, string(), PhotoSize(), get_dimensions(width, width, "prepare_input_file"), nullptr, true,
nullptr);
} else {
td_->documents_manager_->create_document(file_id, string(), PhotoSize(), "sticker.png", "image/png", false);
}

View File

@ -1851,7 +1851,7 @@ RichText get_rich_text(tl_object_ptr<telegram_api::RichText> &&rich_text_ptr,
if (it != documents.end()) {
result.type = RichText::Type::Icon;
result.document_file_id = it->second;
Dimensions dimensions = get_dimensions(rich_text->w_, rich_text->h_);
Dimensions dimensions = get_dimensions(rich_text->w_, rich_text->h_, "textImage");
result.content = PSTRING() << (dimensions.width * static_cast<uint32>(65536) + dimensions.height);
} else {
LOG(ERROR) << "Can't find document " << rich_text->document_id_;
@ -2070,7 +2070,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
}
Dimensions dimensions;
if (has_dimensions) {
dimensions = get_dimensions(page_block->w_, page_block->h_);
dimensions = get_dimensions(page_block->w_, page_block->h_, "pageBlockEmbed");
}
return td::make_unique<WebPageBlockEmbedded>(
std::move(page_block->url_), std::move(page_block->html_), std::move(poster_photo), dimensions,
@ -2221,7 +2221,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
auto page_block = move_tl_object_as<telegram_api::pageBlockMap>(page_block_ptr);
Location location(std::move(page_block->geo_));
auto zoom = page_block->zoom_;
Dimensions dimensions = get_dimensions(page_block->w_, page_block->h_);
Dimensions dimensions = get_dimensions(page_block->w_, page_block->h_, "pageBlockMap");
if (location.empty()) {
LOG(ERROR) << "Receive invalid map location";
break;

View File

@ -485,7 +485,7 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage>
page->embed_type = std::move(web_page->embed_type_);
}
if (web_page->flags_ & WEBPAGE_FLAG_HAS_EMBEDDED_PREVIEW_SIZE) {
page->embed_dimensions = get_dimensions(web_page->embed_width_, web_page->embed_height_);
page->embed_dimensions = get_dimensions(web_page->embed_width_, web_page->embed_height_, "webPage");
}
if (web_page->flags_ & WEBPAGE_FLAG_HAS_DURATION) {
page->duration = web_page->duration_;