|
Inferno #07
31 мая 2005 |
|
Likbez - The principles of converting graphics PC-ZX.

The principles of converting graphics PC-> ZX
This article was written last in a row and in great haste,
so sorry for smurnotu. Perhaps in the future I will write more
detailed article about the conversion.
Previously preferred to convert a 3 screen, since it through
extremely simple: just in Photoshop, upload the screen in 8
colors and transfer points of bmp format in the Spectrum tiny
applets on ZX (now the operation can be performed automatically
cally in any JPEG viewer to ZX). But there are 3 screens
vennye disadvantages:
1. Scary shimmer;
2. Solid white color is especially scary flashes;
3. To show the pictures to spend 2 / 3 of CPU time;
4. Only 8 colors (and even 6912 and then more), respectively,
screen is covered with "dust", "dandruff";
5. The picture is very much weight.
As you can see, I prefer to convert a two-screen
or into one. One screen gives a rough picture, but it
much easier to use in the program. Many of the stories is quite
decent look at one screen. Two screens allow mapping
zit almost anything. Two screens offer 83 colors, if used
walk from the assumptions that:
- Dark shines twice as bright weaker;
- "Black" "bright red" = "dark red" + "dark red", etc.
. Img (Gigascreen) - it's just 2 screens with standard
difference formulation.
And that's what. Mcx:
- 1 st screen sprite;
- The attributes of the 1 st screen sprite;
- 2 nd screen sprite;
- The attributes of the 2 nd screen sprites.
Such pictures you can see in the game Hexagonal Filler. There
the idea of simplified mcx-modes:
a) one of the screens are always black and white;
b) one of the screens clean Spectrum.
These simplified regimes are easily derived without the
turbo, without distortion pictures.
Present to you the converter at Delphi, written
from want and are not intended for this release (I do not
intend to become ptsshnym programmer), but the older version
which was distributed in a shell SpeConvertor by Aprisobal.
To them, I convert the graphics to IG (before that I used
8col). Of course, the result of the conversion must expunge
Manual (6,912 screens - in the BGE, screens img - in DBS), but
the general the result is quite positive.
ZX screen consists of familiarity. Therefore, we must find
each familiarity most successful palette. It is possible
take into account the "average color" of the picture, as can be
seen each familiarity as a separate. But the real rift
realizable only in the conversion of diamond (chankovoy)
hatching which gives a rather blurred image. When the
conversion from Floyd-Steinberg need to distribute the error
representation accumulated at the boundary points of
familiarity, right and down.
Now a brief comment. I hold no error in the register /
variables, and directly into the array that stores the original
picture. That is, if I say "propagating errors, we have
in mind that simply correcting 4 pixels (right, bottom, left
bottom and right below the current one), adding to them the
error before representation of the current pixel, respectively,
with coefficients 1 / 2, 1 / 4, 1 / 8 and 1 / 8.
At first I wanted to handle the border familiarity special
way: distribute the error pixels, standing at the right edge
familiarity on all 8 to the right points. But it turned
disgusting. Therefore, the current version of the converter
limits familiarity is no exception itself does not represent.
To the left edge of the screen can be treated in a special way:
to avoid appears next to her solid vertical lines to the colors
of her pixels to add a random number. It is dangerous to
solid black or white background. But such an operation produces
8col upon conversion of the img / mcx in 8 colors.
I will talk specifically about the problems of conversion is
in img / mcx, conversion to 6912 is somewhat simpler (such
converter is easily make the converter img / mcx simplification
of the program) ...
Conventionally, we denote the levels of each color component
by b0, b1, b2, b3, b4 (from zero to very bright) and obtain a
visual table of all the colors (in each bracket - levels: r, g,
b; right marked brightness included: "B"):
(B0, b1, b2) (b0, b2, b1) (b1, b0, b2) (b1, b2, b0) (b2, b0,
b1) (b2, b1, b0) (B0, b1, b3) (b0, b3, b1) (b1, b0, b3) (b1,
b3, b0) (b3, b0, b1) (b3, b1, b0) B (B0, b2, b3) (b0, b3, b2)
(b2, b0, b3) (b2, b3, b0) (b3, b0, b2) (b3, b2, b0) B (B0, b2,
b4) (b0, b4, b2) (b2, b0, b4) (b2, b4, b0) (b4, b0, b2) (b4,
b2, b0) BB (B1, b2, b3) (b1, b3, b2) (b2, b1, b3) (b2, b3, b1)
(b3, b1, b2) (b3, b2, b1) B 014,124,234,034,134 no
(B0, b0, b1) (b0, b1, b0) (b1, b0, b0) (b0, b1, b1) (b1, b0,
b1) (b1, b1, b0) (B0, b0, b2) (b0, b2, b0) (b2, b0, b0) (b0,
b2, b2) (b2, b0, b2) (b2, b2, b0) (B0, b0, b3) (b0, b3, b0)
(b3, b0, b0) (b0, b3, b3) (b3, b0, b3) (b3, b3, b0) B (B0, b0,
b4) (b0, b4, b0) (b4, b0, b0) (b0, b4, b4) (b4, b0, b4) (b4,
b4, b0) BB (B1, b1, b2) (b1, b2, b1) (b2, b1, b1) (b1, b2, b2)
(b2, b1, b2) (b2, b2, b1) (B1, b1, b3) (b1, b3, b1) (b3, b1,
b1) (b1, b3, b3) (b3, b1, b3) (b3, b3, b1) B (B2, b2, b3) (b2,
b3, b2) (b3, b2, b2) (b2, b3, b3) (b3, b2, b3) (b3, b3, b2) B
(B2, b2, b4) (b2, b4, b2) (b4, b2, b2) (b2, b4, b4) (b4, b2,
b4) (b4, b4, b2) BB 14.34 No
(B0, b0, b0) (b1, b1, b1) (b2, b2, b2) (b3, b3, b3) (b4, b4, b4)
With such a broad palette, we can easily show how
skin tones and bright colors without messing up their redundant
number of "dandruff."
But apart from this palette, we need to bear in mind another
palette: set of all tuples (i1, p1, i2, p2), ie, the attributes
of sign- place on both screens. How many of them can be used
completely unknown (manual counting - a lot of work, fraught
with errors). I have compiled statistics on approximately 20
images, converting to a simple enumeration of colors in the
palette, and received file tablo.dat (sm.ishodnik in the
appendix), containing 1708 palettes. Palettes are ordered by
frequency of use, but restriction of the most frequent 256
palettes, and even the most frequent five hundred nor to no
good cause ...
Here's how I went through the color palettes before this
table:
for b1: = 0 to 1 do for b2: = b1 to do a
for i1: = b1 shl 3 to b1 shl 3 +6 do
for i2: = i1 +1 to b1 shl 3 +7 do
for i3: = b2 shl 3 to b2 shl 3 +6 do
for i4: = i3 +1 to b2 shl 3 +7 do begin
...
But now how to iterate:
for ti: = 0 to datcnt {1707} do begin
i1: = tablo [ti, 0]; i2: = tablo [ti, 1]; i3: = tablo [ti, 2];
i4: = tablo [ti, 3]; ...
Inside the loop evaluation of the quality chosen palette. For
Such is the opinion adopted by the sum of all 64 reporting
errors pixels familiarity with colors from the selected
palette. For the error representation in this case take the
Euclidean distance. But the simple sum of the absolute value of
the difference of 3 components yields a result no worse. Why,
then, sqr, and not the abs? So It turned out that the HRC sqr
runs faster ...
The distance is taken between the point under consideration,
and familiarity considered the most suitable color palette. In
the palette of 4 Color (i1 + i2, i1 + p2, p1 + i2, p1 + p2),
but their number is also adding is the 5 th "average" color:
(i1 + p1 + i2 + p2) / 2. Previously, instead of the 5 colors
was 9, but the difference in the resulting image is almost
invisible.
This search - the slowest place throughout the program.
How to speed it up?
1. Interrupts without exhausting all the pixels, the
accumulation through extremely large total errors on the
palette. Extremely big mistake is one that is more than found
for previous palettes minimum (although you can offer an option
for where we take a break if, for example, after the 40 pixels
of 64 exceeded half of the minimum).
2. This minimum before exhaustion of all palettes pre-
sought for the previous panel (adjacent to the left or above)
familiarity, because it has a chance to be the most successful
firing Roy and the current familiarity.
3. This minimum is for a previous familiarity is multiplied by
factor less than unity (eg 0.75) - then we
We often choose the previous color, but will soon
out of the calculation error on a palette.
Diver>
Are you sure that you choose the most suitable combination of
colors? Alone Coder>
Not at all sure, otherwise there were no striped sky.
"Striped heaven" appear on the broad areas of the picture,
covered with flowers, which can not be accurately represented
by two screens. And these colors are. After all, if we imagine
all possible colors as a cube (one coordinate - R, 2-I - G,
third - B), then even the best we have found presents a palette
just a parallelogram (a kind of "plane of Flowers") inside
the cube. And since the number of palettes, of course, they are
clearly not fill the entire space inside the cube.
Here is a cube, it parallelogram representing one of the
palettes, and the parallelogram are the same 5 points of color
which we compare with this point:
How to find the best palette of knowing about this shortage?
Perhaps converter should be avoided as much as to change the
current palette (More precisely, to actually use it in color)
throughout the more or less monochrome (with no breaks, and
borders), the color spot in the picture. But how can this be
implemented? It is still unknown.
Here is an excerpt from my letter to Diver'u:
What we do is different 2-bitplanovaya palette from the
usual? Meanwhile, that it defines a color cube is not cut, and
some plane (parallelogram), inside which all colors can be
defined our palette with hatching (exactly).
What we do is different from the familiarity familiarity 8x8
1x8? Meanwhile, that the uniform section of a picture (without
breaks) used to determine the familiarity of color in the first
- some color surface, and the second - some color
Line. Thus, we need to find the color parallelogram
that most accurately describe the color of our color line, and
error reporting, and remember that it did not disappear,
add to the colors of the underlying familiarity.
The best would be a parallelogram parallelogram, which
has some minimal total error reporting points
familiarity. Total number of different forms of parallelograms
in the 27-color (Simplified) panel with a well-known to us
there are limitations, if my multiple sclerosis, 20 as well as
in 83-color - not considered, and how much is not the form, and
pieces, of different palettes - the a Horseradish know:)
I have a total error is, I know, wrong, and
so: as the sum of squared deviations (according to the formula
length Euclidean space, with different coefficients for R, G, B)
from nine control points of the parallelogram of color, which
points best describes the palette of this parallelogram. Himself
know that this is in 9 colors:)
Why is this method wrong? because he may deem
best a palette that all points of familiarity will come
For example, on one side of the parallelogram, and all the
familiarity zamazhetsya one color, while all errors will be one
and the same sign.
I later visited this idea:
1. 90% of the pixel brightness familiarity should fall into
the range brightness, defined by the chosen palette.
2. Region in the plane UV (Cb = YB, Cr = YR), filled
Pixel familiarity, should a 90% fall in the palette (it is
necessary table: for each palette value minU, maxU, minV,
maxV).
3. Same as (1, 2), but in the coordinates of RGB, then the
area color space will be set more accurately than a
parallelogram gram.
4. From ravnopodhodyaschih palettes to choose the narrowest.
This idea should think about ... It should not only improve
picture quality, but also accelerate the conversion, which will
write to the ZX similar converter.
Another problem - with chankovoy hatching. It is packed
much better than the Floyd, so the area without the fine details
better to convert through it. As you can see, in my
converter is for such a special allocation of the brush. But
tried to anoint her for img picture, you probably will
disappointed with the result - will float color. Why? I do not
know. I proceed from the obvious to odnoekrannomu conversion
method.
Such a method.
Consider the palette as a segment of the RGB cube, and a
color that need to provide this palette, as some point in the
same cube. Required to find the level of shading (0 = clean
paper'a to 1 = Net ink'a). Create a segment on our real axis:
set 0 on paper'nom end and 1 on ink'ovom. Omitted from the
perpendicular points on the segment. Coordinate perpendicular
base and will desired level (if it is less than 0, then we
assume zero if more 1, we consider the unit).
This method allows for chankovoy hatching the same levels as
Floyd.
Complicate the method for the case of img.
Create a parallelogram on our panel grid
(On the corners again, the zeros and ones). Omit perpendicular
to plane of the parallelogram. We take the coordinates of the
base perpendicular kulyara (again with the amputation of an
overflow) - they will be shading densities on the 1 st and 2 nd
screens.
If all the colors in the palette are collinear (parallel
gram has degenerated into a segment), the method does not work
- you have to apply shamanic recount.
And still the resulting level of shading for some reason not
coincides with Floydovskim ... Maybe I'm wrong led
formula? Sometimes ...
What else is there in the converter:
- Dithering level - the level of "dustiness" of colors that
are close to net. If equal to 1, then all colors will be
"dust". If 0, will use exactly two of graduation. A similar
parameter there is in Photoshop, in my version of JPEG, and in
my videokonvertore. Without it, convert meaningless.
- Saturation - hue (0 - B / W, 1 - normal level of color
In particular, 1.5 - slightly taller, and generally can be
increased without loss tions). Without this option, convert,
too pointless.
- Chankovaya hatching is in 2 versions: 65 levels (8x8) - by
default - and 5 levels (2x2).
- You can prohibit the use of two levels of bright in the
conversion (Sometimes avoids unnecessary "square" image).
- When elozenii mouse on the screen can be seen ZX attributes
each familiarity (for img / mcx - separately for the 1 st screen
separately for the 2-nd).
- Dithering level can be changed and during kistemazaniya
Chanco howl hatching (left mouse button - chankovaya hatching,
right - Floyd). Kistemazanie only works if the
Image originally converted into mode Floyd. Size
brushes can be changed. After kistemazaniya need to click
Save.
- Square button on the left bottom off the image (for
those who have to work behind the head:)).
- Choose a border, which will be cut image
You can enter numbers, but you can Clicking on the picture
itself: the left button (one corner) and right (another angle).
- ZX pictures in all formats that the program can gene
erate, it can also be downloaded.
- All formats (including emg, who never used
forms a) read the handbook Nuts'a "sprites.txt".
- Module tgapng - my old course work. Can use
vat in their programs (there is a function not only for the
retrieval ki, but for the unloading of these formats). Source
GifImage (by Anders Malender) I did not write - it is very big.
If need, look somewhere in the internet. Source jpeg.dcu I,
seems to be no.
I checked the archive: the Delphi 6 program is compiled.
If you have any problems with the compilation, throw out the
program all left formats (jpg, gif, png, tga), together with
their modules - will remain a format bmp.
A. Coder
Other articles:
Similar articles:
В этот день... 2 November