mrcodetastic / ESP32-HUB75-MatrixPanel-DMA

An Adafruit GFX Compatible Library for the ESP32, ESP32-S2, ESP32-S3 to drive HUB75 LED matrix panels using DMA for high refresh rates. Supports panel chaining.
MIT License
946 stars 210 forks source link

Feature request: Display scaling on multiple resolution #430

Closed tsctrl closed 1 year ago

tsctrl commented 1 year ago

hi @mrfaptastic ,

i would like to request for some sort of configuration for display scaling. not sure if it is possible or if this was currently supported, but i am not able to get the current config to work on this feature. motivation: i have multiple display resolution like 32x64px single panel and 4 chained panels 32x64 which resulting 64x128px. since 64x128px is 2x the scale of 32x64px. i would like to reuse display design i have done for 32x64px without recreating new display design for 64x128px. so a configuration with display scaling of 2 will resulting larger display scaling for the same as smaller display without recreating design for larger display from scratch. this will open up more possibilities and option to reduce duplicates codes and lesser development effort. this will be similar as pixel manipulation for image resizing.

graphical representation as below: Screenshot 2023-03-27 204552

tq!

mrcodetastic commented 1 year ago

I get the idea, but this is an gfx library matter. This library is only focused on the electrical / DMA bitstream to a panel.

With that said, a wrapper class like the virtual matrix class could possibly do this, but all the scaling would be done by the adafruit or other gfx library.

tsctrl commented 1 year ago

i am sorry, not really agree, gfx only have option to setTextSize() and the cursor & position will need to be adjusted manually. this is most likely require almost full redesign and i guess gfx library are mostly to work with the graphic/design or the display not on the pixel mapping or rescaling.

gfx libs does not controls the resolution and the chains. pixel mappings as such as pixel scaling are directly related to the hardware itseft to magnify the affected pixels for example gfx writePixel(0,0) will resulting led (0,0), (0,1), (1,0), and (1,1) with the scale of 2.

board707 commented 1 year ago

gfx libs does not controls the resolution and the chains. pixel mappings as such as pixel scaling are directly related to the hardware itseft

I don't think that it related to hardware. For doing that you do not need control resolution and chains, it can be truly logical function - just map any small display point A(x,y) to 4 points of big display:

A1(2*x, 2*y,  A2(2*x +1, 2*y),  A3(2*x, 2*y +1), A4(2*x+1, 2*y +1)
tsctrl commented 1 year ago

thank you @board707,

@mrfaptastic wondering where this could be added. if the 2 is the scaling factor than this could be added as configuration option? similar as ic selector or frequency settings? does it make sense?

edit: could be a base x and y manipulation on prior of panel and mapping settings.. i am ok if this does not goes in library. i need assistance on how this could be added or better if possible to be added without library modification. i am still 50% agree if this is not hardware related. as it does set how many led to lit. 😆

got it! it is a way how to redundant the drawing from one to multiple pixel. yes it does or might not hardware related. but how to achieve this?

mrcodetastic commented 1 year ago

thank you @board707,

@mrfaptastic wondering where this could be added. if the 2 is the scaling factor than this could be added as configuration option? similar as ic selector or frequency settings? does it make sense?

edit: could be a base x and y manipulation on prior of panel and mapping settings.. i am ok if this does not goes in library. i need assistance on how this could be added or better if possible to be added without library modification. i am still 50% agree if this is not hardware related. as it does set how many led to lit. 😆

got it! it is a way how to redundant the drawing from one to multiple pixel. yes it does or might not hardware related. but how to achieve this?

I have a soft spot for you @tsctrl . Will look into it, can add it to the virtual matrix panel class... BUT I have no guarantees on how it will actually look. Stuff might look totally distorted.

mrcodetastic commented 1 year ago

Refer to #432 - The red text 'HJ' is after I used the new 'setScaleFactor(2)'

mrcodetastic commented 1 year ago

@tsctrl - If you can avoid it, please don't raise issues regarding to weird GFX output from using the scaling. What has been implemented is technically sound and what @board707 also suggested, but the underlying Adafruit_GFX library does the drawing.

tsctrl commented 1 year ago

hi @mrfaptastic, understood. from the changes ive seen it was adding the x and y to the scaling factor which will increase the size or the lit to the x and y direction. which can cause distortion as mentioned.

scaled_x_start_pos = x * _scale_factor;

example: add 2 scale factor to the x axis for coordinate of a pixel at position 0, which will draw from 0 and 1 at x.

it is suppose to increase the x to the positive and negative direction. where by example above it should will draw at -0.5, 0 and +0.5 on x.

@board707 do you get the idea?

tsctrl commented 1 year ago

hi @mrfaptastic,

just ignore my previous comment on this, it is what it is suppose to work based on the requested feature. what kind of awkward request is this btw.

i have tested the changes, image, gif works well, font are pixelated(like minecraft texture) expected result as small font have small resolution but scaled, still acceptable for this change. but one issue i have figure out the getTextBounds() function didnt work anymore.

i guess the getTextBounds() result should be adjusted as per the scale changes. if this possible, do you have suggestion on fow to fix this? or if this is not possible or too bad for this library, i am ok for this scaling changes to be reverted and discarded.

edit: i have fix it, need to divide thevirtualMatrix->width() to scaling factor to make it work. no issue. i am so happy! thanks!

tsctrl commented 1 year ago

hi @mrfaptastic,

is it possible to add display descaling too? to fit 64x32 display into 32x16 panels? allowing negative scaling?

mrcodetastic commented 1 year ago

I will not be implementing any more non-core GFX related stuff as this goes beyond the scope of this library. Descaling sounds like just more work as what happens when there's only a '1px' width line (or text) and then one wants to descale it by 50%? It'll dissapear.

I will probably rename the setScaleFactor to setZoomFactor to get rid of any ambiguity.

I suggest you make a custom wrapper library over this library to implement the relevant anti-aliasing / blending you will need

tsctrl commented 1 year ago

yes, 1px in descale will resulting the text or line to be dissappear. is expected as descaling is reduce pixel density to at least the minimum pixel to equal the descale factor. or it will dissappear. basic conversion should be suffice.

i am aware that this is beyond the scope of this project. i understand and accept the decision on this, the wrapper blending and interpolation suggested are overkill for my usecase. thank you again for enabling this scaling function in and this help me to reduce the time and few thousand line of codes for the specific panels chains design. thanks!