// ビット順序を反転する int bit_rev(int a){ if(a == 0){ return a; } int n = bit_num(a); int r = 0; if(n % 2 == 1){ r |= ((a >> (n / 2)) & 1) << (n / 2); }
//huffman编码 void jhuff_encode_one_block(jpeg_compress_info *cinfo,DCTBLOCK src,JHUFF_TBL *dc_tbl,JHUFF_TBL *ac_tbl) { int diff,ssss,rrrr,code; int rs,k; //直流分量编码 diff=src[0]; ssss=bit_num(diff); jhuff_write_bits(cinfo,dc_tbl->ecode[ssss],dc_tbl->esize[ssss]); if (diff<0)diff-=1; jhuff_write_bits(cinfo,diff,ssss); //交流分量编码 rrrr=0; for(k=1;k<DCTSIZE2;k++) { if(src[k]==0) { rrrr++; continue; } else { while(rrrr>15)//write EHUFSI(0xF0) bits of EHUFCO(0xF0) { jhuff_write_bits(cinfo, ac_tbl->ecode[0xF0], ac_tbl->esize[0xF0]); rrrr-=16; } ssss=bit_num(src[k]); rs=((rrrr<<4)|ssss); jhuff_write_bits(cinfo,ac_tbl->ecode[rs],ac_tbl->esize[rs]);//write EHUFSI(rs) bits of EHUFCO(rs) code=src[k]; if(code<0)code-=1; jhuff_write_bits(cinfo,code,ssss);//write ssss bits of rs rrrr=0; } } if(rrrr!=0)jhuff_write_bits(cinfo,ac_tbl->ecode[0x00],ac_tbl->esize[0x00]);//write EOB }
/* Unit should be a power-of-2 (e.g. 1024 to report kilobytes) or 1 (to report bytes) */ static ulong getdiskspace(const char* path, ulong unit, BOOL freespace) { #if defined(_WIN32) char root[16]; DWORD TotalNumberOfClusters; DWORD NumberOfFreeClusters; DWORD BytesPerSector; DWORD SectorsPerCluster; ULARGE_INTEGER avail; ULARGE_INTEGER size; static HINSTANCE hK32; GetDiskFreeSpaceEx_t GetDiskFreeSpaceEx; if(hK32 == NULL) hK32 = LoadLibrary("KERNEL32"); GetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)GetProcAddress(hK32,"GetDiskFreeSpaceExA"); if (GetDiskFreeSpaceEx!=NULL) { /* Windows 95-OSR2 or later */ if(!GetDiskFreeSpaceEx( path, /* pointer to the directory name */ &avail, /* receives the number of bytes on disk avail to the caller */ &size, /* receives the number of bytes on disk */ NULL)) /* receives the free bytes on disk */ return(0); if(freespace) size=avail; if(unit>1) size.QuadPart=Int64ShrlMod32(size.QuadPart,bit_num(unit)); #if defined(_ANONYMOUS_STRUCT) if(size.HighPart) #else if(size.u.HighPart) #endif return(0xffffffff); /* 4GB max */ #if defined(_ANONYMOUS_STRUCT) return(size.LowPart); #else return(size.u.LowPart); #endif } /* Windows 95 (old way), limited to 2GB */ sprintf(root,"%.3s",path); if(!GetDiskFreeSpace( root, /* pointer to root path */ (PDWORD)&SectorsPerCluster, /* pointer to sectors per cluster */ (PDWORD)&BytesPerSector, /* pointer to bytes per sector */ (PDWORD)&NumberOfFreeClusters, /* pointer to number of free clusters */ (PDWORD)&TotalNumberOfClusters /* pointer to total number of clusters */ )) return(0); if(freespace) TotalNumberOfClusters = NumberOfFreeClusters; if(unit>1) TotalNumberOfClusters/=unit; return(TotalNumberOfClusters*SectorsPerCluster*BytesPerSector); #elif defined(__solaris__) || (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 300000000 /* NetBSD 3.0 */)) struct statvfs fs; unsigned long blocks; if (statvfs(path, &fs) < 0) return 0; if(freespace) blocks=fs.f_bavail; else blocks=fs.f_blocks; if(unit>1) blocks/=unit; return fs.f_bsize * blocks; /* statfs is also used under FreeBSD (Though it *supports* statvfs() now too) */ #elif defined(__GLIBC__) || defined(BSD) struct statfs fs; unsigned long blocks; if (statfs(path, &fs) < 0) return 0; if(freespace) blocks=fs.f_bavail; else blocks=fs.f_blocks; if(unit>1) blocks/=unit; return fs.f_bsize * blocks; #else fprintf(stderr,"\n*** !Missing getfreediskspace implementation ***\n"); return(0); #endif }
bool bit_vector::operator==(const bit_vector& v) const { return v.bit_num() == bit_num() && equal(bits_.begin(), bits_.end(), v.bits_.begin()); }
inline u32 get_bit(u32 offset) { return bitmap[int_num(offset)] & (1 << bit_num(offset)); }
inline void clear_bit(u32 offset) { bitmap[int_num(offset)] &= ~(1 << bit_num(offset)); }
inline void set_bit(u32 offset) { bitmap[int_num(offset)] |= (1 << bit_num(offset)); }