Coverage Report

Created: 2025-01-28 06:36

/src/libvips/libvips/foreign/analyzeload.c
Line
Count
Source (jump to first uncovered line)
1
/* load analyze from a file
2
 *
3
 * 5/12/11
4
 *  - from openslideload.c
5
 */
6
7
/*
8
9
  This file is part of VIPS.
10
11
  VIPS is free software; you can redistribute it and/or modify
12
  it under the terms of the GNU Lesser General Public License as published by
13
  the Free Software Foundation; either version 2 of the License, or
14
  (at your option) any later version.
15
16
  This program is distributed in the hope that it will be useful,
17
  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
  GNU Lesser General Public License for more details.
20
21
  You should have received a copy of the GNU Lesser General Public License
22
  along with this program; if not, write to the Free Software
23
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
  02110-1301  USA
25
26
 */
27
28
/*
29
30
  These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
31
32
 */
33
34
/*
35
#define DEBUG
36
 */
37
38
#ifdef HAVE_CONFIG_H
39
#include <config.h>
40
#endif /*HAVE_CONFIG_H*/
41
#include <glib/gi18n-lib.h>
42
43
#include <stdio.h>
44
#include <stdlib.h>
45
#include <string.h>
46
47
#include <vips/vips.h>
48
#include <vips/buf.h>
49
#include <vips/internal.h>
50
51
#ifdef HAVE_ANALYZE
52
53
#include "pforeign.h"
54
55
typedef struct _VipsForeignLoadAnalyze {
56
  VipsForeignLoad parent_object;
57
58
  /* Filename for load.
59
   */
60
  char *filename;
61
62
} VipsForeignLoadAnalyze;
63
64
typedef VipsForeignLoadClass VipsForeignLoadAnalyzeClass;
65
66
G_DEFINE_TYPE(VipsForeignLoadAnalyze, vips_foreign_load_analyze,
67
  VIPS_TYPE_FOREIGN_LOAD);
68
69
static VipsForeignFlags
70
vips_foreign_load_analyze_get_flags_filename(const char *filename)
71
0
{
72
0
  return VIPS_FOREIGN_PARTIAL;
73
0
}
74
75
static VipsForeignFlags
76
vips_foreign_load_analyze_get_flags(VipsForeignLoad *load)
77
0
{
78
0
  return VIPS_FOREIGN_PARTIAL;
79
0
}
80
81
static int
82
vips_foreign_load_analyze_header(VipsForeignLoad *load)
83
0
{
84
0
  VipsForeignLoadAnalyze *analyze = (VipsForeignLoadAnalyze *) load;
85
86
0
  if (vips__analyze_read_header(analyze->filename, load->out))
87
0
    return -1;
88
89
0
  VIPS_SETSTR(load->out->filename, analyze->filename);
90
91
0
  return 0;
92
0
}
93
94
static int
95
vips_foreign_load_analyze_load(VipsForeignLoad *load)
96
0
{
97
0
  VipsForeignLoadAnalyze *analyze = (VipsForeignLoadAnalyze *) load;
98
99
0
  if (vips__analyze_read(analyze->filename, load->real))
100
0
    return -1;
101
102
0
  return 0;
103
0
}
104
105
static const char *vips_foreign_analyze_suffs[] = { ".img", ".hdr", NULL };
106
107
static void
108
vips_foreign_load_analyze_class_init(VipsForeignLoadAnalyzeClass *class)
109
1
{
110
1
  GObjectClass *gobject_class = G_OBJECT_CLASS(class);
111
1
  VipsObjectClass *object_class = (VipsObjectClass *) class;
112
1
  VipsOperationClass *operation_class = VIPS_OPERATION_CLASS(class);
113
1
  VipsForeignClass *foreign_class = (VipsForeignClass *) class;
114
1
  VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class;
115
116
1
  gobject_class->set_property = vips_object_set_property;
117
1
  gobject_class->get_property = vips_object_get_property;
118
119
1
  object_class->nickname = "analyzeload";
120
1
  object_class->description = _("load an Analyze6 image");
121
122
  /* This is fuzzed, but you're unlikely to want to use it on
123
   * untrusted files.
124
   */
125
1
  operation_class->flags |= VIPS_OPERATION_UNTRUSTED;
126
127
1
  foreign_class->suffs = vips_foreign_analyze_suffs;
128
129
  /* is_a() is not that quick ... lower the priority.
130
   */
131
1
  foreign_class->priority = -50;
132
133
1
  load_class->is_a = vips__isanalyze;
134
1
  load_class->get_flags_filename =
135
1
    vips_foreign_load_analyze_get_flags_filename;
136
1
  load_class->get_flags = vips_foreign_load_analyze_get_flags;
137
1
  load_class->header = vips_foreign_load_analyze_header;
138
1
  load_class->load = vips_foreign_load_analyze_load;
139
140
1
  VIPS_ARG_STRING(class, "filename", 1,
141
1
    _("Filename"),
142
1
    _("Filename to load from"),
143
1
    VIPS_ARGUMENT_REQUIRED_INPUT,
144
1
    G_STRUCT_OFFSET(VipsForeignLoadAnalyze, filename),
145
1
    NULL);
146
1
}
147
148
static void
149
vips_foreign_load_analyze_init(VipsForeignLoadAnalyze *analyze)
150
0
{
151
0
}
152
153
#endif /*HAVE_ANALYZE*/
154
155
/**
156
 * vips_analyzeload:
157
 * @filename: file to load
158
 * @out: (out): decompressed image
159
 * @...: %NULL-terminated list of optional named arguments
160
 *
161
 * Load an Analyze 6.0 file. If @filename is "fred.img", this will look for
162
 * an image header called "fred.hdr" and pixel data in "fred.img". You can
163
 * also load "fred" or "fred.hdr".
164
 *
165
 * Images are
166
 * loaded lazilly and byte-swapped, if necessary. The Analyze metadata is read
167
 * and attached.
168
 *
169
 * See also: vips_image_new_from_file().
170
 *
171
 * Returns: 0 on success, -1 on error.
172
 */
173
int
174
vips_analyzeload(const char *filename, VipsImage **out, ...)
175
0
{
176
0
  va_list ap;
177
0
  int result;
178
179
0
  va_start(ap, out);
180
0
  result = vips_call_split("analyzeload", ap, filename, out);
181
0
  va_end(ap);
182
183
0
  return result;
184
0
}