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

📄 displaylin.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
字号:
/* ////////////////////////////////////////////////////////////////////////////                  INTEL CORPORATION PROPRIETARY INFORMATION//     This software is supplied under the terms of a license agreement or//     nondisclosure agreement with Intel Corporation and may not be copied//     or disclosed except in accordance with the terms of that agreement.//          Copyright(c) 2002-2005 Intel Corporation. All Rights Reserved.//////*/#if (defined SYSLIN) && (!defined XSCALE)#include "X11/Xlib.h"#include "X11/Xutil.h"#include "malloc.h"#include "string.h"#include "stdio.h"static void Dither(    unsigned char *dst,    unsigned char *src,    int width,    int height,    int depth,    unsigned int redMask,    unsigned int greenMask,    unsigned int blueMask );inline float ScaleFactor( unsigned int bitMask ){    int i = 0;    while(!((bitMask >> i) & 1))        i++;    while(((bitMask >> i) & 1))        i++;    return (i <= 8) ? 1.0 / (1 << (8 - i)) : 1 << (i - 8);}inline unsigned int ByteOffset(unsigned int bitMask){    switch (bitMask)    {    case 0xFF000000: return 0;    case 0x00FF0000: return 1;    case 0x0000FF00: return 2;    //case 0x000000FF: return 3;    default:        return 3;    }}int DisplayPixMap( unsigned char *pixMap,                   const int      width,                   const int      height,                   const char    *jp2FileName ){    XImage *xImage;    XSetWindowAttributes xswa;    Window win;    GC gc;    Display *dsp = XOpenDisplay(NULL);    int screenNumber = DefaultScreen(dsp);    Visual *visual = DefaultVisual(dsp, screenNumber);    int defaultDepth = DefaultDepth(dsp, screenNumber);    char *ditheredImage;    char windowTitle[300] = "JPEG2000 Viewer - ";    unsigned int mask = CWBackPixel | CWBorderPixel;    if (defaultDepth == 32 || defaultDepth == 24 || defaultDepth == 16) {        mask |= CWColormap;        xswa.colormap = XCreateColormap (dsp, DefaultRootWindow(dsp), visual, AllocNone);    }    xswa.background_pixel = WhitePixel(dsp, screenNumber);    xswa.border_pixel = BlackPixel(dsp, screenNumber);    win = XCreateWindow(dsp, DefaultRootWindow(dsp), 0, 0, width, height, 1,        defaultDepth, InputOutput, visual, mask, &xswa);    if(!win)        return 1;    gc = XCreateGC(dsp, win, 0, NULL);    if(!gc)        return 1;    XMapWindow(dsp, win);    XSelectInput(dsp, win, ExposureMask);    strcat(windowTitle, jp2FileName);    XSetStandardProperties(dsp, win, windowTitle, NULL, None, NULL, 0, NULL);    ditheredImage = (char *)memalign(   4, width * height *        (  defaultDepth == 24 ? 4 : ( defaultDepth == 15 ? 2 : (defaultDepth / 8) )  )   );    Dither((unsigned char *)ditheredImage, (unsigned char *)pixMap, width, height, defaultDepth,        visual->red_mask, visual->green_mask, visual->blue_mask);    xImage = XCreateImage(dsp, visual, defaultDepth, ZPixmap, 0, (char *)ditheredImage, width, height,        defaultDepth == 24 ? 32 : (defaultDepth == 15 ? 16 : defaultDepth), 0);    if(!xImage)        return 1;    for(;;)    {        XEvent x_event;        XNextEvent(dsp, &x_event);        switch (x_event.type)        {        case Expose:            XPutImage(dsp, win, gc, xImage, 0, 0, 0, 0, width, height);            XFlush(dsp);            break;        }    }    free(ditheredImage);    return 0;}static void Dither(    unsigned char *dst,    unsigned char *src,    int width,    int height,    int depth,    unsigned int redMask,    unsigned int greenMask,    unsigned int blueMask){    float rScaleFactor = ScaleFactor(redMask);    float gScaleFactor = ScaleFactor(greenMask);    float bScaleFactor = ScaleFactor(blueMask);    int lineStep = ((width * 3) + 3) & 0xFFFFFFFC;    unsigned char r, g, b;    unsigned int pixel;    int x, y;    switch(depth)    {    case 8:        for(y = 0; y < height; y++)        {            for(x = 0; x < width; x++)            {                b = src[lineStep * (height - y - 1) + 3 * x + 0];                g = src[lineStep * (height - y - 1) + 3 * x + 1];                r = src[lineStep * (height - y - 1) + 3 * x + 2];                pixel = (((unsigned int)(r * rScaleFactor)) & redMask  ) +                        (((unsigned int)(g * gScaleFactor)) & greenMask) +                        (((unsigned int)(b * bScaleFactor)) & blueMask );                dst[width * y + x] = pixel;            }        }        break;    case 16:        for(y = 0; y < height; y++)        {            for(x = 0; x < width; x++)            {                b = src[lineStep * (height - y - 1) + 3 * x + 0];                g = src[lineStep * (height - y - 1) + 3 * x + 1];                r = src[lineStep * (height - y - 1) + 3 * x + 2];                pixel = (((unsigned int)(r * rScaleFactor)) & redMask  ) +                        (((unsigned int)(g * gScaleFactor)) & greenMask) +                        (((unsigned int)(b * bScaleFactor)) & blueMask );                ((unsigned short *)dst)[width * y + x] = pixel;            }        }        break;    case 24:    case 32:        {            unsigned int rOffset = ByteOffset(redMask);            unsigned int gOffset = ByteOffset(greenMask);            unsigned int bOffset = ByteOffset(blueMask);                        for(y = 0; y < height; y++)            {                for(x = 0; x < width; x++)                {                    dst[4 * (width * y + x) + bOffset] = src[lineStep * (height - y - 1) + 3 * x + 0];                    dst[4 * (width * y + x) + gOffset] = src[lineStep * (height - y - 1) + 3 * x + 1];                    dst[4 * (width * y + x) + rOffset] = src[lineStep * (height - y - 1) + 3 * x + 2];                }            }        }        break;    default:        break;    }}#endif // SYSLIN

⌨️ 快捷键说明

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