Converting images into screen 2

Page 3/4
1 | 2 | | 4

By LeandroCorreia

Paladin (947)

LeandroCorreia's picture

15-02-2015, 02:16

@Louthrax, in my I7, it'll take from 3 seconds to 4 minutes, depending on the amount of interlacing used. I used a lot of optimizations to make it quicker, such as look up tables for square roots, skipping the loop if the program finds an exact color (quite common in black and white areas). Also don't forget that I don't need to check by brute force all 256 x 256 color combinations, since 16 x 16 MSX colors would generate a palette with duplicate colors that should be skipped, and even less colors if I lower the interlacing amount.

My code is like my penis: Works fine, but it's too ugly to show in public. As soon as I make some extra adjustments and clean my code, I'll publish it in here. Wink

By hit9918

Prophet (2882)

hit9918's picture

15-02-2015, 08:53

@Louthrax,
a superfast way is to first convert to screen 5 and then to screen 2.
Then instead 65536 loops per 8x1 there is just 8 calls to the colormatch function.
Then take 8x1 pixels, count the colors that occur there, and take the top 2 colors.

But the result is different because the 65536 loop may come up with a mix of all the colors in the 8x1.
I used it for a gamedev tool, it blasts a whole level map fast.

If you still want speed but a mix feature, one cold look at the colors of lower occurence, decide whether they more belong to #1 or #2, and then do a weighted mix to #1 or #2.
It may be some algorithmic ado with multiple times loop for 0 to 15, but the numbers still much below the big 65536.

By LeandroCorreia

Paladin (947)

LeandroCorreia's picture

15-02-2015, 10:19

BTW, people, I'd like my program to save a dump that could be BLOADed in MSX. How would be the structure of such a file?

By ARTRAG

Enlighted (6323)

ARTRAG's picture

15-02-2015, 11:32

Louthrax wrote:

Artrag, how complex is the "perceptually uniform distance" method you use ? I tried to use CIELAB, but the functions are really too complex (RGB to XYZ to CIELAB error using floats), and also it does not define a color-space (which could be usefull for dithering).

Loutrax
The C source code is at
http://www.msx.org/downloads/related/graphics/screen-2-conve...
and my perceptually uniform distance works super fast.

C:\Users>scr2floyd_percept.exe lenna.TGA
TMSopt v.0.1 - TGA 24bpp to TMS9918 converter.
Coded by Eduardo A. Robsy Petrus & Arturo Ragozini 2007.

Credits to Rafael Jannone for his Floyd-Steinberg implementation.

Converting lenna.TGA (256,192) to TMS9918 format in (32,24) screen 2 tiles...
Ok
0.01 million combinations analysed in 0.31 seconds.
Note: the .CLR and .CHR files have correct headers only for 256x192 images.

It would be great if you include my C converter in your awesome tools. I support only raw TGA files because I do not have image libraries for importing more general formats, but your tool already supports various image formats.
My C code is very simple and quite optimised, look yourself, you can just rip my main and include it in your tool.

BTW my color metric is this:


typedef struct {
   float r, g, b;
} RGB;

float ColourDistance(RGB e1, RGB e2)
{
  float r,g,b;
  float rmean;
  
  e1.r/=scale;
  e1.g/=scale;    
  e1.b/=scale;    
  
  e2.r/=scale;
  e2.g/=scale;    
  e2.b/=scale;    

  rmean = ( (int)e1.r + (int)e2.r ) / 2 ;
  r = ((int)e1.r - (int)e2.r);
  g = ((int)e1.g - (int)e2.g);
  b = ((int)e1.b - (int)e2.b);
  return ((((512+rmean)*r*r)/256) + 4*g*g + (((767-rmean)*b*b)/256)); //  instead of return r*r+g*g+b*b;
}

By hit9918

Prophet (2882)

hit9918's picture

15-02-2015, 12:47

7 bytes bload header

        db #FE
        dw start
        dw last_byte
        dw start

by the way I got the suspicion that jannone.org BLOADs hang on casette.
telling start + size instead address of last byte. on a diskette it is not noted because disk doesn't hang.

that third word metioning start address again, it is the address to run a executable bload ,r , it could be another address.
as special feature the file could contain code that copies the file from RAM to vram.
because some machines lack the bload ,S.

another nice thing is that a fullsize 16k bload could contain an image including sprite assist.
mhm, I guess the default sprite mode is the little sprites? then need some code.
sprite assist can use variable height sprites, sort sprites by Y + sprite height. the bigger values go first in the SAT.

well lots brainstorming ideas Smile
I mostly use converters for game tile inspiration. there sprite assist makes no sense. ah well aside that one still could use it in a game.

but titlescreens could need sprite assist.
the converter could put sprites to the place of max error location.
and then there could be a user mode where one can manualy place the sprite boxes.

By hit9918

Prophet (2882)

hit9918's picture

15-02-2015, 12:55

About color conversion, the problem I had was when dark things end up in itching green.
Then I switched the squares method to this errorvalue

299*dr*dr+587*dg*dg+114*db*db;

and got happy.
Weighting the components by their brightness to the eye.

By LeandroCorreia

Paladin (947)

LeandroCorreia's picture

15-02-2015, 15:34

@hit9918 - If you use Lab instead of RGB, it won't go green instead of dark. Wink

By hit9918

Prophet (2882)

hit9918's picture

15-02-2015, 18:55

Is lab "very correct"? With the MSX palette it is not clear what is correct.

When I convert in gimp, the result has little colors.
But when I do paste an RGB pic ctrl-v, it seems to run a simpler code, more like the simple square, and then I get more colors.
So then the more wrong one had the more interesting results, mhm Smile

By LeandroCorreia

Paladin (947)

LeandroCorreia's picture

15-02-2015, 21:48

If you calculate the distance of two colors inside an RGB cube, this distance is much more proportional to what the human eye considers as similar colors, compared to distance inside an RGB model. I suspect that Photoshop also converts images into indexed colors by using an RGB model. At least my simple converter made the images look much better than Photoshop (and remember that I had to use the octet MSX limitation).

By LeandroCorreia

Paladin (947)

LeandroCorreia's picture

22-02-2015, 12:50

How do I dump a screen2 with a BSAVE and how do I load it?

(Yes, I know I asked this here before, but I can't find it). Wink

Page 3/4
1 | 2 | | 4