BOOL fnGetHashListAddrs(void **addrs, BOOL *dontTouchHashList) { ThreadInfo* tip; int index,tid; if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreWait(g_tinfoSem); #else WaitOnLocalSemaphore(g_tinfoSem); #endif //MPK_ON } #ifdef MPK_ON tid=index = abs(kCurrentThread()); #else tid=index = GetThreadID(); #endif //MPK_ON index = INDEXOF(index); // just take the bottom five bits // see if this is already in the table at the index'th offset // for (tip = g_ThreadInfo[index]; tip != NULL; tip = tip->next) { if (tip->tid == tid) { if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreSignal(g_tinfoSem); #else SignalLocalSemaphore(g_tinfoSem); #endif //MPK_ON } *addrs = tip->m_allocList; *dontTouchHashList = tip->m_dontTouchHashLists; return TRUE; } } if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreSignal(g_tinfoSem); #else SignalLocalSemaphore(g_tinfoSem); #endif //MPK_ON } return FALSE; }
BOOL fnRemoveThreadInfo(int tid) { ThreadInfo* tip = NULL; ThreadInfo* prevt = NULL; int index = INDEXOF(tid); // just take the bottom five bits if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreWait(g_tinfoSem); #else WaitOnLocalSemaphore(g_tinfoSem); #endif //MPK_ON } for (tip = g_ThreadInfo[index]; tip != NULL; tip = tip->next) { if (tip->tid == tid) { if (prevt == NULL) g_ThreadInfo[index] = tip->next; else prevt->next = tip->next; free(tip); tip=NULL; if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreSignal(g_tinfoSem); #else SignalLocalSemaphore(g_tinfoSem); #endif //MPK_ON } return TRUE; } prevt = tip; } if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreSignal(g_tinfoSem); #else SignalLocalSemaphore(g_tinfoSem); #endif //MPK_ON } return FALSE; // entry not found }
static Widget camshellof(int id, struct camwins **cwp) { struct camwins *cw; Widget w; if (id < 0 || INDEXOF(id) >= VVCOUNT(camshells)) { return NULL; } cw = VVINDEX(camshells, struct camwins, INDEXOF(id)); if ((w = XtWindowToWidget(dpy, cw->shellwin)) == NULL) { return NULL; } if (cwp) { *cwp = cw; } return w; }
ThreadInfo* fnAddThreadInfo(int tid) { ThreadInfo* tip = NULL; int index = 0; if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreWait(g_tinfoSem); #else WaitOnLocalSemaphore(g_tinfoSem); #endif //MPK_ON } // Add a new one to the beginning of the hash entry // tip = (ThreadInfo *) malloc(sizeof(ThreadInfo)); if (tip == NULL) { if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreSignal(g_tinfoSem); #else SignalLocalSemaphore(g_tinfoSem); #endif //MPK_ON } return NULL; } index = INDEXOF(tid); // just take the bottom five bits tip->next = g_ThreadInfo[index]; tip->tid = tid; tip->m_dontTouchHashLists = FALSE; tip->m_allocList = NULL; g_ThreadInfo [index] = tip; if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreSignal(g_tinfoSem); #else SignalLocalSemaphore(g_tinfoSem); #endif //MPK_ON } return tip; }
ThreadInfo* fnGetThreadInfo(int tid) { ThreadInfo* tip; int index = INDEXOF(tid); // just take the bottom five bits if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreWait(g_tinfoSem); #else WaitOnLocalSemaphore(g_tinfoSem); #endif //MPK_ON } // see if this is already in the table at the index'th offset // for (tip = g_ThreadInfo[index]; tip != NULL; tip = tip->next) { if (tip->tid == tid) { if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreSignal(g_tinfoSem); #else SignalLocalSemaphore(g_tinfoSem); #endif //MPK_ON } return tip; } } if (g_tinfoSem) { #ifdef MPK_ON kSemaphoreSignal(g_tinfoSem); #else SignalLocalSemaphore(g_tinfoSem); #endif //MPK_ON } return NULL; }
// Fast diffuse dither to 3x3x3 color cube // Based on Qt's image conversion functions static bool kdither_32_to_8( const QImage *src, QImage *dst ) { register QRgb *p; uchar *b; int y; //printf("kconvert_32_to_8\n"); if ( !dst->create(src->width(), src->height(), 8, 256) ) { warning("KPixmap: destination image not valid\n"); return FALSE; } int ncols = 256; static uint bm[16][16]; static int init=0; if (!init) { // Build a Bayer Matrix for dithering init = 1; int n, i, j; bm[0][0]=0; for (n=1; n<16; n*=2) { for (i=0; i<n; i++) { for (j=0; j<n; j++) { bm[i][j]*=4; bm[i+n][j]=bm[i][j]+2; bm[i][j+n]=bm[i][j]+3; bm[i+n][j+n]=bm[i][j]+1; } } } for (i=0; i<16; i++) for (j=0; j<16; j++) bm[i][j]<<=8; } dst->setNumColors( ncols ); #define MAX_R 2 #define MAX_G 2 #define MAX_B 2 #define INDEXOF(r,g,b) (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b)) int rc, gc, bc; for ( rc=0; rc<=MAX_R; rc++ ) // build 2x2x2 color cube for ( gc=0; gc<=MAX_G; gc++ ) for ( bc=0; bc<=MAX_B; bc++ ) { dst->setColor( INDEXOF(rc,gc,bc), qRgb( rc*255/MAX_R, gc*255/MAX_G, bc*255/MAX_B ) ); } int sw = src->width(); int* line1[3]; int* line2[3]; int* pv[3]; line1[0] = new int[src->width()]; line2[0] = new int[src->width()]; line1[1] = new int[src->width()]; line2[1] = new int[src->width()]; line1[2] = new int[src->width()]; line2[2] = new int[src->width()]; pv[0] = new int[sw]; pv[1] = new int[sw]; pv[2] = new int[sw]; for ( y=0; y < src->height(); y++ ) { p = (QRgb *)src->scanLine(y); b = dst->scanLine(y); int endian = (QImage::systemByteOrder() == QImage::BigEndian); int x; uchar* q = src->scanLine(y); uchar* q2 = src->scanLine(y+1 < src->height() ? y + 1 : 0); for (int chan = 0; chan < 3; chan++) { b = dst->scanLine(y); int *l1 = (y&1) ? line2[chan] : line1[chan]; int *l2 = (y&1) ? line1[chan] : line2[chan]; if ( y == 0 ) { for (int i=0; i<sw; i++) l1[i] = q[i*4+chan+endian]; } if ( y+1 < src->height() ) { for (int i=0; i<sw; i++) l2[i] = q2[i*4+chan+endian]; } // Bi-directional error diffusion if ( y&1 ) { for (x=0; x<sw; x++) { int pix = QMAX(QMIN(2, (l1[x] * 2 + 128)/ 255), 0); int err = l1[x] - pix * 255 / 2; pv[chan][x] = pix; // Spread the error around... if ( x+1<sw ) { l1[x+1] += (err*7)>>4; l2[x+1] += err>>4; } l2[x]+=(err*5)>>4; if (x>1) l2[x-1]+=(err*3)>>4; } } else { for (x=sw; x-->0; ) { int pix = QMAX(QMIN(2, (l1[x] * 2 + 128)/ 255), 0); int err = l1[x] - pix * 255 / 2; pv[chan][x] = pix; // Spread the error around... if ( x > 0 ) { l1[x-1] += (err*7)>>4; l2[x-1] += err>>4; } l2[x]+=(err*5)>>4; if (x+1 < sw) l2[x+1]+=(err*3)>>4; } }
static void merge (struct aux_data* aux, size_t start, size_t middle, size_t end) { size_t left = start; size_t right = middle; size_t index = 0; while ((left < middle) && (right < end)) { if (aux->compare(INDEXOF(aux->base, left, aux->size), INDEXOF(aux->base, right, aux->size)) < 0) { memcpy(INDEXOF(aux->temp, index, aux->size), INDEXOF(aux->base, left, aux->size), aux->size); left++; } else { memcpy(INDEXOF(aux->temp, index, aux->size), INDEXOF(aux->base, right, aux->size), aux->size); right++; } index++; } if (left < middle) { memcpy(INDEXOF(aux->temp, index, aux->size), INDEXOF(aux->base, left, aux->size), (middle - left) * aux->size); } else if (right < end) { memcpy(INDEXOF(aux->temp, index, aux->size), INDEXOF(aux->base, right, aux->size), (end - right) * aux->size); } memcpy(INDEXOF(aux->base, start, aux->size), aux->temp, (end - start) * aux->size); }