| 1 |
/*****************************************************************************/ |
| 2 |
// Copyright 2006-2019 Adobe Systems Incorporated |
| 3 |
// All Rights Reserved. |
| 4 |
// |
| 5 |
// NOTICE: Adobe permits you to use, modify, and distribute this file in |
| 6 |
// accordance with the terms of the Adobe license agreement accompanying it. |
| 7 |
/*****************************************************************************/ |
| 8 |
|
| 9 |
#include "dng_simple_image.h" |
| 10 |
|
| 11 |
#include "dng_orientation.h" |
| 12 |
#include "dng_tag_types.h" |
| 13 |
#include "dng_tag_values.h" |
| 14 |
|
| 15 |
/*****************************************************************************/ |
| 16 |
|
| 17 |
dng_simple_image::dng_simple_image (const dng_rect &bounds, |
| 18 |
uint32 planes, |
| 19 |
uint32 pixelType, |
| 20 |
dng_memory_allocator &allocator) |
| 21 |
|
| 22 |
: dng_image (bounds, |
| 23 |
planes, |
| 24 |
pixelType) |
| 25 |
|
| 26 |
, fBuffer () |
| 27 |
, fMemory () |
| 28 |
, fAllocator (allocator) |
| 29 |
|
| 30 |
{ |
| 31 |
|
| 32 |
uint32 bytes = ComputeBufferSize (pixelType, |
| 33 |
bounds.Size (), |
| 34 |
planes, |
| 35 |
padSIMDBytes); |
| 36 |
|
| 37 |
fMemory.Reset (allocator.Allocate (bytes)); |
| 38 |
|
| 39 |
fBuffer = dng_pixel_buffer (bounds, |
| 40 |
0, |
| 41 |
planes, |
| 42 |
pixelType, |
| 43 |
pcInterleaved, |
| 44 |
fMemory->Buffer ()); |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
/*****************************************************************************/ |
| 49 |
|
| 50 |
dng_simple_image::dng_simple_image (dng_pixel_buffer &buffer, |
| 51 |
dng_memory_allocator &allocator) |
| 52 |
|
| 53 |
: dng_image (buffer.fArea, |
| 54 |
buffer.fPlanes, |
| 55 |
buffer.fPixelType) |
| 56 |
|
| 57 |
, fBuffer (buffer) |
| 58 |
, fMemory () |
| 59 |
, fAllocator (allocator) |
| 60 |
|
| 61 |
{ |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
/*****************************************************************************/ |
| 66 |
|
| 67 |
dng_simple_image::~dng_simple_image () |
| 68 |
{ |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
/*****************************************************************************/ |
| 73 |
|
| 74 |
dng_image * dng_simple_image::Clone () const |
| 75 |
{ |
| 76 |
|
| 77 |
AutoPtr<dng_simple_image> result (new dng_simple_image (Bounds (), |
| 78 |
Planes (), |
| 79 |
PixelType (), |
| 80 |
fAllocator)); |
| 81 |
|
| 82 |
result->fBuffer.CopyArea (fBuffer, |
| 83 |
Bounds (), |
| 84 |
0, |
| 85 |
Planes ()); |
| 86 |
|
| 87 |
return result.Release (); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
/*****************************************************************************/ |
| 92 |
|
| 93 |
void dng_simple_image::SetPixelType (uint32 pixelType) |
| 94 |
{ |
| 95 |
|
| 96 |
dng_image::SetPixelType (pixelType); |
| 97 |
|
| 98 |
fBuffer.fPixelType = pixelType; |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
/*****************************************************************************/ |
| 103 |
|
| 104 |
void dng_simple_image::Trim (const dng_rect &r) |
| 105 |
{ |
| 106 |
|
| 107 |
fBounds.t = 0; |
| 108 |
fBounds.l = 0; |
| 109 |
|
| 110 |
fBounds.b = r.H (); |
| 111 |
fBounds.r = r.W (); |
| 112 |
|
| 113 |
fBuffer.fData = fBuffer.DirtyPixel (r.t, r.l); |
| 114 |
|
| 115 |
fBuffer.fArea = fBounds; |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
/*****************************************************************************/ |
| 120 |
|
| 121 |
void dng_simple_image::Rotate (const dng_orientation &orientation) |
| 122 |
{ |
| 123 |
|
| 124 |
int32 originH = fBounds.l; |
| 125 |
int32 originV = fBounds.t; |
| 126 |
|
| 127 |
int32 colStep = fBuffer.fColStep; |
| 128 |
int32 rowStep = fBuffer.fRowStep; |
| 129 |
|
| 130 |
uint32 width = fBounds.W (); |
| 131 |
uint32 height = fBounds.H (); |
| 132 |
|
| 133 |
if (orientation.FlipH ()) |
| 134 |
{ |
| 135 |
|
| 136 |
originH += width - 1; |
| 137 |
|
| 138 |
colStep = -colStep; |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
if (orientation.FlipV ()) |
| 143 |
{ |
| 144 |
|
| 145 |
originV += height - 1; |
| 146 |
|
| 147 |
rowStep = -rowStep; |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
if (orientation.FlipD ()) |
| 152 |
{ |
| 153 |
|
| 154 |
int32 temp = colStep; |
| 155 |
|
| 156 |
colStep = rowStep; |
| 157 |
rowStep = temp; |
| 158 |
|
| 159 |
width = fBounds.H (); |
| 160 |
height = fBounds.W (); |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
fBuffer.fData = fBuffer.DirtyPixel (originV, originH); |
| 165 |
|
| 166 |
fBuffer.fColStep = colStep; |
| 167 |
fBuffer.fRowStep = rowStep; |
| 168 |
|
| 169 |
fBounds.r = fBounds.l + width; |
| 170 |
fBounds.b = fBounds.t + height; |
| 171 |
|
| 172 |
fBuffer.fArea = fBounds; |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
/*****************************************************************************/ |
| 177 |
|
| 178 |
void dng_simple_image::Offset (const dng_point &offset) |
| 179 |
{ |
| 180 |
|
| 181 |
fBounds = fBounds + offset; |
| 182 |
|
| 183 |
fBuffer.fArea = fBounds; |
| 184 |
|
| 185 |
} |
| 186 |
|
| 187 |
/*****************************************************************************/ |
| 188 |
|
| 189 |
void dng_simple_image::AcquireTileBuffer (dng_tile_buffer &buffer, |
| 190 |
const dng_rect &area, |
| 191 |
bool dirty) const |
| 192 |
{ |
| 193 |
|
| 194 |
buffer.fArea = area; |
| 195 |
|
| 196 |
buffer.fPlane = fBuffer.fPlane; |
| 197 |
buffer.fPlanes = fBuffer.fPlanes; |
| 198 |
buffer.fRowStep = fBuffer.fRowStep; |
| 199 |
buffer.fColStep = fBuffer.fColStep; |
| 200 |
buffer.fPlaneStep = fBuffer.fPlaneStep; |
| 201 |
buffer.fPixelType = fBuffer.fPixelType; |
| 202 |
buffer.fPixelSize = fBuffer.fPixelSize; |
| 203 |
|
| 204 |
buffer.fData = (void *) fBuffer.ConstPixel (buffer.fArea.t, |
| 205 |
buffer.fArea.l, |
| 206 |
buffer.fPlane); |
| 207 |
|
| 208 |
buffer.fDirty = dirty; |
| 209 |
|
| 210 |
} |
| 211 |
|
| 212 |
/*****************************************************************************/ |