src/fpix1.c
FPIX *
fpixEndianByteSwap(FPIX  *fpixd,
                   FPIX  *fpixs)
{
    PROCNAME("fpixEndianByteSwap");
        
    if (!fpixs)
        return (FPIX *)ERROR_PTR("fpixs not defined", procName, fpixd);
    if (fpixd && (fpixs != fpixd))
        return (FPIX *)ERROR_PTR("fpixd != fpixs", procName, fpixd);

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

        fpixGetDimensions(fpixs, &w, &h);
        fpixd = fpixCopy(fpixd, fpixs);  /* no copy if fpixd == fpixs */

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

    if (fpixd)
        return fpixd;  /* no-op */
    else
        return fpixClone(fpixs);

#endif   /* L_BIG_ENDIAN */
}
/*!
 *  fpixEndianByteSwap()
 *
 *      Input:  fpixd (can be equal to fpixs or NULL)
 *              fpixs
 *      Return: fpixd always
 *
 *  Notes:
 *      (1) On big-endian hardware, this does byte-swapping on each of
 *          the 4-byte floats in the fpix data.  On little-endians,
 *          the data is unchanged.  This is used for serialization
 *          of fpix; 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 fpixd == NULL,
 *          a new fpix is made.  If not in-place, caller must catch
 *          the returned pointer.
 */
fpixEndianByteSwap()
Input:  fpixd (can be equal to fpixs or NULL)
fpixs
Return: fpixd always

(1) On big-endian hardware, this does byte-swapping on each of
the 4-byte floats in the fpix data.  On little-endians,
the data is unchanged.  This is used for serialization
of fpix; 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 fpixd == NULL,
a new fpix is made.  If not in-place, caller must catch
the returned pointer.
fpixEndianByteSwap () Input : fpixd ( can be equal to fpixs or NULL ) fpixs Return : fpixd always ( 1 ) On big - endian hardware this does byte - swapping on each of the 4 - byte floats in the fpix data . On little - endians the data is unchanged . This is used for serialization of fpix ; 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 fpixd == NULL a new fpix is made . If not in - place caller must catch the returned pointer .
FPIX *
fpixEndianByteSwap(FPIX  *fpixd,
                   FPIX  *fpixs)
{
    PROCNAME("fpixEndianByteSwap");
    if (!fpixs)
        return (FPIX *)ERROR_PTR("fpixs not defined", procName, fpixd);
    if (fpixd && (fpixs != fpixd))
        return (FPIX *)ERROR_PTR("fpixd != fpixs", procName, fpixd);
#ifdef L_BIG_ENDIAN
    {
    l_uint32  *data;
    l_int32    i, j, w, h;
    l_uint32   word;
        fpixGetDimensions(fpixs, &w, &h);
        fpixd = fpixCopy(fpixd, fpixs);  
        data = (l_uint32 *)fpixGetData(fpixd);
        for (i = 0; i < h; i++) {
            for (j = 0; j < w; j++, data++) {
                word = *data;
                *data = (word >> 24) |
                        ((word >> 8) & 0x0000ff00) |
                        ((word << 8) & 0x00ff0000) |
                        (word << 24);
            }
        }
        return fpixd;
    }
#else   
    if (fpixd)
        return fpixd;  
    else
        return fpixClone(fpixs);
#endif   
}
FPIX * fpixEndianByteSwap ( FPIX * fpixd , FPIX * fpixs ) { PROCNAME ( " " ) ; if ( ! fpixs ) return ( FPIX * ) ERROR_PTR ( " " , procName , fpixd ) ; if ( fpixd && ( fpixs != fpixd ) ) return ( FPIX * ) ERROR_PTR ( " " , procName , fpixd ) ; #ifdef L_BIG_ENDIAN { l_uint32 * data ; l_int32 i , j , w , h ; l_uint32 word ; fpixGetDimensions ( fpixs , & w , & h ) ; fpixd = fpixCopy ( fpixd , fpixs ) ; data = ( l_uint32 * ) fpixGetData ( fpixd ) ; for ( i = 0 ; i < h ; i ++ ) { for ( j = 0 ; j < w ; j ++ , data ++ ) { word = * data ; * data = ( word >> 24 ) | ( ( word >> 8 ) & 0x0000ff00 ) | ( ( word << 8 ) & 0x00ff0000 ) | ( word << 24 ) ; } } return fpixd ; } #else if ( fpixd ) return fpixd ; else return fpixClone ( fpixs ) ; #endif }
fpixEndianByteSwap()
      Input:  fpixd (can be equal to fpixs or NULL)
              fpixs
      Return: fpixd always
fpixEndianByteSwap () Input : fpixd ( can be equal to fpixs or NULL ) fpixs Return : fpixd always
/* no copy if fpixd == fpixs */ /* L_LITTLE_ENDIAN */ /* no-op */ /* L_BIG_ENDIAN */