home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TIFF / TACS40.ZIP / COMPBLOK.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-10-14  |  3.5 KB  |  157 lines

  1. ; 1D Modified Huffman compression module interface
  2. ; Compatible with Microsoft C
  3.  
  4. page    66,132
  5.  
  6.  
  7. _compress_TEXT     SEGMENT WORD PUBLIC 'CODE'
  8.     ASSUME    CS:_compress_TEXT
  9.  
  10.  
  11.     PUBLIC    _compress_block
  12.     EXTRN    _COMPRESS:NEAR
  13.  
  14. ;  These variables moved from Data segment
  15.  
  16.  
  17. RAW_VID_PTR    DW    ?        ; Pointer to raw video
  18. COMP_PTR    DW    ?        ; Pointer to compressed video
  19. BYTE_COUNT    DW    ?        ; Number of compressed bytes
  20. LIN_SCAN_LENGTH DW    ?        ; Length of one scan line
  21. BLOK_LENGTH    DW    ?        ; Number of scan lines to compress
  22.  
  23.  
  24. ;*****************************************************************************;
  25. ;                                          ;
  26. ; COMPRESS_BLOCK - Compress a block of raw image data                  ;
  27. ;                                          ;
  28. ; The following subroutine is used to compress one block of image data and    ;
  29. ; to save the compressed image in a caller supplied destination buffer.  If   ;
  30. ; compression of the block will result in negative compression (more space    ;
  31. ; to store the compressed than the uncompressed image), compression halts     ;
  32. ; and a failure flag is returned.                          ;
  33. ;                                          ;
  34. ; "C" calling sequence :                                                      ;
  35. ;                                          ;
  36. ;    int    compress_block()    /* Image block compression routine */ ;
  37. ;    char far *raw_video[];        /* Buffer containing raw image */     ;
  38. ;    char far *comp_video[];        /* Buffer for compressed image */     ;
  39. ;    long    line_length;        /* Length of one scan line */          ;
  40. ;    int    block_length;        /* Number of scan lines in block */   ;
  41. ;       .                                      ;
  42. ;       .                                      ;
  43. ;       .                                      ;
  44. ;    count = compress_block (raw_video, comp_video,                  ;
  45. ;                line_length, block_length);              ;
  46. ;    if (count == 0)                               ;
  47. ;       /* Save raw video */                           ;
  48. ;    else                                      ;
  49. ;       /* Save compressed video - number of bytes is in count */          ;
  50. ;                                          ;
  51. ;*****************************************************************************;
  52. ;
  53. _compress_block  PROC     FAR
  54. ;
  55. ; Set up stack frame and get input parameters
  56. ;
  57.     PUSH    BP
  58.     MOV    BP,SP
  59.  
  60. ; New change
  61.  
  62.     PUSH    SI
  63.     PUSH    DI
  64.     PUSH    DS
  65.     PUSH    ES
  66.  
  67. ; End change
  68.  
  69.     MOV    AX,[BP+6]
  70.     MOV    RAW_VID_PTR,AX
  71.  
  72. ; new addition
  73.  
  74.     MOV    AX,[BP+8]        ; Passed segment goes into DS & ES
  75. ;9/12    MOV    DS,AX
  76.     MOV    ES,AX
  77.  
  78. ; new changes
  79.  
  80.     MOV    AX,[BP+10]         ; used to be [bp+6]
  81.     MOV    COMP_PTR,AX
  82.     MOV    AX,[BP+12]        ; used to be [bp+8]
  83.  
  84. ;9/12    MOV    LIN_SCAN_LENGTH,AX
  85.     mov    ds,ax
  86.  
  87.     MOV    AX,[BP+14]        ; used to be [bp+10]
  88.  
  89. ;9/12    MOV    BLOK_LENGTH,AX
  90.     mov    lin_scan_length,ax
  91.  
  92. ;new addition  9/12
  93.  
  94.     mov    ax,[bp+18]
  95.     mov    blok_length,ax
  96.  
  97.  
  98. ; Compress scan lines in block
  99. ; Max lines in a block for now is 25.
  100.  
  101.     MOV    AX,BLOK_LENGTH        ; Compute maximum number of bits
  102.     MOV    CX,LIN_SCAN_LENGTH    ;   before negative compression
  103.     SHL    CX,1
  104.     SHL    CX,1
  105.     SHL    CX,1
  106.     MUL    CX
  107.     MOV    DX,AX
  108.  
  109. ;    MOV    DX,10240
  110.     XOR    AX,AX            ; No residuals yet
  111.     MOV    BYTE_COUNT,0
  112. COMP_LOOP:
  113.     MOV    DI,RAW_VID_PTR        ; Set up param's to compression rtn.
  114.     MOV    SI,COMP_PTR
  115.     MOV    CX,LIN_SCAN_LENGTH
  116.     CALL    _COMPRESS
  117.     ADD    BYTE_COUNT,CX        ; Update number of compressed bytes
  118.     OR    CX,CX            ; Negative compression ?
  119.     JZ    EXIT_COMP        ;   Yes, exit with indication
  120.     ADD    COMP_PTR,CX
  121.     MOV    BX,LIN_SCAN_LENGTH
  122.     ADD    RAW_VID_PTR,BX
  123.     DEC    BLOK_LENGTH
  124.     JNZ    COMP_LOOP
  125. ;
  126. ; If any residual, then add in
  127. ;
  128.     MOV    CX,BYTE_COUNT
  129.     OR    AH,AH
  130.     JZ    EXIT_COMP
  131.     MOV    CL,8
  132.     SUB    CL,AH
  133.     SHL    AL,CL
  134.     MOV    BX,COMP_PTR
  135.     MOV    [BX],AL
  136.     INC    BYTE_COUNT
  137.     MOV    CX,BYTE_COUNT
  138. EXIT_COMP:
  139.  
  140. ; new addition
  141.  
  142.     POP    ES
  143.     POP    DS
  144.     POP    DI
  145.     POP    SI
  146.  
  147. ; end addition
  148.  
  149.     MOV    AX,CX
  150.     POP    BP
  151.     RET
  152.  
  153. _compress_block  ENDP
  154.  
  155. _compress_TEXT     ENDS
  156.     END
  157.