Changeset 14921
- Timestamp:
- Sep 20, 2007, 1:48:47 PM (19 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 2 edited
-
imageops/psImageStructManip.c (modified) (7 diffs)
-
mathtypes/psImage.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageStructManip.c
r14523 r14921 8 8 * @author Robert DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $11 * @date $Date: 2007-0 8-16 02:51:09$10 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2007-09-20 23:48:47 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 23 23 24 24 #include "psMemory.h" 25 #include "psError.h" 26 #include "psAbort.h" 27 25 28 #include "psImageStructManip.h" 26 #include "psError.h"27 28 29 29 30 // col0,row0 are the starting pixel in the input image coordinate frame … … 98 99 if (out != NULL) { 99 100 // if a child, need to orphan (disassociate from parent) first 100 if (out->parent != NULL) { 101 psArrayRemoveData(out->parent->children,psMemIncrRefCounter(out)); 102 // remove from parent's knowledge without triggering a free 103 out->parent = NULL; // break link to parent 101 psImage *parent = (psImage *) out->parent; 102 if (parent != NULL) { 103 // break the back-pointer first so we don't loop 104 out->parent = NULL; 105 106 // drop my entry on my parent's array of children 107 psArrayRemoveDataNoFree (out->parent->children, out); 108 109 // drop my reference to my old parent 110 psFree (parent); 104 111 } 105 112 113 // we recycle out->data.V 106 114 psFree(out->p_rawDataBuffer); // free the previous data reference 107 115 } else { … … 117 125 P_PSIMAGE_SET_ROW0(out, row0); 118 126 119 out->parent = image;127 out->parent = psMemIncrRefCounter(image); // track references to parents 120 128 out->children = NULL; 121 129 out->p_rawDataBuffer = rawData; … … 133 141 134 142 // add output image as a child of the input image. 135 image->children = psArrayAdd (image->children,16,out);136 ps MemDecrRefCounter(out); // don't count the reference held by parent as a true reference143 image->children = psArrayAdd (image->children, 16, out); 144 psFree (out); // the image->children array is an array of views only 137 145 138 146 return (out); … … 307 315 _("Can not operate on a NULL psImage.")); 308 316 return NULL; 317 } 318 319 if ((image->children != NULL) && (image->children->n > 0)) { 320 psAbort ("cannot trim an image with outstanding children"); 309 321 } 310 322 … … 345 357 } 346 358 347 psImageFreeChildren(image);348 349 359 psU32 elementSize = PSELEMTYPE_SIZEOF(image->type.type); 350 360 psU32 numCols = col1-col0; -
trunk/psLib/src/mathtypes/psImage.c
r12813 r14921 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.1 29$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-0 4-12 18:52:57$11 * @version $Revision: 1.130 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-09-20 23:48:30 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 28 28 #include "psError.h" 29 29 #include "psAssert.h" 30 #include "psAbort.h" 31 30 32 #include "psImage.h" 31 33 #include "psString.h" … … 38 40 } 39 41 40 if (image->parent != NULL) { 41 psMemBlock* ptr = ((psMemBlock*)image)-1; 42 int ref = ptr->refCounter; 43 ptr->refCounter = 2; // make sure psFree is not retriggered 44 psArrayRemoveData(image->parent->children,image); 45 ptr->refCounter = ref; // restore previous count (not assuming zero, but should be) 46 47 image->parent = NULL; 48 } 49 50 psImageFreeChildren(image); 51 42 psImage *parent = (psImage *) image->parent; 43 44 // if I am a child, remove me from my parent's array of children 45 if (parent != NULL) { 46 // sanity check : a child cannot also be a parent 47 if ((image->children != NULL) && (image->children->n > 0)) { 48 psAbort ("psImage cannot be both child and parent!"); 49 } 50 51 // break the back-pointer first so we don't loop 52 image->parent = NULL; 53 54 // drop my entry on my parent's array of children 55 psArrayRemoveDataNoFree (parent->children, image); 56 57 // drop my reference to my parent 58 psFree (parent); 59 } 60 61 // sanity check: this function should never be reached if an image still has live children; 62 // they should each be holding a pointer to the image, forcing the number of references to 63 // be > 1. 64 if (image->children && (image->children->n > 0)) { 65 psAbort ("psImage memory management programming error : imageFree called on image with live children"); 66 } 67 68 psFree(image->children); 52 69 psFree(image->p_rawDataBuffer); 53 70 psFree(image->data.V); … … 524 541 } 525 542 526 527 int psImageFreeChildren(psImage* image)528 {529 psS32 numFreed = 0;530 531 if (image == NULL) {532 return numFreed;533 }534 535 if (image->children != NULL) {536 psImage** children = (psImage**)image->children->data;537 numFreed = image->children->n;538 539 // orphan the children first540 // (so psFree doesn't try to modify the parent's children array while I'm using it)541 for (psS32 i=0;i<numFreed;i++) {542 children[i]->parent = NULL;543 }544 545 psFree(image->children);546 image->children = NULL;547 }548 549 return numFreed;550 }551 552 543 bool p_psImagePrint (int fd, 553 544 psImage *a,
Note:
See TracChangeset
for help on using the changeset viewer.
