From ad09e4dcc12102bec9cd36e59862157cd284142f Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Sat, 10 Jun 2023 14:48:34 +1200 Subject: [PATCH] Fix parsing of background-image, attempt to fix image rendering. --- lib/Graphics/Rendering/Rect/CSS/Backgrounds.hs | 1 + lib/Graphics/Rendering/Rect/Image.hs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Graphics/Rendering/Rect/CSS/Backgrounds.hs b/lib/Graphics/Rendering/Rect/CSS/Backgrounds.hs index f503c84..b72ea1c 100644 --- a/lib/Graphics/Rendering/Rect/CSS/Backgrounds.hs +++ b/lib/Graphics/Rendering/Rect/CSS/Backgrounds.hs @@ -40,6 +40,7 @@ instance PropertyParser (Backgrounds Text) where inner [Ident "none"] = Just "" inner [Ident "initial"] = Just "" inner [Url ret] = Just ret + inner [Function "url", String ret, RightParen] = Just ret inner _ = Nothing longhand _ _ _ _ = Nothing diff --git a/lib/Graphics/Rendering/Rect/Image.hs b/lib/Graphics/Rendering/Rect/Image.hs index c56bc56..20da4e1 100644 --- a/lib/Graphics/Rendering/Rect/Image.hs +++ b/lib/Graphics/Rendering/Rect/Image.hs @@ -4,7 +4,8 @@ module Graphics.Rendering.Rect.Image( import qualified Data.HashMap.Lazy as HM import Data.Text (Text) -import Codec.Picture (DynamicImage(..), Image(..), PixelRGBA8(..), generateImage) +import Codec.Picture (DynamicImage(..), Image(..), PixelRGBA8(..), PixelYCbCr8(..), + pixelMap, generateImage) import Codec.Picture.Types (promoteImage, dynamicMap) import Control.Monad.IO.Class (MonadIO(..)) @@ -36,7 +37,7 @@ buildAtlas cb srcs = do forM (zip textures imgs) $ \(texture, dyn) -> do -- NOTE: `unsafe` crashes with a divide-by-zero given a `Vector ()` - let img = dynamicMap (unsafeCast . imageData) dyn :: Vector Word + let img = dynamicMap (unsafeCast . imageData) $ adjustGL dyn :: Vector Word let (format, word) = glFormat dyn liftIO $ glBindTexture GL_TEXTURE_2D texture liftIO $ unsafeWith img $ -- FIXME: Crashes @@ -44,6 +45,10 @@ buildAtlas cb srcs = do (toEnum $ dynamicMap imageWidth dyn) (toEnum $ dynamicMap imageHeight dyn) 0 format word . castPtr + liftIO $ glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_LINEAR + liftIO $ glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER GL_LINEAR + liftIO $ glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_S GL_REPEAT + liftIO $ glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_T GL_REPEAT return $ Atlas $ HM.fromList $ zip srcs textures @@ -51,7 +56,10 @@ data Texture = Texture GLuint atlasLookup :: Text -> Atlas -> Texture atlasLookup key = Texture . fromMaybe 0 . HM.lookup key . unAtlas - +-- OpenGL deals in CrCb not CbCr... +adjustGL (ImageYCbCr8 img) = ImageYCbCr8 $ pixelMap swapCrCb img + where swapCrCb (PixelYCbCr8 y cb cr) = PixelYCbCr8 y cr cb +adjustGL img = img glFormat (ImageY8 _) = (GL_LUMINANCE, GL_UNSIGNED_BYTE) glFormat (ImageY16 _) = (GL_LUMINANCE, GL_UNSIGNED_SHORT) glFormat (ImageY32 _) = (GL_LUMINANCE, GL_UNSIGNED_INT) -- 2.30.2