Skip to content

Commit

Permalink
cellSearch: improve populate_photo_info, read image headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Jul 23, 2022
1 parent d689abb commit 2be105a
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
40 changes: 35 additions & 5 deletions rpcs3/Emu/Cell/Modules/cellSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,20 +368,50 @@ void populate_video_info(CellSearchVideoInfo& info, const utils::media_info& mi,
info.videoBitrate, info.audioBitrate, info.playCount, info.drmEncrypted, info.videoCodec, info.audioCodec, info.status);
}

void populate_photo_info(CellSearchPhotoInfo& info, const utils::media_info& /*mi*/, const fs::dir_entry& item)
void populate_photo_info(CellSearchPhotoInfo& info, const utils::media_info& mi, const fs::dir_entry& item)
{
// TODO - Some kinda file photo analysis and assign the values as such
info.size = item.size;
info.importedDate = -1;
info.takenDate = -1;
info.width = 0;
info.height = 0;
info.orientation = CELL_SEARCH_ORIENTATION_UNKNOWN;
info.codec = CELL_SEARCH_CODEC_UNKNOWN;
info.width = mi.width;
info.height = mi.height;
info.orientation = mi.orientation;
info.status = CELL_SEARCH_CONTENTSTATUS_AVAILABLE;
strcpy_trunc(info.title, item.name.substr(0, item.name.find_last_of('.')));
strcpy_trunc(info.albumTitle, "ALBUM TITLE");

const std::string sub_type = fmt::to_lower(mi.sub_type);

if (sub_type == "jpg" || sub_type == "jpeg")
{
info.codec = CELL_SEARCH_CODEC_JPEG;
}
else if (sub_type == "png")
{
info.codec = CELL_SEARCH_CODEC_PNG;
}
else if (sub_type == "tif" || sub_type == "tiff")
{
info.codec = CELL_SEARCH_CODEC_TIFF;
}
else if (sub_type == "bmp")
{
info.codec = CELL_SEARCH_CODEC_BMP;
}
else if (sub_type == "gif")
{
info.codec = CELL_SEARCH_CODEC_GIF;
}
else if (sub_type == "mpo")
{
info.codec = CELL_SEARCH_CODEC_MPO;
}
else
{
info.codec = CELL_SEARCH_CODEC_UNKNOWN;
}

cellSearch.notice("CellSearchPhotoInfo: title='%s', albumTitle='%s', size=%d, width=%d, height=%d, orientation=%d, codec=%d, status=%d, importedDate=%d, takenDate=%d",
info.title, info.albumTitle, info.size, info.width, info.height, info.orientation, info.codec, info.status, info.importedDate, info.takenDate);
}
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct EmuCallbacks
std::function<std::string(localized_string_id, const char*)> get_localized_string;
std::function<std::u32string(localized_string_id, const char*)> get_localized_u32string;
std::function<void(const std::string&)> play_sound;
std::function<bool(const std::string&, std::string&, s32&, s32&, s32&)> get_image_info; // (filename, sub_type, width, height, CellSearchOrientation)
std::string(*resolve_path)(std::string_view) = [](std::string_view arg){ return std::string{arg}; }; // Resolve path using Qt
};

Expand Down
45 changes: 45 additions & 0 deletions rpcs3/main_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#endif

#include <QFileInfo> // This shouldn't be outside rpcs3qt...
#include <QImageReader> // This shouldn't be outside rpcs3qt...
#include <thread>

LOG_CHANNEL(sys_log, "SYS");
Expand Down Expand Up @@ -147,6 +148,50 @@ EmuCallbacks main_application::CreateCallbacks()
}
};

callbacks.get_image_info = [](const std::string& filename, std::string& sub_type, s32& width, s32& height, s32& orientation) -> bool
{
sub_type.clear();
width = 0;
height = 0;
orientation = 0; // CELL_SEARCH_ORIENTATION_UNKNOWN

bool success = false;
Emu.BlockingCallFromMainThread([&]()
{
const QImageReader reader(QString::fromStdString(filename));
if (reader.canRead())
{
const QSize size = reader.size();
width = size.width();
height = size.height();
sub_type = reader.subType().toStdString();

switch (reader.transformation())
{
case QImageIOHandler::Transformation::TransformationNone:
orientation = 1; // CELL_SEARCH_ORIENTATION_TOP_LEFT = 0°
break;
case QImageIOHandler::Transformation::TransformationRotate90:
orientation = 2; // CELL_SEARCH_ORIENTATION_TOP_RIGHT = 90°
break;
case QImageIOHandler::Transformation::TransformationRotate180:
orientation = 3; // CELL_SEARCH_ORIENTATION_BOTTOM_RIGHT = 180°
break;
case QImageIOHandler::Transformation::TransformationRotate270:
orientation = 4; // CELL_SEARCH_ORIENTATION_BOTTOM_LEFT = 270°
break;
default:
// Ignore other transformations for now
break;
}

success = true;
sys_log.notice("get_image_info found image: filename='%s', sub_type='%s', width=%d, height=%d, orientation=%d", filename, sub_type, width, height, orientation);
}
});
return success;
};

callbacks.resolve_path = [](std::string_view sv)
{
return QFileInfo(QString::fromUtf8(sv.data(), static_cast<int>(sv.size()))).canonicalFilePath().toStdString();
Expand Down
10 changes: 9 additions & 1 deletion rpcs3/util/media_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "logs.hpp"
#include "Utilities/StrUtil.h"
#include "Emu/Cell/Modules/cellSearch.h"
#include "Emu/System.h"

#include <random>

Expand Down Expand Up @@ -67,9 +68,16 @@ namespace utils

std::pair<bool, media_info> get_media_info(const std::string& path, s32 av_media_type)
{
media_info info;
media_info info{};
info.path = path;

if (av_media_type == AVMEDIA_TYPE_UNKNOWN) // Let's use this for image info
{
const bool success = Emu.GetCallbacks().get_image_info(path, info.sub_type, info.width, info.height, info.orientation);
if (!success) media_log.error("get_image_info: failed to get image info for '%s'", path);
return { success, std::move(info) };
}

// Only print FFMPEG errors, fatals and panics
av_log_set_level(AV_LOG_ERROR);

Expand Down
4 changes: 4 additions & 0 deletions rpcs3/util/media_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ namespace utils
struct media_info
{
std::string path;
std::string sub_type; // The sub type if available (png, jpg...)

s32 audio_av_codec_id = 0; // 0 = AV_CODEC_ID_NONE
s32 video_av_codec_id = 0; // 0 = AV_CODEC_ID_NONE
s32 audio_bitrate_bps = 0; // Bit rate in bit/s
s32 video_bitrate_bps = 0; // Bit rate in bit/s
s32 sample_rate = 0; // Samples per second
s64 duration_us = 0; // in AV_TIME_BASE fractional seconds (= microseconds)
s32 width = 0; // Width if available
s32 height = 0; // Height if available
s32 orientation = 0; // Orientation if available (= CellSearchOrientation)

std::unordered_map<std::string, std::string> metadata;

Expand Down

0 comments on commit 2be105a

Please sign in to comment.