[go: up one dir, main page]

Menu

[1f9cef]: / src / jpg.c  Maximize  Restore  History

Download this file

103 lines (95 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* viking -- GPS Data and Topo Analyzer, Explorer, and Manager
*
* Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "jpg.h"
#include "file_magic.h"
#ifdef VIK_CONFIG_GEOTAG
#include "geotag_exif.h"
#endif
/**
* a_jpg_magic_check:
* @filename: The file
*
* Returns: Whether the file is a JPG
*/
gboolean a_jpg_magic_check ( const gchar *filename )
{
return file_magic_check ( filename, "image/jpeg", ".jpg" );
}
/**
* Load a single JPG into a Trackwaypoint Layer as a waypoint
*
* @top: The Aggregate layer that a new TRW layer may be created in
* @filename: The JPG filename
* @vvp: The viewport
*
* Returns: Whether the loading was a success or not
*
* If the JPG has geotag information then the waypoint will be created with the appropriate position.
* Otherwise the waypoint will be positioned at the current screen center.
* If a TRW layer is already selected the waypoint will be created in that layer.
*/
gboolean a_jpg_load_file ( VikAggregateLayer *top, const gchar *filename, VikViewport *vvp )
{
gboolean auto_zoom = TRUE;
VikWindow *vw = (VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(top)));
VikLayersPanel *vlp = vik_window_layers_panel ( vw );
// Auto load into TrackWaypoint layer if one is selected
VikLayer *vtl = vik_layers_panel_get_selected ( vlp );
gboolean create_layer = FALSE;
if ( vtl == NULL || vtl->type != VIK_LAYER_TRW ) {
// Create layer if necessary
vtl = vik_layer_create ( VIK_LAYER_TRW, vvp, FALSE );
vik_layer_rename ( vtl, a_file_basename ( filename ) );
create_layer = TRUE;
}
gchar *name = NULL;
VikWaypoint *wp = NULL;
#ifdef VIK_CONFIG_GEOTAG
wp = a_geotag_create_waypoint_from_file ( filename, vik_viewport_get_coord_mode (vvp), &name );
#endif
if ( wp ) {
// Create name if geotag method didn't return one
if ( !name )
name = g_strdup ( a_file_basename ( filename ) );
vik_trw_layer_filein_add_waypoint ( VIK_TRW_LAYER(vtl), name, wp );
g_free ( name );
}
else {
wp = vik_waypoint_new ();
vik_trw_layer_filein_add_waypoint ( VIK_TRW_LAYER(vtl), (gchar*) a_file_basename(filename), wp );
vik_waypoint_set_image ( wp, filename );
// Simply set position to the current center
wp->coord = *( vik_viewport_get_center ( vvp ) );
auto_zoom = FALSE;
}
// Complete the setup
vik_layer_post_read ( vtl, vvp, TRUE );
if ( create_layer )
vik_aggregate_layer_add_layer ( top, vtl, FALSE );
if ( auto_zoom )
vik_trw_layer_auto_set_view ( VIK_TRW_LAYER(vtl), vvp );
// ATM This routine can't fail
return TRUE;
}