src/fpix1.c
DPIX *
dpixEndianByteSwap(DPIX  *dpixd,
                   DPIX  *dpixs)
{
    PROCNAME("dpixEndianByteSwap");
        
    if (!dpixs)
        return (DPIX *)ERROR_PTR("dpixs not defined", procName, dpixd);
    if (dpixd && (dpixs != dpixd))
        return (DPIX *)ERROR_PTR("dpixd != dpixs", procName, dpixd);

#ifdef L_BIG_ENDIAN
    {
    l_uint32  *data;
    l_int32    i, j, w, h;
    l_uint32   word;

        dpixGetDimensions(dpixs, &w, &h);
        dpixd = dpixCopy(dpixd, dpixs);  /* no copy if dpixd == dpixs */

        data = (l_uint32 *)dpixGetData(dpixd);
        for (i = 0; i < h; i++) {
            for (j = 0; j < 2 * w; j++, data++) {
                word = *data;
                *data = (word >> 24) |
                        ((word >> 8) & 0x0000ff00) |
                        ((word << 8) & 0x00ff0000) |
                        (word << 24);
            }
        }
        return dpixd;
    }
#else   /* L_LITTLE_ENDIAN */

    if (dpixd)
        return dpixd;  /* no-op */
    else
        return dpixClone(dpixs);

#endif   /* L_BIG_ENDIAN */
}
/*!
 *  dpixEndianByteSwap()
 *
 *      Input:  dpixd (can be equal to dpixs or NULL)
 *              dpixs
 *      Return: dpixd always
 *
 *  Notes:
 *      (1) On big-endian hardware, this does byte-swapping on each of
 *          the 4-byte words in the dpix data.  On little-endians,
 *          the data is unchanged.  This is used for serialization
 *          of dpix; the data is serialized in little-endian byte
 *          order because most hardware is little-endian.
 *      (2) The operation can be either in-place or, if dpixd == NULL,
 *          a new dpix is made.  If not in-place, caller must catch
 *          the returned pointer.
 */
dpixEndianByteSwap()
Input:  dpixd (can be equal to dpixs or NULL)
dpixs
Return: dpixd always

(1) On big-endian hardware, this does byte-swapping on each of
the 4-byte words in the dpix data.  On little-endians,
the data is unchanged.  This is used for serialization
of dpix; the data is serialized in little-endian byte
order because most hardware is little-endian.
(2) The operation can be either in-place or, if dpixd == NULL,
a new dpix is made.  If not in-place, caller must catch
the returned pointer.
dpixEndianByteSwap () Input : dpixd ( can be equal to dpixs or NULL ) dpixs Return : dpixd always ( 1 ) On big - endian hardware this does byte - swapping on each of the 4 - byte words in the dpix data . On little - endians the data is unchanged . This is used for serialization of dpix ; the data is serialized in little - endian byte order because most hardware is little - endian . ( 2 ) The operation can be either in - place or if dpixd == NULL a new dpix is made . If not in - place caller must catch the returned pointer .
DPIX *
dpixEndianByteSwap(DPIX  *dpixd,
                   DPIX  *dpixs)
{
    PROCNAME("dpixEndianByteSwap");
    if (!dpixs)
        return (DPIX *)ERROR_PTR("dpixs not defined", procName, dpixd);
    if (dpixd && (dpixs != dpixd))
        return (DPIX *)ERROR_PTR("dpixd != dpixs", procName, dpixd);
#ifdef L_BIG_ENDIAN
    {
    l_uint32  *data;
    l_int32    i, j, w, h;
    l_uint32   word;
        dpixGetDimensions(dpixs, &w, &h);
        dpixd = dpixCopy(dpixd, dpixs);  
        data = (l_uint32 *)dpixGetData(dpixd);
        for (i = 0; i < h; i++) {
            for (j = 0; j < 2 * w; j++, data++) {
                word = *data;
                *data = (word >> 24) |
                        ((word >> 8) & 0x0000ff00) |
                        ((word << 8) & 0x00ff0000) |
                        (word << 24);
            }
        }
        return dpixd;
    }
#else   
    if (dpixd)
        return dpixd;  
    else
        return dpixClone(dpixs);
#endif   
}
DPIX * dpixEndianByteSwap ( DPIX * dpixd , DPIX * dpixs ) { PROCNAME ( " " ) ; if ( ! dpixs ) return ( DPIX * ) ERROR_PTR ( " " , procName , dpixd ) ; if ( dpixd && ( dpixs != dpixd ) ) return ( DPIX * ) ERROR_PTR ( " " , procName , dpixd ) ; #ifdef L_BIG_ENDIAN { l_uint32 * data ; l_int32 i , j , w , h ; l_uint32 word ; dpixGetDimensions ( dpixs , & w , & h ) ; dpixd = dpixCopy ( dpixd , dpixs ) ; data = ( l_uint32 * ) dpixGetData ( dpixd ) ; for ( i = 0 ; i < h ; i ++ ) { for ( j = 0 ; j < 2 * w ; j ++ , data ++ ) { word = * data ; * data = ( word >> 24 ) | ( ( word >> 8 ) & 0x0000ff00 ) | ( ( word << 8 ) & 0x00ff0000 ) | ( word << 24 ) ; } } return dpixd ; } #else if ( dpixd ) return dpixd ; else return dpixClone ( dpixs ) ; #endif }
dpixEndianByteSwap()
      Input:  dpixd (can be equal to dpixs or NULL)
              dpixs
      Return: dpixd always
dpixEndianByteSwap () Input : dpixd ( can be equal to dpixs or NULL ) dpixs Return : dpixd always
/* no copy if dpixd == dpixs */ /* L_LITTLE_ENDIAN */ /* no-op */ /* L_BIG_ENDIAN */