MCPcopy Create free account
hub / github.com/Kitware/VTK / PrepareImageData

Method PrepareImageData

IO/ExportPDF/vtkPDFContextDevice2D.cxx:1857–1925  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1855
1856//------------------------------------------------------------------------------
1857vtkImageData* vtkPDFContextDevice2D::PrepareImageData(vtkImageData* in)
1858{
1859 int numComps = in->GetNumberOfScalarComponents();
1860
1861 // We'll only handle RGB / RGBA:
1862 if (numComps != 3 && numComps != 4)
1863 {
1864 vtkWarningMacro("Images with " << numComps << " components not supported.");
1865 return nullptr;
1866 }
1867
1868 // Need to convert scalar type?
1869 if (in->GetScalarType() != VTK_UNSIGNED_CHAR)
1870 {
1871 vtkNew<vtkImageCast> cast;
1872 cast->SetInputData(in);
1873 cast->SetOutputScalarTypeToUnsignedChar();
1874 cast->Update();
1875 in = cast->GetOutput();
1876 in->Register(this);
1877 }
1878 else
1879 {
1880 in->Register(this); // Keep refcounts consistent
1881 }
1882
1883 if (in->GetNumberOfScalarComponents() == 4)
1884 { // If RGBA, blend into brush color -- Haru doesn't support RGBA.
1885
1886 vtkNew<vtkImageData> background;
1887 { // Fill the background image with brush color, saturate alpha
1888 std::array<unsigned char, 4> bgColor;
1889 this->Brush->GetColor(bgColor.data());
1890 bgColor[3] = 255; // Saturate alpha
1891 background->SetExtent(in->GetExtent());
1892 background->AllocateScalars(VTK_UNSIGNED_CHAR, 4);
1893 auto* scalars = vtkUnsignedCharArray::SafeDownCast(background->GetPointData()->GetScalars());
1894 for (int comp = 0; comp < 4; ++comp)
1895 {
1896 scalars->FillComponent(comp, bgColor[comp]);
1897 }
1898 }
1899
1900 // Blend the input image over the background color:
1901 vtkNew<vtkImageBlend> blender;
1902 blender->AddInputData(0, background);
1903 blender->AddInputData(0, in);
1904 in->UnRegister(this); // Remove ref++ from above
1905 blender->SetBlendModeToNormal();
1906
1907 vtkNew<vtkImageExtractComponents> extract;
1908 extract->SetInputConnection(blender->GetOutputPort(0));
1909 extract->SetComponents(0, 1, 2);
1910 extract->Update();
1911 in = extract->GetOutput();
1912 in->Register(this);
1913 }
1914

Callers 5

DrawPointSpritesMethod · 0.95
DrawImageMethod · 0.95
FillTextureMethod · 0.95
RequestDataMethod · 0.45
RequestDataMethod · 0.45

Calls 15

FillComponentMethod · 0.80
SetComponentsMethod · 0.80
GetScalarTypeMethod · 0.45
SetInputDataMethod · 0.45
UpdateMethod · 0.45
GetOutputMethod · 0.45
RegisterMethod · 0.45
GetColorMethod · 0.45
dataMethod · 0.45
SetExtentMethod · 0.45
GetExtentMethod · 0.45

Tested by

no test coverage detected