⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsegyendianess.c

📁 segy 显示程序!希望能给正在做这部分朋友提供一部分资料
💻 C
📖 第 1 页 / 共 2 页
字号:
        output[i] = 0;
        output[i] = ((guint8)gain << 16) | (guint16)num;

        if (self->swap_bytes)
            output[i] = (output[i] << 24) | ((output[i] >> 24) & 0xff) |
                         ((output[i] & 0xff00) << 8) | ((output[i] & 0xff0000) >> 8);
    }
}

void g_segy_endianess_swap_gint16 (GSEGYEndianess *self, gint16 *input, gint16 *output) {
    guint16 temp = *input;

    if (self->swap_bytes)
        temp = (((temp >> 8) & 0xff) | ((temp & 0xff) << 8));

    *output = temp;
}

void g_segy_endianess_swap_gint16_array (GSEGYEndianess *self, gint16 *input, gint16 *output, guint64 length) {
    guint64 i;

    if (self->swap_bytes) {
        for (i = 0; i < length; i++)
            output[i] = (((input[i] >> 8) & 0xff) | ((input[i] & 0xff) << 8));
    } else if (input != output) {
        for (i = 0; i < length; i++)
            output[i] = input[i];
    }
}

void g_segy_endianess_swap_guint16 (GSEGYEndianess *self, guint16 *input, guint16 *output) {
    guint16 temp = *input;

    if (self->swap_bytes)
        temp = (((temp >> 8) & 0xff) | ((temp & 0xff) << 8));

    *output = temp;
}

void g_segy_endianess_swap_guint16_array (GSEGYEndianess *self, guint16 *input, guint16 *output, guint64 length) {
    guint64 i;

    if (self->swap_bytes) {
        for (i = 0; i < length; i++)
            output[i] = (((input[i] >> 8) & 0xff) | ((input[i] & 0xff) << 8));
    } else if (input != output) {
        for (i = 0; i < length; i++)
            output[i] = input[i];
    }
}

void g_segy_endianess_swap_gint32 (GSEGYEndianess *self, gint32 *input, gint32 *output) {
    guint32 temp = *input;

    if (self->swap_bytes)
        temp = (((temp >> 24) & 0xff) | ((temp & 0xff) << 24) |
                ((temp >> 8) & 0xff00) | ((temp & 0xff00) << 8));

    *output = temp;
}

void g_segy_endianess_swap_gint32_array (GSEGYEndianess *self, gint32 *input, gint32 *output, guint64 length) {
    guint64 i;

    if (self->swap_bytes) {
        for (i = 0; i < length; i++)
            output[i] = (((input[i] >> 24) & 0xff) | ((input[i] & 0xff) << 24) |
                         ((input[i] >> 8) & 0xff00) | ((input[i] & 0xff00) << 8));
    } else if (input != output) {
        for (i = 0; i < length; i++)
            output[i] = input[i];
    }
}

void g_segy_endianess_swap_guint32 (GSEGYEndianess *self, guint32 *input, guint32 *output) {
    guint32 temp = *input;

    if (self->swap_bytes)
        temp = (((temp >> 24) & 0xff) | ((temp & 0xff) << 24) |
                ((temp >> 8) & 0xff00) | ((temp & 0xff00) << 8));

    *output = temp;
}

void g_segy_endianess_swap_guint32_array (GSEGYEndianess *self, guint32 *input, guint32 *output, guint64 length) {
    guint64 i;

    if (self->swap_bytes) {
        for (i = 0; i < length; i++)
            output[i] = (((input[i] >> 24) & 0xff) | ((input[i] & 0xff) << 24) |
                         ((input[i] >> 8) & 0xff00) | ((input[i] & 0xff00) << 8));
    } else if (input != output) {
        for (i = 0; i < length; i++)
            output[i] = input[i];
    }
}

static guint8 ebcdic_to_ascii[256] = {
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  91,  46,  60,  40,  43,  33,
     38,  32,  32,  32,  32,  32,  32,  32,
     32,  32,  93,  36,  42,  41,  59,  94,
     45,  47,  32,  32,  32,  32,  32,  32,
     32,  32, 124,  44,  37,  95,  62,  63,
     32,  32,  32,  32,  32,  32, 238, 160,
    161,  96,  58,  35,  64,  39,  61,  34,
    230,  97,  98,  99, 100, 101, 102, 103,
    104, 105, 164, 165, 228, 163, 229, 168,
    169, 106, 107, 108, 109, 110, 111, 112,
    113, 114, 170, 171, 172, 173, 174, 175,
    239, 126, 115, 116, 117, 118, 119, 120,
    121, 122, 224, 225, 226, 227, 166, 162,
    236, 235, 167, 232, 237, 233, 231, 234,
    158, 128, 129, 150, 132, 133, 148, 131,
    123,  65,  66,  67,  68,  69,  70,  71,
     72,  73, 149, 136, 137, 138, 139, 140,
    125,  74,  75,  76,  77,  78,  79,  80,
     81,  82, 141, 142, 143, 159, 144, 145,
     92,  32,  83,  84,  85,  86,  87,  88,
     89,  90, 146, 147, 134, 130, 156, 155,
     48,  49,  50,  51,  52,  53,  54,  55,
     56,  57, 135, 152, 157, 153, 151,  32
};

void g_segy_endianess_ebcdic_to_ascii (GSEGYEndianess *self, guint8 *input, guint8 *output) {
    *output = ebcdic_to_ascii[*input];
}

void g_segy_endianess_ebcdic_to_ascii_array (GSEGYEndianess *self, guint8 *input, guint8 *output, guint64 length) {
    guint64 i;

    for (i = 0; i < length; i++)
        output[i] = ebcdic_to_ascii[input[i]];
}

static guint8 ascii_to_ebcdic[256] = {
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x4F, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
    0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
    0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
    0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
    0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
    0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
    0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
    0xE7, 0xE8, 0xE9, 0x4A, 0xE0, 0x5A, 0x5F, 0x6D,
    0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
    0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
    0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
    0xA7, 0xA8, 0xA9, 0xC0, 0x6A, 0xD0, 0xA1, 0x40,
    0xB9, 0xBA, 0xED, 0xBF, 0xBC, 0xBD, 0xEC, 0xFA,
    0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xDA, 0xDB, 0xDC,
    0xDE, 0xDF, 0xEA, 0xEB, 0xBE, 0xCA, 0xBB, 0xFE,
    0xFB, 0xFD, 0x7d, 0xEF, 0xEE, 0xFC, 0xB8, 0xDD,
    0x77, 0x78, 0xAF, 0x8D, 0x8A, 0x8B, 0xAE, 0xB2,
    0x8F, 0x90, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0xAA, 0xAB, 0xAC, 0xAD, 0x8C, 0x8E, 0x80, 0xB6,
    0xB3, 0xB5, 0xB7, 0xB1, 0xB0, 0xB4, 0x76, 0xA0,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
    0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 
};

void g_segy_endianess_ascii_to_ebcdic (GSEGYEndianess *self, guint8 *input, guint8 *output) {
    *output = ascii_to_ebcdic[*input];
}

void g_segy_endianess_ascii_to_ebcdic_array (GSEGYEndianess *self, guint8 *input, guint8 *output, guint64 length) {
    guint64 i;

    for (i = 0; i < length; i++)
        output[i] = ascii_to_ebcdic[input[i]];
}

static void g_segy_endianess_init (GSEGYEndianess *self) {
#ifdef G_SEGY_BIG_ENDIAN
    self->swap_bytes = FALSE;
#else
    self->swap_bytes = TRUE;
#endif

#ifdef G_SEGY_IBM_FLOATS
    self->ibm_to_ieee = FALSE;
#else
    self->ibm_to_ieee = TRUE;
#endif

#ifdef DEBUG
    g_print ("<GSEGYEndianess is inited>\n");
#endif
}

static void g_segy_endianess_finalize (GObject *object) {
#ifdef DEBUG
    g_print ("<GSEGYEndianess is finalized>\n");
#endif
    if (G_OBJECT_CLASS (g_segy_endianess_parent_class)->finalize)
        G_OBJECT_CLASS (g_segy_endianess_parent_class)->finalize (object);
}

enum {
    PROP_0,
    PROP_SWAP_BYTES,
    PROP_IBM_TO_IEEE
};

static void g_segy_endianess_set_property (GObject *object, guint prop_id,
                                           const GValue *value, GParamSpec *pspec) {
    GSEGYEndianess *self = G_SEGY_ENDIANESS (object);

    switch (prop_id) {
        case PROP_SWAP_BYTES:
            self->swap_bytes = g_value_get_boolean (value);
            g_object_notify (object, "swap_bytes");
#ifdef DEBUG
            g_print ("Swap bytes - %" G_GUINT32_FORMAT "\n", self->swap_bytes);
#endif
            break;
        case PROP_IBM_TO_IEEE:
            self->ibm_to_ieee = g_value_get_boolean (value);
            g_object_notify (object, "ibm_to_ieee");
#ifdef DEBUG
            g_print ("IBM to IEEE floats - %" G_GUINT32_FORMAT "\n", self->ibm_to_ieee);
#endif
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
            break;
    }
}

static void g_segy_endianess_get_property (GObject *object, guint prop_id,
                                           GValue *value, GParamSpec *pspec) {
    GSEGYEndianess *self = G_SEGY_ENDIANESS (object);

    switch (prop_id) {
        case PROP_SWAP_BYTES:
            g_value_set_boolean (value, self->swap_bytes);
            break;
        case PROP_IBM_TO_IEEE:
            g_value_set_boolean (value, self->ibm_to_ieee);
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
            break;
    }
}

static void g_segy_endianess_class_init (GSEGYEndianessClass *klass) {
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

    gobject_class->finalize = (GObjectFinalizeFunc) g_segy_endianess_finalize;
    gobject_class->set_property = g_segy_endianess_set_property;
    gobject_class->get_property = g_segy_endianess_get_property;

    g_object_class_install_property (gobject_class,
                                     PROP_SWAP_BYTES,
                                     g_param_spec_boolean ("swap_bytes", "SwapBytes",
                                     "TRUE - swap incoming bytes, FALSE - leave as is",
#ifdef G_SEGY_BIG_ENDIAN
                                     FALSE,
#else
                                     TRUE,
#endif
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));

    g_object_class_install_property (gobject_class,
                                     PROP_IBM_TO_IEEE,
                                     g_param_spec_boolean ("ibm_to_ieee", "IBMtoIEEE",
                                     "TRUE - convert IBM floats to IEEE floats, FALSE - leave as is",
#ifdef G_SEGY_IBM_FLOATS
                                     FALSE,
#else
                                     TRUE,
#endif
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));

#ifdef DEBUG
    g_print ("<GSEGYEndianess class is inited>\n");
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -