From 8cd471eda6e1b5250d1ee68d47c456bb75354e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Sun, 25 Oct 2015 21:53:30 +0100 Subject: [PATCH] images.loader.gdiplus: both BGRA and BGRX formats are supported --- basis/images/loader/gdiplus/gdiplus-tests.factor | 9 +++++++++ basis/images/loader/gdiplus/gdiplus.factor | 9 ++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 basis/images/loader/gdiplus/gdiplus-tests.factor diff --git a/basis/images/loader/gdiplus/gdiplus-tests.factor b/basis/images/loader/gdiplus/gdiplus-tests.factor new file mode 100644 index 0000000000..fc6836fa06 --- /dev/null +++ b/basis/images/loader/gdiplus/gdiplus-tests.factor @@ -0,0 +1,9 @@ +USING: images images.loader.gdiplus.private tools.test ; +IN: images.loader.gdiplus.tests + +{ } [ + BGRA check-pixel-format + BGRX check-pixel-format +] unit-test + +[ RGB check-pixel-format ] [ unsupported-pixel-format? ] must-fail-with diff --git a/basis/images/loader/gdiplus/gdiplus.factor b/basis/images/loader/gdiplus/gdiplus.factor index 81fd12b03d..efb55d1f78 100644 --- a/basis/images/loader/gdiplus/gdiplus.factor +++ b/basis/images/loader/gdiplus/gdiplus.factor @@ -59,15 +59,14 @@ os windows? [ ubyte-components >>component-type f >>upside-down? ; -! Only one pixel format supported, but I can't find images in the -! wild, loaded using gdi+, in which the format is different. +! Loaded images usually have the format BGRA, text rendered BGRX. ERROR: unsupported-pixel-format component-order ; -: check-pixel-format ( image -- ) - component-order>> dup BGRA = [ drop ] [ unsupported-pixel-format ] if ; +: check-pixel-format ( component-order -- ) + dup { BGRX BGRA } member? [ drop ] [ unsupported-pixel-format ] if ; : image>gdi+-bitmap ( image -- bitmap ) - dup check-pixel-format + dup component-order>> check-pixel-format [ dim>> first2 ] [ rowstride PixelFormat32bppARGB ] [ bitmap>> ] tri { void* } [ GdipCreateBitmapFromScan0 check-gdi+-status