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

Implement optional 8bpp dithering & image smooth scaling #282

Merged
merged 28 commits into from
Apr 15, 2019

Conversation

NiLuJe
Copy link
Member

@NiLuJe NiLuJe commented Apr 14, 2019

As discussed in koreader/koreader#1833 ;).

I expect the C++11 minor features (constexpr, nullptr) to fantastically blow up on the PB toolchain, so, this'll probably take a second PR with ifdeffery tweaks ;).

NiLuJe added 28 commits April 9, 2019 03:56
We can mask G & A in one go, saving an OR.
Probably already handled by the compiler, since this is unsigned.
Optimized for eInk
(Because we want to be able to only enable it on devices that can't do
it in HW in our frontend).
Ripped out of the current Qt5 dev branch, and reduced to its essential
components for testing in FBInk.
So we can implement a post-processing scaler pass
duplication...

Let's see how much GCC will shout at me because I don't speak C++ xD.
I grok that better, plus, it'll come in handy with the next commit
anyway
Don't play with pointers when you're tired -_-".

We never actually had a buffer holding the *full* decoded image, only
single lines.
So of course trying to scale/print that assuming it was actually an
image-sized buffer was at best printing random bits of heap, at worst
segfaulting.

Anyway, if a post-processing pass is needed, store each lines in a full
buffer, and then use *that* as a source ;).

Bonus point: I can revert the whole mess about the extra argument to
OnEndDecode \o/
(Dither is initialized as true for Gray buffers).
@NiLuJe NiLuJe merged commit 8298d5b into koreader:master Apr 15, 2019
@poire-z
Copy link
Contributor

poire-z commented Jul 5, 2020

I'll be using lvimg.cpp's LVStretchImgSource to resize background images (to solve koreader/koreader#6345 (comment)).

class LVStretchImgSource : public LVImageSource, public LVImageDecoderCallback

LVImageSourceRef LVCreateStretchFilledTransform( LVImageSourceRef src, int newWidth, int newHeight, ImageTransform hTransform, ImageTransform vTransform, int splitX, int splitY )

in lvrend.cpp's DrawBackgroundImage(), a bit like that:

LVImageSourceRef img = enode->getParentNode()->getDocument()->getObjectImageSource(filepath);
int img_w =img->GetWidth();
int img_h =img->GetHeight();
[... some checks for CSS style width and  height ...]
if ( new_w != img_w || new_h != img_h ) {
     printf("bg image resized to w x h : %d %d\n", new_w, new_h);
     img = LVCreateStretchFilledTransform(img, new_w, new_h, IMG_TRANSFORM_STRETCH, IMG_TRANSFORM_STRETCH, 0, 0);
     img_w = new_w;
     img_h = new_h;
}

We would need it to stay a LVImageSource/Ref as it's then again passed to LVCreateStretchFilledTransform() for tiling and position shifting - and it would be best to not pass by a LvDrawBuf and back to a LVImageSource as this might affect colors and transparency (or we'd get back the mess I'll have removed with koreader/koreader#6345 (comment)).

You implemented in this PR smooth scaling (and dithering) when drawing a LVImageSource to a LvDrawBuf.
In case you're bored this summer, could you have a look at LVStretchImgSource and see if it would be feasible to have smooth scaling (and dithering if that makes sense) there too ?

My first test gave the following unsmooth scaling :)
image

@NiLuJe
Copy link
Member Author

NiLuJe commented Jul 5, 2020

@poire-z: Are the h/v transform fields a bitmask, or can there only be a single one set?

@poire-z
Copy link
Contributor

poire-z commented Jul 5, 2020

Nope, not a bitmask. Just one of:

/// type of image transform
enum ImageTransform {
IMG_TRANSFORM_NONE, // just draw w/o any resizing/tiling
IMG_TRANSFORM_SPLIT, // split at specified pixel, fill extra middle space with value of this pixel
IMG_TRANSFORM_STRETCH, // stretch image proportionally to fill whole area
IMG_TRANSFORM_TILE // tile image
};

but transform_h might be one and transform_v an other.

(But it could be another function/class/method, like a new ResizeImage(). CoolReader only uses STRETCH for its own page background drawing.)

@NiLuJe
Copy link
Member Author

NiLuJe commented Jul 5, 2020

@poire-z: Cool, might be doable then, just have to figure out which, if any, OnEndDecode is triggered ^^.

(I suck at OOP ;p).

(I'd probably only take this path is h && v == STRETCH, just in case, though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants