alexzhirkevich/custom-qr-generator

Expose reserved areas

Closed this issue · 15 comments

Is your feature request related to a problem? Please describe.
I created a QR code design which features randomly selected pixel highlights in my apps accent color.
Screenshot_20230709_124750_BitBanana Debug~2
It works fine most of the time as the error correction easily compensates those pixels.
But in some cases, when the higlight happens to be at an important area, like the center of an alignment pattern, it produces hard to read codes.

Describe the solution you'd like
The paint method of QrVectorColor and the shape method of QrVectorPixelShape should have an additional input parameter that gives some extra information about the current pixel.
This could either be a boolean that states if it belongs to a reserved area or an int that works like an enum stating exactly to which area it belongs.

The different reserved areas are:

  • Alignment pattern
  • timing pattern
  • dark module
  • version information
  • format information

Please refer to this page:
https://www.thonky.com/qr-code-tutorial/module-placement-matrix

Describe alternatives you've considered
The alternative would be to not use any highlights or to use a darker color. But I want to use my apps accent color and I like the way it looks now.

You can set highlighting for important areas using highlighting block in DSL builder.

Ok thanks, I'll check that later. But I think it is something different. My background is already white.
I want single pixels to have that bright color, but none of the important pixels.
I could easily do this if the additional parameter was exposed.
And my solution would also allow for even more customization like having squares for the alignment patterns while having circles for the rest etc...

It allows to set different shape and color for pixels from important areas. But its customization is limited. It probably can be extended

The paint method of QrVectorColor ... should have an additional input parameter that gives some extra information about the current pixel.

It is impossible because in most of cases paint created for the whole dark/light pixels at once (not for one pixel). And QrVectorColor is a common interface for all types of paints like frames, balls, etc. May be it can provide info about the current component in general

Makes sense. In theory wouldn't it be possible to just set this parameter to null/false/unavailable or something like that for all cases where all pixels are drawn at once?
But I am not too deep into your code, maybe there are more elegant solutions.

Hi,
I now tried if the highlighting feature helps. But all I could achieve was that the pixels that are white anyway are highlighted now in a specific color. (purple in this example)
What I wanted to do though is to ensure that specific pixels are always black even though a color was used for the dark pixels (yellow in this example).
img
I also noticed that the 1 pixel frame of the version eye vanishes completely when highlighting is used. It doesn't really matter though as it doesn't help me in my situation anyway.

I am actually very close now.
I changed my approach to have all dark pixels dark and add the accent color in the bright pixels.
So instead of turning some of the black pixels to yellow I turn some of the white pixels to yellow.
The highlighting feature can then be used to ensure some pixels stay white.
This way I was able to protect the eyes and the timing pattern, but I can't get the version eyes to look correct, as the highlight also overrides some of the dark pixels (the frame of the version eye).

Highlighting will be extended in the next version and will allow to set shape and color of the highlighting as well as shape and color of the element being highlighted

Currently shape of version eye aka alignment pattern is combined from frame and ball of corner eyes as well as its color as far as i remember

the 1 pixel frame of the version eye vanishes completely

It is a result of applying rounded corner shape designed for 7-pixel eye to 5-pixel eye (bug). It works fine with other frame shapes

This should help in 2.0.0-alpha01 if you rollback to random colors in dark pixels

highlighting {
    timingLines = HighlightingType.Styled(
        color = QrVectorColor.Unspecified,
        elementShape = /*your dark pixel shape goes here*/,
        elementColor =  /*your dark pixel color without randomness goes here*/
    )
    versionEyes = HighlightingType.Styled(
        color = QrVectorColor.Unspecified,
        elementShape = QrVersionEyeShape(
            frame = QrVectorFrameShape.AsPixelShape(
                pixelShape = /*your dark pixel shape goes here. */,
                size = 5
            ),
            ball = /*your dark pixel shape goes here. 
                   you can use same ball shape or call pixelShape.asBallShape() */
        ),

        elementColor =  /*your dark pixel color without randomness goes here*/
    )
}

Hi,
I tried to implement the changes, but had to leave for work before I was finished.
As I use the library from within java, my implementation alway looks a bit different.
Timing pattern highlight already worked like a charm!
I was about to do the versionEye highlight when I had to leave. But it seemed there was no QrVersionEyeShape() at all.
Anyway, I'll work on it again tomorrow.
Thanks for all your help!

it seemed there was no QrVersionEyeShape() at all.

It's a function from QrHighlighting.kt so you have to use QrHighlightingKt.QrVersionEyeShape i guess

.asBallShape() is an extension from QVectorShapeUtils.kt (withourt 'r', wrongly named, will be changed)

Hi,
everything works as expected!!
Thanks!