OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [generic/] [tkImgUtil.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tkImgUtil.c --
3
 *
4
 *      This file contains image related utility functions.
5
 *
6
 * Copyright (c) 1995 Sun Microsystems, Inc.
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 * RCS: @(#) $Id: tkImgUtil.c,v 1.1.1.1 2002-01-16 10:25:52 markom Exp $
12
 */
13
 
14
#include "tkInt.h"
15
#include "tkPort.h"
16
#include "xbytes.h"
17
 
18
 
19
/*
20
 *----------------------------------------------------------------------
21
 *
22
 * TkAlignImageData --
23
 *
24
 *      This function takes an image and copies the data into an
25
 *      aligned buffer, performing any necessary bit swapping.
26
 *
27
 * Results:
28
 *      Returns a newly allocated buffer that should be freed by the
29
 *      caller.
30
 *
31
 * Side effects:
32
 *      None.
33
 *
34
 *----------------------------------------------------------------------
35
 */
36
 
37
char *
38
TkAlignImageData(image, alignment, bitOrder)
39
    XImage *image;              /* Image to be aligned. */
40
    int alignment;              /* Number of bytes to which the data should
41
                                 * be aligned (e.g. 2 or 4) */
42
    int bitOrder;               /* Desired bit order: LSBFirst or MSBFirst. */
43
{
44
    long dataWidth;
45
    char *data, *srcPtr, *destPtr;
46
    int i, j;
47
 
48
    if (image->bits_per_pixel != 1) {
49
        panic("TkAlignImageData: Can't handle image depths greater than 1.");
50
    }
51
 
52
    /*
53
     * Compute line width for output data buffer.
54
     */
55
 
56
    dataWidth = image->bytes_per_line;
57
    if (dataWidth % alignment) {
58
        dataWidth += (alignment - (dataWidth % alignment));
59
    }
60
 
61
    data = ckalloc(dataWidth * image->height);
62
 
63
    destPtr = data;
64
    for (i = 0; i < image->height; i++) {
65
        srcPtr = &image->data[i * image->bytes_per_line];
66
        for (j = 0; j < dataWidth; j++) {
67
            if (j >= image->bytes_per_line) {
68
                *destPtr = 0;
69
            } else if (image->bitmap_bit_order != bitOrder) {
70
                *destPtr = xBitReverseTable[(unsigned char)(*(srcPtr++))];
71
            } else {
72
                *destPtr = *(srcPtr++);
73
            }
74
            destPtr++;
75
        }
76
    }
77
    return data;
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.