Exemplo n.º 1
0
        public static void TransformImage(DisplayData currentPage, IntPtr outputRGBBuffer)
        {
            try
            {
                if (outputRGBBuffer == IntPtr.Zero)
                {
                    return;
                }

                PresentationState pstate = currentPage.PState;

                int renderWidth  = pstate.RenderWidth;
                int renderHeight = pstate.RenderHeight;

                int    samplesPerPixel     = currentPage.SamplesPerPixel;
                int    width               = currentPage.Width;
                int    height              = currentPage.Height;
                int    pixelBits           = currentPage.PixelBits;
                int    pixelRepresentation = currentPage.PixelRepresentation;
                double rescaleSlope        = currentPage.RescaleSlope;
                double rescaleIntercept    = currentPage.RescaleIntercept;

                //if a image is a original PET image, its SopClassUID is 1.2.840.10008.5.1.4.1.1.128, So we use bIsOriPT to describe
                //if a image, its Modality is PT and it's not a RGB image, we use bIsNotRGBPT to describe
                bool bIsOriPT       = (currentPage.SOPClassUID == "1.2.840.10008.5.1.4.1.1.128");
                bool bIsNotRGBPT    = (currentPage.Modality == Modality.PT && currentPage.SamplesPerPixel == 1);
                bool bIsPseudoColor = false;
                if (bIsOriPT)
                {
                    bIsPseudoColor = !(PresentationState.PalettesEqual(pstate.Palette, PresentationState.DefaultPalette) ||
                                       PresentationState.PalettesEqual(pstate.Palette, PresentationState.GetInversePalette(PresentationState.DefaultPalette)));
                }
                IntPtr imageDataPtr = currentPage.CreateSafePixelDataPtr();
                IntPtr imageMaskPtr = currentPage.CreateSafeMaskDataPtr();

                if (imageDataPtr != IntPtr.Zero)
                {
                    NativeMethods.ImageTransform(renderWidth, renderHeight,
                                                 0, 0, renderWidth, renderHeight, imageDataPtr, imageMaskPtr, outputRGBBuffer,
                                                 width, height, samplesPerPixel, pixelBits, pixelRepresentation, rescaleSlope, rescaleIntercept,
                                                 pstate.RotationClockwise, pstate.OffsetLeft, pstate.OffsetTop,
                                                 pstate.ScaleX, pstate.ScaleY, pstate.WindowLevel.WindowCenter,
                                                 pstate.WindowLevel.WindowWidth, pstate.EnhancePara, pstate.PaletteData,
                                                 (bIsOriPT && !bIsPseudoColor) ? !pstate.IsPaletteReversed : pstate.IsPaletteReversed,
                                                 (int)DisplayData.InterpMode.Bilinear, bIsNotRGBPT);
                }
                else
                {
                    int stride = (renderWidth * 3 % 4 == 0) ? (renderWidth * 3) : ((renderWidth * 3 / 4 + 1) * 4);
                    NativeMethods.MemSet(outputRGBBuffer, 0, (uint)(stride * renderHeight));
                }

                currentPage.FreeSafePixelDataPtr();
                currentPage.FreeSafeMaskDataPtr();
            }
            catch (Exception exp)
            {
                MedViewerLogger.Instance.LogDevError(MedViewerLogger.Source,
                                                     "Exception: " + exp.ToString());
            }
        }