~ubuntu-branches/ubuntu/precise/nvidia-settings/precise-proposed

« back to all changes in this revision

Viewing changes to nvidia-settings-1.0/src/image_data/image.c

  • Committer: Bazaar Package Importer
  • Author(s): Randall Donald
  • Date: 2004-07-03 19:09:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040703190917-rqkze2s58ux5pamy
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * nvidia-settings: A tool for configuring the NVIDIA X driver on Unix
 
3
 * and Linux systems.
 
4
 *
 
5
 * Copyright (C) 2004 NVIDIA Corporation.
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of Version 2 of the GNU General Public
 
9
 * License as published by the Free Software Foundation.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2
 
14
 * of the GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the:
 
18
 *
 
19
 *           Free Software Foundation, Inc.
 
20
 *           59 Temple Place - Suite 330
 
21
 *           Boston, MA 02111-1307, USA
 
22
 *
 
23
 */
 
24
 
 
25
/*
 
26
 * This source file contains a simple routine for uncompressing RGB
 
27
 * 1-byte-run-length-encoded images as generated by gimp when saving
 
28
 * as "C-Source".
 
29
 */
 
30
 
 
31
#include "image.h"
 
32
 
 
33
#include <stdlib.h>
 
34
#include <string.h>
 
35
 
 
36
#define GIMP_IMAGE_RUN_LENGTH_DECODE(image_buf, rle_data, size, bpp) \
 
37
do {                                                                 \
 
38
    unsigned int __bpp;                                              \
 
39
    unsigned char *__ip;                                             \
 
40
    const unsigned char *__il, *__rd;                                \
 
41
                                                                     \
 
42
    __bpp = (bpp);                                                   \
 
43
    __ip = (image_buf);                                              \
 
44
    __il = __ip + (size) * __bpp;                                    \
 
45
    __rd = (rle_data);                                               \
 
46
                                                                     \
 
47
    if (__bpp > 3) { /* RGBA */                                      \
 
48
        while (__ip < __il) {                                        \
 
49
            unsigned int __l = *(__rd++);                            \
 
50
            if (__l & 128) {                                         \
 
51
                __l = __l - 128;                                     \
 
52
                do {                                                 \
 
53
                    memcpy (__ip, __rd, 4); __ip += 4;               \
 
54
                } while (--__l);                                     \
 
55
                __rd += 4;                                           \
 
56
            } else {                                                 \
 
57
                __l *= 4;                                            \
 
58
                memcpy (__ip, __rd, __l);                            \
 
59
                __ip += __l; __rd += __l;                            \
 
60
            }                                                        \
 
61
        }                                                            \
 
62
    } else { /* RGB */                                               \
 
63
        while (__ip < __il) {                                        \
 
64
            unsigned int __l = *(__rd++);                            \
 
65
            if (__l & 128) {                                         \
 
66
                __l = __l - 128;                                     \
 
67
                do {                                                 \
 
68
                    memcpy (__ip, __rd, 3); __ip += 3;               \
 
69
                } while (--__l); __rd += 3;                          \
 
70
            } else {                                                 \
 
71
                __l *= 3;                                            \
 
72
                memcpy (__ip, __rd, __l);                            \
 
73
                __ip += __l; __rd += __l;                            \
 
74
            }                                                        \
 
75
        }                                                            \
 
76
    }                                                                \
 
77
} while (0)
 
78
 
 
79
unsigned char *decompress_image_data(const nv_image_t *img)
 
80
{
 
81
    unsigned char *buf = malloc(img->width *
 
82
                                img->height *
 
83
                                img->bytes_per_pixel);
 
84
 
 
85
    GIMP_IMAGE_RUN_LENGTH_DECODE(buf, img->rle_pixel_data,
 
86
                                 img->width * img->height,
 
87
                                 img->bytes_per_pixel);
 
88
    return buf;
 
89
}
 
90
 
 
91
 
 
92
void free_decompressed_image(unsigned char *buf, void *ptr)
 
93
{
 
94
    free(buf);
 
95
}