Sinclair Town #01
31 марта 1995

Beginners - the basic methods of image scaling.

<b>Beginners</b> - the basic methods of image scaling.
           BEGINNING.


   The theme of this and more of the following articles - 
scaling images. We consider the basic methods of scaling

image. All this will be
considered by the example of zooming in twice.



   With the advent of the market file
Image IBM standards, and
otsifrovok images before
I faced the problem of reducing these pictures to screen size. 
It is most urgent, for the owners of 48 KB

computers that you want
look at not reaching them
pictures, as well as artists and
people who want a good draw
their program.

   On a floppy disk you'll be offered an example of a program 
to reduce image files with any extension of twice.


   Wesy.asm program designed to give a universal base for your 
own further research this area.



       BASIC METHODS

       Scaling.


   1) Delete / add extra

   pixels;

   2) Averaging and metal threshold
   method:

    a) uniform;

    b) The weighted;

   3) approximation of semitones;



    Removing unnecessary pixels.


   The method is based on the fact
that a certain number of pixels in the original image
zoom out (the compression of the image) is simply not included 
in the resulting image. Or, if there magnification, what

then the original screen pixels are duplicated.

   This algorithm is more efficient to reduce image
to 1,5 times, but sometimes halving has a good
result.

   Reduction algorithm in two times is simple: Take a starting 
point (Eg (0,0)) and copy it

on the screen at (1,1), go to
the next point (2,0), copy on
(1,0), etc. to fill the screen.

   The program of this method is implemented on a label BEIN2.

   Disadvantages of the method: when you remove half of the 
information is lost and simply ignored.




         Averaging.


   So we have a compressible
Image: 512 * 384. We want
reduce it by half and get a display file 256 * 192.

   We see that each
system on display pixel corresponds to 4 points of the original 
image (2 * 2). And are based on this the following methods.


   Averaging can be of two types.

   With a uniform averaging we
count the number of pixels with
Color INK. The amount will not be
greater than 4. This amount is called
intensity of display pixel I. If the sum is greater than 2, then
a display pixel has a color
INK, otherwise PAPER. Thus
determine the color at each point
screen.

Location Showing

  pixel on the screen

    A B I = int ((A + B + C + D) / 2.5)

    C D
Here A, B, C, D-color pixel at the corresponding point of a 
compressible image. (INK-1, PAPER-0);



   You can get better results if we use
method of weighted averaging.
This method takes into account the greater number of points 
(not 4), assigning each point of your weight. (cm

2). Then the resulting intensity will be:
 I_R = 1 * A +2 * B +1 * C +2 * D +4 * E +2 * F +

     +1 * G +2 * H +1 * K, where
A, B, C, D, E, F, G, H, K-pixel color in
corresponding point on the compressed
image. (INK-1, PAPER-0);

E - central pixel in the analysis.


   LOCATION WEIGHT

     pixel pixel

      A B C 1 2 1

      D E F 2 4 2

      G H K 1 2 1
Figure 2. Weighted averaging.


   Calculated the resulting
intensity we compare with
number 8. Draw color INK point on the screen, if I_R more than 
8. Then go to the next coordinate (increasing the current

coordinates on the 2 on one of the axes
and if you want the second). That is
we make the central point
compressed image through one.

   Sub-weighted averaging is located on a label
BEGIN.


   What makes for "Spectrum" threshold methods from methods
averaging? Virtually nothing.
We simply compare the resulting
intensity of the display pixel is not a fixed number (2
or 8), a with a certain threshold
value of the intensity I, entered from the keyboard.


       TO BE CONTINUED


; Works CLS (without RESET POINT)
, Ie CLS needed before starting
; Weighting method
START JR BEGIN

        NOP
; Removal Methods
START2 JP BEIN2

        DEFS 27
; SUB file download
; CD
LOADER JP LOAD
; Image intensity
INTENSIVE

        DEFB 5
; To what coord. ON X PRINT
; In pixels Compress files.
RAZM_X DEFW 376
; To what coord. PRINT ON Y
RAZM_Y DEFW 270
, The number of bytes into a string
; IMAGES
RAZ_B DEFW 82
; Start address Compress files
NACALO DEFW 30018
, At which point Compress files
; BEGINS WORK ALGORITHM
NAC_X DEFW 0001
NAC_Y DEFW 0001
; WHERE loaded in Compressible Files
LOA_BE DEFW 30000
; END describe the data.



; BALANCING ALGORITHM
BEGIN

        LD DE, (NAC_X)
; X-0 .. 255
CIKL_I LD BC, (NAC_Y)
; Y-0 .. 176
; Zero the H.
, Formed in the resultant
, The intensity of the analyzed
; Pixels compressed image
CIKL_J LD H, 0
; Save the coordinates:
; X (DE) and Y (BC)

        PUSH DE

        PUSH BC
; Next, we analyze the point of contraction; ible images in the 
following ; Order: have weights:

; A B C 1 2 1
; D E F 2 4 2
; G H K 1 2 1
;
; *** Analysis of point A:
, Shifted by A

        DEC DE

        DEC BC
; Analyze the value of a point on
; According to the coordinates X (DE) and Y (BC)
; The output of 0 or 1.

        CALL POINT
; Add the value of the pixel to
, The resulting efficiency.

        ADD A, H

        LD H, A
; *** Analysis of point B
; Shifts to B

        INC DE

        CALL POINT
; Of gaining intensity, T at this point, the image the mind; 
knife at 2. See matrix. 

        SLA A

        ADD A, H

        LD H, A
; *** Analysis of point C

        INC DE

        CALL POINT

        ADD A, H

        LD H, A
; *** Analysis of F

        INC BC

        CALL POINT

        SLA A

        ADD A, H

        LD H, A
; *** Analysis of point E

        DEC DE

        CALL POINT

        SLA A

        SLA A

        ADD A, H

        LD H, A
; *** Analysis of point D

        DEC DE

        CALL POINT

        SLA A

        ADD A, H

        LD H, A
; *** Analysis of G-Spot

        INC BC

        CALL POINT

        ADD A, H

        LD H, A
; *** Analysis of the H-point

        INC DE

        CALL POINT

        SLA A

        ADD A, H

        LD H, A
; *** Analysis of the K point

        INC DE

        CALL POINT

        ADD A, H

        LD H, A
; H = A + C + G + K +2 * (D + B + F + H) +4 * E
, Determines the coordinates of O
, A point on the screen

        DEC DE

        DEC BC

        SRA D

        RR E

        SRA B

        RR C
; Compare the intensity of the problem, under consideration, 
the user account, and Noah. 

        LD A, (INTENSIVE)

        CP H

        JR NC, NEXT
; If INTENSIVE-H <0, then draw
; Point on the screen. If not, then
; Circumvent routine painting.

        CALL SETING
; To recall the old X and Y
NEXT POP BC

        POP DE
; Transition into the next Y and verified; ka at the end of 
vertical construction, the vertical line. 

        INC BC

        INC BC

        LD HL, (RAZM_Y)

        SBC HL, BC

        JP NC, CIKL_J
; If pressed any Clavey; step, the output from the subroutine

        BIT 5, (IY +1)

        RET NZ
; Transition into the next X and verified; ka at the end of the 
construction of the screen. 

        INC DE

        INC DE

        LD HL, (RAZM_X)

        SBC HL, DE

        JP NC, CIKL_I

        RET
; *** END OF THE WEIGHT OF THE METHOD



; *** Deletion algorithm
BEIN2
; Download in DE and BC are the initial
, The values ​​of X and Y.

        LD DE, (NAC_X)
; X-0 .. 255
C2KL_I LD BC, (NAC_Y)
; Y-0 .. 176
C2KL_J
; Memorization coordinates X, Y.

        PUSH DE

        PUSH BC
; Processing point coordinates.

        CALL POINT
And displays schitanye point on
; Screen.

        SRA D

        RR E

        SRA B

        RR C

        AND A

        JR Z, NEXT2

        CALL SETING
; Remembering X and Y.
NEXT2 POP BC

        POP DE

        INC BC

        INC BC
; Go to the following coordinates

        LD HL, (RAZM_Y)

        SBC HL, BC

        JP NC, C2KL_J

        INC DE

        INC DE

        LD HL, (RAZM_X)

        SBC HL, DE

        JP NC, C2KL_I

        RET
; *** End of removal.


; *** Installing point
; To screen coordinates:
; BC-Y (upper left)
; DE-X
SETING PUSH BC

        PUSH DE
; Address the pixel count
, And the number of bits.

        CALL RASCHET
; Converts byte mask

        LD B, # 0FF

        XOR B

        OR (HL)

        LD (HL), A

        POP DE

        POP BC

        RET
; *** End of installation procedures
; *** Point.


; *** The procedure of analysis point in
; Compresses the images.
POINT PUSH BC

        PUSH DE

        PUSH HL
; Get the address in the file is compressed; ICDO image and 
select ; The desired bit.


        CALL RASHET

        LD B, # 0FF

        XOR B

        LD B, A

        LD A, (HL)

        AND B
, Check to see if the desired bit 0
; If not, then send to A = 1,
, Otherwise it remains 0

        JR Z, NEXT_POINT

        LD A, 1
NEXT_POINT *
; Remembering all the registers.

        POP HL

        POP DE

        POP BC

        RET
; *** End of analysis procedures.


; *** The procedure for calculating the address
; Familiarity in a compressible file.
RASHET
; Memorize X

        PUSH DE
; In HL address of the first Bait
; Image.
; Believe HL = HL + DE / 8

        LD HL, (NACALO)

        SRA D

        RR E

        SRA D

        RR E

        SRA D

        RR E

        ADD HL, DE
; Read the size of a single row
; Image.

        LD DE, (RAZ_B)
; HL = HL + DE * BC
SRAD SRA D

        RR E

        JR NC, NOL

        ADD HL, BC
NOL SLA C

        RL B

        LD A, D

        OR E

        JR NZ, SRAD
; In HL-ADDRESS. It remains to find bits.
END1 POP DE

        LD A, E

        AND # 7

        INC A

        LD B, A

        LD A, # FE
LOOPA RRCA

        DJNZ LOOPA
, NOW IN A will be 0 in the right
; Discharge.

        RET
; *** End of calculating an address for
; POINT


; *** Calculating addresses for SETTING
; OUTPUT IN (HL)-byte at
; In B 11101111 IN THE APPROPRIATE
; Discharge. For more details see
, Applied Graphics, Inforkom

RASCHET

        LD A, E

        LD D, A

        LD A, C

        LD E, A

        AND A

        RRA

        SCF

        RRA

        AND A

        RRA

        XOR E

        AND # 0F8

        XOR E

        LD H, A

        LD A, D

        RLCA

        RLCA

        RLCA

        XOR E

        AND # C7

        XOR E

        RLCA

        RLCA

        LD L, A

        LD A, D

        AND 7

        LD B, A

        INC B

        LD A, # FE
LOOP RRCA

        DJNZ LOOP

        RET
; *** End of sub SETTING


; *** Sub-boot.
LOAD
; Adjusts to find a file on
; Name (8 characters).

        LD A, 8

        LD (23814), A
; We are looking for a file named stored on
, At 23773.

        LD BC, 10

        CALL # 3D13
; Check if the file in the kata; log.

        LD A, C

        BIT 7, A

        RET NZ
; Read the file name.

        LD C, 8

        CALL # 3D13
; Read the file found

        LD HL, (LOA_BEG)

        LD A, (23786)

        LD DE, (23787)

        LD B, A

        LD C, 5

        CALL # 3D13

        RET
; *** End of sub downloads.



        BASIC PROGRAM.


   On the disc are two demo BASIC program:

   WesyScr - for a reduction in

              double screen

              files.

   Scma.02 - for file format

              IMAGE.

   Code blocks these programs
slightly different.

   To be halved
Zoom in Scma.02 you need
to know its format. To do this,
look in the "IBM SCREENER" this screen, set it up the keys 9 
and 0, and press 1. Next will give you a hint. Remember her 
from the number of bytes in line. Next, read the file

Scma.02, a picture and a question
"LINE SIZE?" enter that number.
If you press "ENTER" will
taken the previous number (in the
early 82).

   Next you are asked about the form of the algorithm: 0 - 
gravimetric method 

         1 - removal method

   Enter the intensity and the initial pixel processing
(0th or first X and Y).

   If you want to cut some
another piece of the image,
ispravte starting address of 100
line.

   After the construction of (or in the process of building for 
the gravimetric method), pressing the following keys will 
result in any effect: 

   S - written on the current screen

       disc

   E - go to BASIC.

   L - switch to input the following items

       file.

   I - to introduce a threshold intensity
       The intensity and begin to construct
       enie again.
 Any other key will result in
change all the parameters of the program.




Other articles:

appeal to readers - Why have begun the creation of this magazine?

Muzykalka - Overview of musical demonstrations: Absent, Shock.

Author! - About the authors of this journal and adventyurnoy game "LENIN".

Sweetest ... - The analysis of the game "GREMLINS".

Worlds 128 - About the best programs for 128 of the first computer. Game "ROD * LAND 128".

Series - Series game programs.

Series - Novella on adventyurnoy 3D game "TOTAL ECLIPSE part 1."

Ha hacker - This section is intended for people with a sense of humor and abusing them. "100 anecdotes about the Chukchi."

black box - Category, which will answer your questions, and also define your own. Analysis of letters from readers of the magazine.

black box - parsing RPG game "DRAGON'S OF THE FLAMES".

black box - analysis of games "BARD'S TALE", "ELITE" and "STRANGER".

Beginners - the basic methods of image scaling.

Exam - Three "unpretentious" issue.

Advertising - Ads and Classified.

Archive - On programs for existing PC "ZX-SPECTRUM": AMAUROTE, ATIC ATAC, ALIEN HIGHWAY, ACE 2088, RESCATE ATLANTIDA part 1 & 2.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Introduction - Third number Cheboksary irregular almost modem independent newspaper.
Iron - Ability to connect a computer ZX spectrum to the TV via Scart.
Mosaic - O emulsion, the firm Scorpio and rectify the "FAST FORMAT"-a.

В этот день...   29 April