Revision: 28721
          http://sourceforge.net/p/bibdesk/svn/28721
Author:   hofman
Date:     2024-02-10 16:51:32 +0000 (Sat, 10 Feb 2024)
Log Message:
-----------
copy image buffer data using property

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageUtilities.mm
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageBuffer.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageBuffer.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageUtilities.mm
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageUtilities.mm     
2024-02-10 16:07:42 UTC (rev 28720)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageUtilities.mm     
2024-02-10 16:51:32 UTC (rev 28721)
@@ -990,9 +990,7 @@
     // tell this buffer not to call free() when it deallocs, so we avoid 
copying the data
     CFDataRef data = NULL;
     if (kvImageNoError == ret) {
-        [interleavedImageBuffer setFreeBufferOnDealloc:NO];
-        CFAllocatorRef alloc = [interleavedImageBuffer allocator];
-        data = CFDataCreateWithBytesNoCopy(CFAllocatorGetDefault(), (uint8_t 
*)interleavedBuffer->data, interleavedBuffer->rowBytes * 
interleavedBuffer->height, alloc);
+        data = [interleavedImageBuffer copyBufferData];
     }
     
     // cleanup is safe now

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageBuffer.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageBuffer.h   2024-02-10 
16:07:42 UTC (rev 28720)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageBuffer.h   2024-02-10 
16:51:32 UTC (rev 28721)
@@ -86,16 +86,11 @@
  @return An initialized buffer instance. */
 - (id)initWithWidth:(size_t)w height:(size_t)h bytesPerSample:(size_t)bps;
 
-/** @internal @brief Byte buffer transfer.
- Pass NO to transfer ownership of the vImage data to e.g. CFData.  This is 
always set to YES for new instances.
- @param flag NO to allow another object to free the underlying vImage_Buffer 
data. */
-- (void)setFreeBufferOnDealloc:(BOOL)flag;
-
-/** @internal @brief FVImageBuffer allocator.
+/** @internal @brief Copy of the buffer data copy.
  
- If you set _freeBufferOnDealloc to NO, use this allocator to free 
buffer->data when you're finished with it.  Do not rely on this returning the 
same allocator for all instances.
- @return A CFAllocator instance. */
-@property (nonatomic, readonly) CFAllocatorRef allocator;
+ A CFDataRef copy wrapping buffer->data.  The data takes ownership of 
buffer->data, this instance will not free it whenthis is returned. This should 
be used at most once for each buffer.
+ @return A CFDataRef instance. */
+@property (nonatomic, readonly) CFDataRef copyBufferData;
 
 /** @internal @brief Internal buffer size.
  

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageBuffer.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageBuffer.m   2024-02-10 
16:07:42 UTC (rev 28720)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageBuffer.m   2024-02-10 
16:51:32 UTC (rev 28721)
@@ -47,8 +47,8 @@
 
 @implementation FVImageBuffer
 
-@dynamic allocator;
 @synthesize bufferSize=_bufferSize;
+@dynamic copyBufferData;
 
 + (uint64_t)allocatedBytes
 {
@@ -75,7 +75,7 @@
             buffer->height = 1;
             buffer->rowBytes = bufferSize;
             _bufferSize = bufferSize;
-            buffer->data = CFAllocatorAllocate([self allocator], bufferSize, 
0);
+            buffer->data = CFAllocatorAllocate(FVAllocatorGetDefault(), 
bufferSize, 0);
             FVAtomicAdd64(_allocatedBytes, _bufferSize);
             if (NULL == buffer->data) {
                 self = nil;
@@ -106,7 +106,6 @@
 - (id)copyWithZone:(NSZone *)aZone
 {
     FVImageBuffer *copy = [[[self class] allocWithZone:aZone] 
_initWithBufferSize:_bufferSize];
-    copy->_freeBufferOnDealloc = _freeBufferOnDealloc;
     copy->buffer->rowBytes = buffer->rowBytes;
     copy->buffer->height = buffer->height;
     copy->buffer->width = buffer->width;
@@ -116,16 +115,20 @@
 
 - (void)dealloc
 {
-    if (_freeBufferOnDealloc) CFAllocatorDeallocate([self allocator], 
buffer->data);
+    if (_freeBufferOnDealloc) CFAllocatorDeallocate(FVAllocatorGetDefault(), 
buffer->data);
     FVAtomicSub64(_allocatedBytes, _bufferSize);
     if (buffer != NULL) NSZoneFree(NULL, buffer);
 }
 
-- (void)setFreeBufferOnDealloc:(BOOL)flag;
+- (CFDataRef)copyBufferData;
 {
-    _freeBufferOnDealloc = flag;
+    // tell this buffer not to call free() when it deallocs, so we avoid 
copying the data
+    CFAllocatorRef alloc = kCFAllocatorNull;
+    if (_freeBufferOnDealloc) {
+        _freeBufferOnDealloc = NO;
+        alloc = FVAllocatorGetDefault();
+    }
+    return CFDataCreateWithBytesNoCopy(CFAllocatorGetDefault(), (uint8_t 
*)buffer->data, buffer->rowBytes * buffer->height, alloc);
 }
 
-- (CFAllocatorRef)allocator { return FVAllocatorGetDefault(); }
-
 @end

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to