#include "rgn.h" #include #include #include #include template T mymin(const T x, const T y) {return (xWidth(), im->Height(), 8)) { if(im->GetFmt()->IsRGB()) { fprintf(stderr, "Edge detection with non-YUV image\n"); return; } if (zz == 0) zz = 1; if (edge== 0) edge = 1; const int avs = ((1<Blur(edge); for (i = 0; i < upl; i++) res[i]=((avm::yuv*)src->Data())[i].Y; Maximize(res, Width(), Height(), zz); memset(data, 0, upl); // for(i=0; idata())[i].Y); upl -= (Width() * avs + avs); int dist = avs * (Width() + 1); for (i = avs + Width() * avs; i < upl; i++) { max = res[i-dist]; int val = max - ((avm::yuv*)src->Data())[i].Y; data[i] = (val < (_qual-256)) ? 255 : 128 - mymin((val-_qual + 256) * 2, 128); } delete src; delete res; } void CEdgeRgn::Normalize() { for (unsigned char* ch = Data() + Pixels() - 1; ch >= Data(); ch--) *ch = (*ch > 128) ? 0 : 255; } void CEdgeRgn::Blur(int depth, int src) { #ifdef ARCH_X86_32 const int limit = Pixels(); unsigned lim = 1 << depth; unsigned ach = 1 << src; unsigned char* p = Data(); while (ach < lim) { __asm__ __volatile__ ( "pushl %%eax\n\t" "pushl %%ebx\n\t" "pushl %%ecx\n\t" "pushl %%edx\n\t" "pushl %%edi\n\t" "movl %0, %%ebx\n\t" "mov %0, %%ecx\n\t" "add %1, %%ecx\n\t" "mov %0, %%ebx\n\t" "mov %1, %%ecx\n\t" "mov %0, %%edx\n\t" "add %2, %%edx\n\t" "sub %1, %%edx\n\t" "movl %%edx, %%edi\n\t" // %%ebx = p // %%ecx = ach // %%edi = p + limit - ach "xor %%eax, %%eax\n\t" "xor %%edx, %%edx\n\t" "0:\n\t" "movb (%%ebx), %%al\n\t" "movb (%%ebx, %%ecx), %%dl\n\t" "addw %%dx, %%ax\n\t" "shr $1, %%eax\n\t" "movb %%al, (%%ebx)\n\t" "incl %%ebx\n\t" "cmpl %%edi, %%ebx\n\t" "jb 0b\n\t" "popl %%edi\n\t" "popl %%edx\n\t" "popl %%ecx\n\t" "popl %%ebx\n\t" "popl %%eax\n\t" : :"r"(p), "r"(ach), "r"(limit) ); ach *= Width(); __asm__ __volatile__ ( "pushl %%eax\n\t" "pushl %%ebx\n\t" "pushl %%ecx\n\t" "pushl %%edx\n\t" "pushl %%edi\n\t" "movl %0, %%ebx\n\t" "mov %0, %%ecx\n\t" "add %1, %%ecx\n\t" "mov %0, %%ebx\n\t" "mov %1, %%ecx\n\t" "mov %0, %%edx\n\t" "add %2, %%edx\n\t" "sub %1, %%edx\n\t" "movl %%edx, %%edi\n\t" // %%ebx = p // %%ecx = ach // %%edi = p + limit - ach "xor %%eax, %%eax\n\t" "xor %%edx, %%edx\n\t" "1:\n\t" "movb (%%ebx), %%al\n\t" "movb (%%ebx, %%ecx), %%dl\n\t" "addw %%dx, %%ax\n\t" "shr $1, %%eax\n\t" "movb %%al, (%%ebx)\n\t" "incl %%ebx\n\t" "cmpl %%edi, %%ebx\n\t" "jb 1b\n\t" "popl %%edi\n\t" "popl %%edx\n\t" "popl %%ecx\n\t" "popl %%ebx\n\t" "popl %%eax\n\t" : :"r"(p), "r"(ach), "r"(limit) ); ach /= Width(); ach*=2; } #else #warning Blur x86 version only - FIXME #endif }