我正在使用dcmtk库来修改多帧压缩dicom图像的像素数据。所以,在一个`for`循环的某个阶段,我获取每个解压后的帧的像素数据并根据我的意愿进行修改,并尝试逐帧将每个修改后的像素数据连接在一起形成一个大的内存缓冲区。该`for`循环的核心过程如下。
问题是在第一次迭代之后,当我调用`getUncompressedFrame`函数时,代码行处会分配内存。我认为这是因为我在这一行中使用了`memcpy(fullBuffer+(i*sizeF),newBuffer,sizeF)`,因为当我删除该行时,在那个时候就没有错误,整个`for`循环也运行得非常好。
请问我在使用`memcpy`时是否犯了错误?谢谢。
问题是在第一次迭代之后,当我调用`getUncompressedFrame`函数时,代码行处会分配内存。我认为这是因为我在这一行中使用了`memcpy(fullBuffer+(i*sizeF),newBuffer,sizeF)`,因为当我删除该行时,在那个时候就没有错误,整个`for`循环也运行得非常好。
请问我在使用`memcpy`时是否犯了错误?谢谢。
Uint32 sizeF=828072;// I just wrote it to show what is the data type.
Uint8 * fullBuffer = new Uint8(int(sizeF*numOfFrames));//The big memory buffer
for(int i=0;i<numOfFrames;i++)
{
Uint8 * buffer = new Uint8[int(sizeF)];//Buffer for each frame
Uint8 * newBuffer = new Uint8[int(sizeF)];//Buffer in which the modified frame data is stored
DcmFileCache * cache=NULL;
OFCondition cond=element->getUncompressedFrame(dataset,i,startFragment,buffer,sizeF,decompressedColorModel,cache);
//I get the uncompressed individual frame pixel data
if(buffer != NULL)
{
for(unsigned long y = 0; y < rows; y++)
{
for(unsigned long x = 0; x < cols; x++)
{
if(planarConfiguration==0)
{
if(x>xmin && x<xmax && y>ymin && y<ymax)
{
index=(x + y + y*(cols-1))*samplePerPixel;
if(index<sizeF-2)
{
newBuffer[index] = 0;
newBuffer[index + 1] = 0;
newBuffer[index +2] = 0;
}
}
else
{
index=(x + y + y*(cols-1))*samplePerPixel;
if(index<sizeF-2)
{
newBuffer[index] = buffer[index];
newBuffer[index + 1] = buffer[index + 1];
newBuffer[index + 2] = buffer[index + 2];
}
}
}
}
}
memcpy(fullBuffer+(i*sizeF),newBuffer,sizeF);
//concatenate the modified frame by frame pixel data
}
i
和sizeF
的值是否正确。如果它没有停止,那么设置一个断点。 - Some programmer dude