Esempio n. 1
0
static void
prep_infoblock(ide_device_info *device)
{
	ide_device_infoblock *infoblock = &device->infoblock;

	B_BENDIAN_TO_HOST_MULTI((uint16 *)infoblock->serial_number, 
		sizeof(infoblock->serial_number) / 2);

	B_BENDIAN_TO_HOST_MULTI( (uint16 *)infoblock->firmware_version, 
		sizeof(infoblock->firmware_version) / 2);

	B_BENDIAN_TO_HOST_MULTI( (uint16 *)infoblock->model_number, 
		sizeof(infoblock->model_number) / 2);

	infoblock->LBA_total_sectors = B_LENDIAN_TO_HOST_INT32(infoblock->LBA_total_sectors);
	infoblock->LBA48_total_sectors = B_LENDIAN_TO_HOST_INT64(infoblock->LBA48_total_sectors);
}
Esempio n. 2
0
Layer*
Layer::readLayer(BFile& file, ImageView* imageView, int32 new_id,
                 bool is_little_endian, int32 compression_method)
{
    // This is the new way of reading the layers.
    int32 marker;
    if (file.Read(&marker,sizeof(int32)) != sizeof(int32))
        return NULL;

    if (is_little_endian)
        marker = B_LENDIAN_TO_HOST_INT32(marker);
    else
        marker = B_BENDIAN_TO_HOST_INT32(marker);

    if (marker != PROJECT_FILE_LAYER_START_MARKER)
        return NULL;

    int32 width;
    int32 height;
    layer_type layerType;
    int32 layer_visibility;
    int64 length;
    if (file.Read(&width,sizeof(int32)) != sizeof(int32))
        return NULL;
    if (file.Read(&height,sizeof(int32)) != sizeof(int32))
        return NULL;
    if (file.Read(&layerType,sizeof(int32)) != sizeof(int32))
        return NULL;
    if (file.Read(&layer_visibility,sizeof(int32)) != sizeof(int32))
        return NULL;
    if (file.Read(&length,sizeof(int64)) != sizeof(int64))
        return NULL;

    if (is_little_endian) {
        width = B_LENDIAN_TO_HOST_INT32(width);
        height = B_LENDIAN_TO_HOST_INT32(height);
        layerType = layer_type(B_LENDIAN_TO_HOST_INT32(layerType));
        length = B_LENDIAN_TO_HOST_INT64(length);
    }
    else {
        width = B_BENDIAN_TO_HOST_INT32(width);
        height = B_BENDIAN_TO_HOST_INT32(height);
        layerType = layer_type(B_BENDIAN_TO_HOST_INT32(layerType));
        length = B_BENDIAN_TO_HOST_INT64(length);
    }

    Layer* layer = new Layer(BRect(0, 0, width - 1, height - 1), new_id,
                             imageView, layerType);
    layer->SetVisibility((uint32(layer_visibility) == 0xFFFFFFFF));
    int8* bits = (int8*)layer->Bitmap()->Bits();
    if (file.Read(bits,length) != length) {
        delete layer;
        return NULL;
    }

    // Read the end-marker.
    if (file.Read(&marker,sizeof(int32)) != sizeof(int32)) {
        delete layer;
        return NULL;
    }
    if (is_little_endian)
        marker = B_LENDIAN_TO_HOST_INT32(marker);
    else
        marker = B_BENDIAN_TO_HOST_INT32(marker);

    if (marker != PROJECT_FILE_LAYER_END_MARKER) {
        delete layer;
        return NULL;
    }

    // Here try to read the extra-data block.
    if (file.Read(&marker,sizeof(int32)) == sizeof(int32)) {
        if (is_little_endian)
            marker = B_LENDIAN_TO_HOST_INT32(marker);
        else
            marker = B_BENDIAN_TO_HOST_INT32(marker);

        if (marker == PROJECT_FILE_LAYER_EXTRA_DATA_START_MARKER) {
            // Read the length of this section
            int32 length;
            if (file.Read(&length,sizeof(int32)) != sizeof(int32)) {
                delete layer;
                return NULL;
            }

            if (is_little_endian)
                length = B_LENDIAN_TO_HOST_INT32(length);
            else
                length = B_BENDIAN_TO_HOST_INT32(length);

            // Read the transparency coefficient
            float coeff;
            if (file.Read(&coeff,sizeof(float)) != sizeof(float)) {
                delete layer;
                return NULL;
            }
            if (is_little_endian)
                coeff = B_LENDIAN_TO_HOST_FLOAT(coeff);
            else
                coeff = B_BENDIAN_TO_HOST_FLOAT(coeff);

            layer->SetTransparency(coeff);
            length -= sizeof(float);

            // Skip the extra data that we do not recognize.
            file.Seek(length,SEEK_CUR);

            // Here we should get the end-marker for layer's extra data
            if (file.Read(&marker,sizeof(int32)) != sizeof(int32)) {
                delete layer;
                return NULL;
            }
            if (is_little_endian)
                marker = B_LENDIAN_TO_HOST_INT32(marker);
            else
                marker = B_BENDIAN_TO_HOST_INT32(marker);

            if (marker != PROJECT_FILE_LAYER_EXTRA_DATA_END_MARKER) {
                delete layer;
                return NULL;
            }

        }
        else {
            // Somehow -sizeof(int32) does not seem to work????
            file.Seek(-4,SEEK_CUR);
        }
    }

    // Before returning calculate the layer's miniature image.
    layer->calc_mini_image();

    return layer;
}