⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xdisplay.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 2 页
字号:
            "\nDISPLAY> Enter 1 for show histogram "
            "0 for don't");
         printf("\nDISPLAY> ___");
         get_integer(&int_response);
         *show_hist = int_response;
      }  /* ends if r == 6 */

   }  /* ends while not_finished  */
}  /* ends display_menu  */




   /********************************
   *
   *   display_image_portion(...
   *
   *********************************/

display_image_portion(image, x, y, display_colors, 
                      image_colors, invert)
   int      invert, display_colors, image_colors;
   short    image[ROWS][COLS];
   unsigned int x, y;
{
   unsigned int color, i, j;

      if(invert == 1){
        for(i=0; i<ROWS; i++)
           for(j=0; j<COLS; j++)
              image[i][j] = (display_colors-1)
                             - image[i][j];
      }  /* ends if invert == 1 */

      for(i=0; i<ROWS; i++){
         for(j=0; j<COLS; j++){

        _setcolor(image[i][j]);
        _setpixel(j+x, i+y);
/*****
my_set_pixel(j+x, i+y, image[i][j]);
******/

         }  /* ends loop over j  */
      }     /* ends loop over i  */

}  /* ends display_image_portion  */





   /**********************************************
   *
   *   map_16_shades_of_gray(...
   *
   *   This function maps 16 shades of gray into
   *   the first 16 color indices.  This allows
   *   you to display a true "black and white"
   *   image on a color monitor.
   *
   *********************************************/

map_16_shades_of_gray(display_mode)
   int display_mode;
{
   /* all MSC 6.0 statements */
_setvideomode(display_mode);
_remappalette(0,  0x000000L);
_remappalette(1,  0x040404L);
_remappalette(2,  0x080808L);
_remappalette(3,  0x0c0c0cL);
_remappalette(4,  0x101010L);
_remappalette(5,  0x141414L);
_remappalette(6,  0x181818L);
_remappalette(7,  0x1c1c1cL);
_remappalette(8,  0x202020L);
_remappalette(9,  0x242424L);
_remappalette(10, 0x282828L);
_remappalette(11, 0x2c2c2cL);
_remappalette(12, 0x303030L);
_remappalette(13, 0x343434L);
_remappalette(14, 0x383838L);
_remappalette(15, 0x3f3f3fL);
}




   /*********************************************
   *
   *   transform_the_colors(...
   *
   *   This function transforms the gray shades
   *   in the image array for display.  It can either
   *   do it in straight mode by multiplying or
   *   dividing or it can do it with hist
   *   equalization by calling the function
   *   perform_histogram_equalization.
   *
   *************************************************/

transform_the_colors(image, color_transform,
                     display_colors, image_colors,
                     histogram, horizontal,
                     vertical)
   char   color_transform[];
   int    display_colors, horizontal,
          image_colors, vertical;
   short  image[ROWS][COLS];
   unsigned long histogram[];
{
   int         color, i, j;
   float new_grays, area;
   unsigned long x;

   if(color_transform[0] == 'S'){
      for(i=0; i<ROWS; i++){
         for(j=0; j<COLS; j++){

            if( (display_colors == 16) &&
                (image_colors  == 256))
               color = image[i][j]/16;
            if( (display_colors == 16) &&
                (image_colors  == 16))
               color = image[i][j];
            if( (display_colors == 256) &&
                (image_colors  == 256))
               color = image[i][j];
            if( (display_colors == 256) &&
                (image_colors  == 16))
               color = image[i][j]*16;

            image[i][j] = color;

         }  /* ends loop over j        */
      }        /* ends loop over i        */
   }  /* ends if transform is straight */

   if(color_transform[0] == 'H'){

      area      = ((long)(vertical)) *
                  ((long)(horizontal));
      area      = area*10000.0;
      new_grays = display_colors;

      perform_histogram_equalization(image, histogram,
                                     new_grays, area);

   }  /* ends if transform is hist equalization */

}  /* ends transform_the_colors */




   /**********************************
   *
   *   NOT USED IN CIPS
   *
   *   Modes for the SigmaVGA Legend
   *               (hex)
   *   10 - 640x350x64?
   *   12 - 640x480x16
   *   29 - 800x600x16
   *   30 - 800x600x256
   *   38 - 1024x768x256
   *
   ***********************************/

my_set_video_mode()
{

   union REGS regs;

   regs.h.al = 0x29; /* mode */
   regs.h.ah = 0x00;
   int86(0x10, &regs, &regs);


}  /* ends my_set_video_mode */


   /*************************
   *
   *   NOT USED IN CIPS
   *
   *************************/

my_set_pixel(x, y, color)
   unsigned int x, y, color;
{

union REGS regs;
char  r[80];
int i;

   regs.h.ah = 0x0c;
   regs.x.dx = y;
   regs.x.cx = x;
   regs.h.al = color;
   regs.h.bh = 0x00;

   int86(0x10, &regs, &regs);

}  /* ends my_set_pixel */




   /*************************
   *
   *   NOT USED IN CIPS
   *
   *************************/

my_set_colors()
{

 union REGS regs;
 int i;


      /*********************
         this works for 256 color modes
         it does not work for 16 color modes
      *********************/

   _asm{

      mov   ax,0030h ; set graphics mode 30h=800x600x256
      int   10h

      mov ax,0h
      mov dx,3c8h ; select first DAC register

      out dx,al
      inc dx          ; set DAC data register

      mov al,0h
      out dx,al
      out dx,al
      out dx,al

      mov al,4h
      out dx,al
      out dx,al
      out dx,al

      mov al,8h
      out dx,al
      out dx,al
      out dx,al

      mov al,ch
      out dx,al
      out dx,al
      out dx,al

      mov al,10h
      out dx,al
      out dx,al
      out dx,al

      mov al,14h
      out dx,al
      out dx,al
      out dx,al

      mov al,18h
      out dx,al
      out dx,al
      out dx,al

      mov al,1ch
      out dx,al
      out dx,al
      out dx,al

      mov al,20h
      out dx,al
      out dx,al
      out dx,al

      mov al,24h
      out dx,al
      out dx,al
      out dx,al

      mov al,28h
      out dx,al
      out dx,al
      out dx,al

      mov al,2ch
      out dx,al
      out dx,al
      out dx,al

      mov al,30h
      out dx,al
      out dx,al
      out dx,al

      mov al,34h
      out dx,al
      out dx,al
      out dx,al

      mov al,38h
      out dx,al
      out dx,al
      out dx,al

      mov al,3ch
      out dx,al
      out dx,al
      out dx,al
   } /* ends asm */



}  /* ends my_set_colors */




   /*************************
   *
   *   NOT USED IN CIPS
   *
   *************************/

put_pixel(ppx, ppy, color)
   int color, ppx, ppy;
{

int RW_Page=0x0ff;
int W_Page=0x0ff;
int R_Page=0x0ff;
int PAGE_SEL_PORT=0x3cd;

printf("\ny=%d x=%d color=%d Page=%d offset=%d", 
ppy, ppx, color, (ppy*800
+ ppx)/0x10000, (ppy*800 + ppx)%0x10000);

/******************

   _asm{
             ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
             ;
             ;         taken from file
             ;         d:\supervga\256col\wpixel.asm
             ;
             ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


        PUSH        BP     ;Preserve BP
        MOV     BP,SP      ;Preserve stack pointer

        PUSH    ES         ;Preserve segment and index registers
        PUSH    DS
        PUSH    DI
        PUSH    SI
        ; Convert x,y pixel address to Page and Offset

        MOV        AX,ppy     ;Fetch y coordinate
                              ;Video_Pitch=SCREEN_PITCH=800
        MUL        cs:800     ;multiply by width in bytes
        ADD        AX,ppx     ;add x coordinate to compute offset
        ADC        DX,0       ;add overflow to upper 16 bits
                              ;Graph_Seg=0aoooh
        MOV        DS,CS:0a000h   ;Put new address in DS:SI
        MOV        DI,AX
        MOV     AL,DL             ;Copy page number into AL
        JMP        Select_Page    ;Select proper page
Ret_Page:


        ; Set pixel to supplied value

        MOV        AL,color     ;Fetch color to use
        MOV     [DI],AL         ;Set the pixel

        ; Clean up and return

        POP     SI       ;Restore segment and index registers
        POP     DI
        POP     DS
        POP     ES

        MOV     SP,BP    ;Restore stack pointer
        POP     BP       ;Restore BP

        JMP        The_End


Select_Page:
        CMP        AL,CS:RW_Page  ;Check if already selected
        JNE        SP_Go
        JMP        Ret_Page
SP_Go:
        PUSH        AX
        PUSH        DX    MOV  DX,PAGE_SEL_PORT        ;Fetch address of page select
        AND        AL,7                ;Force page number into 0-7
        MOV        CS:RW_Page,AL       ;Save most recently selected page
        MOV        CS:R_Page,0FFh
        MOV        CS:W_Page,0FFh
        MOV        AH,AL               ;Copy page into AH
        SHL        AH,1                ;Shift page number
        SHL        AH,1
        SHL        AH,1
        OR        AL,AH                ;Move page number into "write" bits
        OR        AL,40h               ;Force bit 6
        OUT        DX,AL               ;Write out the new page select
        POP        DX
        POP        AX
        JMP        Ret_Page

The_End:

   }*******/        /* ends _asm */

}  /* ends put_pixel */






   /*******************************************
   *
   *   map_64_shades_of_gray()
   *
   *   This function maps 256 DAC registers to
   *   gray shades.  Taken from p. 73 of
   *   Sutty and Blair's text on superVGA
   *
   ********************************************/


map_64_shades_of_gray()
{

   _asm{
      mov ax,0013h ;mod 13h is 320x200x256
      int 10h

      mov ah,10h   ; function 10h
      mov al,1bh   ; sub function 1bh
      mov bx,0h    ; first DAC register to change
      mov cx,100h  ; change 256 DAC registers
      int 10h

   } /* ends asm */
}  /* ends map_64_shades_of_gray */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -