~ubuntu-branches/ubuntu/vivid/rawstudio/vivid

« back to all changes in this revision

Viewing changes to librawstudio/rs-tiff-ifd.c

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2011-07-28 17:36:32 UTC
  • mfrom: (2.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110728173632-5czluz9ye3c83zc5
Tags: 2.0-1
* [3750b2cf] Merge commit 'upstream/2.0'
* [63637468] Removing Patch, not necessary anymore.
* [2fb580dc] Add new build-dependencies.
* [c57d953b] Run dh_autoreconf due to patches in configure.in
* [13febe39] Add patch to remove the libssl requirement.
* [5ae773fe] Replace libjpeg62-dev by libjpeg8-dev :)
* [1969d755] Don't build static libraries.
* [7cfe0a2e] Add a patch to fix the plugin directory path.
  As plugins are shared libraries, they need to go into /usr/lib,
  not into /usr/share.
  Thanks to Andrew McMillan
* [c1d0d9dd] Don't install .la files for all plugins and libraries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * * Copyright (C) 2006-2011 Anders Brander <anders@brander.dk>, 
 
3
 * * Anders Kvist <akv@lnxbx.dk> and Klaus Post <klauspost@gmail.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include <rawstudio.h>
 
21
#include "rs-tiff-ifd.h"
 
22
 
 
23
G_DEFINE_TYPE (RSTiffIfd, rs_tiff_ifd, G_TYPE_OBJECT)
 
24
 
 
25
static void read_entries(RSTiffIfd *ifd);
 
26
 
 
27
enum {
 
28
        PROP_0,
 
29
        PROP_TIFF,
 
30
        PROP_OFFSET,
 
31
        PROP_NEXT_IFD,
 
32
};
 
33
 
 
34
static void
 
35
rs_tiff_ifd_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 
36
{
 
37
        RSTiffIfd *ifd = RS_TIFF_IFD(object);
 
38
 
 
39
        switch (property_id)
 
40
        {
 
41
                case PROP_NEXT_IFD:
 
42
                        g_value_set_uint(value, ifd->next_ifd);
 
43
                        break;
 
44
                default:
 
45
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
46
        }
 
47
}
 
48
 
 
49
static void
 
50
rs_tiff_ifd_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 
51
{
 
52
        RSTiffIfd *ifd = RS_TIFF_IFD(object);
 
53
 
 
54
        switch (property_id)
 
55
        {
 
56
                case PROP_TIFF:
 
57
                        ifd->tiff = g_object_ref(g_value_get_object(value));
 
58
                        if (ifd->tiff && ifd->offset)
 
59
                                RS_TIFF_IFD_GET_CLASS(ifd)->read(ifd);
 
60
                        break;
 
61
                case PROP_OFFSET:
 
62
                        ifd->offset = g_value_get_uint(value);
 
63
                        if (ifd->tiff && ifd->offset)
 
64
                                RS_TIFF_IFD_GET_CLASS(ifd)->read(ifd);
 
65
                        break;
 
66
                default:
 
67
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
68
        }
 
69
}
 
70
 
 
71
static void
 
72
rs_tiff_ifd_dispose(GObject *object)
 
73
{
 
74
        RSTiffIfd *ifd = RS_TIFF_IFD(object);
 
75
 
 
76
        if (!ifd->dispose_has_run)
 
77
        {
 
78
                ifd->dispose_has_run = TRUE;
 
79
                g_object_unref(ifd->tiff);
 
80
                g_list_foreach(ifd->entries, (GFunc)g_object_unref, NULL);
 
81
                g_list_free(ifd->entries);
 
82
        }
 
83
 
 
84
        G_OBJECT_CLASS(rs_tiff_ifd_parent_class)->dispose (object);
 
85
}
 
86
 
 
87
static void
 
88
rs_tiff_ifd_finalize(GObject *object)
 
89
{
 
90
        G_OBJECT_CLASS(rs_tiff_ifd_parent_class)->finalize (object);
 
91
}
 
92
 
 
93
static void
 
94
rs_tiff_ifd_class_init(RSTiffIfdClass *klass)
 
95
{
 
96
        GObjectClass *object_class = G_OBJECT_CLASS(klass);
 
97
 
 
98
        object_class->get_property = rs_tiff_ifd_get_property;
 
99
        object_class->set_property = rs_tiff_ifd_set_property;
 
100
        object_class->dispose = rs_tiff_ifd_dispose;
 
101
        object_class->finalize = rs_tiff_ifd_finalize;
 
102
 
 
103
        g_object_class_install_property(object_class,
 
104
                PROP_TIFF, g_param_spec_object(
 
105
                        "tiff", "tiff", "The RSTiff associated with the RSTiffIfd",
 
106
                        RS_TYPE_TIFF, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
 
107
 
 
108
        g_object_class_install_property(object_class,
 
109
                PROP_OFFSET, g_param_spec_uint(
 
110
                        "offset", "offset", "IFD offset",
 
111
                        0, G_MAXUINT, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
 
112
 
 
113
        g_object_class_install_property(object_class,
 
114
                PROP_NEXT_IFD, g_param_spec_uint(
 
115
                        "next-ifd", "next-ifd", "Offset for next ifd",
 
116
                        0, G_MAXUINT, 0, G_PARAM_READABLE));
 
117
 
 
118
        klass->read = read_entries;
 
119
}
 
120
 
 
121
static void
 
122
rs_tiff_ifd_init(RSTiffIfd *self)
 
123
{
 
124
}
 
125
 
 
126
RSTiffIfd *
 
127
rs_tiff_ifd_new(RSTiff *tiff, guint offset)
 
128
{
 
129
        g_assert(RS_IS_TIFF(tiff));
 
130
 
 
131
        return g_object_new(RS_TYPE_TIFF_IFD, "tiff", tiff, "offset", offset, NULL);
 
132
}
 
133
 
 
134
guint
 
135
rs_tiff_ifd_get_next(RSTiffIfd *ifd)
 
136
{
 
137
        g_assert(RS_IS_TIFF_IFD(ifd));
 
138
 
 
139
        return ifd->next_ifd;
 
140
}
 
141
 
 
142
static void
 
143
read_entries(RSTiffIfd *ifd)
 
144
{
 
145
        gint i;
 
146
 
 
147
        ifd->num_entries = rs_tiff_get_ushort(ifd->tiff, ifd->offset);
 
148
        ifd->next_ifd = rs_tiff_get_uint(ifd->tiff, ifd->offset + 2 + ifd->num_entries*12);
 
149
 
 
150
        if (ifd->next_ifd == ifd->offset)
 
151
                ifd->next_ifd = 0;
 
152
        else if (ifd->next_ifd > (ifd->tiff->map_length-12))
 
153
                ifd->next_ifd = 0;
 
154
 
 
155
        /* Read all entries */
 
156
        for(i=0;i<ifd->num_entries;i++)
 
157
                ifd->entries = g_list_append(ifd->entries, rs_tiff_ifd_entry_new(ifd->tiff, ifd->offset + 2 + i * 12));
 
158
}
 
159
 
 
160
static gint
 
161
_tag_search(RSTiffIfdEntry *entry, gushort tag)
 
162
{
 
163
        return entry->tag - tag;
 
164
}
 
165
 
 
166
RSTiffIfdEntry *
 
167
rs_tiff_ifd_get_entry_by_tag(RSTiffIfd *ifd, gushort tag)
 
168
{
 
169
        g_assert(RS_IS_TIFF_IFD(ifd));
 
170
        GList *found;
 
171
        RSTiffIfdEntry *ret = NULL;
 
172
 
 
173
        found = g_list_find_custom(ifd->entries, GUINT_TO_POINTER((guint) tag), (GCompareFunc) _tag_search);
 
174
 
 
175
        if (found)
 
176
                ret = g_object_ref(found->data);
 
177
 
 
178
        return ret;
 
179
}