Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[8c9294]: metadata.c Maximize Restore History

Download this file

metadata.c    168 lines (138 with data), 4.3 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* metadata.c
*
* Many of the routines are based on the program PTStitcher by Helmut
* Dersch.
*
* Copyright Helmut Dersch, Daniel M. German
*
* Dec 2006
*
* 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 software 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 software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* Author: Daniel M German dmgerman at uvic doooot ca
*
*/
// update metadata from an image. IT does not update cropped information
#include <stdio.h>
#include <assert.h>
#include "panorama.h"
#include "metadata.h"
int panoMetadataUpdateFromImage(Image *im)
{
im->metadata.imageWidth = im->width;
im->metadata.imageHeight = im->height;
im->metadata.bytesPerLine = im->bytesPerLine;
im->metadata.bitsPerSample = (uint16_t)(im->bitsPerPixel / 4);
im->metadata.samplesPerPixel = 4;
im->metadata.bytesPerPixel = im->bitsPerPixel/8;
im->metadata.bitsPerPixel = im->bitsPerPixel;
return 1;
}
// Sometimes we need to convert an image from cropped to uncropped. This function
// takes care of setting the metadata accordingly
void panoUnCropMetadata(pano_ImageMetadata * metadata)
{
metadata->imageWidth = metadata->cropInfo.fullWidth;
metadata->imageHeight = metadata->cropInfo.fullHeight;
metadata->isCropped = 0;
metadata->bytesPerLine = metadata->imageWidth * metadata->bytesPerPixel;
}
void panoMetadataCropSizeUpdate(pano_ImageMetadata * metadata, pano_CropInfo *cropInfo)
{
// Update metadata with cropped info.
metadata->imageWidth = cropInfo->croppedWidth;
metadata->imageHeight = cropInfo->croppedHeight;
metadata->bytesPerLine = metadata->imageWidth * metadata->bytesPerPixel;
// now the crop info in the metadata
metadata->cropInfo.croppedWidth = cropInfo->croppedWidth;
metadata->cropInfo.croppedHeight = cropInfo->croppedHeight;
metadata->cropInfo.xOffset += cropInfo->xOffset;
metadata->cropInfo.yOffset += cropInfo->yOffset;
metadata->cropInfo.fullWidth = cropInfo->fullWidth;
metadata->cropInfo.fullHeight = cropInfo->fullHeight;
metadata->isCropped = (cropInfo->croppedWidth != cropInfo->fullWidth) ||
(cropInfo->croppedHeight != cropInfo->fullHeight);
// The full size remains the same,
// The rest of the metadata should be the same
}
int panoImageIsCropped(Image *image)
{
assert(image!= NULL);
return (image->metadata.isCropped);
}
int panoImageBytesPerPixel(Image *image)
{
return (image->metadata.bitsPerSample * image->metadata.samplesPerPixel )/ 8;
}
int panoImageBytesPerLine(Image *image)
{
return (image->metadata.bytesPerLine);
}
int panoImageBitsPerSample(Image *image)
{
return (image->metadata.bitsPerSample);
}
int panoImageBytesPerSample(Image *image)
{
return (image->metadata.bitsPerSample/8);
}
int panoImageFullWidth(Image *image)
{
assert(image!= NULL);
if (panoImageIsCropped(image))
return image->metadata.cropInfo.fullWidth;
else
return image->width;
}
int panoImageWidth(Image *image)
{
assert(image!= NULL);
return image->width;
}
int panoImageHeight(Image *image)
{
assert(image!= NULL);
return image->height;
}
int panoImageFullHeight(Image *image)
{
assert(image!= NULL);
if (panoImageIsCropped(image))
return image->metadata.cropInfo.fullHeight;
else
return image->height;
}
int panoImageOffsetX(Image *image)
{
assert(image!= NULL);
if (panoImageIsCropped(image))
return image->metadata.cropInfo.xOffset;
else
return 0;
}
int panoImageOffsetY(Image *image)
{
assert(image!= NULL);
if (panoImageIsCropped(image))
return image->metadata.cropInfo.yOffset;
else
return 0;
}
unsigned char *panoImageData(Image *image)
{
return *(image->data);
}