From 67b3fd813bcf50073ec3d668ef30933e8bc010f5 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Wed, 20 Jul 2016 17:18:54 +0200 Subject: [PATCH] Removed additional members from sk_imageinfo_t --- include/c/sk_types.h | 3 -- src/c/sk_bitmap.cpp | 7 ++-- src/c/sk_codec.cpp | 14 ++++---- src/c/sk_image.cpp | 5 +-- src/c/sk_surface.cpp | 10 +++--- src/c/sk_types_priv.h | 91 +++++++++++++++++++++++++-------------------------- 6 files changed, 66 insertions(+), 64 deletions(-) diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 69c5e18..5f70b0d 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -72,10 +72,7 @@ typedef enum { BGR_V_SK_PIXELGEOMETRY, } sk_pixelgeometry_t; -typedef struct sk_colorspace_t sk_colorspace_t; - typedef struct { - sk_colorspace_t* colorSpace; int32_t width; int32_t height; sk_colortype_t colorType; diff --git a/src/c/sk_bitmap.cpp b/src/c/sk_bitmap.cpp index 1ebdb8c..38ef5a5 100644 --- a/src/c/sk_bitmap.cpp +++ b/src/c/sk_bitmap.cpp @@ -74,7 +74,7 @@ sk_bitmap_t* sk_bitmap_new() void sk_bitmap_get_info(sk_bitmap_t* cbitmap, sk_imageinfo_t* info) { - *info = ToImageInfo(AsBitmap(cbitmap)->info()); + from_sk(AsBitmap(cbitmap)->info(), info); } void* sk_bitmap_get_pixels(sk_bitmap_t* cbitmap, size_t* length) @@ -237,7 +237,8 @@ bool sk_bitmap_try_alloc_pixels(sk_bitmap_t* cbitmap, const sk_imageinfo_t* requ { SkBitmap* bmp = AsBitmap(cbitmap); - const SkImageInfo* info = AsImageInfo(requestedInfo); + SkImageInfo info; + from_c(*requestedInfo, &info); - return bmp->tryAllocPixels(*info, rowBytes); + return bmp->tryAllocPixels(info, rowBytes); } diff --git a/src/c/sk_codec.cpp b/src/c/sk_codec.cpp index 487b079..d5a0e62 100644 --- a/src/c/sk_codec.cpp +++ b/src/c/sk_codec.cpp @@ -33,7 +33,7 @@ void sk_codec_destroy(sk_codec_t* codec) void sk_codec_get_info(sk_codec_t* codec, sk_imageinfo_t* info) { - *info = ToImageInfo(AsCodec(codec)->getInfo()); + from_sk(AsCodec(codec)->getInfo(), info); } sk_colorspace_t* sk_codec_get_color_space(sk_codec_t* codec) @@ -63,16 +63,18 @@ sk_encoded_format_t sk_codec_get_encoded_format(sk_codec_t* codec) sk_codec_result_t sk_codec_get_pixels(sk_codec_t* codec, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_codec_options_t* coptions, sk_color_t ctable[], int* ctableCount) { - const SkImageInfo* info = AsImageInfo(cinfo); + SkImageInfo info; + from_c(*cinfo, &info); SkCodec::Options options; - if (!find_sk(*coptions, &options)) { + if (!from_c(*coptions, &options)) { return INVALID_PARAMETERS_SK_CODEC_RESULT; } - return (sk_codec_result_t)AsCodec(codec)->getPixels(*info, pixels, rowBytes, &options, ctable, ctableCount); + return (sk_codec_result_t)AsCodec(codec)->getPixels(info, pixels, rowBytes, &options, ctable, ctableCount); } sk_codec_result_t sk_codec_get_pixels_using_defaults(sk_codec_t* codec, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes) { - const SkImageInfo* info = AsImageInfo(cinfo); - return (sk_codec_result_t)AsCodec(codec)->getPixels(*info, pixels, rowBytes); + SkImageInfo info; + from_c(*cinfo, &info); + return (sk_codec_result_t)AsCodec(codec)->getPixels(info, pixels, rowBytes); } diff --git a/src/c/sk_image.cpp b/src/c/sk_image.cpp index 8eb4f22..da99c67 100644 --- a/src/c/sk_image.cpp +++ b/src/c/sk_image.cpp @@ -22,8 +22,9 @@ sk_image_t* sk_image_new_from_bitmap (const sk_bitmap_t* cbitmap) sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pixels, size_t rowBytes) { - const SkImageInfo* info = AsImageInfo(cinfo); - return (sk_image_t*)SkImage::MakeRasterCopy(SkPixmap(*info, pixels, rowBytes)).release(); + SkImageInfo info; + from_c(*cinfo, &info); + return (sk_image_t*)SkImage::MakeRasterCopy(SkPixmap(info, pixels, rowBytes)).release(); } sk_image_t* sk_image_new_from_encoded(const sk_data_t* cdata, const sk_irect_t* subset) { diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp index 0ced6ac..a79705b 100644 --- a/src/c/sk_surface.cpp +++ b/src/c/sk_surface.cpp @@ -31,17 +31,19 @@ sk_colortype_t sk_colortype_get_default_8888() { sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo, const sk_surfaceprops_t* props) { - const SkImageInfo* info = AsImageInfo(cinfo); + SkImageInfo info; + from_c(*cinfo, &info); SkSurfaceProps surfProps(0, props ? (SkPixelGeometry)props->pixelGeometry : SkPixelGeometry::kUnknown_SkPixelGeometry); - return (sk_surface_t*)SkSurface::MakeRaster(*info, &surfProps).release(); + return (sk_surface_t*)SkSurface::MakeRaster(info, &surfProps).release(); } sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_surfaceprops_t* props) { - const SkImageInfo* info = AsImageInfo(cinfo); + SkImageInfo info; + from_c(*cinfo, &info); SkSurfaceProps surfProps(0, props ? (SkPixelGeometry)props->pixelGeometry : SkPixelGeometry::kUnknown_SkPixelGeometry); - return (sk_surface_t*)SkSurface::MakeRasterDirect(*info, pixels, rowBytes, &surfProps).release(); + return (sk_surface_t*)SkSurface::MakeRasterDirect(info, pixels, rowBytes, &surfProps).release(); } void sk_surface_unref(sk_surface_t* csurf) { diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h index c159424..0807327 100644 --- a/src/c/sk_types_priv.h +++ b/src/c/sk_types_priv.h @@ -204,17 +204,6 @@ static inline sk_colorspace_t* ToColorSpace(SkColorSpace* colorspace) { return reinterpret_cast(colorspace); } -static inline void from_c(const sk_matrix_t* cmatrix, SkMatrix* matrix) { - matrix->setAll( - cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2], - cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5], - cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]); -} - -static inline void from_sk(const SkMatrix* matrix, sk_matrix_t* cmatrix) { - matrix->get9(cmatrix->mat); -} - static inline sk_shader_t* ToShader(SkShader* shader) { return reinterpret_cast(shader); } @@ -383,45 +372,10 @@ static inline sk_document_t* ToDocument(SkDocument* document) { return reinterpret_cast(document); } -static inline SkImageInfo* AsImageInfo(sk_imageinfo_t* cinfo) { - return reinterpret_cast(cinfo); -} static inline SkPath::Iter* AsPathIter(sk_path_iterator_t* iter) { return reinterpret_cast(iter); } -static inline const SkImageInfo* AsImageInfo(const sk_imageinfo_t* cinfo) { - return reinterpret_cast(cinfo); -} - -static inline sk_imageinfo_t* ToImageInfo(SkImageInfo* info) { - return reinterpret_cast(info); -} - -static inline sk_imageinfo_t& ToImageInfo(SkImageInfo& info) { - return reinterpret_cast(info); -} - -static inline const sk_imageinfo_t* ToImageInfo(const SkImageInfo* info) { - return reinterpret_cast(info); -} - -static inline const sk_imageinfo_t& ToImageInfo(const SkImageInfo& info) { - return reinterpret_cast(info); -} - -static inline bool find_sk(const sk_codec_options_t& coptions, SkCodec::Options* options) { - if (options) { - *options = SkCodec::Options(); - options->fZeroInitialized = (SkCodec::ZeroInitialized)coptions.fZeroInitialized; - if (coptions.fHasSubset) { - options->fSubset = AsIRect((sk_irect_t*)&coptions.fSubset); - } - } - return true; -} - - static inline sk_path_iterator_t* ToPathIter(SkPath::Iter* iter) { return reinterpret_cast(iter); } @@ -450,4 +404,49 @@ static inline const sk_path_effect_t* ToPathEffect(const SkPathEffect* p) { return reinterpret_cast(p); } +static inline void from_c(const sk_matrix_t* cmatrix, SkMatrix* matrix) { + matrix->setAll( + cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2], + cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5], + cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]); +} + +static inline void from_sk(const SkMatrix* matrix, sk_matrix_t* cmatrix) { + matrix->get9(cmatrix->mat); +} + +static inline bool from_c(const sk_codec_options_t& coptions, SkCodec::Options* options) { + if (options) { + *options = SkCodec::Options(); + options->fZeroInitialized = (SkCodec::ZeroInitialized)coptions.fZeroInitialized; + if (coptions.fHasSubset) { + options->fSubset = AsIRect((sk_irect_t*)&coptions.fSubset); + } + } + return true; +} + +static inline bool from_c(const sk_imageinfo_t& cinfo, SkImageInfo* info) { + if (info) { + *info = SkImageInfo::Make( + cinfo.width, + cinfo.height, + (SkColorType)cinfo.colorType, + (SkAlphaType)cinfo.alphaType); + } + return true; +} + +static inline bool from_sk(const SkImageInfo& info, sk_imageinfo_t* cinfo) { + if (cinfo) { + *cinfo = { + info.width(), + info.height(), + (sk_colortype_t)info.colorType(), + (sk_alphatype_t)info.alphaType() + }; + } + return true; +} + #endif -- 2.7.4