src/rotateorthlow.c
void
flipLRLow(l_uint32  *data,
          l_int32    w,
          l_int32    h,
          l_int32    d,
          l_int32    wpl,
          l_uint8   *tab,
          l_uint32  *buffer)
{
l_int32    extra, shift, databpl, bpl, i, j;
l_uint32   val;
l_uint32  *line;

    PROCNAME("flipLRLow");

    bpl = 4 * wpl;
    switch (d)
    {
        case 32: 
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < w; j++)
                    line[j] = buffer[w - 1 - j];
            }
            break;
        case 16:
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < w; j++) {
                    val = GET_DATA_TWO_BYTES(buffer, w - 1 - j);
                    SET_DATA_TWO_BYTES(line, j, val);
                }
            }
            break;
        case 8:
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < w; j++) {
                    val = GET_DATA_BYTE(buffer, w - 1 - j);
                    SET_DATA_BYTE(line, j, val);
                }
            }
            break;
        case 4:
            extra = (w * d) & 31;
            if (extra)
                shift = 8 - extra / 4;
            else
                shift = 0;
            if (shift)
                rasteropHipLow(data, h, d, wpl, 0, h, shift);

            databpl = (w + 1) / 2;
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < databpl; j++) {
                    val = GET_DATA_BYTE(buffer, bpl - 1 - j);
                    SET_DATA_BYTE(line, j, tab[val]);
                }
            }
            break;
        case 2:
            extra = (w * d) & 31;
            if (extra)
                shift = 16 - extra / 2;
            else
                shift = 0;
            if (shift)
                rasteropHipLow(data, h, d, wpl, 0, h, shift);

            databpl = (w + 3) / 4;
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < databpl; j++) {
                    val = GET_DATA_BYTE(buffer, bpl - 1 - j);
                    SET_DATA_BYTE(line, j, tab[val]);
                }
            }
            break;
        case 1:
            extra = (w * d) & 31;
            if (extra)
                shift = 32 - extra;
            else
                shift = 0;
            if (shift)
                rasteropHipLow(data, h, d, wpl, 0, h, shift);

            databpl = (w + 7) / 8;
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < databpl; j++) {
                    val = GET_DATA_BYTE(buffer, bpl - 1 - j);
                    SET_DATA_BYTE(line, j, tab[val]);
                }
            }
            break;
        default:
            L_ERROR("depth not permitted for LR rot", procName);
            return;
    }

    return;
}
/*!
 *  flipLRLow()
 *
 *  Notes:
 *      (1) The pixel access routines allow a trivial implementation.
 *          However, for d < 8, it is more efficient to right-justify
 *          each line to a 32-bit boundary and then extract bytes and
 *          do pixel reversing.   In those cases, as in the 180 degree
 *          rotation, we right-shift the data (if necessary) to
 *          right-justify on the 32 bit boundary, and then read the
 *          bytes off each raster line in reverse order, reversing
 *          the pixels in each byte using a table.  These functions
 *          for 1, 2 and 4 bpp were tested against the "trivial"
 *          version (shown here for 4 bpp):
 *              for (i = 0; i < h; i++) {
 *                  line = data + i * wpl;
 *                  memcpy(buffer, line, bpl);
 *                    for (j = 0; j < w; j++) {
 *                      val = GET_DATA_QBIT(buffer, w - 1 - j);
 *                        SET_DATA_QBIT(line, j, val);
 *                  }
 *              }
 *      (2) This operation is in-place.
 */
flipLRLow()
Notes:
(1) The pixel access routines allow a trivial implementation.
However, for d < 8, it is more efficient to right-justify
each line to a 32-bit boundary and then extract bytes and
do pixel reversing.   In those cases, as in the 180 degree
rotation, we right-shift the data (if necessary) to
right-justify on the 32 bit boundary, and then read the
bytes off each raster line in reverse order, reversing
the pixels in each byte using a table.
flipLRLow () Notes : ( 1 ) The pixel access routines allow a trivial implementation . However for d < 8 it is more efficient to right - justify each line to a 32 - bit boundary and then extract bytes and do pixel reversing . In those cases as in the 180 degree rotation we right - shift the data ( if necessary ) to right - justify on the 32 bit boundary and then read the bytes off each raster line in reverse order reversing the pixels in each byte using a table .
void
flipLRLow(l_uint32  *data,
          l_int32    w,
          l_int32    h,
          l_int32    d,
          l_int32    wpl,
          l_uint8   *tab,
          l_uint32  *buffer)
{
l_int32    extra, shift, databpl, bpl, i, j;
l_uint32   val;
l_uint32  *line;
    PROCNAME("flipLRLow");
    bpl = 4 * wpl;
    switch (d)
    {
        case 32: 
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < w; j++)
                    line[j] = buffer[w - 1 - j];
            }
            break;
        case 16:
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < w; j++) {
                    val = GET_DATA_TWO_BYTES(buffer, w - 1 - j);
                    SET_DATA_TWO_BYTES(line, j, val);
                }
            }
            break;
        case 8:
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < w; j++) {
                    val = GET_DATA_BYTE(buffer, w - 1 - j);
                    SET_DATA_BYTE(line, j, val);
                }
            }
            break;
        case 4:
            extra = (w * d) & 31;
            if (extra)
                shift = 8 - extra / 4;
            else
                shift = 0;
            if (shift)
                rasteropHipLow(data, h, d, wpl, 0, h, shift);
            databpl = (w + 1) / 2;
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < databpl; j++) {
                    val = GET_DATA_BYTE(buffer, bpl - 1 - j);
                    SET_DATA_BYTE(line, j, tab[val]);
                }
            }
            break;
        case 2:
            extra = (w * d) & 31;
            if (extra)
                shift = 16 - extra / 2;
            else
                shift = 0;
            if (shift)
                rasteropHipLow(data, h, d, wpl, 0, h, shift);
            databpl = (w + 3) / 4;
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < databpl; j++) {
                    val = GET_DATA_BYTE(buffer, bpl - 1 - j);
                    SET_DATA_BYTE(line, j, tab[val]);
                }
            }
            break;
        case 1:
            extra = (w * d) & 31;
            if (extra)
                shift = 32 - extra;
            else
                shift = 0;
            if (shift)
                rasteropHipLow(data, h, d, wpl, 0, h, shift);
            databpl = (w + 7) / 8;
            for (i = 0; i < h; i++) {
                line = data + i * wpl;
                memcpy(buffer, line, bpl);
                for (j = 0; j < databpl; j++) {
                    val = GET_DATA_BYTE(buffer, bpl - 1 - j);
                    SET_DATA_BYTE(line, j, tab[val]);
                }
            }
            break;
        default:
            L_ERROR("depth not permitted for LR rot", procName);
            return;
    }
    return;
}
void flipLRLow ( l_uint32 * data , l_int32 w , l_int32 h , l_int32 d , l_int32 wpl , l_uint8 * tab , l_uint32 * buffer ) { l_int32 extra , shift , databpl , bpl , i , j ; l_uint32 val ; l_uint32 * line ; PROCNAME ( " " ) ; bpl = 4 * wpl ; switch ( d ) { case 32 : for ( i = 0 ; i < h ; i ++ ) { line = data + i * wpl ; memcpy ( buffer , line , bpl ) ; for ( j = 0 ; j < w ; j ++ ) line [ j ] = buffer [ w - 1 - j ] ; } break ; case 16 : for ( i = 0 ; i < h ; i ++ ) { line = data + i * wpl ; memcpy ( buffer , line , bpl ) ; for ( j = 0 ; j < w ; j ++ ) { val = GET_DATA_TWO_BYTES ( buffer , w - 1 - j ) ; SET_DATA_TWO_BYTES ( line , j , val ) ; } } break ; case 8 : for ( i = 0 ; i < h ; i ++ ) { line = data + i * wpl ; memcpy ( buffer , line , bpl ) ; for ( j = 0 ; j < w ; j ++ ) { val = GET_DATA_BYTE ( buffer , w - 1 - j ) ; SET_DATA_BYTE ( line , j , val ) ; } } break ; case 4 : extra = ( w * d ) & 31 ; if ( extra ) shift = 8 - extra / 4 ; else shift = 0 ; if ( shift ) rasteropHipLow ( data , h , d , wpl , 0 , h , shift ) ; databpl = ( w + 1 ) / 2 ; for ( i = 0 ; i < h ; i ++ ) { line = data + i * wpl ; memcpy ( buffer , line , bpl ) ; for ( j = 0 ; j < databpl ; j ++ ) { val = GET_DATA_BYTE ( buffer , bpl - 1 - j ) ; SET_DATA_BYTE ( line , j , tab [ val ] ) ; } } break ; case 2 : extra = ( w * d ) & 31 ; if ( extra ) shift = 16 - extra / 2 ; else shift = 0 ; if ( shift ) rasteropHipLow ( data , h , d , wpl , 0 , h , shift ) ; databpl = ( w + 3 ) / 4 ; for ( i = 0 ; i < h ; i ++ ) { line = data + i * wpl ; memcpy ( buffer , line , bpl ) ; for ( j = 0 ; j < databpl ; j ++ ) { val = GET_DATA_BYTE ( buffer , bpl - 1 - j ) ; SET_DATA_BYTE ( line , j , tab [ val ] ) ; } } break ; case 1 : extra = ( w * d ) & 31 ; if ( extra ) shift = 32 - extra ; else shift = 0 ; if ( shift ) rasteropHipLow ( data , h , d , wpl , 0 , h , shift ) ; databpl = ( w + 7 ) / 8 ; for ( i = 0 ; i < h ; i ++ ) { line = data + i * wpl ; memcpy ( buffer , line , bpl ) ; for ( j = 0 ; j < databpl ; j ++ ) { val = GET_DATA_BYTE ( buffer , bpl - 1 - j ) ; SET_DATA_BYTE ( line , j , tab [ val ] ) ; } } break ; default : L_ERROR ( " " , procName ) ; return ; } return ; }
flipLRLow()
  Notes:
      (1) The pixel access routines allow a trivial implementation.
flipLRLow () Notes : ( 1 ) The pixel access routines allow a trivial implementation .