Skip to content

Commit

Permalink
genericize pixelize lib
Browse files Browse the repository at this point in the history
  • Loading branch information
9vult committed Sep 25, 2024
1 parent d09c274 commit 0e06345
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
14 changes: 7 additions & 7 deletions Holo/Plugins/LibassSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ public unsafe void DrawSubtitles(ref VideoFrame frame, long time)
{
// Copy frame data from copy
fixed (byte* ptr = frame.Copy)
Pixelize_External.CopyFrame(ptr, frame.Data, frame.Width * frame.Height * BGRA_WIDTH);
SpeedDemon_External.CopyFrame(ptr, frame.Data, frame.Width * frame.Height * BGRA_WIDTH);
}
else
{
// Copy frame data to copy
frame.Copy = new byte[frame.Width * frame.Height * BGRA_WIDTH];
fixed (byte* ptr = frame.Copy)
Pixelize_External.CopyFrame(frame.Data, ptr, frame.Width * frame.Height * BGRA_WIDTH);
SpeedDemon_External.CopyFrame(frame.Data, ptr, frame.Width * frame.Height * BGRA_WIDTH);
}

Pixelize_External.RenderSubs(frame.Data, frame.Width, frame.Height, image);
SpeedDemon_External.RenderSubs(frame.Data, frame.Width, frame.Height, image);
}

public void LoadSubtitles(File file, int time = -1)
Expand Down Expand Up @@ -127,15 +127,15 @@ public IDictionary<string, dynamic> GetProperties()
throw new NotImplementedException();
}

private partial class Pixelize_External
private partial class SpeedDemon_External
{
[LibraryImport("Pixelize", EntryPoint = "render_subs")]
[LibraryImport("SpeedDemon", EntryPoint = "render_subs")]
public static unsafe partial void RenderSubs(IntPtr frameData, int width, int height, LibassCS.Structures.NativeImage* img);

[LibraryImport("Pixelize", EntryPoint = "copy_frame")]
[LibraryImport("SpeedDemon", EntryPoint = "copy_frame")]
public static unsafe partial void CopyFrame(IntPtr source, byte* destination, int size);

[LibraryImport("Pixelize", EntryPoint = "copy_frame")]
[LibraryImport("SpeedDemon", EntryPoint = "copy_frame")]
public static unsafe partial void CopyFrame(byte* source, IntPtr destination, int size);
}
}
Expand Down
32 changes: 0 additions & 32 deletions Wrappers/Pixelize/CMakeLists.txt

This file was deleted.

File renamed without changes.
32 changes: 32 additions & 0 deletions Wrappers/SpeedDemon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.10)
project(SpeedDemon VERSION 1.0 LANGUAGES CXX)

# Define library output type
add_library(SpeedDemon SHARED
src/SpeedDemon.cpp
)

# Add include directories
target_include_directories(SpeedDemon PUBLIC include)

# Cross-platform dynamic library properties
if(WIN32)
set_target_properties(SpeedDemon PROPERTIES
PREFIX ""
SUFFIX ".dll")
elseif(APPLE)
set_target_properties(SpeedDemon PROPERTIES
PREFIX "" # lib?
SUFFIX ".dylib")
else()
set_target_properties(SpeedDemon PROPERTIES
PREFIX "" # lib?
SUFFIX ".so")
endif()

# Set the C++ standard
set_target_properties(SpeedDemon PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES)

# Installation (optional)
install(TARGETS SpeedDemon DESTINATION lib)
install(FILES include/SpeedDemon.h DESTINATION include)
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ extern "C" {
#endif

// Export macro
#ifndef PIXELIZE_API
#ifndef SPEED_DEMON_API
#ifdef _WIN32
#define PIXELIZE_API __declspec(dllexport)
#define SPEED_DEMON_API __declspec(dllexport)
#else
#define PIXELIZE_API __attribute__((visibility("default")))
#define SPEED_DEMON_API __attribute__((visibility("default")))
#endif
#endif

Expand All @@ -30,9 +30,9 @@ typedef struct ass_image {
} type;
} ASS_Image;

PIXELIZE_API void copy_frame(unsigned char* source, unsigned char* destination, int size);
SPEED_DEMON_API void copy_frame(unsigned char* source, unsigned char* destination, int size);

PIXELIZE_API void render_subs(unsigned char* frameData, int width, int height, ASS_Image* img);
SPEED_DEMON_API void render_subs(unsigned char* frameData, int width, int height, ASS_Image* img);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "pixelize.hpp"
#include "SpeedDemon.hpp"

PIXELIZE_API void copy_frame(unsigned char* source, unsigned char* destination, int size) {
SPEED_DEMON_API void copy_frame(unsigned char* source, unsigned char* destination, int size) {
std::copy(source, source + size, destination);
}

PIXELIZE_API void render_subs(unsigned char* frameData, int width, int height, ASS_Image* img) {
SPEED_DEMON_API void render_subs(unsigned char* frameData, int width, int height, ASS_Image* img) {
for (; img; img = img->next) {
unsigned int o = 255 - img->color & 0xFF;
unsigned int r = img->color >> 24;
Expand Down

0 comments on commit 0e06345

Please sign in to comment.