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

📄 display.cc

📁 ac3的解码程序
💻 CC
📖 第 1 页 / 共 4 页
字号:
    error("unable to install error handler for XIL");  if (!(displayimage=xil_create_from_window(State, display, window)))    exit(1); // XIL sends error message to stderr if xil_create_from_window fails  ximage=xil_create(State, coded_picture_width, coded_picture_height, bands, XIL_BYTE);  ximage2=xil_create(State, coded_picture_width, coded_picture_height, bands, XIL_BYTE);  resized_image=xil_create(State, coded_picture_width, coded_picture_height, bands, XIL_BYTE);/*  // Only when using XIL colorspace conversion; this seems rather slow  if (bands==3){    XilColorspace cspace=xil_colorspace_get_by_name(State, "ycc601");    xil_set_colorspace(ximage, cspace);    cspace=xil_colorspace_get_by_name(State, "ycc601");    xil_set_colorspace(resized_image, cspace);    cspace=xil_colorspace_get_by_name(State, "rgb709");    xil_set_colorspace(displayimage, cspace);  }*/  XSelectInput(display, window, StructureNotifyMask);#else#ifdef SH_MEM  char dummy;  shmem_flag = 0;#ifdef USE_DGA             /* enable this if you want to have DGA support */  int EventBase, ErrorBase, flags,vp_width,vp_height,bank,ram;  if (XF86DGAQueryExtension (display, &EventBase, &ErrorBase)) {      XF86DGAQueryDirectVideo (display, XDefaultScreen (display), &flags);      if ((flags & XF86DGADirectPresent) == 0) {          if (!quiet) message ("dga: no direct present");      }      else {          shmem_flag = 2;          if (!quiet) message ("using DGA ");      }      XF86DGAGetVideo (display, XDefaultScreen (display), (char **) &dithered_image,                        &xwidth, &bank, &ram);      dithered_image2 = dithered_image;      XF86DGAGetViewPortSize (display, XDefaultScreen (display),                        &vp_width, &vp_height);      if (vp_height < v_size || vp_width < h_size) {        if (!quiet) message("View Port too small for DGA");        shmem_flag = 0;      }      else {        XF86DGASetViewPort (display, XDefaultScreen (display), 0, 0);        XF86DGADirectVideo (display, XDefaultScreen (display),XF86DGADirectGraphics );      }  }#endif  if (!shmem_flag)     if (XShmQueryExtension(display)) shmem_flag = 1;    else {      shmem_flag = 0;      if (!quiet){        message("Shared memory not supported");        message("Reverting to normal Xlib");      }    }  if (shmem_flag==1) CompletionType = XShmGetEventBase(display) + ShmCompletion;  InstallXErrorHandler();  if (shmem_flag==1){    ximage = XShmCreateImage(display, None, bpp, ZPixmap, NULL,                             &shminfo1,                             coded_picture_width, coded_picture_height);    if (!prog_seq)      ximage2 = XShmCreateImage(display, None, bpp, ZPixmap, NULL,                                &shminfo2,                                coded_picture_width, coded_picture_height);    /* If no go, then revert to normal Xlib calls. */    if (ximage==NULL || (!prog_seq && ximage2==NULL)){      if (ximage!=NULL) XDestroyImage(ximage);      if (!prog_seq && ximage2!=NULL) XDestroyImage(ximage2);      if (!quiet)        fprintf(stderr, "Shared memory error, disabling (Ximage error)\n");      goto shmemerror;    }    /* Success here, continue. */    shminfo1.shmid = shmget(IPC_PRIVATE,                             ximage->bytes_per_line * ximage->height,                            IPC_CREAT | 0777);    if (!prog_seq)      shminfo2.shmid = shmget(IPC_PRIVATE,                               ximage2->bytes_per_line * ximage2->height,                              IPC_CREAT | 0777);    if (shminfo1.shmid<0 || (!prog_seq && shminfo2.shmid<0)){      XDestroyImage(ximage);      if (!prog_seq) XDestroyImage(ximage2);      if (!quiet)        fprintf(stderr, "Shared memory error, disabling (seg id error)\n");      goto shmemerror;    }    shminfo1.shmaddr = (char *) shmat(shminfo1.shmid, 0, 0);    shminfo2.shmaddr = (char *) shmat(shminfo2.shmid, 0, 0);    if (shminfo1.shmaddr==((char *) -1) ||        (!prog_seq && shminfo2.shmaddr==((char *) -1))){      XDestroyImage(ximage);      if (shminfo1.shmaddr!=((char *) -1)) shmdt(shminfo1.shmaddr);      if (!prog_seq){        XDestroyImage(ximage2);        if (shminfo2.shmaddr!=((char *) -1))          shmdt(shminfo2.shmaddr);      }      if (!quiet)      {        fprintf(stderr, "Shared memory error, disabling (address error)\n");      }      goto shmemerror;    }    ximage->data = shminfo1.shmaddr;    dithered_image = (unsigned char *)ximage->data;    shminfo1.readOnly = False;    XShmAttach(display, &shminfo1);    if (!prog_seq){      ximage2->data = shminfo2.shmaddr;      dithered_image2 = (unsigned char *)ximage2->data;      shminfo2.readOnly = False;      XShmAttach(display, &shminfo2);    }    XSync(display, False);    if (gXErrorFlag){      /* Ultimate failure here. */      XDestroyImage(ximage);      shmdt(shminfo1.shmaddr);      if (!prog_seq){        XDestroyImage(ximage2);        shmdt(shminfo2.shmaddr);      }      if (!quiet)        fprintf(stderr, "Shared memory error, disabling.\n");      gXErrorFlag = 0;      goto shmemerror;    }    else {      shmctl(shminfo1.shmid, IPC_RMID, 0);      if (!prog_seq)        shmctl(shminfo2.shmid, IPC_RMID, 0);    }    if (!quiet){      fprintf(stderr, "Sharing memory.\n");    }  }  else if (shmem_flag != 2) {shmemerror:    shmem_flag = 0;#endif    ximage = XCreateImage(display,None,bpp,ZPixmap,0,&dummy,                          coded_picture_width,coded_picture_height,8,0);    if (!(dithered_image = new unsigned char[coded_picture_width*                                                   coded_picture_height]))      error("new failed");    if (!prog_seq){      ximage2 = XCreateImage(display,None,bpp,ZPixmap,0,&dummy,                             coded_picture_width,coded_picture_height,8,0);      if (!(dithered_image2 = new unsigned char[coded_picture_width*                                                      coded_picture_height]))        error("new failed");    }#ifdef SH_MEM  }  DeInstallXErrorHandler();#endif#endif // SOLARIS_SDK_XIL  display_lock.unlock();  return 1;}void DisplayX11::exit_display(){#ifdef SOLARIS_SDK_XIL  xil_destroy(displayimage);  xil_destroy(resized_image);  if (ximage) xil_destroy(ximage);  if (ximage2) xil_destroy(ximage2);  xil_close(State);  XCloseDisplay(display);#else#ifdef SH_MEM#ifdef USE_DGA  if (shmem_flag==2)    XF86DGADirectVideo (display, XDefaultScreen (display), 0);#endif  if (shmem_flag==1){    XShmDetach(display, &shminfo1);    shmdt(shminfo1.shmaddr);    if (!prog_seq){      XShmDetach(display, &shminfo2);      XDestroyImage(ximage2);      shmdt(shminfo2.shmaddr);    }  }#else  XDestroyImage(ximage);#endif#endif}#ifdef SOLARIS_SDK_XILvoid DisplayX11::display_image(XilImage ximg, unsigned char *dithered_img){#elsevoid DisplayX11::display_image(XImage *ximg, unsigned char *dithered_img){#endif  DEBUGGER("void DisplayX11::display_image(ximage, unsigned char *dithered_image)");  playedlastframe=1;  // indicate that frame is displayed  if (sync)  {    sync->wait(1);    // wait for presentation time stamp (PTS), id=1  }#ifdef SH_MEM                            // display dithered image  if (shmem_flag==2)    return;#endif#ifdef SOLARIS_SDK_XIL  xil_import(ximg, TRUE);  if (resized){    // , general and linear are Ok (These is no good for this: bilinear, bicubic)    xil_scale(ximage, resized_image, "general", horizontal_factor, vertical_factor);    // if (bands==1)   // Use XIL for color conversion    xil_copy(resized_image, displayimage);    // else     //   xil_color_convert(resized_image, displayimage);  }  else {    // if (bands==1)   // Use XIL for color conversion    xil_copy(ximg, displayimage);    // else     //   xil_color_convert(ximg, displayimage);  }  // check for geometry changes  if (XCheckWindowEvent(display, window, StructureNotifyMask, &event))  resize();#else#ifdef SH_MEM                            // display dithered image  if (shmem_flag==1){    XShmPutImage(display, window, gc, ximg, 0,0,0,0,ximg->width,ximg->height,True);    XFlush(display);  }  else #endif // SH_MEM  {    ximg->data=(char*) dithered_img;    XPutImage(display, window, gc, ximg, 0, 0, 0, 0, ximg->width, ximg->height);  }#endif // SOLARIS_SDK_XIL}#ifdef SOLARIS_SDK_XILint DisplayX11::dither_image_rgb24(unsigned char* src[], unsigned char* dithered_img){  register int h=0, w=-1;  register unsigned char *Y, *Cb, *Cr;    Y=src[0];  Cb=src[1];  Cr=src[2];  register Xil_unsigned8* data;  data=dithered_img;    //  map data in XIL image    for (h=0; h<coded_picture_height; h++){    for (w=0; w<coded_picture_width; w++){      *data++ = clp[(int)(*Y + 1.371*(*Cr-128))];        *data++ = clp[(int)(*Y - 0.698*(*Cr-128) - 0.336*(*Cr-128))];       *data++ = clp[(int)(*Y++ + 1.732*(*Cb-128))];      if ((w % 4)==0){        Cr++;        Cb++;      }    }  }  return 0;};#endif#if defined(LINUX) && defined(HAVE_MMX)extern "C" void yuv_2_rgb(void *,void *,void *,int,int,int,int,int,void *,int,int,int,int);static long long MMX_0 = 0L;static unsigned long  MMX_10w[]         = {0x00100010, 0x00100010};                     //dd    00010 0010h, 000100010hstatic unsigned long  MMX_80w[]         = {0x00800080, 0x00800080};                     //dd    00080 0080h, 000800080hstatic unsigned long  MMX_00FFw[]       = {0x00ff00ff, 0x00ff00ff};                     //dd    000FF 00FFh, 000FF00FFhstatic unsigned short MMX_Ublucoeff[]   = {0x81, 0x81, 0x81, 0x81};                     //dd    00081 0081h, 000810081hstatic unsigned short MMX_Vredcoeff[]   = {0x66, 0x66, 0x66, 0x66};                     //dd    00066 0066h, 000660066hstatic unsigned short MMX_Ugrncoeff[]   = {0xffe8, 0xffe8, 0xffe8, 0xffe8};             //dd    0FFE7 FFE7h, 0FFE7FFE7hstatic unsigned short MMX_Vgrncoeff[]   = {0xffcd, 0xffcd, 0xffcd, 0xffcd};             //dd    0FFCC FFCCh, 0FFCCFFCChstatic unsigned short MMX_Ycoeff[]      = {0x4a, 0x4a, 0x4a, 0x4a};                     //dd    0004A 004Ah, 0004A004Ahstatic unsigned short MMX_redmask[]     = {0xf800, 0xf800, 0xf800, 0xf800};             //dd    07c00 7c00h, 07c007c00hstatic unsigned short MMX_grnmask[]     = {0x7e0, 0x7e0, 0x7e0, 0x7e0};                 //dd    003e0 03e0h, 003e003e0h// static unsigned short MMX_blumask[]  = {0x1f, 0x1f, 0x1f, 0x1f};                     //dd    0001f 001fh, 0001f001fh/* Need to have access to the memory after*/voidColor16DitherImageMod(  unsigned char *lum, unsigned char *cr, unsigned char *cb,                                                                unsigned char *out, int rows, int cols, int mod){   unsigned short *row1;   int x;        unsigned char *y;        int col1;   row1 = (unsigned short *)out;        col1 = cols +mod;        mod += cols +mod;        mod *=2;   y = lum +cols*rows;        x = 0;        __asm__ __volatile__(                ".align 8\n"                "1:\n"                        "movd           (%1),                   %%mm0\n"        // 4 Cb         0  0  0  0 u3 u2 u1 u0                        "pxor           %%mm7,                  %%mm7\n"                        "movd           (%0),                   %%mm1\n" // 4 Cr                0  0  0  0 v3 v2 v1 v0                        "punpcklbw      %%mm7,                  %%mm0\n" // 4 W cb   0 u3  0 u2  0 u1  0 u0                        "punpcklbw      %%mm7,                  %%mm1\n" // 4 W cr   0 v3  0 v2  0 v1  0 v0                        "psubw          MMX_80w,                %%mm0\n"                        "psubw          MMX_80w,                %%mm1\n"                        "movq           %%mm0,                  %%mm2\n"        // Cb                   0 u3  0 u2  0 u1  0 u0                        "movq           %%mm1,                  %%mm3\n" // Cr                        "pmullw         MMX_Ugrncoeff,          %%mm2\n" // Cb2green 0 R3  0 R2  0 R1  0 R0                        "movq           (%2),                   %%mm6\n"        // L1      l7 L6 L5 L4 L3 L2 L1 L0                        "pmullw         MMX_Ublucoeff,          %%mm0\n" // Cb2blue                        "pand           MMX_00FFw,              %%mm6\n" // L1      00 L6 00 L4 00 L2 00 L0                        "pmullw         MMX_Vgrncoeff,          %%mm3\n" // Cr2green                        "movq           (%2),                   %%mm7\n" // L2                        "pmullw         MMX_Vredcoeff,          %%mm1\n" // Cr2red//                      "psubw          MMX_10w,                %%mm6\n"                        "psrlw          $8,                     %%mm7\n"        // L2           00 L7 00 L5 00 L3 00 L1                        "pmullw         MMX_Ycoeff,             %%mm6\n" // lum1//                      "psubw          MMX_10w,                %%mm7\n" // L2                        "paddw          %%mm3,                  %%mm2\n" // Cb2green + Cr2green == green                        "pmullw         MMX_Ycoeff,             %%mm7\n"  // lum2                        "movq           %%mm6,                  %%mm4\n"  // lum1                        "paddw          %%mm0,                  %%mm6\n"  // lum1 +blue 00 B6 00 B4 00 B2 00 B0

⌨️ 快捷键说明

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