1/*****************************************************************************/ 2// Copyright 2006-2008 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/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_simple_image.cpp#1 $ */ 10/* $DateTime: 2012/05/30 13:28:51 $ */ 11/* $Change: 832332 $ */ 12/* $Author: tknoll $ */ 13 14/*****************************************************************************/ 15 16#include "dng_simple_image.h" 17 18#include "dng_memory.h" 19#include "dng_orientation.h" 20#include "dng_tag_types.h" 21#include "dng_tag_values.h" 22 23/*****************************************************************************/ 24 25dng_simple_image::dng_simple_image (const dng_rect &bounds, 26 uint32 planes, 27 uint32 pixelType, 28 dng_memory_allocator &allocator) 29 30 : dng_image (bounds, 31 planes, 32 pixelType) 33 34 , fMemory () 35 , fAllocator (allocator) 36 37 { 38 39 uint32 bytes = 40 ComputeBufferSize (pixelType, bounds.Size (), planes, pad16Bytes); 41 42 fMemory.Reset (allocator.Allocate (bytes)); 43 44 fBuffer = dng_pixel_buffer (bounds, 0, planes, pixelType, pcInterleaved, fMemory->Buffer ()); 45 46 } 47 48/*****************************************************************************/ 49 50dng_simple_image::~dng_simple_image () 51 { 52 53 } 54 55/*****************************************************************************/ 56 57dng_image * dng_simple_image::Clone () const 58 { 59 60 AutoPtr<dng_simple_image> result (new dng_simple_image (Bounds (), 61 Planes (), 62 PixelType (), 63 fAllocator)); 64 65 result->fBuffer.CopyArea (fBuffer, 66 Bounds (), 67 0, 68 Planes ()); 69 70 return result.Release (); 71 72 } 73 74/*****************************************************************************/ 75 76void dng_simple_image::SetPixelType (uint32 pixelType) 77 { 78 79 dng_image::SetPixelType (pixelType); 80 81 fBuffer.fPixelType = pixelType; 82 83 } 84 85/*****************************************************************************/ 86 87void dng_simple_image::Trim (const dng_rect &r) 88 { 89 90 fBounds.t = 0; 91 fBounds.l = 0; 92 93 fBounds.b = r.H (); 94 fBounds.r = r.W (); 95 96 fBuffer.fData = fBuffer.DirtyPixel (r.t, r.l); 97 98 fBuffer.fArea = fBounds; 99 100 } 101 102/*****************************************************************************/ 103 104void dng_simple_image::Rotate (const dng_orientation &orientation) 105 { 106 107 int32 originH = fBounds.l; 108 int32 originV = fBounds.t; 109 110 int32 colStep = fBuffer.fColStep; 111 int32 rowStep = fBuffer.fRowStep; 112 113 uint32 width = fBounds.W (); 114 uint32 height = fBounds.H (); 115 116 if (orientation.FlipH ()) 117 { 118 119 originH += width - 1; 120 121 colStep = -colStep; 122 123 } 124 125 if (orientation.FlipV ()) 126 { 127 128 originV += height - 1; 129 130 rowStep = -rowStep; 131 132 } 133 134 if (orientation.FlipD ()) 135 { 136 137 int32 temp = colStep; 138 139 colStep = rowStep; 140 rowStep = temp; 141 142 width = fBounds.H (); 143 height = fBounds.W (); 144 145 } 146 147 fBuffer.fData = fBuffer.DirtyPixel (originV, originH); 148 149 fBuffer.fColStep = colStep; 150 fBuffer.fRowStep = rowStep; 151 152 fBounds.r = fBounds.l + width; 153 fBounds.b = fBounds.t + height; 154 155 fBuffer.fArea = fBounds; 156 157 } 158 159/*****************************************************************************/ 160 161void dng_simple_image::AcquireTileBuffer (dng_tile_buffer &buffer, 162 const dng_rect &area, 163 bool dirty) const 164 { 165 166 buffer.fArea = area; 167 168 buffer.fPlane = fBuffer.fPlane; 169 buffer.fPlanes = fBuffer.fPlanes; 170 buffer.fRowStep = fBuffer.fRowStep; 171 buffer.fColStep = fBuffer.fColStep; 172 buffer.fPlaneStep = fBuffer.fPlaneStep; 173 buffer.fPixelType = fBuffer.fPixelType; 174 buffer.fPixelSize = fBuffer.fPixelSize; 175 176 buffer.fData = (void *) fBuffer.ConstPixel (buffer.fArea.t, 177 buffer.fArea.l, 178 buffer.fPlane); 179 180 buffer.fDirty = dirty; 181 182 } 183 184/*****************************************************************************/ 185 186