MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / af_save_image_memory

Function af_save_image_memory

src/api/c/imageio.cpp:860–1037  ·  view source on GitHub ↗

Save an image to memory.

Source from the content-addressed store, hash-verified

858
859// Save an image to memory.
860af_err af_save_image_memory(void** ptr, const af_array in_,
861 const af_image_format format) {
862 try {
863 FreeImage_Module& _ = getFreeImagePlugin();
864
865 // set our own FreeImage error handler
866 _.FreeImage_SetOutputMessage(FreeImageErrorHandler);
867
868 // try to guess the file format from the file extension
869 auto fif = static_cast<FREE_IMAGE_FORMAT>(format);
870
871 if (fif == FIF_UNKNOWN || fif > 34) { // FreeImage FREE_IMAGE_FORMAT
872 // has upto 34 enums as of 3.17
873 AF_ERROR("FreeImage Error: Unknown Filetype", AF_ERR_NOT_SUPPORTED);
874 }
875
876 const ArrayInfo& info = getInfo(in_);
877 // check image color type
878 uint channels = info.dims()[2];
879 DIM_ASSERT(1, channels <= 4);
880 DIM_ASSERT(1, channels != 2);
881
882 uint fi_bpp = channels * 8;
883
884 // sizes
885 uint fi_w = info.dims()[1];
886 uint fi_h = info.dims()[0];
887
888 // create the result image storage using FreeImage
889 bitmap_ptr pResultBitmap = make_bitmap_ptr(_.FreeImage_Allocate(
890 fi_w, fi_h, static_cast<int>(fi_bpp), 0, 0, 0));
891 if (pResultBitmap == NULL) {
892 AF_ERROR("FreeImage Error: Error creating image or file",
893 AF_ERR_RUNTIME);
894 }
895
896 // FI assumes [0-255]
897 // If array is in 0-1 range, multiply by 255
898 af_array in;
899 double max_real, max_imag;
900 bool free_in = false;
901 AF_CHECK(af_max_all(&max_real, &max_imag, in_));
902 if (max_real <= 1) {
903 af_array c255;
904 AF_CHECK(af_constant(&c255, 255.0, info.ndims(), info.dims().get(),
905 f32));
906 AF_CHECK(af_mul(&in, in_, c255, false));
907 AF_CHECK(af_release_array(c255));
908 free_in = true;
909 } else {
910 in = in_;
911 }
912
913 // FI = row major | AF = column major
914 uint nDstPitch = _.FreeImage_GetPitch(pResultBitmap.get());
915 uchar* pDstLine =
916 _.FreeImage_GetBits(pResultBitmap.get()) + nDstPitch * (fi_h - 1);
917 af_array rr = 0, gg = 0, bb = 0, aa = 0;

Callers 1

saveImageMemFunction · 0.50

Calls 13

make_bitmap_ptrFunction · 0.85
af_max_allFunction · 0.85
af_mulFunction · 0.85
af_constantFunction · 0.70
af_release_arrayFunction · 0.70
channel_splitFunction · 0.70
af_transposeFunction · 0.70
af_get_data_ptrFunction · 0.70
pinnedFreeFunction · 0.50
dimsMethod · 0.45
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected