Karoshi MSX Community
05 de Julio de 2021, 03:37:44 pm *
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.

Ingresar con nombre de usuario, contraseña y duración de la sesión
Noticias:
 
   Inicio   Ayuda Buscar Ingresar Registrarse  
Páginas: [1]
  Imprimir  
Autor Tema: vdp encoder  (Leído 5049 veces)
0 Usuarios y 1 Visitante están viendo este tema.
ARTRAG
Visitante
« : 15 de Mayo de 2007, 07:54:35 pm »

To whom it may concern Grin

http://ragozini.googlepages.com/vdpenc2

Anyone willing to provide a function able to convert a 8x8 bitmap block (24 bit RBG) in a screen 2 char (MSX 1 palette)?

I would appreciate a bit of help for implementing some dithering algorithm (like Floyd-Stainemberg) within each 8x8 block
« Última modificación: 16 de Mayo de 2007, 09:31:29 am por ARTRAG » En línea
nerlaska
Karoshi Excellent Member
******
Mensajes: 1102


Programador


WWW Email
« Respuesta #1 : 16 de Mayo de 2007, 12:33:43 pm »

Maybe i can help you. I have a MSX Screen Converter and i can translate TGA or PCX to Screen2.
Let me know by email. Thank you.
En línea

MSX4EVER2GETHER
www.nerlaska.com
ARTRAG
Visitante
« Respuesta #2 : 16 de Mayo de 2007, 02:12:06 pm »

My current routine for screen 2 conversion is the following: (can you read matlab code ?)
 
Código:
function [ OUT ] = quantize( T )
%QUANTIZE Summary of this function goes here

% T is NVx192 matrix encoding NV 8x8 blocks
% each row vector correspondes to a 8x8 block in RGB - i.e. 8x8x3=192
% columns 1:64 are red, columns 65:128 are blue, columns 129:192 blue
% the 8x8 block is scanned by row
%
% OUT has the same structure of T and returns the NV 8x8 blocks
% encoded in screen 2 of a TMS9918

% RGB palette of the TMS9918
pal = [ 0, 0, 0
        0, 0, 0
        0, 241, 20
        68, 249, 86
        85, 79, 255
        128, 111, 255
        250, 80, 51
        12, 255, 255
        255, 81, 52
        255, 115, 86
        226, 210, 4
        242, 217, 71
        4, 212, 19
        231, 80, 229
        208, 208, 208
        255, 255, 255 ];



% number of blocks to be converted
NV = size(T,1);

C = uint8(zeros(size(T)));

R = T(:,1:64);
G = T(:,65:128);
B = T(:,129:192);

% encode each block individually
for j=1:NV
    r = uint8(zeros(1,64));
    g = uint8(zeros(1,64));
    b = uint8(zeros(1,64));
   
    % encode each block line by line
    for n=0:7
        t = [(n*8):(n*8+7)] + 1;
       
        p = [ R(j,t)' G(j,t)' B(j,t)']; % this is 8x3 matrix representing a line
       
        % scan all possible couples of colors for each line
        % the couples of backgound-foreground colors are numbere
        % avoiding duplications  - there are 105 possibilities
        dold=1e41;
        for c1=2:16;
            for c2=(c1+1):16;
                c = [pal(c1,:) ; pal(c2,:)]; % this is 2x3 matrix with the 2 tentative colors
                [x,i]=min(distfun(p,c)');     % associate the 8 points to the closest of the 2 colors
                d=sum(x);
                if d<dold
                    cold=c;
                    dold=d;
                    iold=i;
                end
            end
        end
        r(t) = uint8(cold(iold,1));
        g(t) = uint8(cold(iold,2));
        b(t) = uint8(cold(iold,3));       
    end
    C(j,:) = [r g b];
end
OUT=C;


%%%%%%%%%%%%

function D = distfun(X, C)
%DISTFUN Calculate point to cluster centroid distances.

[n,p] = size(X);
D = zeros(n,size(C,1));
clusts = 1:size(C,1);

for i = clusts
    D(:,i) = sum((double(X) - double(C(repmat(i,n,1),:))).^2, 2);
end



It does flat conversion: this implies that the scr2 color clash and the color quantization
due to msx1 palette affect the result drammatically.
 
I would like to introduce Floyd dithering in the conversion, like in Jannone's converter.
The results on the webpage VDPENC2 have been obtained using his converter on the
full color 24bit tiles and they look fine. Dithering improves a lot the final result.
Moreover, having a fast routine, dithering could be included in the kmeans algorithm
used for tile optimization. This could improve the result even further - but here more
tests are required.
 
Unfortunately Jannone's tool can be only used by converting the tiles as they are a
single image 256x192. This implies that errors on colors diffuse across boundaries of the
tiles that are displayed in adjacent positions.This should be avoided, as each tile can be
placed in any position of the screen by the player.
Can anyone help me in implementing a fast color dithering to be applied
within the 8x8 block during conversion to scr2 ?
« Última modificación: 16 de Mayo de 2007, 02:17:23 pm por ARTRAG » En línea
jltursan
Karoshi Forum's Guru
*******
Mensajes: 1516


¿Que es lo que has aprendido hoy?


WWW Email
« Respuesta #3 : 16 de Mayo de 2007, 02:23:59 pm »

I don't know the details of the Floyd's algorithm; but, can not be easily adapted from 256x192 dimension to a 8x8 new one?
En línea

Doom dee doom dee doom
ARTRAG
Visitante
« Respuesta #4 : 16 de Mayo de 2007, 03:19:27 pm »

I know the standard Floyd for black/white images, as it is pubblic.
Color versions of Floyd are not easy to develop. Moreover,
developing one version able to include screen 2 limitations is quite
a different issue.
I do not know how Jannone did, but this does not seems a trival task.
« Última modificación: 17 de Mayo de 2007, 09:18:23 am por ARTRAG » En línea
ARTRAG
Visitante
« Respuesta #5 : 17 de Mayo de 2007, 10:13:27 am »

I need to pass from the use of Jannone's scr2 converter to a my own algorithm for Floyd-Steinberg able to work on 8x8 blocks.
Floyd-Steinberg for colors and screen2 conversion are hard by themself and harder to be integrated,
and IMHO screen 2 conversion should be embedded in dithering.
Screen  2 conversion implies large errors on colors of single pixels (due to colorclash and palette limitations).

Dithering allows to spread on adjacent pixels the errors due to color quantization, thus giving a spatial
masking of the errors.
In order to make everything work, screen 2 conversion must be included in the first step of dithering,
where you compute the quantization error on a single pixel to be spread on adjacent pixels.

In our case things get harder and harder wrt the standard Floyd, as adopting a color for one pixel
constrains the choice on the successive points on the same line, thus the algorithm should try to
optimize somehow the choice of the colors on the whole line in order to minimize the error spread
on adjacent lines.

Definitely I have the feeling that what should be minimized in the choice on the two colors per 8 pixel line
is not only the distortion on the current line but also the value of the errors spread on the successive line.

on msx1 we have 105 couples of colors.

we could choice the couple, by brute force search, that minimize the squared error with respect to
the sum of the current line and the errors from the previous line.
Than we apply Floyd on that line having fixed the two colors, and we get the error line to be added to
next line.

The draft algorithm could be like this:

1) by brute force search, find the couple of colors that minimize the squared error on line 1
2) apply Floyd on line 1 using the two colors selected above and get a error line to be added to line 2
3) by brute force search, find the couple of colors that minimize the squared error on line 2 + the error line
4) apply Floyd on line 2 using the two colors selected above and get a error line to be added to line 3
etc.

Can it work ? Does anyone have experience on dithering ?  Embarrassed
« Última modificación: 17 de Mayo de 2007, 10:47:32 am por ARTRAG » En línea
pitpan
Karoshi Forum's Guru
*******
Mensajes: 1812


« Respuesta #6 : 17 de Mayo de 2007, 04:27:52 pm »

Dithering based on error-diffussion algorithms does not make sense for such small images (8x8, a block). I'd suggest to look for a pattern-based conversion o use flat conversion. In my own C language experiments, flat conversion works pretty well for non-photographic images.

I'm not a MatLab geek, but I guess that our approaches are quite similar regarding SC2 conversion.
En línea
ARTRAG
Visitante
« Respuesta #7 : 17 de Mayo de 2007, 05:40:43 pm »

I see your objection, never the less now I use jannone's converter with dithering on the whole page of the tiles,
like they where a single image and, even if dithering leads errors across the boundaries of the tiles,
the result improves (look at my experiments).

For this reason, I think that dithering into 8x8 blocks cannot go worst than this but only improve the result.

En línea
ARTRAG
Visitante
« Respuesta #8 : 17 de Mayo de 2007, 11:41:07 pm »

new images converted on the site
Robsy: compare the dragon with and without dithering (those on the last line)



« Última modificación: 17 de Mayo de 2007, 11:56:27 pm por ARTRAG » En línea
pitpan
Karoshi Forum's Guru
*******
Mensajes: 1812


« Respuesta #9 : 18 de Mayo de 2007, 09:20:33 am »

Artrag: please check this snippet.

I've tried to use it on your VDP encoder examples, but the problem is that the image of the tiles does not have the same order as the MSX example.
En línea
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.21 | SMF © 2013, Simple Machines XHTML 1.0 válido! CSS válido!