4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "bcresources.h"
25 #include "bcsignals.h"
27 #include "bccmodels.h"
34 #include <X11/extensions/Xvlib.h>
37 int BC_Bitmap::max_active_buffers = 0;
38 int BC_Bitmap::zombies = 0;
41 BC_BitmapImage::BC_BitmapImage(BC_Bitmap *bitmap, int index)
44 this->bitmap = bitmap;
45 this->top_level = bitmap->top_level;
50 this->bytesPerLine = 0;
51 this->bitsPerPixel = 0;
54 BC_BitmapImage::~BC_BitmapImage()
60 bool BC_BitmapImage::is_avail()
62 return list == &bitmap->avail;
65 BC_BitmapImage *BC_Bitmap::cur_bfr()
68 avail_lock->lock("BC_Bitmap::cur_bfr 1");
69 if( (!use_shm || top_level->is_running()) &&
70 (active_bfr=avail.first) != 0 )
71 avail.remove_pointer(active_bfr);
73 update_buffers(buffer_count+1, 0);
74 if( (active_bfr=avail.first) != 0 )
75 avail.remove_pointer(active_bfr);
77 active_bfr = new_buffer(type, -1);
85 read_frame_rgb(VFrame *frame)
87 int w = bitmap->w, h = bitmap->h;
88 if( frame->get_w() != w || frame->get_h() != h ||
89 frame->get_color_model() != BC_RGB888 )
90 frame->reallocate(0, 0, 0, 0, 0, w, h, BC_RGB888, -1);
91 uint8_t *dp = frame->get_data();
92 int rmask = ximage->red_mask;
93 int gmask = ximage->green_mask;
94 int bmask = ximage->blue_mask;
95 //due to a bug in the xserver, the mask is being cleared by XShm.C:402
96 // when a faulty data in a XShmGetImage reply returns a zero visual
97 //workaround, use the original visual for the mask data
98 if ( !rmask ) rmask = bitmap->top_level->vis->red_mask;
99 if ( !gmask ) gmask = bitmap->top_level->vis->green_mask;
100 if ( !bmask ) bmask = bitmap->top_level->vis->blue_mask;
101 double fr = 255.0 / rmask;
102 double fg = 255.0 / gmask;
103 double fb = 255.0 / bmask;
104 int nbyte = (ximage->bits_per_pixel+7)/8;
105 int b0 = ximage->byte_order == MSBFirst ? 0 : nbyte-1;
106 int bi = ximage->byte_order == MSBFirst ? 1 : -1;
107 uint8_t *data = (uint8_t *)ximage->data;
109 for( int y=0; y<h; ++y ) {
110 uint8_t *cp = data + y*ximage->bytes_per_line + b0;
111 for( int x=0; x<w; ++x, cp+=nbyte ) {
112 uint8_t *bp = cp; uint32_t n = *bp;
113 for( int i=nbyte; --i>0; n=(n<<8)|*bp ) bp += bi;
114 *dp++ = (int)((n&rmask)*fr + 0.5);
115 *dp++ = (int)((n&gmask)*fg + 0.5);
116 *dp++ = (int)((n&bmask)*fb + 0.5);
122 void BC_Bitmap::reque(BC_BitmapImage *bfr)
124 avail_lock->lock("BC_Bitmap::reque");
127 avail_lock->unlock();
132 BC_XvShmImage::BC_XvShmImage(BC_Bitmap *bitmap, int index,
133 int w, int h, int color_model)
134 : BC_BitmapImage(bitmap, index)
136 Display *display = top_level->get_display();
137 int id = BC_CModels::bc_to_x(color_model);
138 // Create the XvImage
139 xv_image = XvShmCreateImage(display, bitmap->xv_portid, id,
141 dataSize = xv_image->data_size;
142 // Create the shared memory
143 shm_info.shmid = shmget(IPC_PRIVATE,
144 dataSize + 8, IPC_CREAT | 0777);
145 if(shm_info.shmid < 0)
146 perror("BC_XvShmImage::BC_XvShmImage shmget");
147 data = (unsigned char *)shmat(shm_info.shmid, NULL, 0);
148 // This causes it to automatically delete when the program exits.
149 shmctl(shm_info.shmid, IPC_RMID, 0);
150 // setting ximage->data stops BadValue
151 xv_image->data = shm_info.shmaddr = (char*)data;
152 shm_info.readOnly = 0;
153 // Get the real parameters
155 h = xv_image->height;
156 if(!XShmAttach(top_level->display, &shm_info))
157 perror("BC_XvShmImage::BC_XvShmImage XShmAttach");
158 if( color_model == BC_YUV422 || color_model == BC_UVY422 ) {
161 row_data = new unsigned char*[h];
162 for( int i=0; i<h; ++i )
163 row_data[i] = &data[i*bytesPerLine];
167 BC_XvShmImage::~BC_XvShmImage()
171 XShmDetach(top_level->display, &shm_info);
172 shmdt(shm_info.shmaddr);
177 BC_XShmImage::BC_XShmImage(BC_Bitmap *bitmap, int index,
178 int w, int h, int color_model)
179 : BC_BitmapImage(bitmap, index)
181 Display *display = top_level->display;
182 Visual *visual = top_level->vis;
183 int default_depth = bitmap->get_default_depth();
184 ximage = XShmCreateImage(display, visual,
185 default_depth, default_depth == 1 ? XYBitmap : ZPixmap,
186 (char*)NULL, &shm_info, w, h);
187 // Create shared memory
188 bytesPerLine = ximage->bytes_per_line;
189 bitsPerPixel = ximage->bits_per_pixel;
190 dataSize = h * bytesPerLine;
191 shm_info.shmid = shmget(IPC_PRIVATE,
192 dataSize + 8, IPC_CREAT | 0777);
193 if(shm_info.shmid < 0)
194 perror("BC_XShmImage::BC_XShmImage shmget");
195 data = (unsigned char *)shmat(shm_info.shmid, NULL, 0);
196 // This causes it to automatically delete when the program exits.
197 shmctl(shm_info.shmid, IPC_RMID, 0);
198 ximage->data = shm_info.shmaddr = (char*)data;
199 shm_info.readOnly = 0;
200 // Get the real parameters
201 if(!XShmAttach(top_level->display, &shm_info))
202 perror("BC_XShmImage::BC_XShmImage XShmAttach");
203 row_data = new unsigned char*[h];
204 for( int i=0; i<h; ++i )
205 row_data[i] = &data[i*bytesPerLine];
208 BC_XShmImage::~BC_XShmImage()
212 XDestroyImage(ximage);
213 XShmDetach(top_level->display, &shm_info);
214 XFlush(top_level->display);
215 shmdt(shm_info.shmaddr);
221 BC_XvImage::BC_XvImage(BC_Bitmap *bitmap, int index,
222 int w, int h, int color_model)
223 : BC_BitmapImage(bitmap, index)
225 Display *display = top_level->display;
226 int id = BC_CModels::bc_to_x(color_model);
227 xv_image = XvCreateImage(display, bitmap->xv_portid, id, 0, w, h);
228 dataSize = xv_image->data_size;
229 long data_sz = dataSize + 8;
230 data = new unsigned char[data_sz];
231 memset(data, 0, data_sz);
232 xv_image->data = (char *) data;
234 h = xv_image->height;
235 if( color_model == BC_YUV422 || color_model == BC_UVY422 ) {
236 int bytesPerLine = w*2;
237 row_data = new unsigned char*[h];
238 for( int i=0; i<h; ++i )
239 row_data[i] = &data[i*bytesPerLine];
243 BC_XvImage::~BC_XvImage()
250 BC_XImage::BC_XImage(BC_Bitmap *bitmap, int index,
251 int w, int h, int color_model)
252 : BC_BitmapImage(bitmap, index)
254 Display *display = top_level->display;
255 Visual *visual = top_level->vis;
256 int default_depth = bitmap->get_default_depth();
257 ximage = XCreateImage(display, visual, default_depth,
258 default_depth == 1 ? XYBitmap : ZPixmap,
259 0, (char*)data, w, h, 8, 0);
260 bytesPerLine = ximage->bytes_per_line;
261 bitsPerPixel = ximage->bits_per_pixel;
262 dataSize = h * bytesPerLine;
263 long data_sz = dataSize + 8;
264 data = new unsigned char[data_sz];
265 memset(data, 0, data_sz);
266 ximage->data = (char*) data;
267 row_data = new unsigned char*[h];
268 for( int i=0; i<h; ++i )
269 row_data[i] = &data[i*bytesPerLine];
272 BC_XImage::~BC_XImage()
277 XDestroyImage(ximage);
281 BC_Bitmap::BC_Bitmap(BC_WindowBase *parent_window, unsigned char *png_data, double scale)
283 // Decompress data into a temporary vframe
284 VFramePng frame(png_data, scale);
287 // Initialize the bitmap
288 initialize(parent_window,
291 parent_window->get_color_model(),
294 // Copy the vframe to the bitmap
295 read_frame(&frame, 0, 0, w, h);
298 BC_Bitmap::BC_Bitmap(BC_WindowBase *parent_window, VFrame *frame)
301 // Initialize the bitmap
302 initialize(parent_window,
305 parent_window->get_color_model(),
308 // Copy the vframe to the bitmap
309 read_frame(frame, 0, 0, w, h);
312 BC_Bitmap::BC_Bitmap(BC_WindowBase *parent_window,
313 int w, int h, int color_model, int use_shm)
316 initialize(parent_window, w, h, color_model, use_shm);
319 BC_Bitmap::~BC_Bitmap()
325 int BC_Bitmap::initialize(BC_WindowBase *parent_window,
326 int w, int h, int color_model, int use_shm)
328 BC_Resources *resources = parent_window->get_resources();
329 this->parent_window = parent_window;
330 this->top_level = parent_window->top_level;
331 this->xv_portid = resources->use_xvideo ? top_level->xvideo_port_id : -1;
336 this->color_model = color_model;
337 this->use_shm = !use_shm ? 0 : need_shm();
338 this->shm_reply = this->use_shm && resources->shm_reply ? 1 : 0;
339 // dont use shm for less than one page
340 if( !this->avail_lock )
341 this->avail_lock = new Mutex("BC_Bitmap::avail_lock");
343 this->avail_lock->reset();
346 this->active_bfr = 0;
347 this->buffer_count = 0;
348 this->max_buffer_count = 0;
349 this->active_buffers = 0;
354 int BC_Bitmap::match_params(int w, int h, int color_model, int use_shm)
356 if( use_shm ) use_shm = need_shm();
357 if(this->w /* != */ < w || this->h /* != */ < h ||
358 this->color_model != color_model || this->use_shm != use_shm) {
360 initialize(parent_window, w, h, color_model, use_shm);
366 int BC_Bitmap::params_match(int w, int h, int color_model, int use_shm)
369 if( use_shm ) use_shm = need_shm();
370 if(this->w == w && this->h == h && this->color_model == color_model) {
371 if(use_shm == this->use_shm || use_shm == BC_INFINITY)
377 BC_BitmapImage *BC_Bitmap::new_buffer(int type, int idx)
379 BC_BitmapImage *buffer = 0;
381 if( type == bmXShmImage ) type = bmXImage;
383 else if( type == bmXvShmImage ) type = bmXvImage;
389 buffer = new BC_XImage(this, idx, w, h, color_model);
393 buffer = new BC_XvImage(this, idx, w, h, color_model);
396 buffer = new BC_XShmImage(this, idx, w, h, color_model);
399 buffer = new BC_XvShmImage(this, idx, w, h, color_model);
403 if( buffer->is_zombie() ) ++zombies;
408 update_buffers(int count, int lock_avail)
411 // can deadlock in XReply (libxcb bug) without this lock
412 //top_level->lock_window("BC_Bitmap::update_buffers");
413 if( lock_avail ) avail_lock->lock("BC_Bitmap::update_buffers");
414 if( count > max_buffer_count ) count = max_buffer_count;
415 BC_BitmapImage **new_buffers = !count ? 0 : new BC_BitmapImage *[count];
416 if( buffer_count < count ) {
417 for( i=0; i<buffer_count; ++i )
418 new_buffers[i] = buffers[i];
420 BC_BitmapImage *buffer = new_buffer(type, i);
421 new_buffers[i] = buffer;
422 avail.append(buffer);
427 for( i=0; i<count; ++i )
428 new_buffers[i] = buffers[i];
429 while( i < buffer_count ) {
430 BC_BitmapImage *buffer = buffers[i];
431 if( buffer == active_bfr ) active_bfr = 0;
432 if( buffer->is_avail() ) {
443 buffers = new_buffers;
444 buffer_count = count;
445 XFlush(top_level->display);
446 if( lock_avail ) avail_lock->unlock();
447 //top_level->unlock_window();
450 int BC_Bitmap::allocate_data()
453 max_buffer_count = MAX_BITMAP_BUFFERS;
454 if(use_shm) { // Use shared memory.
455 int bsz = best_buffer_size();
456 if( bsz >= 0x800000 ) max_buffer_count = 2;
457 else if( bsz >= 0x400000 ) max_buffer_count /= 8;
458 else if( bsz >= 0x100000 ) max_buffer_count /= 4;
459 else if( bsz >= 0x10000 ) max_buffer_count /= 2;
462 hardware_scaling() ? bmXvShmImage :
465 count = MIN_BITMAP_BUFFERS;
467 else // use unshared memory.
470 hardware_scaling() ? bmXvImage :
473 update_buffers(count);
477 int BC_Bitmap::delete_data()
479 //printf("BC_Bitmap::delete_data 1\n");
483 max_buffer_count = 0;
487 int BC_Bitmap::get_default_depth()
489 return color_model == BC_TRANSPARENCY ? 1 : top_level->default_depth;
492 long BC_Bitmap::best_buffer_size()
494 long pixelsize = BC_CModels::calculate_pixelsize(get_color_model());
495 return pixelsize * w * h;
498 int BC_Bitmap::need_shm()
500 // dont use shm for less than one page
501 return best_buffer_size() < 0x1000 ? 0 :
502 parent_window->get_resources()->use_shm > 0 ? 1 : 0;
505 int BC_Bitmap::invert()
507 for( int j=0; j<buffer_count; ++j ) {
508 unsigned char **rows = buffers[j]->get_row_data();
509 if( !rows ) continue;
510 long bytesPerLine = buffers[j]->bytes_per_line();
511 for( int k=0; k<h; ++k ) {
512 unsigned char *bp = rows[k];
513 for( int i=0; i<bytesPerLine; ++i )
520 int BC_XShmImage::get_shm_size()
522 return bytesPerLine * bitmap->h;
525 int BC_Bitmap::write_drawable(Drawable &pixmap, GC &gc,
526 int dest_x, int dest_y, int source_x, int source_y,
527 int dest_w, int dest_h, int dont_wait)
529 return write_drawable(pixmap, gc,
530 source_x, source_y, get_w() - source_x, get_h() - source_y,
531 dest_x, dest_y, dest_w, dest_h, dont_wait);
534 int BC_XImage::write_drawable(Drawable &pixmap, GC &gc,
535 int source_x, int source_y, int source_w, int source_h,
536 int dest_x, int dest_y, int dest_w, int dest_h)
538 XPutImage(top_level->display, pixmap, gc,
539 ximage, source_x, source_y,
540 dest_x, dest_y, dest_w, dest_h);
544 int BC_XShmImage::write_drawable(Drawable &pixmap, GC &gc,
545 int source_x, int source_y, int source_w, int source_h,
546 int dest_x, int dest_y, int dest_w, int dest_h)
548 XShmPutImage(top_level->display, pixmap, gc,
549 ximage, source_x, source_y,
550 dest_x, dest_y, dest_w, dest_h, bitmap->shm_reply);
555 int BC_XvImage::write_drawable(Drawable &pixmap, GC &gc,
556 int source_x, int source_y, int source_w, int source_h,
557 int dest_x, int dest_y, int dest_w, int dest_h)
559 XvPutImage(top_level->display,
560 bitmap->xv_portid, pixmap, gc, xv_image,
561 source_x, source_y, source_w, source_h,
562 dest_x, dest_y, dest_w, dest_h);
566 int BC_XvShmImage::write_drawable(Drawable &pixmap, GC &gc,
567 int source_x, int source_y, int source_w, int source_h,
568 int dest_x, int dest_y, int dest_w, int dest_h)
570 XvShmPutImage(top_level->display,
571 bitmap->xv_portid, pixmap, gc, xv_image,
572 source_x, source_y, source_w, source_h,
573 dest_x, dest_y, dest_w, dest_h, bitmap->shm_reply);
578 int BC_Bitmap::write_drawable(Drawable &pixmap, GC &gc,
579 int source_x, int source_y, int source_w, int source_h,
580 int dest_x, int dest_y, int dest_w, int dest_h,
583 //printf("BC_Bitmap::write_drawable 1 %p %d\n", this, current_ringbuffer); fflush(stdout);
584 //if( dont_wait ) XSync(top_level->display, False);
585 BC_BitmapImage *bfr = cur_bfr();
586 if( !bfr->is_zombie() && is_shared() && shm_reply ) {
587 //printf("activate %p %08lx\n",bfr,bfr->get_shmseg());
588 top_level->active_bitmaps.insert(bfr, pixmap);
589 if( ++active_buffers > max_active_buffers )
590 max_active_buffers = active_buffers;
592 bfr->write_drawable(pixmap, gc,
593 source_x, source_y, source_w, source_h,
594 dest_x, dest_y, dest_w, dest_h);
595 XFlush(top_level->display);
596 avail_lock->lock(" BC_Bitmap::write_drawable");
597 if( bfr->is_zombie() ) {
601 else if( is_unshared() || !shm_reply )
604 avail_lock->unlock();
605 if( !dont_wait && !shm_reply )
606 XSync(top_level->display, False);
611 int BC_XImage::read_drawable(Drawable &pixmap, int source_x, int source_y)
613 XGetSubImage(top_level->display, pixmap,
614 source_x, source_y, bitmap->w, bitmap->h,
615 0xffffffff, ZPixmap, ximage, 0, 0);
619 int BC_XShmImage::read_drawable(Drawable &pixmap, int source_x, int source_y)
621 XShmGetImage(top_level->display, pixmap,
622 ximage, source_x, source_y, 0xffffffff);
626 int BC_Bitmap::read_drawable(Drawable &pixmap, int source_x, int source_y, VFrame *frame)
628 BC_BitmapImage *bfr = cur_bfr();
629 int result = bfr->read_drawable(pixmap, source_x, source_y);
630 if( !result && frame ) result = bfr->read_frame_rgb(frame);
635 // ============================ Decoding VFrames
637 int BC_Bitmap::read_frame(VFrame *frame, int x1, int y1, int x2, int y2)
639 return read_frame(frame, x1, y1, x2, y2, parent_window->get_bg_color());
642 int BC_Bitmap::read_frame(VFrame *frame, int x1, int y1, int x2, int y2, int bg_color)
644 return read_frame(frame,
645 0, 0, frame->get_w(), frame->get_h(),
646 x1, y1, x2 - x1, y2 - y1, bg_color);
650 int BC_Bitmap::read_frame(VFrame *frame,
651 int in_x, int in_y, int in_w, int in_h,
652 int out_x, int out_y, int out_w, int out_h, int bg_color)
654 BC_BitmapImage *bfr = cur_bfr();
655 if( hardware_scaling() && frame->get_color_model() == color_model ) {
656 // Hardware accelerated bitmap
657 switch(color_model) {
659 memcpy(bfr->get_y_data(), frame->get_y(), w * h);
660 memcpy(bfr->get_u_data(), frame->get_u(), w * h / 4);
661 memcpy(bfr->get_v_data(), frame->get_v(), w * h / 4);
664 memcpy(bfr->get_y_data(), frame->get_y(), w * h);
665 memcpy(bfr->get_u_data(), frame->get_u(), w * h / 2);
666 memcpy(bfr->get_v_data(), frame->get_v(), w * h / 2);
671 memcpy(get_data(), frame->get_data(), w * h + w * h);
678 //printf("BC_Bitmap::read_frame %d -> %d %d %d %d %d -> %d %d %d %d\n",
679 // frame->get_color_model(), color_model,
680 // in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
681 //if(color_model == 6 && frame->get_color_model() == 19)
682 //printf("BC_Bitmap::read_frame 1 %d %d %d %d\n", frame->get_w(), frame->get_h(), get_w(), get_h());
683 BC_CModels::transfer(
684 bfr->get_row_data(), frame->get_rows(),
685 bfr->get_y_data(), bfr->get_u_data(), bfr->get_v_data(),
686 frame->get_y(), frame->get_u(), frame->get_v(),
687 in_x, in_y, in_w, in_h,
688 out_x, out_y, out_w, out_h,
689 frame->get_color_model(), color_model,
690 bg_color, frame->get_w(), w);
692 if( color_model == BC_TRANSPARENCY && !top_level->server_byte_order )
693 transparency_bitswap(frame->get_data(), w, h);
694 //if(color_model == 6 && frame->get_color_model() == 19)
695 //printf("BC_Bitmap::read_frame 2\n");
701 uint8_t BC_Bitmap::bitswap[256]={
702 0x00,0x80,0x40,0xc0,0x20,0xa0,0x60,0xe0,0x10,0x90,0x50,0xd0,0x30,0xb0,0x70,0xf0,
703 0x08,0x88,0x48,0xc8,0x28,0xa8,0x68,0xe8,0x18,0x98,0x58,0xd8,0x38,0xb8,0x78,0xf8,
704 0x04,0x84,0x44,0xc4,0x24,0xa4,0x64,0xe4,0x14,0x94,0x54,0xd4,0x34,0xb4,0x74,0xf4,
705 0x0c,0x8c,0x4c,0xcc,0x2c,0xac,0x6c,0xec,0x1c,0x9c,0x5c,0xdc,0x3c,0xbc,0x7c,0xfc,
706 0x02,0x82,0x42,0xc2,0x22,0xa2,0x62,0xe2,0x12,0x92,0x52,0xd2,0x32,0xb2,0x72,0xf2,
707 0x0a,0x8a,0x4a,0xca,0x2a,0xaa,0x6a,0xea,0x1a,0x9a,0x5a,0xda,0x3a,0xba,0x7a,0xfa,
708 0x06,0x86,0x46,0xc6,0x26,0xa6,0x66,0xe6,0x16,0x96,0x56,0xd6,0x36,0xb6,0x76,0xf6,
709 0x0e,0x8e,0x4e,0xce,0x2e,0xae,0x6e,0xee,0x1e,0x9e,0x5e,0xde,0x3e,0xbe,0x7e,0xfe,
710 0x01,0x81,0x41,0xc1,0x21,0xa1,0x61,0xe1,0x11,0x91,0x51,0xd1,0x31,0xb1,0x71,0xf1,
711 0x09,0x89,0x49,0xc9,0x29,0xa9,0x69,0xe9,0x19,0x99,0x59,0xd9,0x39,0xb9,0x79,0xf9,
712 0x05,0x85,0x45,0xc5,0x25,0xa5,0x65,0xe5,0x15,0x95,0x55,0xd5,0x35,0xb5,0x75,0xf5,
713 0x0d,0x8d,0x4d,0xcd,0x2d,0xad,0x6d,0xed,0x1d,0x9d,0x5d,0xdd,0x3d,0xbd,0x7d,0xfd,
714 0x03,0x83,0x43,0xc3,0x23,0xa3,0x63,0xe3,0x13,0x93,0x53,0xd3,0x33,0xb3,0x73,0xf3,
715 0x0b,0x8b,0x4b,0xcb,0x2b,0xab,0x6b,0xeb,0x1b,0x9b,0x5b,0xdb,0x3b,0xbb,0x7b,0xfb,
716 0x07,0x87,0x47,0xc7,0x27,0xa7,0x67,0xe7,0x17,0x97,0x57,0xd7,0x37,0xb7,0x77,0xf7,
717 0x0f,0x8f,0x4f,0xcf,0x2f,0xaf,0x6f,0xef,0x1f,0x9f,0x5f,0xdf,0x3f,0xbf,0x7f,0xff,
720 void BC_Bitmap::transparency_bitswap(uint8_t *buf, int w, int h)
725 for(i=0 ; i+8<=len ; i+=8){
726 buf[i+0] = bitswap[buf[i+0]];
727 buf[i+1] = bitswap[buf[i+1]];
728 buf[i+2] = bitswap[buf[i+2]];
729 buf[i+3] = bitswap[buf[i+3]];
730 buf[i+4] = bitswap[buf[i+4]];
731 buf[i+5] = bitswap[buf[i+5]];
732 buf[i+6] = bitswap[buf[i+6]];
733 buf[i+7] = bitswap[buf[i+7]];
736 buf[i+0] = bitswap[buf[i+0]];