Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Android Codec (DEPENDANT PR) #91

Open
wants to merge 2 commits into
base: xamarin-mobile-bindings
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions include/c/sk_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ SK_C_API void sk_codec_get_frame_info(sk_codec_t* codec, sk_codec_frameinfo_t* f
SK_C_API bool sk_codec_get_frame_info_for_index(sk_codec_t* codec, int index, sk_codec_frameinfo_t* frameInfo);
SK_C_API int sk_codec_get_repetition_count(sk_codec_t* codec);

// SK Android Codec


SK_C_API sk_android_codec_t* sk_android_codec_new_from_codec(sk_codec_t* codec, sk_android_codec_exif_orientation_behavior_t behaviour);
SK_C_API sk_android_codec_t* sk_android_codec_new_from_data(sk_data_t* data, sk_pngchunkreader_t* chunk_reader);
SK_C_API sk_android_codec_t* sk_android_codec_new_from_stream(sk_stream_t* stream, sk_pngchunkreader_t* chunk_reader);
SK_C_API void sk_android_codec_destroy(sk_android_codec_t* codec);
SK_C_API void sk_android_codec_get_info(sk_android_codec_t* codec, sk_imageinfo_t* info);
SK_C_API void sk_android_codec_get_sampled_dimensions(sk_android_codec_t* codec, int32_t sampleSize, sk_isize_t* dimensions);
SK_C_API bool sk_android_codec_get_supported_subset(sk_android_codec_t* codec, sk_irect_t* desiredSubset);
SK_C_API void sk_android_codec_get_sampled_subset_dimensions(sk_android_codec_t* codec, int32_t sampleSize, sk_isize_t* dimensions, sk_irect_t* subset);
SK_C_API sk_encoded_image_format_t sk_android_codec_get_encoded_format(sk_android_codec_t* codec);
SK_C_API sk_codec_result_t sk_android_codec_get_android_pixels(sk_android_codec_t* codec, const sk_imageinfo_t* info, void* pixels, size_t rowBytes, const sk_android_codec_options_t* options);
SK_C_API sk_codec_result_t sk_android_codec_get_android_pixels_simplified(sk_android_codec_t* codec, const sk_imageinfo_t* info, void* pixels, size_t rowBytes);
SK_C_API sk_codec_result_t sk_android_codec_get_pixels(sk_android_codec_t* codec, const sk_imageinfo_t* info, void* pixels, size_t rowBytes);
SK_C_API const sk_colorspace_icc_profile_t* sk_android_codec_get_icc_profile(sk_android_codec_t* codec);
SK_C_API sk_colortype_t sk_android_codec_compute_output_color_type(sk_android_codec_t* codec, sk_colortype_t requested_color_type);
SK_C_API sk_alphatype_t sk_android_codec_compute_output_alpha(sk_android_codec_t* codec, bool requestedUnpremul);
SK_C_API sk_colorspace_t* sk_android_codec_compute_output_color_space(sk_android_codec_t* codec, sk_colortype_t output_color_type, sk_colorspace_t* prefColorSpace);
SK_C_API int32_t sk_android_codec_compute_sample_size(sk_android_codec_t* codec, sk_isize_t* size);
SK_C_API sk_codec_t* sk_android_codec_get_codec(sk_android_codec_t* codec);

SK_C_PLUS_PLUS_END_GUARD

#endif
12 changes: 12 additions & 0 deletions include/c/sk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ typedef struct sk_fontstyleset_t sk_fontstyleset_t;
* Abstraction layer directly on top of an image codec.
*/
typedef struct sk_codec_t sk_codec_t;
typedef struct sk_android_codec_t sk_android_codec_t;
typedef struct sk_colorspace_t sk_colorspace_t;
/**
Various stream types
Expand Down Expand Up @@ -514,6 +515,17 @@ typedef enum {
BOTTOM_UP_SK_CODEC_SCANLINE_ORDER,
} sk_codec_scanline_order_t;

typedef enum {
kIgnore,
kRespect,
} sk_android_codec_exif_orientation_behavior_t;

typedef struct {
sk_codec_zero_initialized_t fZeroInitialized;
sk_irect_t* fSubset;
int fSampleSize;
} sk_android_codec_options_t;

// The verbs that can be foudn on a path
typedef enum {
MOVE_SK_PATH_VERB,
Expand Down
86 changes: 86 additions & 0 deletions src/c/sk_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,89 @@ bool sk_codec_get_frame_info_for_index(sk_codec_t* codec, int index, sk_codec_fr
int sk_codec_get_repetition_count(sk_codec_t* codec) {
return AsCodec(codec)->getRepetitionCount();
}


// SK Android Codec

#include "include/codec/SkAndroidCodec.h"

sk_android_codec_t* sk_android_codec_new_from_codec(sk_codec_t* codec, sk_android_codec_exif_orientation_behavior_t behaviour) {
std::unique_ptr<SkCodec> skcodec(AsCodec(codec));
return ToAndroidCodec(
SkAndroidCodec::MakeFromCodec(std::move(skcodec), (SkAndroidCodec::ExifOrientationBehavior)behaviour).release()
);
}

sk_android_codec_t* sk_android_codec_new_from_stream(sk_stream_t* stream, sk_pngchunkreader_t* chunk_reader) {
std::unique_ptr<SkStream> skstream(AsStream(stream));
return ToAndroidCodec(
SkAndroidCodec::MakeFromStream(std::move(skstream), AsPngChunkReader(chunk_reader)).release()
);
}

sk_android_codec_t* sk_android_codec_new_from_data(sk_data_t* data, sk_pngchunkreader_t* chunk_reader) {
return ToAndroidCodec(
SkAndroidCodec::MakeFromData(sk_ref_sp(AsData(data)), AsPngChunkReader(chunk_reader)).release()
);
}

void sk_android_codec_destroy(sk_android_codec_t* codec) {
delete AsAndroidCodec(codec);
}

void sk_android_codec_get_info(sk_android_codec_t* codec, sk_imageinfo_t* info) {
*info = ToImageInfo(AsAndroidCodec(codec)->getInfo());
}

void sk_android_codec_get_sampled_dimensions(sk_android_codec_t* codec, int32_t sampleSize, sk_isize_t* dimensions) {
*dimensions = ToISize(AsAndroidCodec(codec)->getSampledDimensions(sampleSize));
}

bool sk_android_codec_get_supported_subset(sk_android_codec_t* codec, sk_irect_t* desiredSubset) {
return AsAndroidCodec(codec)->getSupportedSubset(AsIRect(desiredSubset));
}

void sk_android_codec_get_sampled_subset_dimensions(sk_android_codec_t* codec, int32_t sampleSize, sk_isize_t* dimensions, sk_irect_t* subset) {
SkIRect* s = AsIRect(subset);
*dimensions = ToISize(AsAndroidCodec(codec)->getSampledSubsetDimensions(sampleSize, *s));
}

sk_encoded_image_format_t sk_android_codec_get_encoded_format(sk_android_codec_t* codec) {
return (sk_encoded_image_format_t)AsAndroidCodec(codec)->getEncodedFormat();
}

sk_codec_result_t sk_android_codec_get_android_pixels(sk_android_codec_t* codec, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_android_codec_options_t* coptions) {
return (sk_codec_result_t)AsAndroidCodec(codec)->getAndroidPixels(AsImageInfo(cinfo), pixels, rowBytes, AsAndroidCodecOptions(coptions));
}

sk_codec_result_t sk_android_codec_get_android_pixels_simplified(sk_android_codec_t* codec, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes) {
return (sk_codec_result_t)AsAndroidCodec(codec)->getAndroidPixels(AsImageInfo(cinfo), pixels, rowBytes);
}

sk_codec_result_t sk_android_codec_get_pixels(sk_android_codec_t* codec, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes) {
return (sk_codec_result_t)AsAndroidCodec(codec)->getPixels(AsImageInfo(cinfo), pixels, rowBytes);
}

const sk_colorspace_icc_profile_t* sk_android_codec_get_icc_profile(sk_android_codec_t* codec) {
return ToColorSpaceIccProfile(AsAndroidCodec(codec)->getICCProfile());
}

sk_colortype_t sk_android_codec_compute_output_color_type(sk_android_codec_t* codec, sk_colortype_t requested_color_type) {
return (sk_colortype_t)AsAndroidCodec(codec)->computeOutputColorType((SkColorType)requested_color_type);
}

sk_alphatype_t sk_android_codec_compute_output_alpha(sk_android_codec_t* codec, bool requestedUnpremul) {
return (sk_alphatype_t)AsAndroidCodec(codec)->computeOutputAlphaType(requestedUnpremul);
}

sk_colorspace_t* sk_android_codec_compute_output_color_space(sk_android_codec_t* codec, sk_colortype_t output_color_type, sk_colorspace_t* prefColorSpace) {
return ToColorSpace(AsAndroidCodec(codec)->computeOutputColorSpace((SkColorType)output_color_type, sk_sp(AsColorSpace(prefColorSpace))).release());
}

int32_t sk_android_codec_compute_sample_size(sk_android_codec_t* codec, sk_isize_t* size) {
return AsAndroidCodec(codec)->computeSampleSize(AsISize(size));
}

sk_codec_t* sk_android_codec_get_codec(sk_android_codec_t* codec) {
return ToCodec(AsAndroidCodec(codec)->codec());
}
4 changes: 4 additions & 0 deletions src/c/sk_types_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ DEF_CLASS_MAP(Sk3DView, sk_3dview_t, 3DView)
DEF_CLASS_MAP(SkBitmap, sk_bitmap_t, Bitmap)
DEF_CLASS_MAP(SkCanvas, sk_canvas_t, Canvas)
DEF_CLASS_MAP(SkCodec, sk_codec_t, Codec)
DEF_CLASS_MAP(SkAndroidCodec, sk_android_codec_t, AndroidCodec)
DEF_CLASS_MAP(SkColorFilter, sk_colorfilter_t, ColorFilter)
DEF_CLASS_MAP(SkColorSpace, sk_colorspace_t, ColorSpace)
DEF_CLASS_MAP(SkColorTable, sk_colortable_t, ColorTable)
Expand Down Expand Up @@ -185,6 +186,9 @@ DEF_MAP(SkCanvas::Lattice, sk_lattice_t, Lattice)
DEF_MAP(SkCodec::FrameInfo, sk_codec_frameinfo_t, FrameInfo)
DEF_MAP(SkCodec::Options, sk_codec_options_t, CodecOptions)

#include "include/codec/SkAndroidCodec.h"
DEF_MAP(SkAndroidCodec::AndroidOptions, sk_android_codec_options_t, AndroidCodecOptions)

#include "include/core/SkColor.h"
DEF_MAP(SkColor4f, sk_color4f_t, Color4f)

Expand Down
3 changes: 3 additions & 0 deletions src/xamarin/SkiaKeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ void** KeepSkiaCSymbols (void)
(void*)sk_colortype_get_default_8888,
(void*)gr_recording_context_unref,
(void*)gr_glinterface_create_native_interface,
(void*)sk_android_codec_new_from_data,
(void*)sk_android_codec_new_from_stream,
(void*)sk_android_codec_new_from_codec,
(void*)sk_bitmap_new,
(void*)sk_canvas_destroy,
(void*)sk_codec_min_buffered_bytes_needed,
Expand Down