TRAVIS_OS_NAME=linux TRAVIS_PYTHON_VERSION=3.7 <<<<<< ENV .appveyor.yml .ci/after_success.sh .ci/build.sh .ci/install.sh .ci/test.sh .coveragerc .editorconfig .gitattributes .github/CONTRIBUTING.md .github/FUNDING.yml .github/ISSUE_TEMPLATE/ISSUE_REPORT.md .github/PULL_REQUEST_TEMPLATE.md .github/SECURITY.md .github/mergify.yml .github/workflows/lint.yml .github/workflows/macos-install.sh .github/workflows/system-info.py .github/workflows/test-docker.yml .github/workflows/test-windows.yml .github/workflows/test.yml .gitignore .pre-commit-config.yaml .readthedocs.yml .travis.yml CHANGES.rst LICENSE MANIFEST.in Makefile README.md RELEASING.md Tests/32bit_segfault_check.py Tests/README.rst Tests/__init__.py Tests/bench_cffi_access.py Tests/check_fli_oob.py Tests/check_fli_overflow.py Tests/check_icns_dos.py Tests/check_imaging_leaks.py Tests/check_j2k_dos.py Tests/check_j2k_leaks.py Tests/check_j2k_overflow.py Tests/check_jp2_overflow.py Tests/check_jpeg_leaks.py Tests/check_large_memory.py Tests/check_large_memory_numpy.py Tests/check_libtiff_segfault.py Tests/check_png_dos.py Tests/conftest.py Tests/createfontdatachunk.py Tests/fonts/10x20-ISO8859-1.pcf Tests/fonts/10x20.pbm Tests/fonts/10x20.pil Tests/fonts/AdobeVFPrototype.ttf Tests/fonts/ArefRuqaa-Regular.ttf Tests/fonts/BungeeColor-Regular_colr_Windows.ttf Tests/fonts/DejaVuSans-24-1-stripped.ttf Tests/fonts/DejaVuSans-24-2-stripped.ttf Tests/fonts/DejaVuSans-24-4-stripped.ttf Tests/fonts/DejaVuSans-24-8-stripped.ttf Tests/fonts/DejaVuSans.ttf Tests/fonts/FreeMono.ttf Tests/fonts/KhmerOSBattambang-Regular.ttf Tests/fonts/LICENSE.txt Tests/fonts/NotoColorEmoji.ttf Tests/fonts/NotoNastaliqUrdu-Regular.ttf Tests/fonts/NotoSans-Regular.ttf Tests/fonts/NotoSansJP-Regular.otf Tests/fonts/NotoSansSymbols-Regular.ttf Tests/fonts/OpenSansCondensed-LightItalic.ttf Tests/fonts/TINY5x3GX.ttf Tests/fonts/ter-x20b-cp1250.pbm Tests/fonts/ter-x20b-cp1250.pil Tests/fonts/ter-x20b-iso8859-1.pbm Tests/fonts/ter-x20b-iso8859-1.pil Tests/fonts/ter-x20b-iso8859-2.pbm Tests/fonts/ter-x20b-iso8859-2.pil Tests/fonts/ter-x20b.pcf Tests/helper.py Tests/icc/LICENSE.txt Tests/icc/sRGB_IEC61966-2-1_black_scaled.icc Tests/icc/sRGB_v4_ICC_preference.icc Tests/images/00r0_gray_l.jp2 Tests/images/00r1_graya_la.jp2 Tests/images/01r_00.pcx Tests/images/10ct_32bit_128.tiff Tests/images/12bit.cropped.tif Tests/images/12in16bit.tif Tests/images/16_bit_binary.pgm Tests/images/16_bit_binary_pgm.png Tests/images/16_bit_noise.tif Tests/images/16bit.MM.cropped.tif Tests/images/16bit.MM.deflate.tif Tests/images/16bit.cropped.j2k Tests/images/16bit.cropped.jp2 Tests/images/16bit.cropped.tif Tests/images/16bit.deflate.tif Tests/images/16bit.s.tif Tests/images/1_trns.png Tests/images/7x13.png Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.dds Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.png Tests/images/DXGI_FORMAT_R8G8B8A8_UNORM_SRGB.dds Tests/images/DXGI_FORMAT_R8G8B8A8_UNORM_SRGB.png Tests/images/WAlaska.wind.7days.grb Tests/images/a.fli Tests/images/a_fli.png Tests/images/anim_frame1.webp Tests/images/anim_frame2.webp Tests/images/apng/blend_op_over.png Tests/images/apng/blend_op_over_near_transparent.png Tests/images/apng/blend_op_source_near_transparent.png Tests/images/apng/blend_op_source_solid.png Tests/images/apng/blend_op_source_transparent.png Tests/images/apng/chunk_actl_after_idat.png Tests/images/apng/chunk_multi_actl.png Tests/images/apng/chunk_no_actl.png Tests/images/apng/chunk_no_fctl.png Tests/images/apng/chunk_no_fdat.png Tests/images/apng/chunk_repeat_fctl.png Tests/images/apng/delay.png Tests/images/apng/delay_round.png Tests/images/apng/delay_short_max.png Tests/images/apng/delay_zero_denom.png Tests/images/apng/delay_zero_numer.png Tests/images/apng/dispose_op_background.png Tests/images/apng/dispose_op_background_before_region.png Tests/images/apng/dispose_op_background_final.png Tests/images/apng/dispose_op_background_p_mode.png Tests/images/apng/dispose_op_background_region.png Tests/images/apng/dispose_op_none.png Tests/images/apng/dispose_op_none_region.png Tests/images/apng/dispose_op_previous.png Tests/images/apng/dispose_op_previous_final.png Tests/images/apng/dispose_op_previous_first.png Tests/images/apng/dispose_op_previous_region.png Tests/images/apng/fctl_actl.png Tests/images/apng/mode_16bit.png Tests/images/apng/mode_greyscale.png Tests/images/apng/mode_greyscale_alpha.png Tests/images/apng/mode_palette.png Tests/images/apng/mode_palette_1bit_alpha.png Tests/images/apng/mode_palette_alpha.png Tests/images/apng/num_plays.png Tests/images/apng/num_plays_1.png Tests/images/apng/sequence_fdat_fctl.png Tests/images/apng/sequence_gap.png Tests/images/apng/sequence_reorder.png Tests/images/apng/sequence_reorder_chunk.png Tests/images/apng/sequence_repeat.png Tests/images/apng/sequence_repeat_chunk.png Tests/images/apng/sequence_start.png Tests/images/apng/single_frame.png Tests/images/apng/single_frame_default.png Tests/images/apng/split_fdat.png Tests/images/apng/split_fdat_zero_chunk.png Tests/images/apng/syntax_num_frames_high.png Tests/images/apng/syntax_num_frames_invalid.png Tests/images/apng/syntax_num_frames_low.png Tests/images/apng/syntax_num_frames_zero.png Tests/images/apng/syntax_num_frames_zero_default.png Tests/images/app13-multiple.jpg Tests/images/app13.jpg Tests/images/argb-32bpp_MipMaps-1.dds Tests/images/argb-32bpp_MipMaps-1.png Tests/images/bad_palette_entry.gpl Tests/images/bad_palette_file.gpl Tests/images/balloon.jpf Tests/images/bc7-argb-8bpp_MipMaps-1.dds Tests/images/bc7-argb-8bpp_MipMaps-1.png Tests/images/binary_preview_map.eps Tests/images/bitmap_font_1_basic.png Tests/images/bitmap_font_1_raqm.png Tests/images/bitmap_font_2_basic.png Tests/images/bitmap_font_2_raqm.png Tests/images/bitmap_font_4_basic.png Tests/images/bitmap_font_4_raqm.png Tests/images/bitmap_font_8_basic.png Tests/images/bitmap_font_8_raqm.png Tests/images/blp/blp1_jpeg.blp Tests/images/blp/blp2_dxt1.blp Tests/images/blp/blp2_dxt1.png Tests/images/blp/blp2_dxt1a.blp Tests/images/blp/blp2_dxt1a.png Tests/images/blp/blp2_raw.blp Tests/images/blp/blp2_raw.png Tests/images/bmp/README.txt Tests/images/bmp/b/badbitcount.bmp Tests/images/bmp/b/badbitssize.bmp Tests/images/bmp/b/baddens1.bmp Tests/images/bmp/b/baddens2.bmp Tests/images/bmp/b/badfilesize.bmp Tests/images/bmp/b/badheadersize.bmp Tests/images/bmp/b/badpalettesize.bmp Tests/images/bmp/b/badplanes.bmp Tests/images/bmp/b/badrle.bmp Tests/images/bmp/b/badwidth.bmp Tests/images/bmp/b/pal8badindex.bmp Tests/images/bmp/b/reallybig.bmp Tests/images/bmp/b/rletopdown.bmp Tests/images/bmp/b/shortfile.bmp Tests/images/bmp/g/pal1.bmp Tests/images/bmp/g/pal1bg.bmp Tests/images/bmp/g/pal1wb.bmp Tests/images/bmp/g/pal4.bmp Tests/images/bmp/g/pal4rle.bmp Tests/images/bmp/g/pal8-0.bmp Tests/images/bmp/g/pal8.bmp Tests/images/bmp/g/pal8nonsquare.bmp Tests/images/bmp/g/pal8os2.bmp Tests/images/bmp/g/pal8rle.bmp Tests/images/bmp/g/pal8topdown.bmp Tests/images/bmp/g/pal8v4.bmp Tests/images/bmp/g/pal8v5.bmp Tests/images/bmp/g/pal8w124.bmp Tests/images/bmp/g/pal8w125.bmp Tests/images/bmp/g/pal8w126.bmp Tests/images/bmp/g/rgb16-565.bmp Tests/images/bmp/g/rgb16-565pal.bmp Tests/images/bmp/g/rgb16.bmp Tests/images/bmp/g/rgb24.bmp Tests/images/bmp/g/rgb24pal.bmp Tests/images/bmp/g/rgb32.bmp Tests/images/bmp/g/rgb32bf.bmp Tests/images/bmp/html/bkgd.png Tests/images/bmp/html/bmpsuite.html Tests/images/bmp/html/fakealpha.png Tests/images/bmp/html/pal1.png Tests/images/bmp/html/pal1bg.png Tests/images/bmp/html/pal1p1.png Tests/images/bmp/html/pal2.png Tests/images/bmp/html/pal4.png Tests/images/bmp/html/pal4rletrns-0.png Tests/images/bmp/html/pal4rletrns-b.png Tests/images/bmp/html/pal4rletrns.png Tests/images/bmp/html/pal8.png Tests/images/bmp/html/pal8nonsquare-e.png Tests/images/bmp/html/pal8nonsquare-v.png Tests/images/bmp/html/pal8rletrns-0.png Tests/images/bmp/html/pal8rletrns-b.png Tests/images/bmp/html/pal8rletrns.png Tests/images/bmp/html/pal8w124.png Tests/images/bmp/html/pal8w125.png Tests/images/bmp/html/pal8w126.png Tests/images/bmp/html/rgb16-231.png Tests/images/bmp/html/rgb16-565.png Tests/images/bmp/html/rgb16.png Tests/images/bmp/html/rgb24.jpg Tests/images/bmp/html/rgb24.png Tests/images/bmp/html/rgba16-4444.png Tests/images/bmp/html/rgba32.png Tests/images/bmp/q/pal1p1.bmp Tests/images/bmp/q/pal2.bmp Tests/images/bmp/q/pal4rletrns.bmp Tests/images/bmp/q/pal8offs.bmp Tests/images/bmp/q/pal8os2sp.bmp Tests/images/bmp/q/pal8os2v2-16.bmp Tests/images/bmp/q/pal8os2v2.bmp Tests/images/bmp/q/pal8oversizepal.bmp Tests/images/bmp/q/pal8rletrns.bmp Tests/images/bmp/q/rgb16-231.bmp Tests/images/bmp/q/rgb24jpeg.bmp Tests/images/bmp/q/rgb24largepal.bmp Tests/images/bmp/q/rgb24lprof.bmp Tests/images/bmp/q/rgb24png.bmp Tests/images/bmp/q/rgb24prof.bmp Tests/images/bmp/q/rgb32-111110.bmp Tests/images/bmp/q/rgb32bf-xbgr.bmp Tests/images/bmp/q/rgb32fakealpha.bmp Tests/images/bmp/q/rgba16-4444.bmp Tests/images/bmp/q/rgba32.bmp Tests/images/bmp/q/rgba32abf.bmp Tests/images/broken.png Tests/images/broken_data_stream.png Tests/images/bw_gradient.png Tests/images/caption_6_33_22.png Tests/images/cbdt_notocoloremoji.png Tests/images/cbdt_notocoloremoji_mask.png Tests/images/chi.gif Tests/images/clipboard.dib Tests/images/clipboard_target.png Tests/images/cmx3g8_wv_1998.260_0745_mcidas.ara Tests/images/cmx3g8_wv_1998.260_0745_mcidas.png Tests/images/color_snakes.png Tests/images/colr_bungee.png Tests/images/colr_bungee_mask.png Tests/images/combined_larger_than_size.psd Tests/images/compression.tif Tests/images/copyleft.png Tests/images/copyleft.tiff Tests/images/corner.lut Tests/images/courB08.bdf Tests/images/courB08.pbm Tests/images/courB08.pil Tests/images/create_eps.gnuplot Tests/images/custom_gimp_palette.gpl Tests/images/decompression_bomb.gif Tests/images/decompression_bomb.ico Tests/images/deerstalker.cur Tests/images/default_font.png Tests/images/dilation4.lut Tests/images/dilation8.lut Tests/images/dispose_bgnd.gif Tests/images/dispose_none.gif Tests/images/dispose_prev.gif Tests/images/drawing.emf Tests/images/drawing.wmf Tests/images/drawing_emf_ref.png Tests/images/drawing_roundDown.emf Tests/images/drawing_wmf_ref.png Tests/images/drawing_wmf_ref_144.png Tests/images/dummy.container Tests/images/dxt1-rgb-4bbp-noalpha_MipMaps-1.dds Tests/images/dxt1-rgb-4bbp-noalpha_MipMaps-1.png Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.dds Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.png Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.dds Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.png Tests/images/edge.lut Tests/images/effect_mandelbrot.png Tests/images/effect_spread.png Tests/images/empty_gps_ifd.jpg Tests/images/erosion4.lut Tests/images/erosion8.lut Tests/images/exif-200dpcm.jpg Tests/images/exif-72dpi-int.jpg Tests/images/exif-dpi-zerodivision.jpg Tests/images/exif-ifd-offset.jpg Tests/images/exif.png Tests/images/exif_gps.jpg Tests/images/exif_gps_typeerror.jpg Tests/images/exif_imagemagick.png Tests/images/exif_text.png Tests/images/exif_typeerror.jpg Tests/images/fli_oob/02r/02r00.fli Tests/images/fli_oob/02r/notes Tests/images/fli_oob/02r/others/02r01.fli Tests/images/fli_oob/02r/others/02r02.fli Tests/images/fli_oob/02r/others/02r03.fli Tests/images/fli_oob/02r/others/02r04.fli Tests/images/fli_oob/02r/reproducing Tests/images/fli_oob/03r/03r00.fli Tests/images/fli_oob/03r/notes Tests/images/fli_oob/03r/others/03r01.fli Tests/images/fli_oob/03r/others/03r02.fli Tests/images/fli_oob/03r/others/03r03.fli Tests/images/fli_oob/03r/others/03r04.fli Tests/images/fli_oob/03r/others/03r05.fli Tests/images/fli_oob/03r/others/03r06.fli Tests/images/fli_oob/03r/others/03r07.fli Tests/images/fli_oob/03r/others/03r08.fli Tests/images/fli_oob/03r/others/03r09.fli Tests/images/fli_oob/03r/others/03r10.fli Tests/images/fli_oob/03r/others/03r11.fli Tests/images/fli_oob/03r/reproducing Tests/images/fli_oob/04r/04r00.fli Tests/images/fli_oob/04r/initial.fli Tests/images/fli_oob/04r/notes Tests/images/fli_oob/04r/others/04r01.fli Tests/images/fli_oob/04r/others/04r02.fli Tests/images/fli_oob/04r/others/04r03.fli Tests/images/fli_oob/04r/others/04r04.fli Tests/images/fli_oob/04r/others/04r05.fli Tests/images/fli_oob/04r/reproducing Tests/images/fli_oob/05r/05r00.fli Tests/images/fli_oob/05r/notes Tests/images/fli_oob/05r/others/05r01.fli Tests/images/fli_oob/05r/others/05r02.fli Tests/images/fli_oob/05r/others/05r03.fli Tests/images/fli_oob/05r/others/05r04.fli Tests/images/fli_oob/05r/others/05r05.fli Tests/images/fli_oob/05r/others/05r06.fli Tests/images/fli_oob/05r/others/05r07.fli Tests/images/fli_oob/05r/reproducing Tests/images/fli_oob/06r/06r00.fli Tests/images/fli_oob/06r/notes Tests/images/fli_oob/06r/others/06r01.fli Tests/images/fli_oob/06r/others/06r02.fli Tests/images/fli_oob/06r/others/06r03.fli Tests/images/fli_oob/06r/others/06r04.fli Tests/images/fli_oob/06r/reproducing Tests/images/fli_oob/patch0/000000 Tests/images/fli_oob/patch0/000001 Tests/images/fli_oob/patch0/000002 Tests/images/fli_oob/patch0/000003 Tests/images/fli_overflow.fli Tests/images/fli_overrun.bin Tests/images/fli_overrun2.bin Tests/images/flower.jpg Tests/images/flower.webp Tests/images/flower2.jpg Tests/images/flower2.webp Tests/images/frozenpond.mpo Tests/images/ftex_dxt1.ftc Tests/images/ftex_dxt1.png Tests/images/ftex_uncompressed.ftu Tests/images/ftex_uncompressed.png Tests/images/fujifilm.mpo Tests/images/g4-fillorder-test.png Tests/images/g4-fillorder-test.tif Tests/images/g4-multi.tiff Tests/images/g4_orientation_1.tif Tests/images/g4_orientation_2.tif Tests/images/g4_orientation_3.tif Tests/images/g4_orientation_4.tif Tests/images/g4_orientation_5.tif Tests/images/g4_orientation_6.tif Tests/images/g4_orientation_7.tif Tests/images/g4_orientation_8.tif Tests/images/gbr.gbr Tests/images/gbr.png Tests/images/gfs.t06z.rassda.tm00.bufr_d Tests/images/gif_header_data.pkl Tests/images/gimp_gradient.ggr Tests/images/gimp_gradient_with_name.ggr Tests/images/hdf5.h5 Tests/images/high_ascii_chars.png Tests/images/hopper-XYZ.png Tests/images/hopper.Lab.tif Tests/images/hopper.bmp Tests/images/hopper.bw Tests/images/hopper.dcx Tests/images/hopper.fits Tests/images/hopper.fli Tests/images/hopper.gd Tests/images/hopper.gif Tests/images/hopper.iccprofile.tif Tests/images/hopper.iccprofile_binary.tif Tests/images/hopper.ico Tests/images/hopper.im Tests/images/hopper.jpg Tests/images/hopper.mic Tests/images/hopper.msp Tests/images/hopper.p7 Tests/images/hopper.pcd Tests/images/hopper.png Tests/images/hopper.pnm Tests/images/hopper.ppm Tests/images/hopper.psd Tests/images/hopper.pxr Tests/images/hopper.ras Tests/images/hopper.rgb Tests/images/hopper.sgi Tests/images/hopper.spider Tests/images/hopper.tar Tests/images/hopper.tif Tests/images/hopper.wal Tests/images/hopper.webp Tests/images/hopper.xbm Tests/images/hopper.xpm Tests/images/hopper16.rgb Tests/images/hopper_16bit_qtables.jpg Tests/images/hopper_256x256.ico Tests/images/hopper_45.png Tests/images/hopper_bad.p7 Tests/images/hopper_bad_checksum.msp Tests/images/hopper_bad_exif.jpg Tests/images/hopper_bw_500.png Tests/images/hopper_draw.ico Tests/images/hopper_emboss.bmp Tests/images/hopper_emboss_more.bmp Tests/images/hopper_g4.tif Tests/images/hopper_g4_500.tif Tests/images/hopper_gray.jpg Tests/images/hopper_gray_4bpp.tif Tests/images/hopper_idat_after_image_end.png Tests/images/hopper_jpg.tif Tests/images/hopper_long_name.im Tests/images/hopper_lzw.tif Tests/images/hopper_merged.psd Tests/images/hopper_orientation_2.jpg Tests/images/hopper_orientation_2.webp Tests/images/hopper_orientation_3.jpg Tests/images/hopper_orientation_3.webp Tests/images/hopper_orientation_4.jpg Tests/images/hopper_orientation_4.webp Tests/images/hopper_orientation_5.jpg Tests/images/hopper_orientation_5.webp Tests/images/hopper_orientation_6.jpg Tests/images/hopper_orientation_6.webp Tests/images/hopper_orientation_7.jpg Tests/images/hopper_orientation_7.webp Tests/images/hopper_orientation_8.jpg Tests/images/hopper_orientation_8.webp Tests/images/hopper_roundDown.bmp Tests/images/hopper_roundDown_2.tif Tests/images/hopper_roundDown_3.tif Tests/images/hopper_roundDown_None.tif Tests/images/hopper_roundUp_2.tif Tests/images/hopper_roundUp_3.tif Tests/images/hopper_roundUp_None.tif Tests/images/hopper_underscore.xbm Tests/images/hopper_unexpected.ico Tests/images/hopper_unknown_pixel_mode.tif Tests/images/hopper_webp_bits.ppm Tests/images/hopper_webp_write.ppm Tests/images/hopper_zero_comment_subblocks.gif Tests/images/i_trns.png Tests/images/icc-after-SOF.jpg Tests/images/icc_profile.png Tests/images/icc_profile_big.jpg Tests/images/icc_profile_none.png Tests/images/ifd_tag_type.tiff Tests/images/illu10_no_preview.eps Tests/images/illu10_preview.eps Tests/images/illuCS6_no_preview.eps Tests/images/illuCS6_preview.eps Tests/images/imagedraw/line_horizontal_slope1px_w2px.png Tests/images/imagedraw/line_horizontal_w101px.png Tests/images/imagedraw/line_horizontal_w2px_inverted.png Tests/images/imagedraw/line_horizontal_w2px_normal.png Tests/images/imagedraw/line_horizontal_w3px.png Tests/images/imagedraw/line_oblique_45_w3px_a.png Tests/images/imagedraw/line_oblique_45_w3px_b.png Tests/images/imagedraw/line_vertical_slope1px_w2px.png Tests/images/imagedraw/line_vertical_w101px.png Tests/images/imagedraw/line_vertical_w2px_inverted.png Tests/images/imagedraw/line_vertical_w2px_normal.png Tests/images/imagedraw/line_vertical_w3px.png Tests/images/imagedraw/square.png Tests/images/imagedraw/triangle_right.png Tests/images/imagedraw2_text.png Tests/images/imagedraw_arc.png Tests/images/imagedraw_arc_end_le_start.png Tests/images/imagedraw_arc_high.png Tests/images/imagedraw_arc_no_loops.png Tests/images/imagedraw_arc_width.png Tests/images/imagedraw_arc_width_fill.png Tests/images/imagedraw_arc_width_non_whole_angle.png Tests/images/imagedraw_arc_width_pieslice.png Tests/images/imagedraw_big_rectangle.png Tests/images/imagedraw_bitmap.png Tests/images/imagedraw_chord_L.png Tests/images/imagedraw_chord_RGB.png Tests/images/imagedraw_chord_too_fat.png Tests/images/imagedraw_chord_width.png Tests/images/imagedraw_chord_width_fill.png Tests/images/imagedraw_chord_zero_width.png Tests/images/imagedraw_ellipse_L.png Tests/images/imagedraw_ellipse_RGB.png Tests/images/imagedraw_ellipse_edge.png Tests/images/imagedraw_ellipse_translucent.png Tests/images/imagedraw_ellipse_various_sizes.png Tests/images/imagedraw_ellipse_various_sizes_filled.png Tests/images/imagedraw_ellipse_width.png Tests/images/imagedraw_ellipse_width_fill.png Tests/images/imagedraw_ellipse_width_large.png Tests/images/imagedraw_ellipse_zero_width.png Tests/images/imagedraw_floodfill2.png Tests/images/imagedraw_floodfill_L.png Tests/images/imagedraw_floodfill_RGB.png Tests/images/imagedraw_floodfill_RGBA.png Tests/images/imagedraw_floodfill_not_negative.png Tests/images/imagedraw_line.png Tests/images/imagedraw_line_joint_curve.png Tests/images/imagedraw_outline_chord_L.png Tests/images/imagedraw_outline_chord_RGB.png Tests/images/imagedraw_outline_ellipse_L.png Tests/images/imagedraw_outline_ellipse_RGB.png Tests/images/imagedraw_outline_pieslice_L.png Tests/images/imagedraw_outline_pieslice_RGB.png Tests/images/imagedraw_outline_polygon_L.png Tests/images/imagedraw_outline_polygon_RGB.png Tests/images/imagedraw_outline_rectangle_L.png Tests/images/imagedraw_outline_rectangle_RGB.png Tests/images/imagedraw_outline_shape_L.png Tests/images/imagedraw_outline_shape_RGB.png Tests/images/imagedraw_pieslice.png Tests/images/imagedraw_pieslice_wide.png Tests/images/imagedraw_pieslice_width.png Tests/images/imagedraw_pieslice_width_fill.png Tests/images/imagedraw_pieslice_zero_width.png Tests/images/imagedraw_point.png Tests/images/imagedraw_polygon.png Tests/images/imagedraw_polygon_1px_high.png Tests/images/imagedraw_polygon_kite_L.png Tests/images/imagedraw_polygon_kite_RGB.png Tests/images/imagedraw_rectangle.png Tests/images/imagedraw_rectangle_I.png Tests/images/imagedraw_rectangle_width.png Tests/images/imagedraw_rectangle_width_fill.png Tests/images/imagedraw_rectangle_zero_width.png Tests/images/imagedraw_regular_octagon.png Tests/images/imagedraw_shape1.png Tests/images/imagedraw_shape2.png Tests/images/imagedraw_square.png Tests/images/imagedraw_square_rotate_45.png Tests/images/imagedraw_stroke_descender.png Tests/images/imagedraw_stroke_different.png Tests/images/imagedraw_stroke_multiline.png Tests/images/imagedraw_stroke_same.png Tests/images/imagedraw_wide_line_dot.png Tests/images/imagedraw_wide_line_larger_than_int.png Tests/images/imageops_pad_h_0.jpg Tests/images/imageops_pad_h_1.jpg Tests/images/imageops_pad_h_2.jpg Tests/images/imageops_pad_v_0.jpg Tests/images/imageops_pad_v_1.jpg Tests/images/imageops_pad_v_2.jpg Tests/images/input_bw_five_bands.fpx Tests/images/invalid-exif-without-x-resolution.jpg Tests/images/invalid-exif.jpg Tests/images/invalid.spider Tests/images/iptc.jpg Tests/images/iptc_roundDown.jpg Tests/images/iptc_roundUp.jpg Tests/images/iss634.apng Tests/images/iss634.gif Tests/images/iss634.webp Tests/images/issue_2278.tif Tests/images/issue_2811.gif Tests/images/itxt_chunks.png Tests/images/jpeg_ff00_header.jpg Tests/images/junk_jpeg_header.jpg Tests/images/l2rgb_read.bmp Tests/images/l_trns.png Tests/images/la.tga Tests/images/lab-green.tif Tests/images/lab-red.tif Tests/images/lab.tif Tests/images/libtiff_segfault.tif Tests/images/linear_gradient.png Tests/images/morph_a.png Tests/images/multiline_text.png Tests/images/multiline_text_center.png Tests/images/multiline_text_right.png Tests/images/multiline_text_spacing.png Tests/images/multipage-lastframe.tif Tests/images/multipage-mmap.tiff Tests/images/multipage.tiff Tests/images/negative_size.ppm Tests/images/no-dpi-in-exif.jpg Tests/images/no_cursors.cur Tests/images/no_rows_per_strip.tif Tests/images/non_zero_bb.eps Tests/images/non_zero_bb.png Tests/images/non_zero_bb_scale2.png Tests/images/old-style-jpeg-compression.png Tests/images/old-style-jpeg-compression.tif Tests/images/p_trns_single.png Tests/images/pcx_overrun.bin Tests/images/pcx_overrun2.bin Tests/images/photoshop-200dpi-broken.jpg Tests/images/photoshop-200dpi.jpg Tests/images/pil123p.png Tests/images/pil123rgba.png Tests/images/pil136.png Tests/images/pil136.tiff Tests/images/pil168.png Tests/images/pil168.tif Tests/images/pil184.pcx Tests/images/pil_sample_cmyk.eps Tests/images/pil_sample_cmyk.jpg Tests/images/pil_sample_rgb.jpg Tests/images/pillow.icns Tests/images/pillow.ico Tests/images/pillow2.icns Tests/images/pillow3.icns Tests/images/png_decompression_dos.png Tests/images/pngtest_bad.png.bin Tests/images/pport_g4.tif Tests/images/python.ico Tests/images/radial_gradient.png Tests/images/radial_gradients.png Tests/images/raw_negative_stride.bin Tests/images/rdf.tif Tests/images/rectangle_surrounding_text.png Tests/images/reqd_showpage.eps Tests/images/reqd_showpage.png Tests/images/rgb.jpg Tests/images/rgb32bf-rgba.bmp Tests/images/rgb32rle.tga Tests/images/rgb_trns.png Tests/images/rgb_trns_ycbc.j2k Tests/images/rgb_trns_ycbc.jp2 Tests/images/rotate_45_no_fill.png Tests/images/rotate_45_with_fill.png Tests/images/sgi_crash.bin Tests/images/sgi_overrun.bin Tests/images/sgi_overrun_expandrow.bin Tests/images/sgi_overrun_expandrow2.bin Tests/images/sgi_overrun_expandrowF04.bin Tests/images/standard_embedded.png Tests/images/sugarshack.mpo Tests/images/sugarshack_bad_mpo_header.jpg Tests/images/sugarshack_frame_size.mpo Tests/images/sugarshack_ifd_offset.mpo Tests/images/sugarshack_no_data.mpo Tests/images/sunraster.im1 Tests/images/sunraster.im1.png Tests/images/tRNS_null_1x1.png Tests/images/test-card-lossless.jp2 Tests/images/test-card-lossy-tiled.jp2 Tests/images/test-card.png Tests/images/test-ole-file.doc Tests/images/test.colors.gif Tests/images/test.gpl Tests/images/test_Nastalifont_text.png Tests/images/test_anchor_multiline_lm_center.png Tests/images/test_anchor_multiline_lm_left.png Tests/images/test_anchor_multiline_lm_right.png Tests/images/test_anchor_multiline_ma_center.png Tests/images/test_anchor_multiline_md_center.png Tests/images/test_anchor_multiline_mm_center.png Tests/images/test_anchor_multiline_mm_left.png Tests/images/test_anchor_multiline_mm_right.png Tests/images/test_anchor_multiline_rm_center.png Tests/images/test_anchor_multiline_rm_left.png Tests/images/test_anchor_multiline_rm_right.png Tests/images/test_anchor_quick_ls.png Tests/images/test_anchor_quick_ma.png Tests/images/test_anchor_quick_mb.png Tests/images/test_anchor_quick_md.png Tests/images/test_anchor_quick_mm.png Tests/images/test_anchor_quick_ms.png Tests/images/test_anchor_quick_mt.png Tests/images/test_anchor_quick_rs.png Tests/images/test_anchor_ttb_f_lt.png Tests/images/test_anchor_ttb_f_mm.png Tests/images/test_anchor_ttb_f_rb.png Tests/images/test_anchor_ttb_f_sm.png Tests/images/test_arabictext_features.png Tests/images/test_combine_caron.png Tests/images/test_combine_caron_below.png Tests/images/test_combine_caron_below_lb.png Tests/images/test_combine_caron_below_ld.png Tests/images/test_combine_caron_below_ls.png Tests/images/test_combine_caron_below_ttb.png Tests/images/test_combine_caron_below_ttb_lb.png Tests/images/test_combine_caron_la.png Tests/images/test_combine_caron_ls.png Tests/images/test_combine_caron_lt.png Tests/images/test_combine_caron_ttb.png Tests/images/test_combine_caron_ttb_lt.png Tests/images/test_combine_double_breve_below.png Tests/images/test_combine_double_breve_below_ma.png Tests/images/test_combine_double_breve_below_ra.png Tests/images/test_combine_double_breve_below_ttb.png Tests/images/test_combine_double_breve_below_ttb_mt.png Tests/images/test_combine_double_breve_below_ttb_rt.png Tests/images/test_combine_double_breve_below_ttb_st.png Tests/images/test_combine_multiline_lm_center.png Tests/images/test_combine_multiline_lm_left.png Tests/images/test_combine_multiline_lm_right.png Tests/images/test_combine_multiline_mm_center.png Tests/images/test_combine_multiline_mm_left.png Tests/images/test_combine_multiline_mm_right.png Tests/images/test_combine_multiline_rm_center.png Tests/images/test_combine_multiline_rm_left.png Tests/images/test_combine_multiline_rm_right.png Tests/images/test_combine_overline.png Tests/images/test_combine_overline_la.png Tests/images/test_combine_overline_ra.png Tests/images/test_combine_overline_ttb.png Tests/images/test_combine_overline_ttb_mt.png Tests/images/test_combine_overline_ttb_rt.png Tests/images/test_combine_overline_ttb_st.png Tests/images/test_complex_unicode_text.png Tests/images/test_complex_unicode_text2.png Tests/images/test_direction_ltr.png Tests/images/test_direction_rtl.png Tests/images/test_direction_ttb.png Tests/images/test_direction_ttb_stroke.png Tests/images/test_draw_pbm_target.png Tests/images/test_draw_pbm_ter_en_target.png Tests/images/test_draw_pbm_ter_pl_target.png Tests/images/test_extents.gif Tests/images/test_kerning_features.png Tests/images/test_language.png Tests/images/test_ligature_features.png Tests/images/test_text.png Tests/images/test_x_max_and_y_offset.png Tests/images/test_y_offset.png Tests/images/text_mono.gif Tests/images/tga/common/1x1_l.png Tests/images/tga/common/1x1_l_bl_raw.tga Tests/images/tga/common/1x1_l_bl_rle.tga Tests/images/tga/common/1x1_l_tl_raw.tga Tests/images/tga/common/1x1_l_tl_rle.tga Tests/images/tga/common/200x32_l.png Tests/images/tga/common/200x32_l_bl_raw.tga Tests/images/tga/common/200x32_l_bl_rle.tga Tests/images/tga/common/200x32_l_tl_raw.tga Tests/images/tga/common/200x32_l_tl_rle.tga Tests/images/tga/common/200x32_la.png Tests/images/tga/common/200x32_la_bl_raw.tga Tests/images/tga/common/200x32_la_bl_rle.tga Tests/images/tga/common/200x32_la_tl_raw.tga Tests/images/tga/common/200x32_la_tl_rle.tga Tests/images/tga/common/200x32_p.png Tests/images/tga/common/200x32_p_bl_raw.tga Tests/images/tga/common/200x32_p_bl_rle.tga Tests/images/tga/common/200x32_p_tl_raw.tga Tests/images/tga/common/200x32_p_tl_rle.tga Tests/images/tga/common/200x32_rgb.png Tests/images/tga/common/200x32_rgb_bl_raw.tga Tests/images/tga/common/200x32_rgb_bl_rle.tga Tests/images/tga/common/200x32_rgb_tl_raw.tga Tests/images/tga/common/200x32_rgb_tl_rle.tga Tests/images/tga/common/200x32_rgba.png Tests/images/tga/common/200x32_rgba_bl_raw.tga Tests/images/tga/common/200x32_rgba_bl_rle.tga Tests/images/tga/common/200x32_rgba_tl_raw.tga Tests/images/tga/common/200x32_rgba_tl_rle.tga Tests/images/tga/common/readme.txt Tests/images/tga_id_field.tga Tests/images/tiff_16bit_RGB.tiff Tests/images/tiff_16bit_RGB_target.png Tests/images/tiff_16bit_RGBa.tiff Tests/images/tiff_16bit_RGBa_target.png Tests/images/tiff_adobe_deflate.png Tests/images/tiff_adobe_deflate.tif Tests/images/tiff_gray_2_4_bpp/hopper2.tif Tests/images/tiff_gray_2_4_bpp/hopper2I.tif Tests/images/tiff_gray_2_4_bpp/hopper2IR.tif Tests/images/tiff_gray_2_4_bpp/hopper2R.tif Tests/images/tiff_gray_2_4_bpp/hopper4.tif Tests/images/tiff_gray_2_4_bpp/hopper4I.tif Tests/images/tiff_gray_2_4_bpp/hopper4IR.tif Tests/images/tiff_gray_2_4_bpp/hopper4R.tif Tests/images/tiff_overflow_rows_per_strip.tif Tests/images/tiff_strip_cmyk_16l_jpeg.tif Tests/images/tiff_strip_cmyk_jpeg.tif Tests/images/tiff_strip_planar_raw.tif Tests/images/tiff_strip_planar_raw_with_overviews.tif Tests/images/tiff_strip_raw.tif Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif Tests/images/tiff_strip_ycbcr_jpeg_2x2_sampling.tif Tests/images/tiff_tiled_cmyk_jpeg.tif Tests/images/tiff_tiled_planar_raw.tif Tests/images/tiff_tiled_raw.tif Tests/images/tiff_tiled_ycbcr_jpeg_1x1_sampling.tif Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif Tests/images/tiff_wrong_bits_per_sample.tiff Tests/images/total-pages-zero.tif Tests/images/transparent.gif Tests/images/transparent.png Tests/images/transparent.sgi Tests/images/transparent.webp Tests/images/transparent_background_text.png Tests/images/truncated_image.png Tests/images/truncated_jpeg.jpg Tests/images/tv.rgb Tests/images/tv16.sgi Tests/images/uint16_1_4660.tif Tests/images/unbound_variable.jp2 Tests/images/uncompressed_rgb.dds Tests/images/uncompressed_rgb.png Tests/images/unicode_extended.png Tests/images/unimplemented_dxgi_format.dds Tests/images/unimplemented_pixel_format.dds Tests/images/variation_adobe.png Tests/images/variation_adobe_axes.png Tests/images/variation_adobe_name.png Tests/images/variation_adobe_older_harfbuzz.png Tests/images/variation_adobe_older_harfbuzz_axes.png Tests/images/variation_adobe_older_harfbuzz_name.png Tests/images/variation_tiny.png Tests/images/variation_tiny_axes.png Tests/images/variation_tiny_name.png Tests/images/xmp_tags_orientation.png Tests/images/zero_bb.eps Tests/images/zero_bb.png Tests/images/zero_bb_emptyline.eps Tests/images/zero_bb_scale2.png Tests/test_000_sanity.py Tests/test_binary.py Tests/test_bmp_reference.py Tests/test_box_blur.py Tests/test_color_lut.py Tests/test_core_resources.py Tests/test_decompression_bomb.py Tests/test_features.py Tests/test_file_apng.py Tests/test_file_blp.py Tests/test_file_bmp.py Tests/test_file_bufrstub.py Tests/test_file_container.py Tests/test_file_cur.py Tests/test_file_dcx.py Tests/test_file_dds.py Tests/test_file_eps.py Tests/test_file_fitsstub.py Tests/test_file_fli.py Tests/test_file_fpx.py Tests/test_file_ftex.py Tests/test_file_gbr.py Tests/test_file_gd.py Tests/test_file_gif.py Tests/test_file_gimpgradient.py Tests/test_file_gimppalette.py Tests/test_file_gribstub.py Tests/test_file_hdf5stub.py Tests/test_file_icns.py Tests/test_file_ico.py Tests/test_file_im.py Tests/test_file_iptc.py Tests/test_file_jpeg.py Tests/test_file_jpeg2k.py Tests/test_file_libtiff.py Tests/test_file_libtiff_small.py Tests/test_file_mcidas.py Tests/test_file_mic.py Tests/test_file_mpo.py Tests/test_file_msp.py Tests/test_file_palm.py Tests/test_file_pcd.py Tests/test_file_pcx.py Tests/test_file_pdf.py Tests/test_file_pixar.py Tests/test_file_png.py Tests/test_file_ppm.py Tests/test_file_psd.py Tests/test_file_sgi.py Tests/test_file_spider.py Tests/test_file_sun.py Tests/test_file_tar.py Tests/test_file_tga.py Tests/test_file_tiff.py Tests/test_file_tiff_metadata.py Tests/test_file_wal.py Tests/test_file_webp.py Tests/test_file_webp_alpha.py Tests/test_file_webp_animated.py Tests/test_file_webp_lossless.py Tests/test_file_webp_metadata.py Tests/test_file_wmf.py Tests/test_file_xbm.py Tests/test_file_xpm.py Tests/test_file_xvthumb.py Tests/test_font_bdf.py Tests/test_font_leaks.py Tests/test_font_pcf.py Tests/test_font_pcf_charsets.py Tests/test_format_hsv.py Tests/test_format_lab.py Tests/test_image.py Tests/test_image_access.py Tests/test_image_array.py Tests/test_image_convert.py Tests/test_image_copy.py Tests/test_image_crop.py Tests/test_image_draft.py Tests/test_image_entropy.py Tests/test_image_filter.py Tests/test_image_frombytes.py Tests/test_image_fromqimage.py Tests/test_image_getbands.py Tests/test_image_getbbox.py Tests/test_image_getcolors.py Tests/test_image_getdata.py Tests/test_image_getextrema.py Tests/test_image_getim.py Tests/test_image_getpalette.py Tests/test_image_getprojection.py Tests/test_image_histogram.py Tests/test_image_load.py Tests/test_image_mode.py Tests/test_image_paste.py Tests/test_image_point.py Tests/test_image_putalpha.py Tests/test_image_putdata.py Tests/test_image_putpalette.py Tests/test_image_quantize.py Tests/test_image_reduce.py Tests/test_image_resample.py Tests/test_image_resize.py Tests/test_image_rotate.py Tests/test_image_split.py Tests/test_image_thumbnail.py Tests/test_image_tobitmap.py Tests/test_image_tobytes.py Tests/test_image_transform.py Tests/test_image_transpose.py Tests/test_imagechops.py Tests/test_imagecms.py Tests/test_imagecolor.py Tests/test_imagedraw.py Tests/test_imagedraw2.py Tests/test_imageenhance.py Tests/test_imagefile.py Tests/test_imagefont.py Tests/test_imagefontctl.py Tests/test_imagegrab.py Tests/test_imagemath.py Tests/test_imagemorph.py Tests/test_imageops.py Tests/test_imageops_usm.py Tests/test_imagepalette.py Tests/test_imagepath.py Tests/test_imageqt.py Tests/test_imagesequence.py Tests/test_imageshow.py Tests/test_imagestat.py Tests/test_imagetk.py Tests/test_imagewin.py Tests/test_imagewin_pointers.py Tests/test_lib_image.py Tests/test_lib_pack.py Tests/test_locale.py Tests/test_main.py Tests/test_map.py Tests/test_mode_i16.py Tests/test_numpy.py Tests/test_pdfparser.py Tests/test_pickle.py Tests/test_psdraw.py Tests/test_pyroma.py Tests/test_qt_image_fromqpixmap.py Tests/test_qt_image_toqimage.py Tests/test_qt_image_toqpixmap.py Tests/test_sgi_crash.py Tests/test_shell_injection.py Tests/test_tiff_crashes.py Tests/test_tiff_ifdrational.py Tests/test_uploader.py Tests/test_util.py Tests/test_webp_leaks.py codecov.yml conftest.py depends/README.rst depends/diffcover-install.sh depends/diffcover-run.sh depends/download-and-extract.sh depends/install_extra_test_images.sh depends/install_imagequant.sh depends/install_openjpeg.sh depends/install_raqm.sh depends/install_raqm_cmake.sh depends/install_webp.sh depends/termux.sh docs/COPYING docs/Guardfile docs/Makefile docs/PIL.rst docs/about.rst docs/conf.py docs/deprecations.rst docs/example/DdsImagePlugin.py docs/example/anchors.png docs/example/anchors.py docs/handbook/appendices.rst docs/handbook/concepts.rst docs/handbook/image-file-formats.rst docs/handbook/index.rst docs/handbook/overview.rst docs/handbook/text-anchors.rst docs/handbook/tutorial.rst docs/handbook/writing-your-own-file-decoder.rst docs/index.rst docs/installation.rst docs/make.bat docs/porting.rst docs/reference/ExifTags.rst docs/reference/Image.rst docs/reference/ImageChops.rst docs/reference/ImageCms.rst docs/reference/ImageColor.rst docs/reference/ImageDraw.rst docs/reference/ImageEnhance.rst docs/reference/ImageFile.rst docs/reference/ImageFilter.rst docs/reference/ImageFont.rst docs/reference/ImageGrab.rst docs/reference/ImageMath.rst docs/reference/ImageMorph.rst docs/reference/ImageOps.rst docs/reference/ImagePalette.rst docs/reference/ImagePath.rst docs/reference/ImageQt.rst docs/reference/ImageSequence.rst docs/reference/ImageShow.rst docs/reference/ImageStat.rst docs/reference/ImageTk.rst docs/reference/ImageWin.rst docs/reference/JpegPresets.rst docs/reference/PSDraw.rst docs/reference/PixelAccess.rst docs/reference/PyAccess.rst docs/reference/TiffTags.rst docs/reference/block_allocator.rst docs/reference/features.rst docs/reference/index.rst docs/reference/internal_design.rst docs/reference/internal_modules.rst docs/reference/limits.rst docs/reference/open_files.rst docs/reference/plugins.rst docs/releasenotes/2.7.0.rst docs/releasenotes/2.8.0.rst docs/releasenotes/3.0.0.rst docs/releasenotes/3.1.0.rst docs/releasenotes/3.1.1.rst docs/releasenotes/3.1.2.rst docs/releasenotes/3.2.0.rst docs/releasenotes/3.3.0.rst docs/releasenotes/3.3.2.rst docs/releasenotes/3.4.0.rst docs/releasenotes/4.0.0.rst docs/releasenotes/4.1.0.rst docs/releasenotes/4.1.1.rst docs/releasenotes/4.2.0.rst docs/releasenotes/4.2.1.rst docs/releasenotes/4.3.0.rst docs/releasenotes/5.0.0.rst docs/releasenotes/5.1.0.rst docs/releasenotes/5.2.0.rst docs/releasenotes/5.3.0.rst docs/releasenotes/5.4.0.rst docs/releasenotes/5.4.1.rst docs/releasenotes/6.0.0.rst docs/releasenotes/6.1.0.rst docs/releasenotes/6.2.0.rst docs/releasenotes/6.2.1.rst docs/releasenotes/6.2.2.rst docs/releasenotes/7.0.0.rst docs/releasenotes/7.1.0.rst docs/releasenotes/7.1.1.rst docs/releasenotes/7.1.2.rst docs/releasenotes/7.2.0.rst docs/releasenotes/8.0.0.rst docs/releasenotes/8.0.1.rst docs/releasenotes/index.rst docs/releasenotes/template.rst docs/resources/anchor_horizontal.svg docs/resources/anchor_vertical.svg docs/resources/css/dark.css docs/resources/favicon.ico docs/resources/js/script.js requirements.txt selftest.py setup.cfg setup.py src/PIL/BdfFontFile.py src/PIL/BlpImagePlugin.py src/PIL/BmpImagePlugin.py src/PIL/BufrStubImagePlugin.py src/PIL/ContainerIO.py src/PIL/CurImagePlugin.py src/PIL/DcxImagePlugin.py src/PIL/DdsImagePlugin.py src/PIL/EpsImagePlugin.py src/PIL/ExifTags.py src/PIL/FitsStubImagePlugin.py src/PIL/FliImagePlugin.py src/PIL/FontFile.py src/PIL/FpxImagePlugin.py src/PIL/FtexImagePlugin.py src/PIL/GbrImagePlugin.py src/PIL/GdImageFile.py src/PIL/GifImagePlugin.py src/PIL/GimpGradientFile.py src/PIL/GimpPaletteFile.py src/PIL/GribStubImagePlugin.py src/PIL/Hdf5StubImagePlugin.py src/PIL/IcnsImagePlugin.py src/PIL/IcoImagePlugin.py src/PIL/ImImagePlugin.py src/PIL/Image.py src/PIL/ImageChops.py src/PIL/ImageCms.py src/PIL/ImageColor.py src/PIL/ImageDraw.py src/PIL/ImageDraw2.py src/PIL/ImageEnhance.py src/PIL/ImageFile.py src/PIL/ImageFilter.py src/PIL/ImageFont.py src/PIL/ImageGrab.py src/PIL/ImageMath.py src/PIL/ImageMode.py src/PIL/ImageMorph.py src/PIL/ImageOps.py src/PIL/ImagePalette.py src/PIL/ImagePath.py src/PIL/ImageQt.py src/PIL/ImageSequence.py src/PIL/ImageShow.py src/PIL/ImageStat.py src/PIL/ImageTk.py src/PIL/ImageTransform.py src/PIL/ImageWin.py src/PIL/ImtImagePlugin.py src/PIL/IptcImagePlugin.py src/PIL/Jpeg2KImagePlugin.py src/PIL/JpegImagePlugin.py src/PIL/JpegPresets.py src/PIL/McIdasImagePlugin.py src/PIL/MicImagePlugin.py src/PIL/MpegImagePlugin.py src/PIL/MpoImagePlugin.py src/PIL/MspImagePlugin.py src/PIL/PSDraw.py src/PIL/PaletteFile.py src/PIL/PalmImagePlugin.py src/PIL/PcdImagePlugin.py src/PIL/PcfFontFile.py src/PIL/PcxImagePlugin.py src/PIL/PdfImagePlugin.py src/PIL/PdfParser.py src/PIL/PixarImagePlugin.py src/PIL/PngImagePlugin.py src/PIL/PpmImagePlugin.py src/PIL/PsdImagePlugin.py src/PIL/PyAccess.py src/PIL/SgiImagePlugin.py src/PIL/SpiderImagePlugin.py src/PIL/SunImagePlugin.py src/PIL/TarIO.py src/PIL/TgaImagePlugin.py src/PIL/TiffImagePlugin.py src/PIL/TiffTags.py src/PIL/WalImageFile.py src/PIL/WebPImagePlugin.py src/PIL/WmfImagePlugin.py src/PIL/XVThumbImagePlugin.py src/PIL/XbmImagePlugin.py src/PIL/XpmImagePlugin.py src/PIL/__init__.py src/PIL/__main__.py src/PIL/_binary.py src/PIL/_tkinter_finder.py src/PIL/_util.py src/PIL/_version.py src/PIL/features.py src/Tk/_tkmini.h src/Tk/tkImaging.c src/_imaging.c src/_imagingcms.c src/_imagingft.c src/_imagingmath.c src/_imagingmorph.c src/_imagingtk.c src/_webp.c src/decode.c src/display.c src/encode.c src/libImaging/Access.c src/libImaging/AlphaComposite.c src/libImaging/Bands.c src/libImaging/BcnDecode.c src/libImaging/Bit.h src/libImaging/BitDecode.c src/libImaging/Blend.c src/libImaging/BoxBlur.c src/libImaging/Chops.c src/libImaging/ColorLUT.c src/libImaging/Convert.c src/libImaging/ConvertYCbCr.c src/libImaging/Copy.c src/libImaging/Crop.c src/libImaging/Dib.c src/libImaging/Draw.c src/libImaging/Effects.c src/libImaging/EpsEncode.c src/libImaging/Except.c src/libImaging/File.c src/libImaging/Fill.c src/libImaging/Filter.c src/libImaging/FliDecode.c src/libImaging/Geometry.c src/libImaging/GetBBox.c src/libImaging/Gif.h src/libImaging/GifDecode.c src/libImaging/GifEncode.c src/libImaging/HexDecode.c src/libImaging/Histo.c src/libImaging/ImDib.h src/libImaging/ImPlatform.h src/libImaging/Imaging.h src/libImaging/ImagingUtils.h src/libImaging/Jpeg.h src/libImaging/Jpeg2K.h src/libImaging/Jpeg2KDecode.c src/libImaging/Jpeg2KEncode.c src/libImaging/JpegDecode.c src/libImaging/JpegEncode.c src/libImaging/Matrix.c src/libImaging/ModeFilter.c src/libImaging/Negative.c src/libImaging/Offset.c src/libImaging/Pack.c src/libImaging/PackDecode.c src/libImaging/Palette.c src/libImaging/Paste.c src/libImaging/PcdDecode.c src/libImaging/PcxDecode.c src/libImaging/PcxEncode.c src/libImaging/Point.c src/libImaging/Quant.c src/libImaging/QuantHash.c src/libImaging/QuantHash.h src/libImaging/QuantHeap.c src/libImaging/QuantHeap.h src/libImaging/QuantOctree.c src/libImaging/QuantOctree.h src/libImaging/QuantPngQuant.c src/libImaging/QuantPngQuant.h src/libImaging/QuantTypes.h src/libImaging/RankFilter.c src/libImaging/Raw.h src/libImaging/RawDecode.c src/libImaging/RawEncode.c src/libImaging/Reduce.c src/libImaging/Resample.c src/libImaging/Sgi.h src/libImaging/SgiRleDecode.c src/libImaging/Storage.c src/libImaging/SunRleDecode.c src/libImaging/TgaRleDecode.c src/libImaging/TgaRleEncode.c src/libImaging/TiffDecode.c src/libImaging/TiffDecode.h src/libImaging/Unpack.c src/libImaging/UnpackYCC.c src/libImaging/UnsharpMask.c src/libImaging/XbmDecode.c src/libImaging/XbmEncode.c src/libImaging/ZipCodecs.h src/libImaging/ZipDecode.c src/libImaging/ZipEncode.c src/libImaging/codec_fd.c src/libImaging/raqm.h src/map.c src/outline.c src/path.c tox.ini winbuild/README.md winbuild/build.rst winbuild/build_prepare.py winbuild/fribidi.cmake winbuild/raqm.cmake winbuild/tiff.opt <<<<<< network # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Point.c.gcov -: 0:Source:src/libImaging/Point.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Point.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Point.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * point (pixel) translation -: 6: * -: 7: * history: -: 8: * 1995-11-27 fl Created -: 9: * 1996-03-31 fl Fixed colour support -: 10: * 1996-08-13 fl Support 8-bit to "1" thresholding -: 11: * 1997-05-31 fl Added floating point transform -: 12: * 1998-07-02 fl Added integer point transform -: 13: * 1998-07-17 fl Support L to anything lookup -: 14: * 2004-12-18 fl Refactored; added I to L lookup -: 15: * -: 16: * Copyright (c) 1997-2004 by Secret Labs AB. -: 17: * Copyright (c) 1995-2004 by Fredrik Lundh. -: 18: * -: 19: * See the README file for information on usage and redistribution. -: 20: */ -: 21: -: 22: -: 23:#include "Imaging.h" -: 24: -: 25:typedef struct { -: 26: const void* table; -: 27:} im_point_context; -: 28: -: 29:static void function im_point_8_8 called 19 returned 100% blocks executed 100% 19: 30:im_point_8_8(Imaging imOut, Imaging imIn, im_point_context* context) -: 31:{ -: 32: int x, y; -: 33: /* 8-bit source, 8-bit destination */ 19: 34: UINT8* table = (UINT8*) context->table; 2399: 35: for (y = 0; y < imIn->ysize; y++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 2380: 36: UINT8* in = imIn->image8[y]; 2380: 37: UINT8* out = imOut->image8[y]; 706108: 38: for (x = 0; x < imIn->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 703728: 39: out[x] = table[in[x]]; -: 40: } -: 41: } 19: 42:} -: 43: -: 44:static void function im_point_2x8_2x8 called 0 returned 0% blocks executed 0% #####: 45:im_point_2x8_2x8(Imaging imOut, Imaging imIn, im_point_context* context) -: 46:{ -: 47: int x, y; -: 48: /* 2x8-bit source, 2x8-bit destination */ #####: 49: UINT8* table = (UINT8*) context->table; #####: 50: for (y = 0; y < imIn->ysize; y++) { branch 0 never executed branch 1 never executed #####: 51: UINT8* in = (UINT8*) imIn->image[y]; #####: 52: UINT8* out = (UINT8*) imOut->image[y]; #####: 53: for (x = 0; x < imIn->xsize; x++) { branch 0 never executed branch 1 never executed #####: 54: out[0] = table[in[0]]; #####: 55: out[3] = table[in[3]+256]; #####: 56: in += 4; out += 4; -: 57: } -: 58: } #####: 59:} -: 60: -: 61:static void function im_point_3x8_3x8 called 18 returned 100% blocks executed 100% 18: 62:im_point_3x8_3x8(Imaging imOut, Imaging imIn, im_point_context* context) -: 63:{ -: 64: int x, y; -: 65: /* 3x8-bit source, 3x8-bit destination */ 18: 66: UINT8* table = (UINT8*) context->table; 2448: 67: for (y = 0; y < imIn->ysize; y++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 2430: 68: UINT8* in = (UINT8*) imIn->image[y]; 2430: 69: UINT8* out = (UINT8*) imOut->image[y]; 805214: 70: for (x = 0; x < imIn->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 802784: 71: out[0] = table[in[0]]; 802784: 72: out[1] = table[in[1]+256]; 802784: 73: out[2] = table[in[2]+512]; 802784: 74: in += 4; out += 4; -: 75: } -: 76: } 18: 77:} -: 78: -: 79:static void function im_point_4x8_4x8 called 0 returned 0% blocks executed 0% #####: 80:im_point_4x8_4x8(Imaging imOut, Imaging imIn, im_point_context* context) -: 81:{ -: 82: int x, y; -: 83: /* 4x8-bit source, 4x8-bit destination */ #####: 84: UINT8* table = (UINT8*) context->table; #####: 85: for (y = 0; y < imIn->ysize; y++) { branch 0 never executed branch 1 never executed #####: 86: UINT8* in = (UINT8*) imIn->image[y]; #####: 87: UINT8* out = (UINT8*) imOut->image[y]; #####: 88: for (x = 0; x < imIn->xsize; x++) { branch 0 never executed branch 1 never executed #####: 89: out[0] = table[in[0]]; #####: 90: out[1] = table[in[1]+256]; #####: 91: out[2] = table[in[2]+512]; #####: 92: out[3] = table[in[3]+768]; #####: 93: in += 4; out += 4; -: 94: } -: 95: } #####: 96:} -: 97: -: 98:static void function im_point_8_32 called 1 returned 100% blocks executed 100% 1: 99:im_point_8_32(Imaging imOut, Imaging imIn, im_point_context* context) -: 100:{ -: 101: int x, y; -: 102: /* 8-bit source, 32-bit destination */ 1: 103: char* table = (char*) context->table; 129: 104: for (y = 0; y < imIn->ysize; y++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 128: 105: UINT8* in = imIn->image8[y]; 128: 106: INT32* out = imOut->image32[y]; 16512: 107: for (x = 0; x < imIn->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 32768: 108: memcpy(out + x, table + in[x] * sizeof(INT32), sizeof(INT32)); -: 109: } -: 110: } 1: 111:} -: 112: -: 113:static void function im_point_32_8 called 1 returned 100% blocks executed 90% 1: 114:im_point_32_8(Imaging imOut, Imaging imIn, im_point_context* context) -: 115:{ -: 116: int x, y; -: 117: /* 32-bit source, 8-bit destination */ 1: 118: UINT8* table = (UINT8*) context->table; 129: 119: for (y = 0; y < imIn->ysize; y++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 128: 120: INT32* in = imIn->image32[y]; 128: 121: UINT8* out = imOut->image8[y]; 16512: 122: for (x = 0; x < imIn->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 123: int v = in[x]; 16384: 124: if (v < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 125: v = 0; 16384: 126: } else if (v > 65535) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 127: v = 65535; -: 128: } 16384: 129: out[x] = table[v]; -: 130: } -: 131: } 1: 132:} -: 133: -: 134:Imaging function ImagingPoint called 40 returned 100% blocks executed 89% 40: 135:ImagingPoint(Imaging imIn, const char* mode, const void* table) -: 136:{ -: 137: /* lookup table transform */ -: 138: -: 139: ImagingSectionCookie cookie; -: 140: Imaging imOut; -: 141: im_point_context context; -: 142: void (*point)(Imaging imIn, Imaging imOut, im_point_context* context); -: 143: 40: 144: if (!imIn) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 145: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 146: } -: 147: 40: 148: if (!mode) { branch 0 taken 93% (fallthrough) branch 1 taken 8% 37: 149: mode = imIn->mode; -: 150: } -: 151: 40: 152: if (imIn->type != IMAGING_TYPE_UINT8) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 2: 153: if (imIn->type != IMAGING_TYPE_INT32 || strcmp(mode, "L") != 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 50% (fallthrough) branch 3 taken 50% branch 4 taken 50% branch 5 taken 50% -: 154: goto mode_mismatch; -: 155: } 38: 156: } else if (!imIn->image8 && strcmp(imIn->mode, mode) != 0) { branch 0 taken 47% (fallthrough) branch 1 taken 53% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 157: goto mode_mismatch; -: 158: } -: 159: 39: 160: imOut = ImagingNew(mode, imIn->xsize, imIn->ysize); call 0 returned 100% 39: 161: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 162: return NULL; -: 163: } -: 164: -: 165: /* find appropriate handler */ 39: 166: if (imIn->type == IMAGING_TYPE_UINT8) { branch 0 taken 97% (fallthrough) branch 1 taken 3% 38: 167: if (imIn->bands == imOut->bands && imIn->type == imOut->type) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 97% (fallthrough) branch 3 taken 3% 37: 168: switch (imIn->bands) { branch 0 taken 0% branch 1 taken 49% branch 2 taken 0% branch 3 taken 51% -: 169: case 1: -: 170: point = im_point_8_8; -: 171: break; -: 172: case 2: #####: 173: point = im_point_2x8_2x8; #####: 174: break; -: 175: case 3: 18: 176: point = im_point_3x8_3x8; 18: 177: break; -: 178: case 4: #####: 179: point = im_point_4x8_4x8; #####: 180: break; -: 181: default: -: 182: /* this cannot really happen */ -: 183: point = im_point_8_8; -: 184: break; -: 185: } -: 186: } else { -: 187: point = im_point_8_32; -: 188: } -: 189: } else { -: 190: point = im_point_32_8; -: 191: } -: 192: 39: 193: ImagingCopyPalette(imOut, imIn); call 0 returned 100% -: 194: 39: 195: ImagingSectionEnter(&cookie); call 0 returned 100% -: 196: 39: 197: context.table = table; 39: 198: point(imOut, imIn, &context); call 0 returned 100% -: 199: 39: 200: ImagingSectionLeave(&cookie); call 0 returned 100% -: 201: 39: 202: return imOut; -: 203: -: 204: mode_mismatch: 1: 205: return (Imaging) ImagingError_ValueError( call 0 returned 100% -: 206: "point operation not supported for this mode" -: 207: ); -: 208:} -: 209: -: 210: -: 211:Imaging function ImagingPointTransform called 4 returned 100% blocks executed 70% 4: 212:ImagingPointTransform(Imaging imIn, double scale, double offset) -: 213:{ -: 214: /* scale/offset transform */ -: 215: -: 216: ImagingSectionCookie cookie; -: 217: Imaging imOut; -: 218: int x, y; -: 219: 5: 220: if (!imIn || (strcmp(imIn->mode, "I") != 0 && branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 75% (fallthrough) branch 3 taken 25% branch 4 taken 25% (fallthrough) branch 5 taken 75% branch 6 taken 100% (fallthrough) branch 7 taken 0% 2: 221: strcmp(imIn->mode, "I;16") != 0 && branch 0 taken 0% (fallthrough) branch 1 taken 100% 1: 222: strcmp(imIn->mode, "F") != 0)) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 223: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 224: } -: 225: 4: 226: imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); call 0 returned 100% 4: 227: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 228: return NULL; -: 229: } -: 230: 4: 231: switch (imIn->type) { branch 0 taken 75% branch 1 taken 25% branch 2 taken 0% branch 3 taken 0% -: 232: case IMAGING_TYPE_INT32: 3: 233: ImagingSectionEnter(&cookie); 387: 234: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 384: 235: INT32* in = imIn->image32[y]; 384: 236: INT32* out = imOut->image32[y]; -: 237: /* FIXME: add clipping? */ 49536: 238: for (x = 0; x < imIn->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 49152: 239: out[x] = in[x] * scale + offset; -: 240: } -: 241: } 3: 242: ImagingSectionLeave(&cookie); call 0 returned 100% 3: 243: break; -: 244: case IMAGING_TYPE_FLOAT32: 1: 245: ImagingSectionEnter(&cookie); 129: 246: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 128: 247: FLOAT32* in = (FLOAT32*) imIn->image32[y]; 128: 248: FLOAT32* out = (FLOAT32*) imOut->image32[y]; 16512: 249: for (x = 0; x < imIn->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 250: out[x] = in[x] * scale + offset; -: 251: } -: 252: } 1: 253: ImagingSectionLeave(&cookie); call 0 returned 100% 1: 254: break; -: 255: case IMAGING_TYPE_SPECIAL: #####: 256: if (strcmp(imIn->mode,"I;16") == 0) { branch 0 never executed branch 1 never executed #####: 257: ImagingSectionEnter(&cookie); #####: 258: for (y = 0; y < imIn->ysize; y++) { call 0 never executed branch 1 never executed branch 2 never executed #####: 259: char* in = (char*)imIn->image[y]; #####: 260: char* out = (char*)imOut->image[y]; -: 261: /* FIXME: add clipping? */ #####: 262: for (x = 0; x < imIn->xsize; x++) { branch 0 never executed branch 1 never executed -: 263: UINT16 v; #####: 264: memcpy(&v, in + x * sizeof(v), sizeof(v)); #####: 265: v = v * scale + offset; #####: 266: memcpy(out + x * sizeof(UINT16), &v, sizeof(v)); -: 267: } -: 268: } #####: 269: ImagingSectionLeave(&cookie); call 0 never executed #####: 270: break; -: 271: } -: 272: /* FALL THROUGH */ -: 273: default: #####: 274: ImagingDelete(imOut); call 0 never executed #####: 275: return (Imaging) ImagingError_ValueError("internal error"); call 0 never executed -: 276: } -: 277: -: 278: return imOut; -: 279:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#JpegDecode.c.gcov -: 0:Source:src/libImaging/JpegDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/JpegDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/JpegDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for JPEG image data. -: 6: * -: 7: * history: -: 8: * 1996-05-02 fl Created -: 9: * 1996-05-05 fl Handle small JPEG files correctly -: 10: * 1996-05-28 fl Added "draft mode" support -: 11: * 1997-01-25 fl Added colour conversion override -: 12: * 1998-01-31 fl Adapted to libjpeg 6a -: 13: * 1998-07-12 fl Extended YCbCr support -: 14: * 1998-12-29 fl Added new state to handle suspension in multipass modes -: 15: * 2000-10-12 fl Suppress warnings -: 16: * 2000-12-04 fl Suppress errors beyond end of image data -: 17: * -: 18: * Copyright (c) 1998-2000 Secret Labs AB -: 19: * Copyright (c) 1996-2000 Fredrik Lundh -: 20: * -: 21: * See the README file for details on usage and redistribution. -: 22: */ -: 23: -: 24: -: 25:#include "Imaging.h" -: 26: -: 27:#ifdef HAVE_LIBJPEG -: 28: -: 29:#undef HAVE_PROTOTYPES -: 30:#undef HAVE_STDLIB_H -: 31:#undef HAVE_STDDEF_H -: 32:#undef UINT8 -: 33:#undef UINT16 -: 34:#undef UINT32 -: 35:#undef INT16 -: 36:#undef INT32 -: 37: -: 38:#include "Jpeg.h" -: 39: -: 40: -: 41:#define STRINGIFY(x) #x -: 42:#define TOSTRING(x) STRINGIFY(x) -: 43: -: 44:// There is no way to compare versions on compile time, -: 45:// so we have to do that in runtime. -: 46:#ifdef LIBJPEG_TURBO_VERSION -: 47:char *libjpeg_turbo_version = TOSTRING(LIBJPEG_TURBO_VERSION); -: 48:#else -: 49:char *libjpeg_turbo_version = NULL; -: 50:#endif -: 51: -: 52:int function ImagingJpegUseJCSExtensions called 348 returned 100% blocks executed 100% 348: 53:ImagingJpegUseJCSExtensions() -: 54:{ 348: 55: int use_jcs_extensions = 0; -: 56: #ifdef JCS_EXTENSIONS -: 57: #if defined(LIBJPEG_TURBO_VERSION_NUMBER) -: 58: #if LIBJPEG_TURBO_VERSION_NUMBER >= 1002010 -: 59: use_jcs_extensions = 1; -: 60: #endif -: 61: #else 348: 62: if (libjpeg_turbo_version) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 348: 63: use_jcs_extensions = strcmp(libjpeg_turbo_version, "1.2.1") >= 0; -: 64: } -: 65: #endif -: 66: #endif 348: 67: return use_jcs_extensions; -: 68:} -: 69: -: 70:/* -------------------------------------------------------------------- */ -: 71:/* Suspending input handler */ -: 72:/* -------------------------------------------------------------------- */ -: 73: -: 74:METHODDEF(void) function stub called 380 returned 100% blocks executed 100% 380: 75:stub(j_decompress_ptr cinfo) -: 76:{ -: 77: /* empty */ 380: 78:} -: 79: -: 80:METHODDEF(boolean) function fill_input_buffer called 26 returned 100% blocks executed 100% 26: 81:fill_input_buffer(j_decompress_ptr cinfo) -: 82:{ -: 83: /* Suspension */ 26: 84: return FALSE; -: 85:} -: 86: -: 87:METHODDEF(void) function skip_input_data called 179 returned 100% blocks executed 100% 179: 88:skip_input_data(j_decompress_ptr cinfo, long num_bytes) -: 89:{ 185: 90: JPEGSOURCE* source = (JPEGSOURCE*) cinfo->src; -: 91: 185: 92: if (num_bytes > (long) source->pub.bytes_in_buffer) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 taken 3% (fallthrough) branch 3 taken 97% -: 93: /* We need to skip more data than we have in the buffer. -: 94: This will force the JPEG library to suspend decoding. */ 6: 95: source->skip = num_bytes - source->pub.bytes_in_buffer; 6: 96: source->pub.next_input_byte += source->pub.bytes_in_buffer; 6: 97: source->pub.bytes_in_buffer = 0; -: 98: } else { -: 99: /* Skip portion of the buffer */ 179: 100: source->pub.bytes_in_buffer -= num_bytes; 179: 101: source->pub.next_input_byte += num_bytes; 179: 102: source->skip = 0; -: 103: } 179: 104:} -: 105: -: 106: -: 107:GLOBAL(void) function jpeg_buffer_src called 191 returned 100% blocks executed 100% 191: 108:jpeg_buffer_src(j_decompress_ptr cinfo, JPEGSOURCE* source) -: 109:{ 191: 110: cinfo->src = (void*) source; -: 111: -: 112: /* Prepare for suspending reader */ 191: 113: source->pub.init_source = stub; 191: 114: source->pub.fill_input_buffer = fill_input_buffer; 191: 115: source->pub.skip_input_data = skip_input_data; 191: 116: source->pub.resync_to_restart = jpeg_resync_to_restart; 191: 117: source->pub.term_source = stub; 191: 118: source->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ -: 119: 191: 120: source->skip = 0; 191: 121:} -: 122: -: 123: -: 124:/* -------------------------------------------------------------------- */ -: 125:/* Error handler */ -: 126:/* -------------------------------------------------------------------- */ -: 127: -: 128:METHODDEF(void) function error called 0 returned 0% blocks executed 0% #####: 129:error(j_common_ptr cinfo) -: 130:{ -: 131: JPEGERROR* error; #####: 132: error = (JPEGERROR*) cinfo->err; #####: 133: longjmp(error->setjmp_buffer, 1); -: 134:} -: 135: -: 136:METHODDEF(void) function output called 1 returned 100% blocks executed 100% 1: 137:output(j_common_ptr cinfo) -: 138:{ -: 139: /* nothing */ 1: 140:} -: 141: -: 142:/* -------------------------------------------------------------------- */ -: 143:/* Decoder */ -: 144:/* -------------------------------------------------------------------- */ -: 145: -: 146:int function ImagingJpegDecode called 215 returned 100% blocks executed 75% 215: 147:ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) -: 148:{ 215: 149: JPEGSTATE* context = (JPEGSTATE*) state->context; -: 150: int ok; -: 151: 215: 152: if (setjmp(context->error.setjmp_buffer)) { branch 0 taken 0% branch 1 taken 100% -: 153: /* JPEG error handler */ #####: 154: jpeg_destroy_decompress(&context->cinfo); call 0 never executed #####: 155: state->errcode = IMAGING_CODEC_BROKEN; #####: 156: return -1; -: 157: } -: 158: 215: 159: if (!state->state) { branch 0 taken 89% (fallthrough) branch 1 taken 11% -: 160: -: 161: /* Setup decompression context */ 191: 162: context->cinfo.err = jpeg_std_error(&context->error.pub); call 0 returned 100% 191: 163: context->error.pub.error_exit = error; 191: 164: context->error.pub.output_message = output; 191: 165: jpeg_create_decompress(&context->cinfo); call 0 returned 100% 191: 166: jpeg_buffer_src(&context->cinfo, &context->source); call 0 returned 100% -: 167: -: 168: /* Ready to decode */ 191: 169: state->state = 1; -: 170: -: 171: } -: 172: -: 173: /* Load the source buffer */ 215: 174: context->source.pub.next_input_byte = buf; 215: 175: context->source.pub.bytes_in_buffer = bytes; -: 176: 215: 177: if (context->source.skip > 0) { branch 0 taken 3% (fallthrough) branch 1 taken 97% 12: 178: skip_input_data(&context->cinfo, context->source.skip); 6: 179: if (context->source.skip > 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 180: return context->source.pub.next_input_byte - buf; -: 181: } -: 182: } -: 183: 215: 184: switch (state->state) { branch 0 taken 92% branch 1 taken 1% branch 2 taken 7% branch 3 taken 0% branch 4 taken 0% -: 185: -: 186: case 1: -: 187: -: 188: /* Read JPEG header, until we find an image body. */ -: 189: do { -: 190: -: 191: /* Note that we cannot return unless we have decoded -: 192: as much data as possible. */ 197: 193: ok = jpeg_read_header(&context->cinfo, FALSE); call 0 returned 100% -: 194: 197: 195: } while (ok == JPEG_HEADER_TABLES_ONLY); branch 0 taken 0% branch 1 taken 100% (fallthrough) -: 196: 197: 197: if (ok == JPEG_SUSPENDED) { branch 0 taken 97% (fallthrough) branch 1 taken 3% -: 198: break; -: 199: } -: 200: -: 201: /* Decoder settings */ -: 202: -: 203: /* jpegmode indicates whats in the file; if not set, we'll -: 204: trust the decoder */ 191: 205: if (strcmp(context->jpegmode, "L") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 taken 0% (fallthrough) branch 3 taken 100% #####: 206: context->cinfo.jpeg_color_space = JCS_GRAYSCALE; 191: 207: } else if (strcmp(context->jpegmode, "RGB") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed branch 4 never executed branch 5 never executed branch 6 taken 0% (fallthrough) branch 7 taken 100% #####: 208: context->cinfo.jpeg_color_space = JCS_RGB; 191: 209: } else if (strcmp(context->jpegmode, "CMYK") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 210: context->cinfo.jpeg_color_space = JCS_CMYK; 191: 211: } else if (strcmp(context->jpegmode, "YCbCr") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 212: context->cinfo.jpeg_color_space = JCS_YCbCr; 191: 213: } else if (strcmp(context->jpegmode, "YCbCrK") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 214: context->cinfo.jpeg_color_space = JCS_YCCK; -: 215: } -: 216: -: 217: /* rawmode indicates what we want from the decoder. if not -: 218: set, conversions are disabled */ 191: 219: if (strcmp(context->rawmode, "L") == 0) { branch 0 taken 15% (fallthrough) branch 1 taken 85% branch 2 taken 15% (fallthrough) branch 3 taken 85% 29: 220: context->cinfo.out_color_space = JCS_GRAYSCALE; 162: 221: } else if (strcmp(context->rawmode, "RGB") == 0) { branch 0 taken 88% (fallthrough) branch 1 taken 12% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 0% (fallthrough) branch 7 taken 100% #####: 222: context->cinfo.out_color_space = JCS_RGB; -: 223: } -: 224: #ifdef JCS_EXTENSIONS 162: 225: else if (strcmp(context->rawmode, "RGBX") == 0) { branch 0 taken 88% (fallthrough) branch 1 taken 12% 142: 226: context->cinfo.out_color_space = JCS_EXT_RGBX; -: 227: } -: 228: #endif 40: 229: else if (strcmp(context->rawmode, "CMYK") == 0 || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 95% (fallthrough) branch 3 taken 5% 20: 230: strcmp(context->rawmode, "CMYK;I") == 0) { 19: 231: context->cinfo.out_color_space = JCS_CMYK; 1: 232: } else if (strcmp(context->rawmode, "YCbCr") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 1: 233: context->cinfo.out_color_space = JCS_YCbCr; #####: 234: } else if (strcmp(context->rawmode, "YCbCrK") == 0) { branch 0 never executed branch 1 never executed #####: 235: context->cinfo.out_color_space = JCS_YCCK; -: 236: } else { -: 237: /* Disable decoder conversions */ #####: 238: context->cinfo.jpeg_color_space = JCS_UNKNOWN; #####: 239: context->cinfo.out_color_space = JCS_UNKNOWN; -: 240: } -: 241: 191: 242: if (context->scale > 1) { branch 0 taken 10% (fallthrough) branch 1 taken 90% 19: 243: context->cinfo.scale_num = 1; 19: 244: context->cinfo.scale_denom = context->scale; -: 245: } 191: 246: if (context->draft) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 247: context->cinfo.do_fancy_upsampling = FALSE; #####: 248: context->cinfo.dct_method = JDCT_FASTEST; -: 249: } -: 250: 191: 251: state->state++; -: 252: /* fall through */ -: 253: -: 254: case 2: -: 255: -: 256: /* Set things up for decompression (this processes the entire -: 257: file if necessary to return data line by line) */ 193: 258: if (!jpeg_start_decompress(&context->cinfo)) { call 0 returned 100% branch 1 taken 98% (fallthrough) branch 2 taken 2% -: 259: break; -: 260: } -: 261: 189: 262: state->state++; -: 263: /* fall through */ -: 264: -: 265: case 3: -: 266: -: 267: /* Decompress a single line of data */ -: 268: ok = 1; 35605: 269: while (state->y < state->ysize) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 35416: 270: ok = jpeg_read_scanlines(&context->cinfo, &state->buffer, 1); call 0 returned 100% 35416: 271: if (ok != 1) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 272: break; -: 273: } 106200: 274: state->shuffle((UINT8*) im->image[state->y + state->yoff] + call 0 returned 100% 70800: 275: state->xoff * im->pixelsize, state->buffer, -: 276: state->xsize); 35400: 277: state->y++; -: 278: } 205: 279: if (ok != 1) { branch 0 taken 92% (fallthrough) branch 1 taken 8% -: 280: break; -: 281: } 189: 282: state->state++; -: 283: /* fall through */ -: 284: -: 285: case 4: -: 286: -: 287: /* Finish decompression */ 189: 288: if (!jpeg_finish_decompress(&context->cinfo)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% -: 289: /* FIXME: add strictness mode test */ #####: 290: if (state->y < state->ysize) { branch 0 never executed branch 1 never executed -: 291: break; -: 292: } -: 293: } -: 294: -: 295: /* Clean up */ 189: 296: jpeg_destroy_decompress(&context->cinfo); call 0 returned 100% -: 297: /* if (jerr.pub.num_warnings) return BROKEN; */ -: 298: return -1; -: 299: -: 300: } -: 301: -: 302: /* Return number of bytes consumed */ 26: 303: return context->source.pub.next_input_byte - buf; -: 304: -: 305:} -: 306: -: 307:/* -------------------------------------------------------------------- */ -: 308:/* Cleanup */ -: 309:/* -------------------------------------------------------------------- */ -: 310: function ImagingJpegDecodeCleanup called 382 returned 100% blocks executed 100% 382: 311:int ImagingJpegDecodeCleanup(ImagingCodecState state){ -: 312: /* called to free the decompression engine when the decode terminates -: 313: due to a corrupt or truncated image -: 314: */ 382: 315: JPEGSTATE* context = (JPEGSTATE*) state->context; -: 316: -: 317: /* Clean up */ 382: 318: jpeg_destroy_decompress(&context->cinfo); call 0 returned 100% 382: 319: return -1; -: 320:} -: 321: -: 322:#endif -: 323: <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#SgiRleDecode.c.gcov -: 0:Source:src/libImaging/SgiRleDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/SgiRleDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/SgiRleDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for Sgi RLE data. -: 6: * -: 7: * history: -: 8: * 2017-07-28 mb fixed for images larger than 64KB -: 9: * 2017-07-20 mb created -: 10: * -: 11: * Copyright (c) Mickael Bonfill 2017. -: 12: * -: 13: * See the README file for information on usage and redistribution. -: 14: */ -: 15: -: 16:#include "Imaging.h" -: 17:#include "Sgi.h" -: 18: -: 19:#define SGI_HEADER_SIZE 512 -: 20:#define RLE_COPY_FLAG 0x80 -: 21:#define RLE_MAX_RUN 0x7f -: 22: -: 23:static void read4B(UINT32* dest, UINT8* buf) -: 24:{ 7310: 25: *dest = (UINT32)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); -: 26:} -: 27: function expandrow called 390 returned 100% blocks executed 94% 390: 28:static int expandrow(UINT8* dest, UINT8* src, int n, int z, int xsize) -: 29:{ -: 30: UINT8 pixel, count; 390: 31: int x = 0; -: 32: 4029: 33: for (;n > 0; n--) branch 0 taken 100% branch 1 taken 0% (fallthrough) -: 34: { 4029: 35: pixel = *src++; 4029: 36: if (n == 1 && pixel != 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed -: 37: return n; -: 38: } 4029: 39: count = pixel & RLE_MAX_RUN; 4029: 40: if (!count) { branch 0 taken 10% (fallthrough) branch 1 taken 90% 389: 41: return count; -: 42: } 3640: 43: if (x + count > xsize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 44: return -1; -: 45: } 3639: 46: x += count; 3639: 47: if (pixel & RLE_COPY_FLAG) { branch 0 taken 42% (fallthrough) branch 1 taken 58% 44413: 48: while(count--) { branch 0 taken 97% branch 1 taken 3% 42875: 49: *dest = *src++; 42875: 50: dest += z; -: 51: } -: 52: -: 53: } -: 54: else { 2101: 55: pixel = *src++; 10993: 56: while (count--) { branch 0 taken 76% branch 1 taken 24% (fallthrough) 6791: 57: *dest = pixel; 6791: 58: dest += z; -: 59: } -: 60: } -: 61: -: 62: } -: 63: return 0; -: 64:} -: 65: function expandrow2 called 2289 returned 100% blocks executed 94% 2289: 66:static int expandrow2(UINT8* dest, const UINT8* src, int n, int z, int xsize) -: 67:{ -: 68: UINT8 pixel, count; -: 69: 2289: 70: int x = 0; -: 71: 27832: 72: for (;n > 0; n--) branch 0 taken 100% branch 1 taken 0% (fallthrough) -: 73: { 27832: 74: pixel = src[1]; 27832: 75: src+=2; 27832: 76: if (n == 1 && pixel != 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed -: 77: return n; -: 78: } 27832: 79: count = pixel & RLE_MAX_RUN; 27832: 80: if (!count) { branch 0 taken 8% (fallthrough) branch 1 taken 92% 2286: 81: return count; -: 82: } 25546: 83: if (x + count > xsize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 84: return -1; -: 85: } 25543: 86: x += count; 25543: 87: if (pixel & RLE_COPY_FLAG) { branch 0 taken 57% (fallthrough) branch 1 taken 43% 790014: 88: while(count--) { branch 0 taken 99% branch 1 taken 1% 778949: 89: memcpy(dest, src, 2); 778949: 90: src += 2; 778949: 91: dest += z * 2; -: 92: } -: 93: } -: 94: else { 699326: 95: while (count--) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 684848: 96: memcpy(dest, src, 2); 684848: 97: dest += z * 2; -: 98: } 14478: 99: src+=2; -: 100: } -: 101: } -: 102: return 0; -: 103:} -: 104: -: 105: -: 106:int function ImagingSgiRleDecode called 7 returned 100% blocks executed 97% 7: 107:ImagingSgiRleDecode(Imaging im, ImagingCodecState state, -: 108: UINT8* buf, Py_ssize_t bytes) -: 109:{ -: 110: UINT8 *ptr; -: 111: SGISTATE *c; 7: 112: int err = 0; -: 113: int status; -: 114: -: 115: /* Get all data from File descriptor */ 7: 116: c = (SGISTATE*)state->context; 7: 117: _imaging_seek_pyFd(state->fd, 0L, SEEK_END); call 0 returned 100% 7: 118: c->bufsize = _imaging_tell_pyFd(state->fd); call 0 returned 100% 7: 119: c->bufsize -= SGI_HEADER_SIZE; 7: 120: ptr = malloc(sizeof(UINT8) * c->bufsize); 7: 121: if (!ptr) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 122: return IMAGING_CODEC_MEMORY; -: 123: } 7: 124: _imaging_seek_pyFd(state->fd, SGI_HEADER_SIZE, SEEK_SET); call 0 returned 100% 7: 125: _imaging_read_pyFd(state->fd, (char*)ptr, c->bufsize); call 0 returned 100% -: 126: -: 127: -: 128: /* decoder initialization */ 7: 129: state->count = 0; 7: 130: state->y = 0; 7: 131: if (state->ystep < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 7: 132: state->y = im->ysize - 1; -: 133: } else { #####: 134: state->ystep = 1; -: 135: } -: 136: 14: 137: if (im->xsize > INT_MAX / im->bands || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 7: 138: im->ysize > INT_MAX / im->bands) { -: 139: err = IMAGING_CODEC_MEMORY; -: 140: goto sgi_finish_decode; -: 141: } -: 142: -: 143: /* Allocate memory for RLE tables and rows */ 7: 144: free(state->buffer); 7: 145: state->buffer = NULL; -: 146: /* malloc overflow check above */ 7: 147: state->buffer = calloc(im->xsize * im->bands, sizeof(UINT8) * 2); 7: 148: c->tablen = im->bands * im->ysize; 7: 149: c->starttab = calloc(c->tablen, sizeof(UINT32)); 7: 150: c->lengthtab = calloc(c->tablen, sizeof(UINT32)); 7: 151: if (!state->buffer || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 7: 152: !c->starttab || branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 153: !c->lengthtab) { -: 154: err = IMAGING_CODEC_MEMORY; -: 155: goto sgi_finish_decode; -: 156: } -: 157: /* populate offsets table */ 3662: 158: for (c->tabindex = 0, c->bufindex = 0; c->tabindex < c->tablen; c->tabindex++, c->bufindex+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 7310: 159: read4B(&c->starttab[c->tabindex], &ptr[c->bufindex]); -: 160: } -: 161: /* populate lengths table */ 3662: 162: for (c->tabindex = 0, c->bufindex = c->tablen * sizeof(UINT32); c->tabindex < c->tablen; c->tabindex++, c->bufindex+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 7310: 163: read4B(&c->lengthtab[c->tabindex], &ptr[c->bufindex]); -: 164: } -: 165: 7: 166: state->count += c->tablen * sizeof(UINT32) * 2; -: 167: -: 168: /* read compressed rows */ 898: 169: for (c->rowno = 0; c->rowno < im->ysize; c->rowno++, state->y += state->ystep) branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 170: { 3571: 171: for (c->channo = 0; c->channo < im->bands; c->channo++) branch 0 taken 75% branch 1 taken 25% (fallthrough) -: 172: { 2680: 173: c->rleoffset = c->starttab[c->rowno + c->channo * im->ysize]; 2680: 174: c->rlelength = c->lengthtab[c->rowno + c->channo * im->ysize]; 2680: 175: c->rleoffset -= SGI_HEADER_SIZE; -: 176: 2680: 177: if (c->rleoffset + c->rlelength > c->bufsize) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1: 178: state->errcode = IMAGING_CODEC_OVERRUN; 1: 179: return -1; -: 180: } -: 181: -: 182: /* row decompression */ 2679: 183: if (c->bpc ==1) { branch 0 taken 15% (fallthrough) branch 1 taken 85% 390: 184: status = expandrow(&state->buffer[c->channo], &ptr[c->rleoffset], c->rlelength, im->bands, im->xsize); call 0 returned 100% -: 185: } -: 186: else { 2289: 187: status = expandrow2(&state->buffer[c->channo * 2], &ptr[c->rleoffset], c->rlelength, im->bands, im->xsize); call 0 returned 100% -: 188: } 2679: 189: if (status == -1) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 4: 190: state->errcode = IMAGING_CODEC_OVERRUN; 4: 191: return -1; 2675: 192: } else if (status == 1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 193: goto sgi_finish_decode; -: 194: } -: 195: 2675: 196: state->count += c->rlelength; -: 197: } -: 198: -: 199: /* store decompressed data in image */ 891: 200: state->shuffle((UINT8*)im->image[state->y], state->buffer, im->xsize); call 0 returned 100% -: 201: -: 202: } -: 203: 2: 204: c->bufsize++; -: 205: -: 206:sgi_finish_decode: ; -: 207: 2: 208: free(c->starttab); 2: 209: free(c->lengthtab); 2: 210: free(ptr); 2: 211: if (err != 0){ branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 212: return err; -: 213: } 2: 214: return state->count - c->bufsize; -: 215:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#_imaging.c.gcov -: 0:Source:src/_imaging.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/_imaging.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/_imaging.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * -: 4: * the imaging library bindings -: 5: * -: 6: * history: -: 7: * 1995-09-24 fl Created -: 8: * 1996-03-24 fl Ready for first public release (release 0.0) -: 9: * 1996-03-25 fl Added fromstring (for Jack's "img" library) -: 10: * 1996-03-28 fl Added channel operations -: 11: * 1996-03-31 fl Added point operation -: 12: * 1996-04-08 fl Added new/new_block/new_array factories -: 13: * 1996-04-13 fl Added decoders -: 14: * 1996-05-04 fl Added palette hack -: 15: * 1996-05-12 fl Compile cleanly as C++ -: 16: * 1996-05-19 fl Added matrix conversions, gradient fills -: 17: * 1996-05-27 fl Added display_mode -: 18: * 1996-07-22 fl Added getbbox, offset -: 19: * 1996-07-23 fl Added sequence semantics -: 20: * 1996-08-13 fl Added logical operators, point mode -: 21: * 1996-08-16 fl Modified paste interface -: 22: * 1996-09-06 fl Added putdata methods, use abstract interface -: 23: * 1996-11-01 fl Added xbm encoder -: 24: * 1996-11-04 fl Added experimental path stuff, draw_lines, etc -: 25: * 1996-12-10 fl Added zip decoder, crc32 interface -: 26: * 1996-12-14 fl Added modulo arithmetics -: 27: * 1996-12-29 fl Added zip encoder -: 28: * 1997-01-03 fl Added fli and msp decoders -: 29: * 1997-01-04 fl Added experimental sun_rle and tga_rle decoders -: 30: * 1997-01-05 fl Added gif encoder, getpalette hack -: 31: * 1997-02-23 fl Added histogram mask -: 32: * 1997-05-12 fl Minor tweaks to match the IFUNC95 interface -: 33: * 1997-05-21 fl Added noise generator, spread effect -: 34: * 1997-06-05 fl Added mandelbrot generator -: 35: * 1997-08-02 fl Modified putpalette to coerce image mode if necessary -: 36: * 1998-01-11 fl Added INT32 support -: 37: * 1998-01-22 fl Fixed draw_points to draw the last point too -: 38: * 1998-06-28 fl Added getpixel, getink, draw_ink -: 39: * 1998-07-12 fl Added getextrema -: 40: * 1998-07-17 fl Added point conversion to arbitrary formats -: 41: * 1998-09-21 fl Added support for resampling filters -: 42: * 1998-09-22 fl Added support for quad transform -: 43: * 1998-12-29 fl Added support for arcs, chords, and pieslices -: 44: * 1999-01-10 fl Added some experimental arrow graphics stuff -: 45: * 1999-02-06 fl Added draw_bitmap, font acceleration stuff -: 46: * 2001-04-17 fl Fixed some egcs compiler nits -: 47: * 2001-09-17 fl Added screen grab primitives (win32) -: 48: * 2002-03-09 fl Added stretch primitive -: 49: * 2002-03-10 fl Fixed filter handling in rotate -: 50: * 2002-06-06 fl Added I, F, and RGB support to putdata -: 51: * 2002-06-08 fl Added rankfilter -: 52: * 2002-06-09 fl Added support for user-defined filter kernels -: 53: * 2002-11-19 fl Added clipboard grab primitives (win32) -: 54: * 2002-12-11 fl Added draw context -: 55: * 2003-04-26 fl Tweaks for Python 2.3 beta 1 -: 56: * 2003-05-21 fl Added createwindow primitive (win32) -: 57: * 2003-09-13 fl Added thread section hooks -: 58: * 2003-09-15 fl Added expand helper -: 59: * 2003-09-26 fl Added experimental LA support -: 60: * 2004-02-21 fl Handle zero-size images in quantize -: 61: * 2004-06-05 fl Added ptr attribute (used to access Imaging objects) -: 62: * 2004-06-05 fl Don't crash when fetching pixels from zero-wide images -: 63: * 2004-09-17 fl Added getcolors -: 64: * 2004-10-04 fl Added modefilter -: 65: * 2005-10-02 fl Added access proxy -: 66: * 2006-06-18 fl Always draw last point in polyline -: 67: * -: 68: * Copyright (c) 1997-2006 by Secret Labs AB -: 69: * Copyright (c) 1995-2006 by Fredrik Lundh -: 70: * -: 71: * See the README file for information on usage and redistribution. -: 72: */ -: 73: -: 74:#define PY_SSIZE_T_CLEAN -: 75:#include "Python.h" -: 76: -: 77:#ifdef HAVE_LIBJPEG -: 78:#include "jconfig.h" -: 79:#endif -: 80: -: 81:#ifdef HAVE_LIBZ -: 82:#include "zlib.h" -: 83:#endif -: 84: -: 85:#ifdef HAVE_LIBTIFF -: 86:#ifndef _TIFFIO_ -: 87:#include -: 88:#endif -: 89:#endif -: 90: -: 91:#include "libImaging/Imaging.h" -: 92: -: 93:#define _USE_MATH_DEFINES -: 94:#include -: 95: -: 96:/* Configuration stuff. Feel free to undef things you don't need. */ -: 97:#define WITH_IMAGECHOPS /* ImageChops support */ -: 98:#define WITH_IMAGEDRAW /* ImageDraw support */ -: 99:#define WITH_MAPPING /* use memory mapping to read some file formats */ -: 100:#define WITH_IMAGEPATH /* ImagePath stuff */ -: 101:#define WITH_ARROW /* arrow graphics stuff (experimental) */ -: 102:#define WITH_EFFECTS /* special effects */ -: 103:#define WITH_QUANTIZE /* quantization support */ -: 104:#define WITH_RANKFILTER /* rank filter */ -: 105:#define WITH_MODEFILTER /* mode filter */ -: 106:#define WITH_THREADING /* "friendly" threading support */ -: 107:#define WITH_UNSHARPMASK /* Kevin Cazabon's unsharpmask module */ -: 108: -: 109:#undef VERBOSE -: 110: -: 111:#define B16(p, i) ((((int)p[(i)]) << 8) + p[(i)+1]) -: 112:#define L16(p, i) ((((int)p[(i)+1]) << 8) + p[(i)]) -: 113:#define S16(v) ((v) < 32768 ? (v) : ((v) - 65536)) -: 114: -: 115:/* -------------------------------------------------------------------- */ -: 116:/* OBJECT ADMINISTRATION */ -: 117:/* -------------------------------------------------------------------- */ -: 118: -: 119:typedef struct { -: 120: PyObject_HEAD -: 121: Imaging image; -: 122: ImagingAccess access; -: 123:} ImagingObject; -: 124: -: 125:static PyTypeObject Imaging_Type; -: 126: -: 127:#ifdef WITH_IMAGEDRAW -: 128: -: 129:typedef struct -: 130:{ -: 131: /* to write a character, cut out sxy from glyph data, place -: 132: at current position plus dxy, and advance by (dx, dy) */ -: 133: int dx, dy; -: 134: int dx0, dy0, dx1, dy1; -: 135: int sx0, sy0, sx1, sy1; -: 136:} Glyph; -: 137: -: 138:typedef struct { -: 139: PyObject_HEAD -: 140: ImagingObject* ref; -: 141: Imaging bitmap; -: 142: int ysize; -: 143: int baseline; -: 144: Glyph glyphs[256]; -: 145:} ImagingFontObject; -: 146: -: 147:static PyTypeObject ImagingFont_Type; -: 148: -: 149:typedef struct { -: 150: PyObject_HEAD -: 151: ImagingObject* image; -: 152: UINT8 ink[4]; -: 153: int blend; -: 154:} ImagingDrawObject; -: 155: -: 156:static PyTypeObject ImagingDraw_Type; -: 157: -: 158:#endif -: 159: -: 160:typedef struct { -: 161: PyObject_HEAD -: 162: ImagingObject* image; -: 163: int readonly; -: 164:} PixelAccessObject; -: 165: -: 166:static PyTypeObject PixelAccess_Type; -: 167: -: 168:PyObject* function PyImagingNew called 53148 returned 100% blocks executed 75% 53148: 169:PyImagingNew(Imaging imOut) -: 170:{ -: 171: ImagingObject* imagep; -: 172: 53148: 173: if (!imOut) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 174: return NULL; -: 175: } -: 176: 52932: 177: imagep = PyObject_New(ImagingObject, &Imaging_Type); call 0 returned 100% 52932: 178: if (imagep == NULL) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 179: ImagingDelete(imOut); call 0 never executed #####: 180: return NULL; -: 181: } -: 182: -: 183:#ifdef VERBOSE -: 184: printf("imaging %p allocated\n", imagep); -: 185:#endif -: 186: 52932: 187: imagep->image = imOut; 52932: 188: imagep->access = ImagingAccessNew(imOut); call 0 returned 100% -: 189: 52932: 190: return (PyObject*) imagep; -: 191:} -: 192: -: 193:static void function _dealloc called 52896 returned 100% blocks executed 100% 52896: 194:_dealloc(ImagingObject* imagep) -: 195:{ -: 196: -: 197:#ifdef VERBOSE -: 198: printf("imaging %p deleted\n", imagep); -: 199:#endif -: 200: -: 201: if (imagep->access) { -: 202: ImagingAccessDelete(imagep->image, imagep->access); -: 203: } 52896: 204: ImagingDelete(imagep->image); call 0 returned 100% 52896: 205: PyObject_Del(imagep); call 0 returned 100% 52896: 206:} -: 207: -: 208:#define PyImaging_Check(op) (Py_TYPE(op) == &Imaging_Type) -: 209: function PyImaging_AsImaging called 35472 returned 100% blocks executed 60% 35472: 210:Imaging PyImaging_AsImaging(PyObject *op) -: 211:{ 35472: 212: if (!PyImaging_Check(op)) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 213: PyErr_BadInternalCall(); call 0 never executed #####: 214: return NULL; -: 215: } -: 216: 35472: 217: return ((ImagingObject *)op)->image; -: 218:} -: 219: -: 220: -: 221:/* -------------------------------------------------------------------- */ -: 222:/* THREAD HANDLING */ -: 223:/* -------------------------------------------------------------------- */ -: 224: function ImagingSectionEnter called 2137796 returned 100% blocks executed 100% 2137796: 225:void ImagingSectionEnter(ImagingSectionCookie* cookie) -: 226:{ -: 227:#ifdef WITH_THREADING 2137796: 228: *cookie = (PyThreadState *) PyEval_SaveThread(); call 0 returned 100% -: 229:#endif 2137796: 230:} -: 231: function ImagingSectionLeave called 2137796 returned 100% blocks executed 100% 2137796: 232:void ImagingSectionLeave(ImagingSectionCookie* cookie) -: 233:{ -: 234:#ifdef WITH_THREADING 2137796: 235: PyEval_RestoreThread((PyThreadState*) *cookie); call 0 returned 100% -: 236:#endif 2137796: 237:} -: 238: -: 239:/* -------------------------------------------------------------------- */ -: 240:/* BUFFER HANDLING */ -: 241:/* -------------------------------------------------------------------- */ -: 242:/* Python compatibility API */ -: 243: function PyImaging_CheckBuffer called 3038 returned 100% blocks executed 100% 3038: 244:int PyImaging_CheckBuffer(PyObject* buffer) -: 245:{ 3038: 246: return PyObject_CheckBuffer(buffer); branch 0 taken 4% (fallthrough) branch 1 taken 96% branch 2 taken 0% (fallthrough) branch 3 taken 100% -: 247:} -: 248: function PyImaging_GetBuffer called 109 returned 100% blocks executed 100% 109: 249:int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view) -: 250:{ -: 251: /* must call check_buffer first! */ 109: 252: return PyObject_GetBuffer(buffer, view, PyBUF_SIMPLE); call 0 returned 100% -: 253:} -: 254: -: 255:/* -------------------------------------------------------------------- */ -: 256:/* EXCEPTION REROUTING */ -: 257:/* -------------------------------------------------------------------- */ -: 258: -: 259:/* error messages */ -: 260:static const char* must_be_sequence = "argument must be a sequence"; -: 261:static const char* must_be_two_coordinates = -: 262: "coordinate list must contain exactly 2 coordinates"; -: 263:static const char* wrong_mode = "unrecognized image mode"; -: 264:static const char* wrong_raw_mode = "unrecognized raw mode"; -: 265:static const char* outside_image = "image index out of range"; -: 266:static const char* outside_palette = "palette index out of range"; -: 267:static const char* wrong_palette_size = "invalid palette size"; -: 268:static const char* no_palette = "image has no palette"; -: 269:static const char* readonly = "image is readonly"; -: 270:/* static const char* no_content = "image has no content"; */ -: 271: -: 272:void * function ImagingError_OSError called 0 returned 0% blocks executed 0% #####: 273:ImagingError_OSError(void) -: 274:{ #####: 275: PyErr_SetString(PyExc_OSError, "error when accessing file"); call 0 never executed #####: 276: return NULL; -: 277:} -: 278: -: 279:void * function ImagingError_MemoryError called 2 returned 100% blocks executed 100% 2: 280:ImagingError_MemoryError(void) -: 281:{ 2: 282: return PyErr_NoMemory(); call 0 returned 100% -: 283:} -: 284: -: 285:void * function ImagingError_Mismatch called 0 returned 0% blocks executed 0% #####: 286:ImagingError_Mismatch(void) -: 287:{ #####: 288: PyErr_SetString(PyExc_ValueError, "images do not match"); call 0 never executed #####: 289: return NULL; -: 290:} -: 291: -: 292:void * function ImagingError_ModeError called 32 returned 100% blocks executed 100% 32: 293:ImagingError_ModeError(void) -: 294:{ 32: 295: PyErr_SetString(PyExc_ValueError, "image has wrong mode"); call 0 returned 100% 32: 296: return NULL; -: 297:} -: 298: -: 299:void * function ImagingError_ValueError called 264 returned 100% blocks executed 100% 264: 300:ImagingError_ValueError(const char *message) -: 301:{ 264: 302: PyErr_SetString( branch 0 taken 99% (fallthrough) branch 1 taken 1% call 2 returned 100% -: 303: PyExc_ValueError, -: 304: (message) ? (char*) message : "unrecognized argument value" -: 305: ); 264: 306: return NULL; -: 307:} -: 308: -: 309:void function ImagingError_Clear called 0 returned 0% blocks executed 0% #####: 310:ImagingError_Clear(void) -: 311:{ #####: 312: PyErr_Clear(); call 0 never executed #####: 313:} -: 314: -: 315:/* -------------------------------------------------------------------- */ -: 316:/* HELPERS */ -: 317:/* -------------------------------------------------------------------- */ -: 318: -: 319:static int function getbands called 1 returned 100% blocks executed 100% 1: 320:getbands(const char* mode) -: 321:{ -: 322: Imaging im; -: 323: int bands; -: 324: -: 325: /* FIXME: add primitive to libImaging to avoid extra allocation */ 1: 326: im = ImagingNew(mode, 0, 0); call 0 returned 100% 1: 327: if (!im) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 328: return -1; -: 329: } -: 330: 1: 331: bands = im->bands; -: 332: 1: 333: ImagingDelete(im); call 0 returned 100% -: 334: 1: 335: return bands; -: 336:} -: 337: -: 338:#define TYPE_UINT8 (0x100|sizeof(UINT8)) -: 339:#define TYPE_INT32 (0x200|sizeof(INT32)) -: 340:#define TYPE_FLOAT16 (0x500|sizeof(FLOAT16)) -: 341:#define TYPE_FLOAT32 (0x300|sizeof(FLOAT32)) -: 342:#define TYPE_DOUBLE (0x400|sizeof(double)) -: 343: -: 344:static void* function getlist called 402 returned 100% blocks executed 95% 402: 345:getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type) -: 346:{ -: 347: /* - allocates and returns a c array of the items in the -: 348: python sequence arg. -: 349: - the size of the returned array is in length -: 350: - all of the arg items must be numeric items of the type -: 351: specified in type -: 352: - sequence length is checked against the length parameter IF -: 353: an error parameter is passed in wrong_length -: 354: - caller is responsible for freeing the memory -: 355: */ -: 356: -: 357: Py_ssize_t i, n; -: 358: int itemp; -: 359: double dtemp; -: 360: FLOAT32 ftemp; -: 361: UINT8* list; -: 362: PyObject* seq; -: 363: PyObject* op; -: 364: 402: 365: if ( ! PySequence_Check(arg)) { call 0 returned 100% branch 1 taken 1% (fallthrough) branch 2 taken 99% 1: 366: PyErr_SetString(PyExc_TypeError, must_be_sequence); call 0 returned 100% 1: 367: return NULL; -: 368: } -: 369: 401: 370: n = PySequence_Size(arg); call 0 returned 100% 401: 371: if (length && wrong_length && n != *length) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 88% (fallthrough) branch 3 taken 12% branch 4 taken 1% (fallthrough) branch 5 taken 99% 5: 372: PyErr_SetString(PyExc_ValueError, wrong_length); call 0 returned 100% 5: 373: return NULL; -: 374: } -: 375: -: 376: /* malloc check ok, type & ff is just a sizeof(something) -: 377: calloc checks for overflow */ 396: 378: list = calloc(n, type & 0xff); 396: 379: if ( ! list) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 380: return PyErr_NoMemory(); call 0 never executed -: 381: } -: 382: 396: 383: seq = PySequence_Fast(arg, must_be_sequence); call 0 returned 100% 396: 384: if ( ! seq) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 385: free(list); #####: 386: return NULL; -: 387: } -: 388: 165926: 389: for (i = 0; i < n; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 165926: 390: op = PySequence_Fast_GET_ITEM(seq, i); branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 391: // DRY, branch prediction is going to work _really_ well -: 392: // on this switch. And 3 fewer loops to copy/paste. 165926: 393: switch (type) { branch 0 taken 39% branch 1 taken 11% branch 2 taken 48% branch 3 taken 1% branch 4 taken 0% -: 394: case TYPE_UINT8: 65536: 395: itemp = PyLong_AsLong(op); call 0 returned 100% 65536: 396: list[i] = CLIP8(itemp); branch 0 taken 99% (fallthrough) branch 1 taken 1% 65536: 397: break; -: 398: case TYPE_INT32: 18944: 399: itemp = PyLong_AsLong(op); call 0 returned 100% 18944: 400: memcpy(list + i * sizeof(INT32), &itemp, sizeof(itemp)); -: 401: break; -: 402: case TYPE_FLOAT32: 79664: 403: ftemp = (FLOAT32)PyFloat_AsDouble(op); call 0 returned 100% 79664: 404: memcpy(list + i * sizeof(ftemp), &ftemp, sizeof(ftemp)); -: 405: break; -: 406: case TYPE_DOUBLE: 1782: 407: dtemp = PyFloat_AsDouble(op); call 0 returned 100% 1782: 408: memcpy(list + i * sizeof(dtemp), &dtemp, sizeof(dtemp)); -: 409: break; -: 410: } -: 411: } -: 412: 396: 413: Py_DECREF(seq); branch 0 taken 1% (fallthrough) branch 1 taken 99% call 2 returned 100% -: 414: 396: 415: if (PyErr_Occurred()) { call 0 returned 100% branch 1 taken 1% (fallthrough) branch 2 taken 99% 1: 416: free(list); 1: 417: return NULL; -: 418: } -: 419: 395: 420: if (length) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 395: 421: *length = n; -: 422: } -: 423: -: 424: return list; -: 425:} -: 426: -: 427:FLOAT32 function float16tofloat32 called 2709 returned 100% blocks executed 100% 2709: 428:float16tofloat32(const FLOAT16 in) { -: 429: UINT32 t1; -: 430: UINT32 t2; -: 431: UINT32 t3; -: 432: FLOAT32 out[1] = {0}; -: 433: 2709: 434: t1 = in & 0x7fff; // Non-sign bits 2709: 435: t2 = in & 0x8000; // Sign bit 2709: 436: t3 = in & 0x7c00; // Exponent -: 437: 2709: 438: t1 <<= 13; // Align mantissa on MSB 2709: 439: t2 <<= 16; // Shift sign bit into position -: 440: 2709: 441: t1 += 0x38000000; // Adjust bias -: 442: 2709: 443: t1 = (t3 == 0 ? 0 : t1); // Denormals-as-zero branch 0 taken 91% (fallthrough) branch 1 taken 9% -: 444: 2709: 445: t1 |= t2; // Re-insert sign bit -: 446: 2709: 447: memcpy(out, &t1, 4); 2709: 448: return out[0]; -: 449:} -: 450: -: 451:static inline PyObject* function getpixel.isra.1 called 4641756 returned 100% blocks executed 95% 4641756: 452:getpixel(Imaging im, ImagingAccess access, int x, int y) -: 453:{ -: 454: union { -: 455: UINT8 b[4]; -: 456: UINT16 h; -: 457: INT32 i; -: 458: FLOAT32 f; -: 459: } pixel; -: 460: 4641756: 461: if (x < 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 49286: 462: x = im->xsize + x; -: 463: } 4641756: 464: if (y < 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 49286: 465: y = im->ysize + y; -: 466: } -: 467: 4641756: 468: if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 99% (fallthrough) branch 3 taken 1% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 1% (fallthrough) branch 7 taken 99% 300: 469: PyErr_SetString(PyExc_IndexError, outside_image); call 0 returned 100% -: 470: return NULL; -: 471: } -: 472: 4641456: 473: access->get_pixel(im, x, y, &pixel); call 0 returned 100% -: 474: 4641456: 475: switch (im->type) { branch 0 taken 95% branch 1 taken 3% branch 2 taken 1% branch 3 taken 1% branch 4 taken 0% -: 476: case IMAGING_TYPE_UINT8: 4431905: 477: switch (im->bands) { branch 0 taken 93% branch 1 taken 1% branch 2 taken 5% branch 3 taken 2% branch 4 taken 0% -: 478: case 1: 4120100: 479: return PyLong_FromLong(pixel.b[0]); call 0 returned 100% -: 480: case 2: 30335: 481: return Py_BuildValue("BB", pixel.b[0], pixel.b[1]); call 0 returned 100% -: 482: case 3: 200107: 483: return Py_BuildValue("BBB", pixel.b[0], pixel.b[1], pixel.b[2]); call 0 returned 100% -: 484: case 4: 81363: 485: return Py_BuildValue("BBBB", pixel.b[0], pixel.b[1], pixel.b[2], pixel.b[3]); call 0 returned 100% -: 486: } -: 487: break; -: 488: case IMAGING_TYPE_INT32: 119633: 489: return PyLong_FromLong(pixel.i); call 0 returned 100% -: 490: case IMAGING_TYPE_FLOAT32: 62458: 491: return PyFloat_FromDouble(pixel.f); call 0 returned 100% -: 492: case IMAGING_TYPE_SPECIAL: 27460: 493: if (strncmp(im->mode, "I;16", 4) == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 27460: 494: return PyLong_FromLong(pixel.h); call 0 returned 100% -: 495: } -: 496: break; -: 497: } -: 498: -: 499: /* unknown type */ #####: 500: Py_INCREF(Py_None); -: 501: return Py_None; -: 502:} -: 503: -: 504:static char* function getink called 409620 returned 100% blocks executed 93% 409620: 505:getink(PyObject* color, Imaging im, char* ink) -: 506:{ 409620: 507: int g=0, b=0, a=0; 409620: 508: double f=0; -: 509: /* Windows 64 bit longs are 32 bits, and 0xFFFFFFFF (white) is a -: 510: python long (not int) that raises an overflow error when trying -: 511: to return it into a 32 bit C long -: 512: */ 409620: 513: PY_LONG_LONG r = 0; -: 514: FLOAT32 ftmp; -: 515: INT32 itmp; -: 516: -: 517: /* fill ink buffer (four bytes) with something that can -: 518: be cast to either UINT8 or INT32 */ -: 519: 409620: 520: int rIsInt = 0; 409620: 521: if (PyTuple_Check(color) && PyTuple_Size(color) == 1) { branch 0 taken 45% (fallthrough) branch 1 taken 55% call 2 returned 100% branch 3 taken 1% (fallthrough) branch 4 taken 99% 6: 522: color = PyTuple_GetItem(color, 0); call 0 returned 100% -: 523: } 409620: 524: if (im->type == IMAGING_TYPE_UINT8 || branch 0 taken 1% (fallthrough) branch 1 taken 99% 187: 525: im->type == IMAGING_TYPE_INT32 || branch 0 taken 58% (fallthrough) branch 1 taken 42% -: 526: im->type == IMAGING_TYPE_SPECIAL) { 409542: 527: if (PyLong_Check(color)) { branch 0 taken 55% (fallthrough) branch 1 taken 45% 227221: 528: r = PyLong_AsLongLong(color); call 0 returned 100% 227221: 529: if (r == -1 && PyErr_Occurred()) { branch 0 taken 1% (fallthrough) branch 1 taken 99% call 2 returned 100% branch 3 taken 98% branch 4 taken 2% -: 530: return NULL; -: 531: } -: 532: rIsInt = 1; 182321: 533: } else if (im->type == IMAGING_TYPE_UINT8) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 182312: 534: if (!PyTuple_Check(color)) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 12: 535: PyErr_SetString(PyExc_TypeError, "color must be int or tuple"); call 0 returned 100% 12: 536: return NULL; -: 537: } -: 538: } else { 9: 539: PyErr_SetString(PyExc_TypeError, "color must be int or single-element tuple"); call 0 returned 100% 9: 540: return NULL; -: 541: } -: 542: } -: 543: 409592: 544: switch (im->type) { branch 0 taken 99% branch 1 taken 1% branch 2 taken 1% branch 3 taken 1% branch 4 taken 0% -: 545: case IMAGING_TYPE_UINT8: -: 546: /* unsigned integer */ 409318: 547: if (im->bands == 1) { branch 0 taken 55% (fallthrough) branch 1 taken 45% -: 548: /* unsigned integer, single layer */ 226051: 549: if (rIsInt != 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 550: if (!PyArg_ParseTuple(color, "L", &r)) { call 0 never executed branch 1 never executed branch 2 never executed -: 551: return NULL; -: 552: } -: 553: } 226051: 554: ink[0] = (char) CLIP8(r); branch 0 taken 82% (fallthrough) branch 1 taken 18% branch 2 taken 99% (fallthrough) branch 3 taken 1% 226051: 555: ink[1] = ink[2] = ink[3] = 0; -: 556: } else { 183267: 557: a = 255; 183267: 558: if (rIsInt) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 559: /* compatibility: ABGR */ 967: 560: a = (UINT8) (r >> 24); 967: 561: b = (UINT8) (r >> 16); 967: 562: g = (UINT8) (r >> 8); 967: 563: r = (UINT8) r; -: 564: } else { 182300: 565: if (im->bands == 2) { branch 0 taken 3% (fallthrough) branch 1 taken 97% 5185: 566: if (!PyArg_ParseTuple(color, "L|i", &r, &a)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 567: return NULL; -: 568: } 5185: 569: g = b = r; -: 570: } else { 177115: 571: if (!PyArg_ParseTuple(color, "Lii|i", &r, &g, &b, &a)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 572: return NULL; -: 573: } -: 574: } -: 575: } 183267: 576: ink[0] = (char) CLIP8(r); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% 183267: 577: ink[1] = (char) CLIP8(g); branch 0 taken 92% (fallthrough) branch 1 taken 8% branch 2 taken 100% (fallthrough) branch 3 taken 0% 183267: 578: ink[2] = (char) CLIP8(b); branch 0 taken 92% (fallthrough) branch 1 taken 8% branch 2 taken 100% (fallthrough) branch 3 taken 0% 183267: 579: ink[3] = (char) CLIP8(a); branch 0 taken 98% (fallthrough) branch 1 taken 2% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 580: } -: 581: return ink; -: 582: case IMAGING_TYPE_INT32: -: 583: /* signed integer */ 95: 584: itmp = r; 95: 585: memcpy(ink, &itmp, sizeof(itmp)); 95: 586: return ink; -: 587: case IMAGING_TYPE_FLOAT32: -: 588: /* floating point */ 78: 589: f = PyFloat_AsDouble(color); call 0 returned 100% 78: 590: if (f == -1.0 && PyErr_Occurred()) { branch 0 taken 0% (fallthrough) branch 1 taken 100% call 2 never executed branch 3 never executed branch 4 never executed -: 591: return NULL; -: 592: } 78: 593: ftmp = f; 78: 594: memcpy(ink, &ftmp, sizeof(ftmp)); 78: 595: return ink; -: 596: case IMAGING_TYPE_SPECIAL: 101: 597: if (strncmp(im->mode, "I;16", 4) == 0) { branch 0 taken 95% (fallthrough) branch 1 taken 5% 96: 598: ink[0] = (UINT8) r; 96: 599: ink[1] = (UINT8) (r >> 8); 96: 600: ink[2] = ink[3] = 0; 96: 601: return ink; -: 602: } -: 603: } -: 604: 5: 605: PyErr_SetString(PyExc_ValueError, wrong_mode); call 0 returned 100% 5: 606: return NULL; -: 607:} -: 608: -: 609:/* -------------------------------------------------------------------- */ -: 610:/* FACTORIES */ -: 611:/* -------------------------------------------------------------------- */ -: 612: -: 613:static PyObject* function _fill called 15843 returned 100% blocks executed 100% 15843: 614:_fill(PyObject* self, PyObject* args) -: 615:{ -: 616: char* mode; -: 617: int xsize, ysize; -: 618: PyObject* color; -: 619: char buffer[4]; -: 620: Imaging im; -: 621: 15843: 622: xsize = ysize = 256; 15843: 623: color = NULL; -: 624: 15843: 625: if (!PyArg_ParseTuple(args, "s|(ii)O", &mode, &xsize, &ysize, &color)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 626: return NULL; -: 627: } -: 628: 15843: 629: im = ImagingNewDirty(mode, xsize, ysize); call 0 returned 100% 15843: 630: if (!im) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 631: return NULL; -: 632: } -: 633: 15837: 634: buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0; 15837: 635: if (color) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 15828: 636: if (!getink(color, im, buffer)) { call 0 returned 100% branch 1 taken 1% (fallthrough) branch 2 taken 99% 4: 637: ImagingDelete(im); call 0 returned 100% 4: 638: return NULL; -: 639: } -: 640: } -: 641: -: 642: 15833: 643: (void) ImagingFill(im, buffer); call 0 returned 100% -: 644: 15833: 645: return PyImagingNew(im); call 0 returned 100% -: 646:} -: 647: -: 648:static PyObject* function _new called 5932 returned 100% blocks executed 100% 5932: 649:_new(PyObject* self, PyObject* args) -: 650:{ -: 651: char* mode; -: 652: int xsize, ysize; -: 653: 5932: 654: if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 655: return NULL; -: 656: } -: 657: 5932: 658: return PyImagingNew(ImagingNew(mode, xsize, ysize)); call 0 returned 100% call 1 returned 100% -: 659:} -: 660: -: 661:static PyObject* function _new_block called 0 returned 0% blocks executed 0% #####: 662:_new_block(PyObject* self, PyObject* args) -: 663:{ -: 664: char* mode; -: 665: int xsize, ysize; -: 666: #####: 667: if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize)) { call 0 never executed branch 1 never executed branch 2 never executed -: 668: return NULL; -: 669: } -: 670: #####: 671: return PyImagingNew(ImagingNewBlock(mode, xsize, ysize)); call 0 never executed call 1 never executed -: 672:} -: 673: -: 674:static PyObject* function _linear_gradient called 12 returned 100% blocks executed 100% 12: 675:_linear_gradient(PyObject* self, PyObject* args) -: 676:{ -: 677: char* mode; -: 678: 12: 679: if (!PyArg_ParseTuple(args, "s", &mode)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 680: return NULL; -: 681: } -: 682: 12: 683: return PyImagingNew(ImagingFillLinearGradient(mode)); call 0 returned 100% call 1 returned 100% -: 684:} -: 685: -: 686:static PyObject* function _radial_gradient called 3 returned 100% blocks executed 100% 3: 687:_radial_gradient(PyObject* self, PyObject* args) -: 688:{ -: 689: char* mode; -: 690: 3: 691: if (!PyArg_ParseTuple(args, "s", &mode)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 692: return NULL; -: 693: } -: 694: 3: 695: return PyImagingNew(ImagingFillRadialGradient(mode)); call 0 returned 100% call 1 returned 100% -: 696:} -: 697: -: 698:static PyObject* function _alpha_composite called 6 returned 100% blocks executed 100% 6: 699:_alpha_composite(ImagingObject* self, PyObject* args) -: 700:{ -: 701: ImagingObject* imagep1; -: 702: ImagingObject* imagep2; -: 703: 6: 704: if (!PyArg_ParseTuple(args, "O!O!", call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 705: &Imaging_Type, &imagep1, -: 706: &Imaging_Type, &imagep2)) { -: 707: return NULL; -: 708: } -: 709: 6: 710: return PyImagingNew(ImagingAlphaComposite(imagep1->image, imagep2->image)); call 0 returned 100% call 1 returned 100% -: 711:} -: 712: -: 713:static PyObject* function _blend called 19 returned 100% blocks executed 100% 19: 714:_blend(ImagingObject* self, PyObject* args) -: 715:{ -: 716: ImagingObject* imagep1; -: 717: ImagingObject* imagep2; -: 718: double alpha; -: 719: 19: 720: alpha = 0.5; 19: 721: if (!PyArg_ParseTuple(args, "O!O!|d", call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 722: &Imaging_Type, &imagep1, -: 723: &Imaging_Type, &imagep2, -: 724: &alpha)) { -: 725: return NULL; -: 726: } -: 727: 19: 728: return PyImagingNew(ImagingBlend(imagep1->image, imagep2->image, call 0 returned 100% call 1 returned 100% -: 729: (float) alpha)); -: 730:} -: 731: -: 732:/* -------------------------------------------------------------------- */ -: 733:/* METHODS */ -: 734:/* -------------------------------------------------------------------- */ -: 735: -: 736:static INT16* function _prepare_lut_table called 44 returned 100% blocks executed 92% 44: 737:_prepare_lut_table(PyObject* table, Py_ssize_t table_size) -: 738:{ -: 739: int i; -: 740: Py_buffer buffer_info; 44: 741: INT32 data_type = TYPE_FLOAT32; 44: 742: float item = 0; 44: 743: void* table_data = NULL; 44: 744: int free_table_data = 0; -: 745: INT16* prepared; -: 746: -: 747: /* NOTE: This value should be the same as in ColorLUT.c */ -: 748: #define PRECISION_BITS (16 - 8 - 2) -: 749: 44: 750: const char* wrong_size = ("The table should have table_channels * " -: 751: "size1D * size2D * size3D float items."); -: 752: 44: 753: if (PyObject_CheckBuffer(table)) { branch 0 taken 18% (fallthrough) branch 1 taken 82% branch 2 taken 100% (fallthrough) branch 3 taken 0% 8: 754: if ( ! PyObject_GetBuffer(table, &buffer_info, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 755: PyBUF_CONTIG_RO | PyBUF_FORMAT)) { 8: 756: if (buffer_info.ndim == 1 && buffer_info.shape[0] == table_size) { branch 0 taken 88% (fallthrough) branch 1 taken 13% branch 2 taken 86% (fallthrough) branch 3 taken 14% 6: 757: if (strlen(buffer_info.format) == 1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 6: 758: switch (buffer_info.format[0]) { branch 0 taken 33% branch 1 taken 17% branch 2 taken 17% branch 3 taken 33% -: 759: case 'e': 2: 760: data_type = TYPE_FLOAT16; 2: 761: table_data = buffer_info.buf; 2: 762: break; -: 763: case 'f': 1: 764: data_type = TYPE_FLOAT32; 1: 765: table_data = buffer_info.buf; 1: 766: break; -: 767: case 'd': 1: 768: data_type = TYPE_DOUBLE; 1: 769: table_data = buffer_info.buf; 1: 770: break; -: 771: } -: 772: } -: 773: } 8: 774: PyBuffer_Release(&buffer_info); call 0 returned 100% -: 775: } -: 776: } -: 777: 44: 778: if ( ! table_data) { branch 0 taken 91% (fallthrough) branch 1 taken 9% 40: 779: free_table_data = 1; 40: 780: table_data = getlist(table, &table_size, wrong_size, TYPE_FLOAT32); call 0 returned 100% 40: 781: if ( ! table_data) { branch 0 taken 85% (fallthrough) branch 1 taken 15% -: 782: return NULL; -: 783: } -: 784: } -: 785: -: 786: /* malloc check ok, max is 2 * 4 * 65**3 = 2197000 */ 38: 787: prepared = (INT16*) malloc(sizeof(INT16) * table_size); 38: 788: if ( ! prepared) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 789: if (free_table_data) { branch 0 never executed branch 1 never executed #####: 790: free(table_data); -: 791: } #####: 792: return (INT16*) PyErr_NoMemory(); call 0 never executed -: 793: } -: 794: 85652: 795: for (i = 0; i < table_size; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 796: FLOAT16 htmp; -: 797: double dtmp; 85652: 798: switch (data_type) { branch 0 taken 3% branch 1 taken 94% branch 2 taken 2% branch 3 taken 0% -: 799: case TYPE_FLOAT16: 2709: 800: memcpy(&htmp, ((char*) table_data) + i * sizeof(htmp), sizeof(htmp)); 2709: 801: item = float16tofloat32(htmp); call 0 returned 100% 2709: 802: break; -: 803: case TYPE_FLOAT32: 80864: 804: memcpy(&item, ((char*) table_data) + i * sizeof(FLOAT32), sizeof(FLOAT32)); -: 805: break; -: 806: case TYPE_DOUBLE: 2079: 807: memcpy(&dtmp, ((char*) table_data) + i * sizeof(dtmp), sizeof(dtmp)); 2079: 808: item = (FLOAT32) dtmp; 2079: 809: break; -: 810: } -: 811: /* Max value for INT16 */ 85652: 812: if (item >= (0x7fff - 0.5) / (255 << PRECISION_BITS)) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 12: 813: prepared[i] = 0x7fff; 36: 814: continue; -: 815: } -: 816: /* Min value for INT16 */ 85640: 817: if (item <= (-0x8000 + 0.5) / (255 << PRECISION_BITS)) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 12: 818: prepared[i] = -0x8000; 12: 819: continue; -: 820: } 85628: 821: if (item < 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 12: 822: prepared[i] = item * (255 << PRECISION_BITS) - 0.5; -: 823: } else { 85616: 824: prepared[i] = item * (255 << PRECISION_BITS) + 0.5; -: 825: } -: 826: } -: 827: -: 828: #undef PRECISION_BITS 38: 829: if (free_table_data) { branch 0 taken 89% (fallthrough) branch 1 taken 11% 34: 830: free(table_data); -: 831: } -: 832: return prepared; -: 833:} -: 834: -: 835: -: 836:static PyObject* function _color_lut_3d called 48 returned 100% blocks executed 100% 48: 837:_color_lut_3d(ImagingObject* self, PyObject* args) -: 838:{ -: 839: char* mode; -: 840: int filter; -: 841: int table_channels; -: 842: int size1D, size2D, size3D; -: 843: PyObject* table; -: 844: -: 845: INT16* prepared_table; -: 846: Imaging imOut; -: 847: 48: 848: if ( ! PyArg_ParseTuple(args, "siiiiiO:color_lut_3d", &mode, &filter, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 849: &table_channels, &size1D, &size2D, &size3D, -: 850: &table)) { -: 851: return NULL; -: 852: } -: 853: -: 854: /* actually, it is trilinear */ 48: 855: if (filter != IMAGING_TRANSFORM_BILINEAR) { branch 0 taken 2% (fallthrough) branch 1 taken 98% 1: 856: PyErr_SetString(PyExc_ValueError, call 0 returned 100% -: 857: "Only LINEAR filter is supported."); 1: 858: return NULL; -: 859: } -: 860: 47: 861: if (1 > table_channels || table_channels > 4) { branch 0 taken 2% (fallthrough) branch 1 taken 98% 1: 862: PyErr_SetString(PyExc_ValueError, call 0 returned 100% -: 863: "table_channels should be from 1 to 4"); 1: 864: return NULL; -: 865: } -: 866: 90: 867: if (2 > size1D || size1D > 65 || branch 0 taken 96% (fallthrough) branch 1 taken 4% branch 2 taken 100% (fallthrough) branch 3 taken 0% 132: 868: 2 > size2D || size2D > 65 || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 88: 869: 2 > size3D || size3D > 65 branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 870: ) { 2: 871: PyErr_SetString(PyExc_ValueError, call 0 returned 100% -: 872: "Table size in any dimension should be from 2 to 65"); 2: 873: return NULL; -: 874: } -: 875: 88: 876: prepared_table = _prepare_lut_table( call 0 returned 100% 44: 877: table, table_channels * size1D * size2D * size3D); 44: 878: if ( ! prepared_table) { branch 0 taken 86% (fallthrough) branch 1 taken 14% -: 879: return NULL; -: 880: } -: 881: 38: 882: imOut = ImagingNewDirty(mode, self->image->xsize, self->image->ysize); call 0 returned 100% 38: 883: if ( ! imOut) { branch 0 taken 3% (fallthrough) branch 1 taken 97% 1: 884: free(prepared_table); 1: 885: return NULL; -: 886: } -: 887: 37: 888: if ( ! ImagingColorLUT3D_linear(imOut, self->image, call 0 returned 100% branch 1 taken 19% (fallthrough) branch 2 taken 81% -: 889: table_channels, size1D, size2D, size3D, -: 890: prepared_table)) { 7: 891: free(prepared_table); 7: 892: ImagingDelete(imOut); call 0 returned 100% 7: 893: return NULL; -: 894: } -: 895: 30: 896: free(prepared_table); -: 897: 30: 898: return PyImagingNew(imOut); call 0 returned 100% -: 899:} -: 900: -: 901:static PyObject* function _convert called 7902 returned 100% blocks executed 67% 7902: 902:_convert(ImagingObject* self, PyObject* args) -: 903:{ -: 904: char* mode; 7902: 905: int dither = 0; 7902: 906: ImagingObject *paletteimage = NULL; -: 907: 7902: 908: if (!PyArg_ParseTuple(args, "s|iO", &mode, &dither, &paletteimage)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 909: return NULL; -: 910: } 7902: 911: if (paletteimage != NULL) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 5: 912: if (!PyImaging_Check(paletteimage)) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 913: PyObject_Print((PyObject *)paletteimage, stderr, 0); call 0 never executed #####: 914: PyErr_SetString(PyExc_ValueError, "palette argument must be image with mode 'P'"); call 0 never executed #####: 915: return NULL; -: 916: } 5: 917: if (paletteimage->image->palette == NULL) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 918: PyErr_SetString(PyExc_ValueError, "null palette"); call 0 never executed #####: 919: return NULL; -: 920: } -: 921: } -: 922: 7902: 923: return PyImagingNew(ImagingConvert(self->image, mode, paletteimage ? paletteimage->image->palette : NULL, dither)); branch 0 taken 1% (fallthrough) branch 1 taken 99% call 2 returned 100% call 3 returned 100% -: 924:} -: 925: -: 926:static PyObject* function _convert2 called 0 returned 0% blocks executed 0% #####: 927:_convert2(ImagingObject* self, PyObject* args) -: 928:{ -: 929: ImagingObject* imagep1; -: 930: ImagingObject* imagep2; #####: 931: if (!PyArg_ParseTuple(args, "O!O!", call 0 never executed branch 1 never executed branch 2 never executed -: 932: &Imaging_Type, &imagep1, -: 933: &Imaging_Type, &imagep2)) { -: 934: return NULL; -: 935: } -: 936: #####: 937: if (!ImagingConvert2(imagep1->image, imagep2->image)) { call 0 never executed branch 1 never executed branch 2 never executed -: 938: return NULL; -: 939: } -: 940: #####: 941: Py_INCREF(Py_None); #####: 942: return Py_None; -: 943:} -: 944: -: 945:static PyObject* function _convert_matrix called 4 returned 100% blocks executed 100% 4: 946:_convert_matrix(ImagingObject* self, PyObject* args) -: 947:{ -: 948: char* mode; -: 949: float m[12]; 4: 950: if (!PyArg_ParseTuple(args, "s(ffff)", &mode, m+0, m+1, m+2, m+3)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 4: 951: PyErr_Clear(); call 0 returned 100% 4: 952: if (!PyArg_ParseTuple(args, "s(ffffffffffff)", &mode, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 953: m+0, m+1, m+2, m+3, -: 954: m+4, m+5, m+6, m+7, -: 955: m+8, m+9, m+10, m+11)){ -: 956: return NULL; -: 957: } -: 958: } -: 959: 4: 960: return PyImagingNew(ImagingConvertMatrix(self->image, mode, m)); call 0 returned 100% call 1 returned 100% -: 961:} -: 962: -: 963:static PyObject* function _convert_transparent called 8 returned 100% blocks executed 100% 8: 964:_convert_transparent(ImagingObject* self, PyObject* args) -: 965:{ -: 966: char* mode; -: 967: int r,g,b; 8: 968: if (PyArg_ParseTuple(args, "s(iii)", &mode, &r, &g, &b)) { call 0 returned 100% branch 1 taken 25% (fallthrough) branch 2 taken 75% 2: 969: return PyImagingNew(ImagingConvertTransparent(self->image, mode, r, g, b)); call 0 returned 100% call 1 returned 100% -: 970: } 6: 971: PyErr_Clear(); call 0 returned 100% 6: 972: if (PyArg_ParseTuple(args, "si", &mode, &r)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 6: 973: return PyImagingNew(ImagingConvertTransparent(self->image, mode, r, 0, 0)); call 0 returned 100% call 1 returned 100% -: 974: } -: 975: return NULL; -: 976:} -: 977: -: 978:static PyObject* function _copy called 2565 returned 100% blocks executed 100% 2565: 979:_copy(ImagingObject* self, PyObject* args) -: 980:{ 2565: 981: if (!PyArg_ParseTuple(args, "")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 982: return NULL; -: 983: } -: 984: 2565: 985: return PyImagingNew(ImagingCopy(self->image)); call 0 returned 100% call 1 returned 100% -: 986:} -: 987: -: 988:static PyObject* function _crop called 4182 returned 100% blocks executed 100% 4182: 989:_crop(ImagingObject* self, PyObject* args) -: 990:{ -: 991: int x0, y0, x1, y1; 4182: 992: if (!PyArg_ParseTuple(args, "(iiii)", &x0, &y0, &x1, &y1)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 993: return NULL; -: 994: } -: 995: 4182: 996: return PyImagingNew(ImagingCrop(self->image, x0, y0, x1, y1)); call 0 returned 100% call 1 returned 100% -: 997:} -: 998: -: 999:static PyObject* function _expand_image called 47 returned 100% blocks executed 100% 47: 1000:_expand_image(ImagingObject* self, PyObject* args) -: 1001:{ -: 1002: int x, y; 47: 1003: int mode = 0; 47: 1004: if (!PyArg_ParseTuple(args, "ii|i", &x, &y, &mode)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1005: return NULL; -: 1006: } -: 1007: 47: 1008: return PyImagingNew(ImagingExpand(self->image, x, y, mode)); call 0 returned 100% call 1 returned 100% -: 1009:} -: 1010: -: 1011:static PyObject* function _filter called 47 returned 100% blocks executed 92% 47: 1012:_filter(ImagingObject* self, PyObject* args) -: 1013:{ -: 1014: PyObject* imOut; -: 1015: Py_ssize_t kernelsize; -: 1016: FLOAT32* kerneldata; -: 1017: -: 1018: int xsize, ysize, i; -: 1019: float divisor, offset; 47: 1020: PyObject* kernel = NULL; 47: 1021: if (!PyArg_ParseTuple(args, "(ii)ffO", &xsize, &ysize, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1022: &divisor, &offset, &kernel)) { -: 1023: return NULL; -: 1024: } -: 1025: -: 1026: /* get user-defined kernel */ 47: 1027: kerneldata = getlist(kernel, &kernelsize, NULL, TYPE_FLOAT32); call 0 returned 100% 47: 1028: if (!kerneldata) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1029: return NULL; -: 1030: } 47: 1031: if (kernelsize != (Py_ssize_t) xsize * (Py_ssize_t) ysize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 1032: free(kerneldata); #####: 1033: return ImagingError_ValueError("bad kernel size"); call 0 never executed -: 1034: } -: 1035: 599: 1036: for (i = 0; i < kernelsize; ++i) { branch 0 taken 93% branch 1 taken 7% (fallthrough) 599: 1037: kerneldata[i] /= divisor; -: 1038: } -: 1039: 47: 1040: imOut = PyImagingNew( call 0 returned 100% call 1 returned 100% -: 1041: ImagingFilter(self->image, xsize, ysize, kerneldata, offset) -: 1042: ); -: 1043: 47: 1044: free(kerneldata); -: 1045: 47: 1046: return imOut; -: 1047:} -: 1048: -: 1049:#ifdef WITH_UNSHARPMASK -: 1050:static PyObject* function _gaussian_blur called 15 returned 100% blocks executed 100% 15: 1051:_gaussian_blur(ImagingObject* self, PyObject* args) -: 1052:{ -: 1053: Imaging imIn; -: 1054: Imaging imOut; -: 1055: 15: 1056: float radius = 0; 15: 1057: int passes = 3; 15: 1058: if (!PyArg_ParseTuple(args, "f|i", &radius, &passes)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1059: return NULL; -: 1060: } -: 1061: 15: 1062: imIn = self->image; 15: 1063: imOut = ImagingNewDirty(imIn->mode, imIn->xsize, imIn->ysize); call 0 returned 100% 15: 1064: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1065: return NULL; -: 1066: } -: 1067: 15: 1068: if (!ImagingGaussianBlur(imOut, imIn, radius, passes)) { call 0 returned 100% branch 1 taken 27% (fallthrough) branch 2 taken 73% 4: 1069: ImagingDelete(imOut); call 0 returned 100% 4: 1070: return NULL; -: 1071: } -: 1072: 11: 1073: return PyImagingNew(imOut); call 0 returned 100% -: 1074:} -: 1075:#endif -: 1076: -: 1077:static PyObject* function _getpalette called 906 returned 100% blocks executed 87% 906: 1078:_getpalette(ImagingObject* self, PyObject* args) -: 1079:{ -: 1080: PyObject* palette; 906: 1081: int palettesize = 256; -: 1082: int bits; -: 1083: ImagingShuffler pack; -: 1084: 906: 1085: char* mode = "RGB"; 906: 1086: char* rawmode = "RGB"; 906: 1087: if (!PyArg_ParseTuple(args, "|ss", &mode, &rawmode)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1088: return NULL; -: 1089: } -: 1090: 906: 1091: if (!self->image->palette) { branch 0 taken 57% (fallthrough) branch 1 taken 43% 515: 1092: PyErr_SetString(PyExc_ValueError, no_palette); call 0 returned 100% 515: 1093: return NULL; -: 1094: } -: 1095: 391: 1096: pack = ImagingFindPacker(mode, rawmode, &bits); call 0 returned 100% 391: 1097: if (!pack) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1098: PyErr_SetString(PyExc_ValueError, wrong_raw_mode); call 0 never executed #####: 1099: return NULL; -: 1100: } -: 1101: 391: 1102: palette = PyBytes_FromStringAndSize(NULL, palettesize * bits / 8); call 0 returned 100% 391: 1103: if (!palette) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1104: return NULL; -: 1105: } -: 1106: 782: 1107: pack((UINT8*) PyBytes_AsString(palette), call 0 returned 100% call 1 returned 100% 391: 1108: self->image->palette->palette, palettesize); -: 1109: 391: 1110: return palette; -: 1111:} -: 1112: -: 1113:static PyObject* function _getpalettemode called 98 returned 100% blocks executed 60% 98: 1114:_getpalettemode(ImagingObject* self, PyObject* args) -: 1115:{ 98: 1116: if (!self->image->palette) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1117: PyErr_SetString(PyExc_ValueError, no_palette); call 0 never executed #####: 1118: return NULL; -: 1119: } -: 1120: 98: 1121: return PyUnicode_FromString(self->image->palette->mode); call 0 returned 100% -: 1122:} -: 1123: -: 1124:static inline int function _getxy called 553606 returned 100% blocks executed 43% 553606: 1125:_getxy(PyObject* xy, int* x, int *y) -: 1126:{ -: 1127: PyObject* value; -: 1128: 553606: 1129: if (!PyTuple_Check(xy) || PyTuple_GET_SIZE(xy) != 2) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 1130: goto badarg; -: 1131: } -: 1132: 553606: 1133: value = PyTuple_GET_ITEM(xy, 0); 553606: 1134: if (PyLong_Check(value)) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 553606: 1135: *x = PyLong_AS_LONG(value); call 0 returned 100% #####: 1136: } else if (PyFloat_Check(value)) { branch 0 never executed branch 1 never executed call 2 never executed branch 3 never executed branch 4 never executed #####: 1137: *x = (int) PyFloat_AS_DOUBLE(value); -: 1138: } else { -: 1139: goto badval; -: 1140: } -: 1141: 553606: 1142: value = PyTuple_GET_ITEM(xy, 1); 553606: 1143: if (PyLong_Check(value)) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 553606: 1144: *y = PyLong_AS_LONG(value); call 0 returned 100% #####: 1145: } else if (PyFloat_Check(value)) { branch 0 never executed branch 1 never executed call 2 never executed branch 3 never executed branch 4 never executed #####: 1146: *y = (int) PyFloat_AS_DOUBLE(value); -: 1147: } else { -: 1148: goto badval; -: 1149: } -: 1150: -: 1151: return 0; -: 1152: -: 1153: badarg: #####: 1154: PyErr_SetString( call 0 never executed -: 1155: PyExc_TypeError, -: 1156: "argument must be sequence of length 2" -: 1157: ); #####: 1158: return -1; -: 1159: -: 1160: badval: #####: 1161: PyErr_SetString( call 0 never executed -: 1162: PyExc_TypeError, -: 1163: "an integer is required" -: 1164: ); #####: 1165: return -1; -: 1166:} -: 1167: -: 1168:static PyObject* function _getpixel called 67946 returned 100% blocks executed 67% 67946: 1169:_getpixel(ImagingObject* self, PyObject* args) -: 1170:{ -: 1171: PyObject* xy; -: 1172: int x, y; -: 1173: 67946: 1174: if (PyTuple_GET_SIZE(args) != 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1175: PyErr_SetString( call 0 never executed -: 1176: PyExc_TypeError, -: 1177: "argument 1 must be sequence of length 2" -: 1178: ); #####: 1179: return NULL; -: 1180: } -: 1181: 67946: 1182: xy = PyTuple_GET_ITEM(args, 0); -: 1183: 67946: 1184: if (_getxy(xy, &x, &y)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1185: return NULL; -: 1186: } -: 1187: 67946: 1188: if (self->access == NULL) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1189: Py_INCREF(Py_None); #####: 1190: return Py_None; -: 1191: } -: 1192: 67946: 1193: return getpixel(self->image, self->access, x, y); call 0 returned 100% -: 1194:} -: 1195: -: 1196:union hist_extrema { -: 1197: UINT8 u[2]; -: 1198: INT32 i[2]; -: 1199: FLOAT32 f[2]; -: 1200:}; -: 1201: -: 1202:static union hist_extrema* function parse_histogram_extremap.isra.0 called 1919 returned 100% blocks executed 88% 1919: 1203:parse_histogram_extremap(ImagingObject* self, PyObject* extremap, -: 1204: union hist_extrema* ep) -: 1205:{ -: 1206: int i0, i1; -: 1207: double f0, f1; -: 1208: 1919: 1209: if (extremap) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 10: 1210: switch (self->image->type) { branch 0 taken 60% branch 1 taken 20% branch 2 taken 20% branch 3 taken 0% -: 1211: case IMAGING_TYPE_UINT8: 6: 1212: if (!PyArg_ParseTuple(extremap, "ii", &i0, &i1)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1213: return NULL; -: 1214: } 6: 1215: ep->u[0] = CLIP8(i0); branch 0 taken 0% (fallthrough) branch 1 taken 100% 6: 1216: ep->u[1] = CLIP8(i1); branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 1217: break; -: 1218: case IMAGING_TYPE_INT32: 2: 1219: if (!PyArg_ParseTuple(extremap, "ii", &i0, &i1)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1220: return NULL; -: 1221: } 2: 1222: ep->i[0] = i0; 2: 1223: ep->i[1] = i1; -: 1224: break; -: 1225: case IMAGING_TYPE_FLOAT32: 2: 1226: if (!PyArg_ParseTuple(extremap, "dd", &f0, &f1)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1227: return NULL; -: 1228: } 2: 1229: ep->f[0] = (FLOAT32) f0; 2: 1230: ep->f[1] = (FLOAT32) f1; -: 1231: break; -: 1232: default: -: 1233: return NULL; -: 1234: } -: 1235: } else { -: 1236: return NULL; -: 1237: } -: 1238: return ep; -: 1239:} -: 1240: -: 1241:static PyObject* function _histogram called 1909 returned 100% blocks executed 89% 1909: 1242:_histogram(ImagingObject* self, PyObject* args) -: 1243:{ -: 1244: ImagingHistogram h; -: 1245: PyObject* list; -: 1246: int i; -: 1247: union hist_extrema extrema; -: 1248: union hist_extrema* ep; -: 1249: 1909: 1250: PyObject* extremap = NULL; 1909: 1251: ImagingObject* maskp = NULL; 1909: 1252: if (!PyArg_ParseTuple(args, "|OO!", &extremap, &Imaging_Type, &maskp)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1253: return NULL; -: 1254: } -: 1255: -: 1256: /* Using a var to avoid allocations. */ 1909: 1257: ep = parse_histogram_extremap(self, extremap, &extrema); call 0 returned 100% 1909: 1258: h = ImagingGetHistogram(self->image, (maskp) ? maskp->image : NULL, ep); branch 0 taken 1% (fallthrough) branch 1 taken 99% call 2 returned 100% -: 1259: 1909: 1260: if (!h) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1261: return NULL; -: 1262: } -: 1263: -: 1264: /* Build an integer list containing the histogram */ 1909: 1265: list = PyList_New(h->bands * 256); 502901: 1266: for (i = 0; i < h->bands * 256; i++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) -: 1267: PyObject* item; 500992: 1268: item = PyLong_FromLong(h->histogram[i]); call 0 returned 100% 500992: 1269: if (item == NULL) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1270: Py_DECREF(list); branch 0 never executed branch 1 never executed call 2 never executed -: 1271: list = NULL; -: 1272: break; -: 1273: } 500992: 1274: PyList_SetItem(list, i, item); call 0 returned 100% -: 1275: } -: 1276: -: 1277: /* Destroy the histogram structure */ 1909: 1278: ImagingHistogramDelete(h); call 0 returned 100% -: 1279: 1909: 1280: return list; -: 1281:} -: 1282: -: 1283:static PyObject* function _entropy called 10 returned 100% blocks executed 94% 10: 1284:_entropy(ImagingObject* self, PyObject* args) -: 1285:{ -: 1286: ImagingHistogram h; -: 1287: int idx, length; -: 1288: long sum; -: 1289: double entropy, fsum, p; -: 1290: union hist_extrema extrema; -: 1291: union hist_extrema* ep; -: 1292: 10: 1293: PyObject* extremap = NULL; 10: 1294: ImagingObject* maskp = NULL; 10: 1295: if (!PyArg_ParseTuple(args, "|OO!", &extremap, &Imaging_Type, &maskp)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1296: return NULL; -: 1297: } -: 1298: -: 1299: /* Using a local var to avoid allocations. */ 10: 1300: ep = parse_histogram_extremap(self, extremap, &extrema); call 0 returned 100% 10: 1301: h = ImagingGetHistogram(self->image, (maskp) ? maskp->image : NULL, ep); branch 0 taken 0% (fallthrough) branch 1 taken 100% call 2 returned 100% -: 1302: 10: 1303: if (!h) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1304: return NULL; -: 1305: } -: 1306: -: 1307: /* Calculate the histogram entropy */ -: 1308: /* First, sum the histogram data */ 10: 1309: length = h->bands * 256; 10: 1310: sum = 0; 5642: 1311: for (idx = 0; idx < length; idx++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 5632: 1312: sum += h->histogram[idx]; -: 1313: } -: 1314: -: 1315: /* Next, normalize the histogram data, */ -: 1316: /* using the histogram sum value */ 10: 1317: fsum = (double)sum; 10: 1318: entropy = 0.0; 5642: 1319: for (idx = 0; idx < length; idx++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 5632: 1320: p = (double)h->histogram[idx] / fsum; 5632: 1321: if (p != 0.0) { branch 0 taken 79% (fallthrough) branch 1 taken 21% 4444: 1322: entropy += p * log(p) * M_LOG2E; -: 1323: } -: 1324: } -: 1325: -: 1326: /* Destroy the histogram structure */ 10: 1327: ImagingHistogramDelete(h); call 0 returned 100% -: 1328: 10: 1329: return PyFloat_FromDouble(-entropy); call 0 returned 100% -: 1330:} -: 1331: -: 1332:#ifdef WITH_MODEFILTER -: 1333:static PyObject* function _modefilter called 20 returned 100% blocks executed 100% 20: 1334:_modefilter(ImagingObject* self, PyObject* args) -: 1335:{ -: 1336: int size; 20: 1337: if (!PyArg_ParseTuple(args, "i", &size)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1338: return NULL; -: 1339: } -: 1340: 20: 1341: return PyImagingNew(ImagingModeFilter(self->image, size)); call 0 returned 100% call 1 returned 100% -: 1342:} -: 1343:#endif -: 1344: -: 1345:static PyObject* function _offset called 5 returned 100% blocks executed 100% 5: 1346:_offset(ImagingObject* self, PyObject* args) -: 1347:{ -: 1348: int xoffset, yoffset; 5: 1349: if (!PyArg_ParseTuple(args, "ii", &xoffset, &yoffset)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1350: return NULL; -: 1351: } -: 1352: 5: 1353: return PyImagingNew(ImagingOffset(self->image, xoffset, yoffset)); call 0 returned 100% call 1 returned 100% -: 1354:} -: 1355: -: 1356:static PyObject* function _paste called 14589 returned 100% blocks executed 100% 14589: 1357:_paste(ImagingObject* self, PyObject* args) -: 1358:{ -: 1359: int status; -: 1360: char ink[4]; -: 1361: -: 1362: PyObject* source; -: 1363: int x0, y0, x1, y1; 14589: 1364: ImagingObject* maskp = NULL; 14589: 1365: if (!PyArg_ParseTuple(args, "O(iiii)|O!", call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1366: &source, -: 1367: &x0, &y0, &x1, &y1, -: 1368: &Imaging_Type, &maskp)) { -: 1369: return NULL; -: 1370: } -: 1371: 14589: 1372: if (PyImaging_Check(source)) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 29014: 1373: status = ImagingPaste( call 0 returned 100% branch 1 taken 4% (fallthrough) branch 2 taken 96% call 3 returned 100% -: 1374: self->image, PyImaging_AsImaging(source), 14507: 1375: (maskp) ? maskp->image : NULL, -: 1376: x0, y0, x1, y1 -: 1377: ); -: 1378: -: 1379: } else { 82: 1380: if (!getink(source, self->image, ink)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1381: return NULL; -: 1382: } 164: 1383: status = ImagingFill2( branch 0 taken 29% (fallthrough) branch 1 taken 71% call 2 returned 100% -: 1384: self->image, ink, 82: 1385: (maskp) ? maskp->image : NULL, -: 1386: x0, y0, x1, y1 -: 1387: ); -: 1388: } -: 1389: 14589: 1390: if (status < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1391: return NULL; -: 1392: } -: 1393: 14589: 1394: Py_INCREF(Py_None); 14589: 1395: return Py_None; -: 1396:} -: 1397: -: 1398:static PyObject* function _point called 41 returned 100% blocks executed 72% 41: 1399:_point(ImagingObject* self, PyObject* args) -: 1400:{ -: 1401: static const char* wrong_number = "wrong number of lut entries"; -: 1402: -: 1403: Py_ssize_t n; -: 1404: int i, bands; -: 1405: Imaging im; -: 1406: -: 1407: PyObject* list; -: 1408: char* mode; 41: 1409: if (!PyArg_ParseTuple(args, "Oz", &list, &mode)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1410: return NULL; -: 1411: } -: 1412: 42: 1413: if (mode && !strcmp(mode, "F")) { branch 0 taken 7% (fallthrough) branch 1 taken 93% branch 2 taken 33% (fallthrough) branch 3 taken 67% branch 4 taken 33% (fallthrough) branch 5 taken 67% -: 1414: FLOAT32* data; -: 1415: -: 1416: /* map from 8-bit data to floating point */ 1: 1417: n = 256; 1: 1418: data = getlist(list, &n, wrong_number, TYPE_FLOAT32); call 0 returned 100% 1: 1419: if (!data) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1420: return NULL; -: 1421: } 1: 1422: im = ImagingPoint(self->image, mode, (void*) data); call 0 returned 100% 1: 1423: free(data); -: 1424: 41: 1425: } else if (!strcmp(self->image->mode, "I") && mode && !strcmp(mode, "L")) { branch 0 taken 5% (fallthrough) branch 1 taken 95% branch 2 taken 5% (fallthrough) branch 3 taken 95% branch 4 taken 50% (fallthrough) branch 5 taken 50% branch 6 taken 100% (fallthrough) branch 7 taken 0% branch 8 taken 100% (fallthrough) branch 9 taken 0% -: 1426: UINT8* data; -: 1427: -: 1428: /* map from 16-bit subset of 32-bit data to 8-bit */ -: 1429: /* FIXME: support arbitrary number of entries (requires API change) */ 1: 1430: n = 65536; 1: 1431: data = getlist(list, &n, wrong_number, TYPE_UINT8); call 0 returned 100% 1: 1432: if (!data) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1433: return NULL; -: 1434: } 1: 1435: im = ImagingPoint(self->image, mode, (void*) data); call 0 returned 100% 1: 1436: free(data); -: 1437: -: 1438: } else { -: 1439: INT32* data; -: 1440: UINT8 lut[1024]; -: 1441: 39: 1442: if (mode) { branch 0 taken 3% (fallthrough) branch 1 taken 97% 1: 1443: bands = getbands(mode); call 0 returned 100% 1: 1444: if (bands < 0) { branch 0 taken 100% branch 1 taken 0% 1: 1445: return NULL; -: 1446: } -: 1447: } else { 38: 1448: bands = self->image->bands; -: 1449: } -: 1450: -: 1451: /* map to integer data */ 39: 1452: n = 256 * bands; 39: 1453: data = getlist(list, &n, wrong_number, TYPE_INT32); call 0 returned 100% 39: 1454: if (!data) { branch 0 taken 97% (fallthrough) branch 1 taken 3% -: 1455: return NULL; -: 1456: } -: 1457: 38: 1458: if (mode && !strcmp(mode, "I")) { branch 0 taken 3% (fallthrough) branch 1 taken 97% branch 2 taken 0% (fallthrough) branch 3 taken 100% branch 4 taken 0% (fallthrough) branch 5 taken 100% #####: 1459: im = ImagingPoint(self->image, mode, (void*) data); call 0 never executed 38: 1460: } else if (mode && bands > 1) { branch 0 taken 3% (fallthrough) branch 1 taken 97% branch 2 taken 100% (fallthrough) branch 3 taken 0% #####: 1461: for (i = 0; i < 256; i++) { branch 0 never executed branch 1 never executed #####: 1462: lut[i*4] = CLIP8(data[i]); branch 0 never executed branch 1 never executed #####: 1463: lut[i*4+1] = CLIP8(data[i+256]); branch 0 never executed branch 1 never executed #####: 1464: lut[i*4+2] = CLIP8(data[i+512]); branch 0 never executed branch 1 never executed #####: 1465: if (n > 768) { branch 0 never executed branch 1 never executed #####: 1466: lut[i*4+3] = CLIP8(data[i+768]); branch 0 never executed branch 1 never executed -: 1467: } -: 1468: } #####: 1469: im = ImagingPoint(self->image, mode, (void*) lut); call 0 never executed -: 1470: } else { -: 1471: /* map individual bands */ 18944: 1472: for (i = 0; i < n; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 18944: 1473: lut[i] = CLIP8(data[i]); branch 0 taken 93% (fallthrough) branch 1 taken 7% -: 1474: } 38: 1475: im = ImagingPoint(self->image, mode, (void*) lut); call 0 returned 100% -: 1476: } 38: 1477: free(data); -: 1478: } -: 1479: 40: 1480: return PyImagingNew(im); call 0 returned 100% -: 1481:} -: 1482: -: 1483:static PyObject* function _point_transform called 4 returned 100% blocks executed 100% 4: 1484:_point_transform(ImagingObject* self, PyObject* args) -: 1485:{ 4: 1486: double scale = 1.0; 4: 1487: double offset = 0.0; 4: 1488: if (!PyArg_ParseTuple(args, "|dd", &scale, &offset)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1489: return NULL; -: 1490: } -: 1491: 4: 1492: return PyImagingNew(ImagingPointTransform(self->image, scale, offset)); call 0 returned 100% call 1 returned 100% -: 1493:} -: 1494: -: 1495:static PyObject* function _putdata called 40 returned 100% blocks executed 67% 40: 1496:_putdata(ImagingObject* self, PyObject* args) -: 1497:{ -: 1498: Imaging image; -: 1499: // i & n are # pixels, require py_ssize_t. x can be as large as n. y, just because. -: 1500: Py_ssize_t n, i, x, y; -: 1501: -: 1502: PyObject* data; 40: 1503: PyObject* seq = NULL; -: 1504: PyObject* op; 40: 1505: double scale = 1.0; 40: 1506: double offset = 0.0; -: 1507: 40: 1508: if (!PyArg_ParseTuple(args, "O|dd", &data, &scale, &offset)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1509: return NULL; -: 1510: } -: 1511: 40: 1512: if (!PySequence_Check(data)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 1513: PyErr_SetString(PyExc_TypeError, must_be_sequence); call 0 never executed #####: 1514: return NULL; -: 1515: } -: 1516: 40: 1517: image = self->image; -: 1518: 40: 1519: n = PyObject_Length(data); call 0 returned 100% 40: 1520: if (n > (Py_ssize_t)image->xsize * (Py_ssize_t)image->ysize) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1521: PyErr_SetString(PyExc_TypeError, "too many data entries"); call 0 never executed #####: 1522: return NULL; -: 1523: } -: 1524: 40: 1525: if (image->image8) { branch 0 taken 60% (fallthrough) branch 1 taken 40% 24: 1526: if (PyBytes_Check(data)) { branch 0 taken 4% (fallthrough) branch 1 taken 96% -: 1527: unsigned char* p; 1: 1528: p = (unsigned char*) PyBytes_AS_STRING(data); 1: 1529: if (scale == 1.0 && offset == 0.0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% -: 1530: /* Plain string data */ 16: 1531: for (i = y = 0; i < n; i += image->xsize, y++) { branch 0 taken 94% branch 1 taken 6% 16: 1532: x = n - i; 16: 1533: if (x > (int) image->xsize) { branch 0 taken 94% (fallthrough) branch 1 taken 6% 15: 1534: x = image->xsize; -: 1535: } 32: 1536: memcpy(image->image8[y], p+i, x); -: 1537: } -: 1538: } else { -: 1539: /* Scaled and clipped string data */ #####: 1540: for (i = x = y = 0; i < n; i++) { branch 0 never executed branch 1 never executed #####: 1541: image->image8[y][x] = CLIP8((int) (p[i] * scale + offset)); branch 0 never executed branch 1 never executed #####: 1542: if (++x >= (int) image->xsize) { branch 0 never executed branch 1 never executed #####: 1543: x = 0, y++; -: 1544: } -: 1545: } -: 1546: } -: 1547: } else { 23: 1548: seq = PySequence_Fast(data, must_be_sequence); call 0 returned 100% 23: 1549: if (!seq) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1550: PyErr_SetString(PyExc_TypeError, must_be_sequence); call 0 never executed #####: 1551: return NULL; -: 1552: } 23: 1553: if (scale == 1.0 && offset == 0.0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% -: 1554: /* Clipped data */ 4070356: 1555: for (i = x = y = 0; i < n; i++) { branch 0 taken 99% branch 1 taken 1% 4070356: 1556: op = PySequence_Fast_GET_ITEM(seq, i); branch 0 taken 100% (fallthrough) branch 1 taken 0% 4070356: 1557: image->image8[y][x] = (UINT8) CLIP8(PyLong_AsLong(op)); call 0 returned 100% branch 1 taken 94% (fallthrough) branch 2 taken 6% call 3 returned 100% branch 4 taken 100% (fallthrough) branch 5 taken 0% call 6 returned 100% 4070356: 1558: if (++x >= (int) image->xsize){ branch 0 taken 1% (fallthrough) branch 1 taken 99% 5836: 1559: x = 0, y++; -: 1560: } -: 1561: } -: 1562: -: 1563: } else { -: 1564: /* Scaled and clipped data */ #####: 1565: for (i = x = y = 0; i < n; i++) { branch 0 never executed branch 1 never executed #####: 1566: PyObject *op = PySequence_Fast_GET_ITEM(seq, i); branch 0 never executed branch 1 never executed #####: 1567: image->image8[y][x] = CLIP8( call 0 never executed branch 1 never executed branch 2 never executed call 3 never executed branch 4 never executed branch 5 never executed call 6 never executed -: 1568: (int) (PyFloat_AsDouble(op) * scale + offset)); #####: 1569: if (++x >= (int) image->xsize){ branch 0 never executed branch 1 never executed #####: 1570: x = 0, y++; -: 1571: } -: 1572: } -: 1573: } 23: 1574: PyErr_Clear(); /* Avoid weird exceptions */ call 0 returned 100% -: 1575: } -: 1576: } else { -: 1577: /* 32-bit images */ 16: 1578: seq = PySequence_Fast(data, must_be_sequence); call 0 returned 100% 16: 1579: if (!seq) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1580: PyErr_SetString(PyExc_TypeError, must_be_sequence); call 0 never executed #####: 1581: return NULL; -: 1582: } 16: 1583: switch (image->type) { branch 0 taken 25% branch 1 taken 13% branch 2 taken 63% -: 1584: case IMAGING_TYPE_INT32: 16393: 1585: for (i = x = y = 0; i < n; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16393: 1586: op = PySequence_Fast_GET_ITEM(seq, i); branch 0 taken 100% (fallthrough) branch 1 taken 0% 32786: 1587: IMAGING_PIXEL_INT32(image, x, y) = 16393: 1588: (INT32) (PyFloat_AsDouble(op) * scale + offset); call 0 returned 100% 16393: 1589: if (++x >= (int) image->xsize){ branch 0 taken 1% (fallthrough) branch 1 taken 99% 131: 1590: x = 0, y++; -: 1591: } -: 1592: } 2: 1593: PyErr_Clear(); /* Avoid weird exceptions */ call 0 returned 100% 2: 1594: break; -: 1595: case IMAGING_TYPE_FLOAT32: 46393: 1596: for (i = x = y = 0; i < n; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 46393: 1597: op = PySequence_Fast_GET_ITEM(seq, i); branch 0 taken 100% (fallthrough) branch 1 taken 0% 92786: 1598: IMAGING_PIXEL_FLOAT32(image, x, y) = 46393: 1599: (FLOAT32) (PyFloat_AsDouble(op) * scale + offset); call 0 returned 100% 46393: 1600: if (++x >= (int) image->xsize){ branch 0 taken 1% (fallthrough) branch 1 taken 99% 331: 1601: x = 0, y++; -: 1602: } -: 1603: } 4: 1604: PyErr_Clear(); /* Avoid weird exceptions */ call 0 returned 100% 4: 1605: break; -: 1606: default: 32800: 1607: for (i = x = y = 0; i < n; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 1608: union { -: 1609: char ink[4]; -: 1610: INT32 inkint; -: 1611: } u; -: 1612: 32800: 1613: u.inkint = 0; -: 1614: 32800: 1615: op = PySequence_Fast_GET_ITEM(seq, i); branch 0 taken 100% (fallthrough) branch 1 taken 0% 32800: 1616: if (!op || !getink(op, image, u.ink)) { branch 0 taken 100% (fallthrough) branch 1 taken 0% call 2 returned 100% branch 3 taken 0% (fallthrough) branch 4 taken 100% #####: 1617: Py_DECREF(seq); branch 0 never executed branch 1 never executed call 2 never executed #####: 1618: return NULL; -: 1619: } -: 1620: /* FIXME: what about scale and offset? */ 32800: 1621: image->image32[y][x] = u.inkint; 32800: 1622: if (++x >= (int) image->xsize){ branch 0 taken 1% (fallthrough) branch 1 taken 99% 270: 1623: x = 0, y++; -: 1624: } -: 1625: } 10: 1626: PyErr_Clear(); /* Avoid weird exceptions */ call 0 returned 100% 10: 1627: break; -: 1628: } -: 1629: } -: 1630: 40: 1631: Py_XDECREF(seq); branch 0 taken 98% (fallthrough) branch 1 taken 3% branch 2 taken 28% (fallthrough) branch 3 taken 72% call 4 returned 100% -: 1632: 40: 1633: Py_INCREF(Py_None); 40: 1634: return Py_None; -: 1635:} -: 1636: -: 1637:#ifdef WITH_QUANTIZE -: 1638: -: 1639:static PyObject* function _quantize called 25 returned 100% blocks executed 78% 25: 1640:_quantize(ImagingObject* self, PyObject* args) -: 1641:{ 25: 1642: int colours = 256; 25: 1643: int method = 0; 25: 1644: int kmeans = 0; 25: 1645: if (!PyArg_ParseTuple(args, "|iii", &colours, &method, &kmeans)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1646: return NULL; -: 1647: } -: 1648: 25: 1649: if (!self->image->xsize || !self->image->ysize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% -: 1650: /* no content; return an empty image */ #####: 1651: return PyImagingNew( call 0 never executed call 1 never executed -: 1652: ImagingNew("P", self->image->xsize, self->image->ysize) -: 1653: ); -: 1654: } -: 1655: 25: 1656: return PyImagingNew(ImagingQuantize(self->image, colours, method, kmeans)); call 0 returned 100% call 1 returned 100% -: 1657:} -: 1658:#endif -: 1659: -: 1660:static PyObject* function _putpalette called 955 returned 100% blocks executed 88% 955: 1661:_putpalette(ImagingObject* self, PyObject* args) -: 1662:{ -: 1663: ImagingShuffler unpack; -: 1664: int bits; -: 1665: -: 1666: char* rawmode; -: 1667: UINT8* palette; -: 1668: Py_ssize_t palettesize; 955: 1669: if (!PyArg_ParseTuple(args, "sy#", &rawmode, &palette, &palettesize)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1670: return NULL; -: 1671: } -: 1672: 1783: 1673: if (strcmp(self->image->mode, "L") && strcmp(self->image->mode, "LA") && branch 0 taken 13% (fallthrough) branch 1 taken 87% branch 2 taken 87% (fallthrough) branch 3 taken 13% branch 4 taken 1% (fallthrough) branch 5 taken 99% branch 6 taken 100% (fallthrough) branch 7 taken 0% branch 8 taken 99% (fallthrough) branch 9 taken 1% branch 10 taken 2% (fallthrough) branch 11 taken 98% 841: 1674: strcmp(self->image->mode, "P") && strcmp(self->image->mode, "PA")) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 0% (fallthrough) branch 7 taken 100% #####: 1675: PyErr_SetString(PyExc_ValueError, wrong_mode); call 0 never executed #####: 1676: return NULL; -: 1677: } -: 1678: 955: 1679: unpack = ImagingFindUnpacker("RGB", rawmode, &bits); call 0 returned 100% 955: 1680: if (!unpack) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1681: PyErr_SetString(PyExc_ValueError, wrong_raw_mode); call 0 never executed #####: 1682: return NULL; -: 1683: } -: 1684: 955: 1685: if ( palettesize * 8 / bits > 256) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1: 1686: PyErr_SetString(PyExc_ValueError, wrong_palette_size); call 0 returned 100% 1: 1687: return NULL; -: 1688: } -: 1689: 954: 1690: ImagingPaletteDelete(self->image->palette); call 0 returned 100% -: 1691: 1908: 1692: strcpy(self->image->mode, strlen(self->image->mode) == 2 ? "PA" : "P"); branch 0 taken 98% (fallthrough) branch 1 taken 2% -: 1693: 954: 1694: self->image->palette = ImagingPaletteNew("RGB"); call 0 returned 100% -: 1695: 954: 1696: unpack(self->image->palette->palette, palette, palettesize * 8 / bits); call 0 returned 100% -: 1697: 954: 1698: Py_INCREF(Py_None); 954: 1699: return Py_None; -: 1700:} -: 1701: -: 1702:static PyObject* function _putpalettealpha called 404 returned 100% blocks executed 60% 404: 1703:_putpalettealpha(ImagingObject* self, PyObject* args) -: 1704:{ -: 1705: int index; 404: 1706: int alpha = 0; 404: 1707: if (!PyArg_ParseTuple(args, "i|i", &index, &alpha)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1708: return NULL; -: 1709: } -: 1710: 404: 1711: if (!self->image->palette) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1712: PyErr_SetString(PyExc_ValueError, no_palette); call 0 never executed #####: 1713: return NULL; -: 1714: } -: 1715: 404: 1716: if (index < 0 || index >= 256) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1717: PyErr_SetString(PyExc_ValueError, outside_palette); call 0 never executed #####: 1718: return NULL; -: 1719: } -: 1720: 808: 1721: strcpy(self->image->palette->mode, "RGBA"); 404: 1722: self->image->palette->palette[index*4+3] = (UINT8) alpha; -: 1723: 404: 1724: Py_INCREF(Py_None); 404: 1725: return Py_None; -: 1726:} -: 1727: -: 1728:static PyObject* function _putpalettealphas called 31 returned 100% blocks executed 69% 31: 1729:_putpalettealphas(ImagingObject* self, PyObject* args) -: 1730:{ -: 1731: int i; -: 1732: UINT8 *values; -: 1733: Py_ssize_t length; 31: 1734: if (!PyArg_ParseTuple(args, "y#", &values, &length)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1735: return NULL; -: 1736: } -: 1737: 31: 1738: if (!self->image->palette) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1739: PyErr_SetString(PyExc_ValueError, no_palette); call 0 never executed #####: 1740: return NULL; -: 1741: } -: 1742: 31: 1743: if (length > 256) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1744: PyErr_SetString(PyExc_ValueError, outside_palette); call 0 never executed #####: 1745: return NULL; -: 1746: } -: 1747: 62: 1748: strcpy(self->image->palette->mode, "RGBA"); 7459: 1749: for (i=0; iimage->palette->palette[i*4+3] = (UINT8) values[i]; -: 1751: } -: 1752: 31: 1753: Py_INCREF(Py_None); 31: 1754: return Py_None; -: 1755:} -: 1756: -: 1757:static PyObject* function _putpixel called 91439 returned 100% blocks executed 100% 91439: 1758:_putpixel(ImagingObject* self, PyObject* args) -: 1759:{ -: 1760: Imaging im; -: 1761: char ink[4]; -: 1762: -: 1763: int x, y; -: 1764: PyObject* color; 91439: 1765: if (!PyArg_ParseTuple(args, "(ii)O", &x, &y, &color)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1766: return NULL; -: 1767: } -: 1768: 91439: 1769: im = self->image; -: 1770: 91439: 1771: if (x < 0) { branch 0 taken 36% (fallthrough) branch 1 taken 64% 32834: 1772: x = im->xsize + x; -: 1773: } 91439: 1774: if (y < 0) { branch 0 taken 36% (fallthrough) branch 1 taken 64% 32834: 1775: y = im->ysize + y; -: 1776: } -: 1777: 91439: 1778: if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 99% (fallthrough) branch 3 taken 1% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 0% (fallthrough) branch 7 taken 100% 88: 1779: PyErr_SetString(PyExc_IndexError, outside_image); call 0 returned 100% 88: 1780: return NULL; -: 1781: } -: 1782: 91351: 1783: if (!getink(color, im, ink)) { call 0 returned 100% branch 1 taken 99% (fallthrough) branch 2 taken 1% -: 1784: return NULL; -: 1785: } -: 1786: 91322: 1787: if (self->access) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 91322: 1788: self->access->put_pixel(im, x, y, ink); call 0 returned 100% -: 1789: } -: 1790: 91322: 1791: Py_INCREF(Py_None); 91322: 1792: return Py_None; -: 1793:} -: 1794: -: 1795:#ifdef WITH_RANKFILTER -: 1796:static PyObject* function _rankfilter called 45 returned 100% blocks executed 100% 45: 1797:_rankfilter(ImagingObject* self, PyObject* args) -: 1798:{ -: 1799: int size, rank; 45: 1800: if (!PyArg_ParseTuple(args, "ii", &size, &rank)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1801: return NULL; -: 1802: } -: 1803: 45: 1804: return PyImagingNew(ImagingRankFilter(self->image, size, rank)); call 0 returned 100% call 1 returned 100% -: 1805:} -: 1806:#endif -: 1807: -: 1808:static PyObject* function _resize called 11059 returned 100% blocks executed 100% 11059: 1809:_resize(ImagingObject* self, PyObject* args) -: 1810:{ -: 1811: Imaging imIn; -: 1812: Imaging imOut; -: 1813: -: 1814: int xsize, ysize; 11059: 1815: int filter = IMAGING_TRANSFORM_NEAREST; 11059: 1816: float box[4] = {0, 0, 0, 0}; -: 1817: 11059: 1818: imIn = self->image; 11059: 1819: box[2] = imIn->xsize; 11059: 1820: box[3] = imIn->ysize; -: 1821: 11059: 1822: if (!PyArg_ParseTuple(args, "(ii)|i(ffff)", &xsize, &ysize, &filter, call 0 returned 100% branch 1 taken 99% (fallthrough) branch 2 taken 1% -: 1823: &box[0], &box[1], &box[2], &box[3])) { -: 1824: return NULL; -: 1825: } -: 1826: 11053: 1827: if (xsize < 1 || ysize < 1) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% 2: 1828: return ImagingError_ValueError("height and width must be > 0"); call 0 returned 100% -: 1829: } -: 1830: 11051: 1831: if (box[0] < 0 || box[1] < 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% 12: 1832: return ImagingError_ValueError("box offset can't be negative"); call 0 returned 100% -: 1833: } -: 1834: 11039: 1835: if (box[2] > imIn->xsize || box[3] > imIn->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% 12: 1836: return ImagingError_ValueError("box can't exceed original image size"); call 0 returned 100% -: 1837: } -: 1838: 11027: 1839: if (box[2] - box[0] < 0 || box[3] - box[1] < 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% 18: 1840: return ImagingError_ValueError("box can't be empty"); call 0 returned 100% -: 1841: } -: 1842: -: 1843: // If box's coordinates are int and box size matches requested size 11009: 1844: if (box[0] - (int) box[0] == 0 && box[2] - box[0] == xsize branch 0 taken 9% (fallthrough) branch 1 taken 91% branch 2 taken 10% (fallthrough) branch 3 taken 90% 104: 1845: && box[1] - (int) box[1] == 0 && box[3] - box[1] == ysize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 23% (fallthrough) branch 3 taken 77% 24: 1846: imOut = ImagingCrop(imIn, box[0], box[1], box[2], box[3]); call 0 returned 100% -: 1847: } 10985: 1848: else if (filter == IMAGING_TRANSFORM_NEAREST) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 1849: double a[6]; -: 1850: 110: 1851: memset(a, 0, sizeof a); 110: 1852: a[0] = (double) (box[2] - box[0]) / xsize; 110: 1853: a[4] = (double) (box[3] - box[1]) / ysize; 110: 1854: a[2] = box[0]; 110: 1855: a[5] = box[1]; -: 1856: 110: 1857: imOut = ImagingNewDirty(imIn->mode, xsize, ysize); call 0 returned 100% -: 1858: 110: 1859: imOut = ImagingTransform( call 0 returned 100% -: 1860: imOut, imIn, IMAGING_TRANSFORM_AFFINE, -: 1861: 0, 0, xsize, ysize, -: 1862: a, filter, 1); -: 1863: } -: 1864: else { 10875: 1865: imOut = ImagingResample(imIn, xsize, ysize, filter, box); call 0 returned 100% -: 1866: } -: 1867: 11009: 1868: return PyImagingNew(imOut); call 0 returned 100% -: 1869:} -: 1870: -: 1871:static PyObject* function _reduce called 513 returned 100% blocks executed 100% 513: 1872:_reduce(ImagingObject* self, PyObject* args) -: 1873:{ -: 1874: Imaging imIn; -: 1875: Imaging imOut; -: 1876: -: 1877: int xscale, yscale; 513: 1878: int box[4] = {0, 0, 0, 0}; -: 1879: 513: 1880: imIn = self->image; 513: 1881: box[2] = imIn->xsize; 513: 1882: box[3] = imIn->ysize; -: 1883: 513: 1884: if (!PyArg_ParseTuple(args, "(ii)|(iiii)", &xscale, &yscale, call 0 returned 100% branch 1 taken 99% (fallthrough) branch 2 taken 1% -: 1885: &box[0], &box[1], &box[2], &box[3])) { -: 1886: return NULL; -: 1887: } -: 1888: 511: 1889: if (xscale < 1 || yscale < 1) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 0% (fallthrough) branch 3 taken 100% 2: 1890: return ImagingError_ValueError("scale must be > 0"); call 0 returned 100% -: 1891: } -: 1892: 509: 1893: if (box[0] < 0 || box[1] < 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% 2: 1894: return ImagingError_ValueError("box offset can't be negative"); call 0 returned 100% -: 1895: } -: 1896: 507: 1897: if (box[2] > imIn->xsize || box[3] > imIn->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% 2: 1898: return ImagingError_ValueError("box can't exceed original image size"); call 0 returned 100% -: 1899: } -: 1900: 505: 1901: if (box[2] <= box[0] || box[3] <= box[1]) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% 2: 1902: return ImagingError_ValueError("box can't be empty"); call 0 returned 100% -: 1903: } -: 1904: 503: 1905: if (xscale == 1 && yscale == 1) { branch 0 taken 22% (fallthrough) branch 1 taken 78% branch 2 taken 7% (fallthrough) branch 3 taken 93% 8: 1906: imOut = ImagingCrop(imIn, box[0], box[1], box[2], box[3]); call 0 returned 100% -: 1907: } else { -: 1908: // Change box format: (left, top, width, height) 495: 1909: box[2] -= box[0]; 495: 1910: box[3] -= box[1]; 495: 1911: imOut = ImagingReduce(imIn, xscale, yscale, box); call 0 returned 100% -: 1912: } -: 1913: 503: 1914: return PyImagingNew(imOut); call 0 returned 100% -: 1915:} -: 1916: -: 1917: -: 1918:#define IS_RGB(mode)\ -: 1919: (!strcmp(mode, "RGB") || !strcmp(mode, "RGBA") || !strcmp(mode, "RGBX")) -: 1920: -: 1921:static PyObject* function im_setmode called 22 returned 100% blocks executed 100% 22: 1922:im_setmode(ImagingObject* self, PyObject* args) -: 1923:{ -: 1924: /* attempt to modify the mode of an image in place */ -: 1925: -: 1926: Imaging im; -: 1927: -: 1928: char* mode; -: 1929: Py_ssize_t modelen; 22: 1930: if (!PyArg_ParseTuple(args, "s#:setmode", &mode, &modelen)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1931: return NULL; -: 1932: } -: 1933: 22: 1934: im = self->image; -: 1935: -: 1936: /* move all logic in here to the libImaging primitive */ -: 1937: 22: 1938: if (!strcmp(im->mode, mode)) { branch 0 taken 86% (fallthrough) branch 1 taken 14% -: 1939: ; /* same mode; always succeeds */ 19: 1940: } else if (IS_RGB(im->mode) && IS_RGB(mode)) { branch 0 taken 79% (fallthrough) branch 1 taken 21% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 32% (fallthrough) branch 7 taken 68% branch 8 taken 83% (fallthrough) branch 9 taken 17% branch 10 taken 20% (fallthrough) branch 11 taken 80% branch 12 taken 93% (fallthrough) branch 13 taken 7% branch 14 taken 100% (fallthrough) branch 15 taken 0% branch 16 taken 100% (fallthrough) branch 17 taken 0% branch 18 taken 93% (fallthrough) branch 19 taken 7% branch 20 taken 21% (fallthrough) branch 21 taken 79% branch 22 taken 33% (fallthrough) branch 23 taken 67% -: 1941: /* color to color */ 26: 1942: strcpy(im->mode, mode); 13: 1943: im->bands = modelen; 13: 1944: if (!strcmp(mode, "RGBA")) { branch 0 taken 85% (fallthrough) branch 1 taken 15% 11: 1945: (void) ImagingFillBand(im, 3, 255); call 0 returned 100% -: 1946: } -: 1947: } else { -: 1948: /* trying doing an in-place conversion */ 6: 1949: if (!ImagingConvertInPlace(im, mode)) { call 0 returned 100% branch 1 taken 33% (fallthrough) branch 2 taken 67% -: 1950: return NULL; -: 1951: } -: 1952: } -: 1953: -: 1954: if (self->access) { -: 1955: ImagingAccessDelete(im, self->access); -: 1956: } 18: 1957: self->access = ImagingAccessNew(im); call 0 returned 100% -: 1958: 18: 1959: Py_INCREF(Py_None); 18: 1960: return Py_None; -: 1961:} -: 1962: -: 1963: -: 1964:static PyObject* function _transform2 called 274 returned 100% blocks executed 92% 274: 1965:_transform2(ImagingObject* self, PyObject* args) -: 1966:{ -: 1967: static const char* wrong_number = "wrong number of matrix entries"; -: 1968: -: 1969: Imaging imOut; -: 1970: Py_ssize_t n; -: 1971: double *a; -: 1972: -: 1973: ImagingObject* imagep; -: 1974: int x0, y0, x1, y1; -: 1975: int method; -: 1976: PyObject* data; 274: 1977: int filter = IMAGING_TRANSFORM_NEAREST; 274: 1978: int fill = 1; 274: 1979: if (!PyArg_ParseTuple(args, "(iiii)O!iO|ii", call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1980: &x0, &y0, &x1, &y1, -: 1981: &Imaging_Type, &imagep, -: 1982: &method, &data, -: 1983: &filter, &fill)) { -: 1984: return NULL; -: 1985: } -: 1986: 274: 1987: switch (method) { branch 0 taken 75% branch 1 taken 22% branch 2 taken 3% branch 3 taken 0% -: 1988: case IMAGING_TRANSFORM_AFFINE: 205: 1989: n = 6; 205: 1990: break; -: 1991: case IMAGING_TRANSFORM_PERSPECTIVE: 60: 1992: n = 8; 60: 1993: break; -: 1994: case IMAGING_TRANSFORM_QUAD: 9: 1995: n = 8; 9: 1996: break; -: 1997: default: #####: 1998: n = -1; /* force error */ -: 1999: } -: 2000: 274: 2001: a = getlist(data, &n, wrong_number, TYPE_DOUBLE); call 0 returned 100% 274: 2002: if (!a) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2003: return NULL; -: 2004: } -: 2005: 548: 2006: imOut = ImagingTransform( call 0 returned 100% 274: 2007: self->image, imagep->image, method, -: 2008: x0, y0, x1, y1, a, filter, fill); -: 2009: 274: 2010: free(a); -: 2011: 274: 2012: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2013: return NULL; -: 2014: } -: 2015: 274: 2016: Py_INCREF(Py_None); 274: 2017: return Py_None; -: 2018:} -: 2019: -: 2020:static PyObject* function _transpose called 283 returned 100% blocks executed 87% 283: 2021:_transpose(ImagingObject* self, PyObject* args) -: 2022:{ -: 2023: Imaging imIn; -: 2024: Imaging imOut; -: 2025: -: 2026: int op; 283: 2027: if (!PyArg_ParseTuple(args, "i", &op)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2028: return NULL; -: 2029: } -: 2030: 283: 2031: imIn = self->image; -: 2032: 283: 2033: switch (op) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 43% (fallthrough) branch 3 taken 57% branch 4 taken 0% (fallthrough) branch 5 taken 100% -: 2034: case 0: /* flip left right */ -: 2035: case 1: /* flip top bottom */ -: 2036: case 3: /* rotate 180 */ 122: 2037: imOut = ImagingNewDirty(imIn->mode, imIn->xsize, imIn->ysize); call 0 returned 100% 122: 2038: break; -: 2039: case 2: /* rotate 90 */ -: 2040: case 4: /* rotate 270 */ -: 2041: case 5: /* transpose */ -: 2042: case 6: /* transverse */ 161: 2043: imOut = ImagingNewDirty(imIn->mode, imIn->ysize, imIn->xsize); call 0 returned 100% 161: 2044: break; -: 2045: default: #####: 2046: PyErr_SetString(PyExc_ValueError, "No such transpose operation"); call 0 never executed #####: 2047: return NULL; -: 2048: } -: 2049: 283: 2050: if (imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 283: 2051: switch (op) { branch 0 taken 12% branch 1 taken 11% branch 2 taken 24% branch 3 taken 20% branch 4 taken 16% branch 5 taken 8% branch 6 taken 8% branch 7 taken 0% -: 2052: case 0: 33: 2053: (void) ImagingFlipLeftRight(imOut, imIn); call 0 returned 100% 33: 2054: break; -: 2055: case 1: 31: 2056: (void) ImagingFlipTopBottom(imOut, imIn); call 0 returned 100% 31: 2057: break; -: 2058: case 2: 68: 2059: (void) ImagingRotate90(imOut, imIn); call 0 returned 100% 68: 2060: break; -: 2061: case 3: 58: 2062: (void) ImagingRotate180(imOut, imIn); call 0 returned 100% 58: 2063: break; -: 2064: case 4: 45: 2065: (void) ImagingRotate270(imOut, imIn); call 0 returned 100% 45: 2066: break; -: 2067: case 5: 24: 2068: (void) ImagingTranspose(imOut, imIn); call 0 returned 100% 24: 2069: break; -: 2070: case 6: 24: 2071: (void) ImagingTransverse(imOut, imIn); call 0 returned 100% 24: 2072: break; -: 2073: } -: 2074: } -: 2075: 283: 2076: return PyImagingNew(imOut); call 0 returned 100% -: 2077:} -: 2078: -: 2079:#ifdef WITH_UNSHARPMASK -: 2080:static PyObject* function _unsharp_mask called 16 returned 100% blocks executed 100% 16: 2081:_unsharp_mask(ImagingObject* self, PyObject* args) -: 2082:{ -: 2083: Imaging imIn; -: 2084: Imaging imOut; -: 2085: -: 2086: float radius; -: 2087: int percent, threshold; 16: 2088: if (!PyArg_ParseTuple(args, "fii", &radius, &percent, &threshold)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2089: return NULL; -: 2090: } -: 2091: 16: 2092: imIn = self->image; 16: 2093: imOut = ImagingNewDirty(imIn->mode, imIn->xsize, imIn->ysize); call 0 returned 100% 16: 2094: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2095: return NULL; -: 2096: } -: 2097: 16: 2098: if (!ImagingUnsharpMask(imOut, imIn, radius, percent, threshold)) { call 0 returned 100% branch 1 taken 75% (fallthrough) branch 2 taken 25% -: 2099: return NULL; -: 2100: } -: 2101: 12: 2102: return PyImagingNew(imOut); call 0 returned 100% -: 2103:} -: 2104:#endif -: 2105: -: 2106:static PyObject* function _box_blur called 40 returned 100% blocks executed 100% 40: 2107:_box_blur(ImagingObject* self, PyObject* args) -: 2108:{ -: 2109: Imaging imIn; -: 2110: Imaging imOut; -: 2111: -: 2112: float radius; 40: 2113: int n = 1; 40: 2114: if (!PyArg_ParseTuple(args, "f|i", &radius, &n)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2115: return NULL; -: 2116: } -: 2117: 40: 2118: imIn = self->image; 40: 2119: imOut = ImagingNewDirty(imIn->mode, imIn->xsize, imIn->ysize); call 0 returned 100% 40: 2120: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2121: return NULL; -: 2122: } -: 2123: 40: 2124: if (!ImagingBoxBlur(imOut, imIn, radius, n)) { call 0 returned 100% branch 1 taken 13% (fallthrough) branch 2 taken 88% 5: 2125: ImagingDelete(imOut); call 0 returned 100% 5: 2126: return NULL; -: 2127: } -: 2128: 35: 2129: return PyImagingNew(imOut); call 0 returned 100% -: 2130:} -: 2131: -: 2132:/* -------------------------------------------------------------------- */ -: 2133: -: 2134:static PyObject* function _isblock called 0 returned 0% blocks executed 0% #####: 2135:_isblock(ImagingObject* self, PyObject* args) -: 2136:{ #####: 2137: return PyBool_FromLong(self->image->block != NULL); call 0 never executed -: 2138:} -: 2139: -: 2140:static PyObject* function _getbbox called 158 returned 100% blocks executed 100% 158: 2141:_getbbox(ImagingObject* self, PyObject* args) -: 2142:{ -: 2143: int bbox[4]; 158: 2144: if (!ImagingGetBBox(self->image, bbox)) { call 0 returned 100% branch 1 taken 18% (fallthrough) branch 2 taken 82% 29: 2145: Py_INCREF(Py_None); 29: 2146: return Py_None; -: 2147: } -: 2148: 129: 2149: return Py_BuildValue("iiii", bbox[0], bbox[1], bbox[2], bbox[3]); call 0 returned 100% -: 2150:} -: 2151: -: 2152:static PyObject* function _getcolors called 20 returned 100% blocks executed 100% 20: 2153:_getcolors(ImagingObject* self, PyObject* args) -: 2154:{ -: 2155: ImagingColorItem* items; -: 2156: int i, colors; -: 2157: PyObject* out; -: 2158: 20: 2159: int maxcolors = 256; 20: 2160: if (!PyArg_ParseTuple(args, "i:getcolors", &maxcolors)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2161: return NULL; -: 2162: } -: 2163: 20: 2164: items = ImagingGetColors(self->image, maxcolors, &colors); call 0 returned 100% 20: 2165: if (!items) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2166: return NULL; -: 2167: } -: 2168: 20: 2169: if (colors > maxcolors) { branch 0 taken 30% (fallthrough) branch 1 taken 70% 6: 2170: out = Py_None; 6: 2171: Py_INCREF(out); -: 2172: } else { 14: 2173: out = PyList_New(colors); 50274: 2174: for (i = 0; i < colors; i++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 50260: 2175: ImagingColorItem* v = &items[i]; 50260: 2176: PyObject* item = Py_BuildValue( call 0 returned 100% call 1 returned 100% -: 2177: "iN", v->count, getpixel(self->image, self->access, v->x, v->y) -: 2178: ); 50260: 2179: PyList_SetItem(out, i, item); call 0 returned 100% -: 2180: } -: 2181: } -: 2182: 20: 2183: free(items); -: 2184: 20: 2185: return out; -: 2186:} -: 2187: -: 2188:static PyObject* function _getextrema called 29 returned 100% blocks executed 91% 29: 2189:_getextrema(ImagingObject* self, PyObject* args) -: 2190:{ -: 2191: union { -: 2192: UINT8 u[2]; -: 2193: INT32 i[2]; -: 2194: FLOAT32 f[2]; -: 2195: UINT16 s[2]; -: 2196: } extrema; -: 2197: int status; -: 2198: 29: 2199: status = ImagingGetExtrema(self->image, &extrema); call 0 returned 100% 29: 2200: if (status < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2201: return NULL; -: 2202: } -: 2203: 29: 2204: if (status) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 29: 2205: switch (self->image->type) { branch 0 taken 62% branch 1 taken 14% branch 2 taken 17% branch 3 taken 7% branch 4 taken 0% -: 2206: case IMAGING_TYPE_UINT8: 18: 2207: return Py_BuildValue("BB", extrema.u[0], extrema.u[1]); call 0 returned 100% -: 2208: case IMAGING_TYPE_INT32: 4: 2209: return Py_BuildValue("ii", extrema.i[0], extrema.i[1]); call 0 returned 100% -: 2210: case IMAGING_TYPE_FLOAT32: 5: 2211: return Py_BuildValue("dd", extrema.f[0], extrema.f[1]); call 0 returned 100% -: 2212: case IMAGING_TYPE_SPECIAL: 2: 2213: if (strcmp(self->image->mode, "I;16") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 2: 2214: return Py_BuildValue("HH", extrema.s[0], extrema.s[1]); call 0 returned 100% -: 2215: } -: 2216: } -: 2217: } -: 2218: #####: 2219: Py_INCREF(Py_None); #####: 2220: return Py_None; -: 2221:} -: 2222: -: 2223:static PyObject* function _getprojection called 10 returned 100% blocks executed 86% 10: 2224:_getprojection(ImagingObject* self, PyObject* args) -: 2225:{ -: 2226: unsigned char* xprofile; -: 2227: unsigned char* yprofile; -: 2228: PyObject* result; -: 2229: -: 2230: /* malloc check ok */ 10: 2231: xprofile = malloc(self->image->xsize); 10: 2232: yprofile = malloc(self->image->ysize); -: 2233: 10: 2234: if (xprofile == NULL || yprofile == NULL) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% #####: 2235: free(xprofile); #####: 2236: free(yprofile); #####: 2237: return PyErr_NoMemory(); call 0 never executed -: 2238: } -: 2239: 10: 2240: ImagingGetProjection(self->image, (unsigned char *)xprofile, (unsigned char *)yprofile); call 0 returned 100% -: 2241: 20: 2242: result = Py_BuildValue("y#y#", call 0 returned 100% 10: 2243: xprofile, (Py_ssize_t)self->image->xsize, 10: 2244: yprofile, (Py_ssize_t)self->image->ysize); -: 2245: 10: 2246: free(xprofile); 10: 2247: free(yprofile); -: 2248: 10: 2249: return result; -: 2250:} -: 2251: -: 2252:/* -------------------------------------------------------------------- */ -: 2253: -: 2254:static PyObject* function _getband called 159 returned 100% blocks executed 100% 159: 2255:_getband(ImagingObject* self, PyObject* args) -: 2256:{ -: 2257: int band; -: 2258: 159: 2259: if (!PyArg_ParseTuple(args, "i", &band)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2260: return NULL; -: 2261: } -: 2262: 159: 2263: return PyImagingNew(ImagingGetBand(self->image, band)); call 0 returned 100% call 1 returned 100% -: 2264:} -: 2265: -: 2266:static PyObject* function _fillband called 9 returned 100% blocks executed 100% 9: 2267:_fillband(ImagingObject* self, PyObject* args) -: 2268:{ -: 2269: int band; -: 2270: int color; -: 2271: 9: 2272: if (!PyArg_ParseTuple(args, "ii", &band, &color)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2273: return NULL; -: 2274: } -: 2275: 9: 2276: if (!ImagingFillBand(self->image, band, color)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2277: return NULL; -: 2278: } -: 2279: 9: 2280: Py_INCREF(Py_None); 9: 2281: return Py_None; -: 2282:} -: 2283: -: 2284:static PyObject* function _putband called 61 returned 100% blocks executed 100% 61: 2285:_putband(ImagingObject* self, PyObject* args) -: 2286:{ -: 2287: ImagingObject* imagep; -: 2288: int band; 61: 2289: if (!PyArg_ParseTuple(args, "O!i", call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2290: &Imaging_Type, &imagep, -: 2291: &band)) { -: 2292: return NULL; -: 2293: } -: 2294: 61: 2295: if (!ImagingPutBand(self->image, imagep->image, band)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2296: return NULL; -: 2297: } -: 2298: 61: 2299: Py_INCREF(Py_None); 61: 2300: return Py_None; -: 2301:} -: 2302: -: 2303:static PyObject* function _merge called 252 returned 100% blocks executed 100% 252: 2304:_merge(PyObject* self, PyObject* args) -: 2305:{ -: 2306: char* mode; 252: 2307: ImagingObject *band0 = NULL; 252: 2308: ImagingObject *band1 = NULL; 252: 2309: ImagingObject *band2 = NULL; 252: 2310: ImagingObject *band3 = NULL; 252: 2311: Imaging bands[4] = {NULL, NULL, NULL, NULL}; -: 2312: 252: 2313: if (!PyArg_ParseTuple(args, "sO!|O!O!O!", &mode, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2314: &Imaging_Type, &band0, &Imaging_Type, &band1, -: 2315: &Imaging_Type, &band2, &Imaging_Type, &band3)) { -: 2316: return NULL; -: 2317: } -: 2318: 252: 2319: if (band0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 252: 2320: bands[0] = band0->image; -: 2321: } 252: 2322: if (band1) { branch 0 taken 92% (fallthrough) branch 1 taken 8% 232: 2323: bands[1] = band1->image; -: 2324: } 252: 2325: if (band2) { branch 0 taken 81% (fallthrough) branch 1 taken 19% 204: 2326: bands[2] = band2->image; -: 2327: } 252: 2328: if (band3) { branch 0 taken 49% (fallthrough) branch 1 taken 51% 124: 2329: bands[3] = band3->image; -: 2330: } -: 2331: 252: 2332: return PyImagingNew(ImagingMerge(mode, bands)); call 0 returned 100% call 1 returned 100% -: 2333:} -: 2334: -: 2335:static PyObject* function _split called 1221 returned 100% blocks executed 77% 1221: 2336:_split(ImagingObject* self, PyObject* args) -: 2337:{ 1221: 2338: int fails = 0; -: 2339: Py_ssize_t i; -: 2340: PyObject* list; -: 2341: PyObject* imaging_object; 1221: 2342: Imaging bands[4] = {NULL, NULL, NULL, NULL}; -: 2343: 1221: 2344: if ( ! ImagingSplit(self->image, bands)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2345: return NULL; -: 2346: } -: 2347: 1221: 2348: list = PyTuple_New(self->image->bands); 5009: 2349: for (i = 0; i < self->image->bands; i++) { call 0 returned 100% branch 1 taken 76% branch 2 taken 24% (fallthrough) 3788: 2350: imaging_object = PyImagingNew(bands[i]); call 0 returned 100% 3788: 2351: if ( ! imaging_object) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 2352: fails += 1; -: 2353: } 3788: 2354: PyTuple_SET_ITEM(list, i, imaging_object); -: 2355: } 1221: 2356: if (fails) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 2357: Py_DECREF(list); branch 0 never executed branch 1 never executed call 2 never executed -: 2358: list = NULL; -: 2359: } -: 2360: return list; -: 2361:} -: 2362: -: 2363:/* -------------------------------------------------------------------- */ -: 2364: -: 2365:#ifdef WITH_IMAGECHOPS -: 2366: -: 2367:static PyObject* function _chop_invert called 2 returned 100% blocks executed 100% 2: 2368:_chop_invert(ImagingObject* self, PyObject* args) -: 2369:{ 2: 2370: return PyImagingNew(ImagingNegative(self->image)); call 0 returned 100% call 1 returned 100% -: 2371:} -: 2372: -: 2373:static PyObject* function _chop_lighter called 3 returned 100% blocks executed 100% 3: 2374:_chop_lighter(ImagingObject* self, PyObject* args) -: 2375:{ -: 2376: ImagingObject* imagep; -: 2377: 3: 2378: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2379: return NULL; -: 2380: } -: 2381: 3: 2382: return PyImagingNew(ImagingChopLighter(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2383:} -: 2384: -: 2385:static PyObject* function _chop_darker called 3 returned 100% blocks executed 100% 3: 2386:_chop_darker(ImagingObject* self, PyObject* args) -: 2387:{ -: 2388: ImagingObject* imagep; -: 2389: 3: 2390: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2391: return NULL; -: 2392: } -: 2393: 3: 2394: return PyImagingNew(ImagingChopDarker(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2395:} -: 2396: -: 2397:static PyObject* function _chop_difference called 3 returned 100% blocks executed 100% 3: 2398:_chop_difference(ImagingObject* self, PyObject* args) -: 2399:{ -: 2400: ImagingObject* imagep; -: 2401: 3: 2402: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2403: return NULL; -: 2404: } -: 2405: 3: 2406: return PyImagingNew(ImagingChopDifference(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2407:} -: 2408: -: 2409:static PyObject* function _chop_multiply called 4 returned 100% blocks executed 100% 4: 2410:_chop_multiply(ImagingObject* self, PyObject* args) -: 2411:{ -: 2412: ImagingObject* imagep; -: 2413: 4: 2414: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2415: return NULL; -: 2416: } -: 2417: 4: 2418: return PyImagingNew(ImagingChopMultiply(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2419:} -: 2420: -: 2421:static PyObject* function _chop_screen called 2 returned 100% blocks executed 100% 2: 2422:_chop_screen(ImagingObject* self, PyObject* args) -: 2423:{ -: 2424: ImagingObject* imagep; -: 2425: 2: 2426: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2427: return NULL; -: 2428: } -: 2429: 2: 2430: return PyImagingNew(ImagingChopScreen(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2431:} -: 2432: -: 2433:static PyObject* function _chop_add called 6 returned 100% blocks executed 100% 6: 2434:_chop_add(ImagingObject* self, PyObject* args) -: 2435:{ -: 2436: ImagingObject* imagep; -: 2437: float scale; -: 2438: int offset; -: 2439: 6: 2440: scale = 1.0; 6: 2441: offset = 0; -: 2442: 6: 2443: if (!PyArg_ParseTuple(args, "O!|fi", &Imaging_Type, &imagep, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2444: &scale, &offset)) { -: 2445: return NULL; -: 2446: } -: 2447: 6: 2448: return PyImagingNew(ImagingChopAdd(self->image, imagep->image, call 0 returned 100% call 1 returned 100% -: 2449: scale, offset)); -: 2450:} -: 2451: -: 2452:static PyObject* function _chop_subtract called 6 returned 100% blocks executed 100% 6: 2453:_chop_subtract(ImagingObject* self, PyObject* args) -: 2454:{ -: 2455: ImagingObject* imagep; -: 2456: float scale; -: 2457: int offset; -: 2458: 6: 2459: scale = 1.0; 6: 2460: offset = 0; -: 2461: 6: 2462: if (!PyArg_ParseTuple(args, "O!|fi", &Imaging_Type, &imagep, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2463: &scale, &offset)) { -: 2464: return NULL; -: 2465: } -: 2466: 6: 2467: return PyImagingNew(ImagingChopSubtract(self->image, imagep->image, call 0 returned 100% call 1 returned 100% -: 2468: scale, offset)); -: 2469:} -: 2470: -: 2471:static PyObject* function _chop_and called 12 returned 100% blocks executed 100% 12: 2472:_chop_and(ImagingObject* self, PyObject* args) -: 2473:{ -: 2474: ImagingObject* imagep; -: 2475: 12: 2476: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2477: return NULL; -: 2478: } -: 2479: 12: 2480: return PyImagingNew(ImagingChopAnd(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2481:} -: 2482: -: 2483:static PyObject* function _chop_or called 12 returned 100% blocks executed 100% 12: 2484:_chop_or(ImagingObject* self, PyObject* args) -: 2485:{ -: 2486: ImagingObject* imagep; -: 2487: 12: 2488: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2489: return NULL; -: 2490: } -: 2491: 12: 2492: return PyImagingNew(ImagingChopOr(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2493:} -: 2494: -: 2495:static PyObject* function _chop_xor called 12 returned 100% blocks executed 100% 12: 2496:_chop_xor(ImagingObject* self, PyObject* args) -: 2497:{ -: 2498: ImagingObject* imagep; -: 2499: 12: 2500: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2501: return NULL; -: 2502: } -: 2503: 12: 2504: return PyImagingNew(ImagingChopXor(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2505:} -: 2506: -: 2507:static PyObject* function _chop_add_modulo called 3 returned 100% blocks executed 100% 3: 2508:_chop_add_modulo(ImagingObject* self, PyObject* args) -: 2509:{ -: 2510: ImagingObject* imagep; -: 2511: 3: 2512: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2513: return NULL; -: 2514: } -: 2515: 3: 2516: return PyImagingNew(ImagingChopAddModulo(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2517:} -: 2518: -: 2519:static PyObject* function _chop_subtract_modulo called 74 returned 100% blocks executed 100% 74: 2520:_chop_subtract_modulo(ImagingObject* self, PyObject* args) -: 2521:{ -: 2522: ImagingObject* imagep; -: 2523: 74: 2524: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2525: return NULL; -: 2526: } -: 2527: 74: 2528: return PyImagingNew(ImagingChopSubtractModulo(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2529:} -: 2530: -: 2531:static PyObject* function _chop_soft_light called 2 returned 100% blocks executed 100% 2: 2532:_chop_soft_light(ImagingObject* self, PyObject* args) -: 2533:{ -: 2534: ImagingObject* imagep; -: 2535: 2: 2536: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2537: return NULL; -: 2538: } -: 2539: 2: 2540: return PyImagingNew(ImagingChopSoftLight(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2541:} -: 2542: -: 2543:static PyObject* function _chop_hard_light called 2 returned 100% blocks executed 100% 2: 2544:_chop_hard_light(ImagingObject* self, PyObject* args) -: 2545:{ -: 2546: ImagingObject* imagep; -: 2547: 2: 2548: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2549: return NULL; -: 2550: } -: 2551: 2: 2552: return PyImagingNew(ImagingChopHardLight(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2553:} -: 2554: -: 2555:static PyObject* function _chop_overlay called 2 returned 100% blocks executed 100% 2: 2556:_chop_overlay(ImagingObject* self, PyObject* args) -: 2557:{ -: 2558: ImagingObject* imagep; -: 2559: 2: 2560: if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2561: return NULL; -: 2562: } -: 2563: 2: 2564: return PyImagingNew(ImagingOverlay(self->image, imagep->image)); call 0 returned 100% call 1 returned 100% -: 2565:} -: 2566:#endif -: 2567: -: 2568: -: 2569:/* -------------------------------------------------------------------- */ -: 2570: -: 2571:#ifdef WITH_IMAGEDRAW -: 2572: -: 2573:static PyObject* function _font_new called 16 returned 100% blocks executed 75% 16: 2574:_font_new(PyObject* self_, PyObject* args) -: 2575:{ -: 2576: ImagingFontObject *self; -: 2577: int i, y0, y1; -: 2578: static const char* wrong_length = "descriptor table has wrong size"; -: 2579: -: 2580: ImagingObject* imagep; -: 2581: unsigned char* glyphdata; -: 2582: Py_ssize_t glyphdata_length; 16: 2583: if (!PyArg_ParseTuple(args, "O!y#", call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2584: &Imaging_Type, &imagep, -: 2585: &glyphdata, &glyphdata_length)) { -: 2586: return NULL; -: 2587: } -: 2588: 16: 2589: if (glyphdata_length != 256 * 20) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 2590: PyErr_SetString(PyExc_ValueError, wrong_length); call 0 never executed #####: 2591: return NULL; -: 2592: } -: 2593: 16: 2594: self = PyObject_New(ImagingFontObject, &ImagingFont_Type); call 0 returned 100% 16: 2595: if (self == NULL) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2596: return NULL; -: 2597: } -: 2598: -: 2599: /* glyph bitmap */ 16: 2600: self->bitmap = imagep->image; -: 2601: 16: 2602: y0 = y1 = 0; -: 2603: -: 2604: /* glyph glyphs */ 4112: 2605: for (i = 0; i < 256; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 4096: 2606: self->glyphs[i].dx = S16(B16(glyphdata, 0)); branch 0 taken 0% (fallthrough) branch 1 taken 100% 4096: 2607: self->glyphs[i].dy = S16(B16(glyphdata, 2)); branch 0 taken 0% (fallthrough) branch 1 taken 100% 4096: 2608: self->glyphs[i].dx0 = S16(B16(glyphdata, 4)); branch 0 taken 10% (fallthrough) branch 1 taken 90% 4096: 2609: self->glyphs[i].dy0 = S16(B16(glyphdata, 6)); branch 0 taken 83% (fallthrough) branch 1 taken 17% 4096: 2610: self->glyphs[i].dx1 = S16(B16(glyphdata, 8)); branch 0 taken 0% (fallthrough) branch 1 taken 100% 4096: 2611: self->glyphs[i].dy1 = S16(B16(glyphdata, 10)); branch 0 taken 4% (fallthrough) branch 1 taken 96% 4096: 2612: self->glyphs[i].sx0 = S16(B16(glyphdata, 12)); branch 0 taken 0% (fallthrough) branch 1 taken 100% 4096: 2613: self->glyphs[i].sy0 = S16(B16(glyphdata, 14)); branch 0 taken 0% (fallthrough) branch 1 taken 100% 4096: 2614: self->glyphs[i].sx1 = S16(B16(glyphdata, 16)); branch 0 taken 0% (fallthrough) branch 1 taken 100% 4096: 2615: self->glyphs[i].sy1 = S16(B16(glyphdata, 18)); branch 0 taken 0% (fallthrough) branch 1 taken 100% 4096: 2616: if (self->glyphs[i].dy0 < y0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 40: 2617: y0 = self->glyphs[i].dy0; -: 2618: } 4096: 2619: if (self->glyphs[i].dy1 > y1) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 22: 2620: y1 = self->glyphs[i].dy1; -: 2621: } 4096: 2622: glyphdata += 20; -: 2623: } -: 2624: 16: 2625: self->baseline = -y0; 16: 2626: self->ysize = y1 - y0; -: 2627: -: 2628: /* keep a reference to the bitmap object */ 16: 2629: Py_INCREF(imagep); 16: 2630: self->ref = imagep; -: 2631: 16: 2632: return (PyObject*) self; -: 2633:} -: 2634: -: 2635:static void function _font_dealloc called 16 returned 100% blocks executed 100% 16: 2636:_font_dealloc(ImagingFontObject* self) -: 2637:{ 16: 2638: Py_XDECREF(self->ref); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% call 4 returned 100% 16: 2639: PyObject_Del(self); call 0 returned 100% 16: 2640:} -: 2641: -: 2642:static inline int -: 2643:textwidth(ImagingFontObject* self, const unsigned char* text) -: 2644:{ -: 2645: int xsize; -: 2646: 1025030: 2647: for (xsize = 0; *text; text++) { branch 0 taken 36% branch 1 taken 64% (fallthrough) branch 2 taken 99% branch 3 taken 1% (fallthrough) 1024922: 2648: xsize += self->glyphs[*text].dx; -: 2649: } -: 2650: -: 2651: return xsize; -: 2652:} -: 2653: function _font_text_asBytes called 1187 returned 100% blocks executed 92% 1187: 2654:void _font_text_asBytes(PyObject* encoded_string, unsigned char** text){ -: 2655: /* Allocates *text, returns a 'new reference'. Caller is required to free */ -: 2656: 1187: 2657: PyObject* bytes = NULL; 1187: 2658: Py_ssize_t len = 0; -: 2659: char *buffer; -: 2660: 1187: 2661: *text = NULL; -: 2662: 1187: 2663: if (PyUnicode_CheckExact(encoded_string)){ branch 0 taken 32% (fallthrough) branch 1 taken 68% 380: 2664: bytes = PyUnicode_AsLatin1String(encoded_string); call 0 returned 100% 380: 2665: if (!bytes) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 2666: return; -: 2667: } 378: 2668: PyBytes_AsStringAndSize(bytes, &buffer, &len); call 0 returned 100% 807: 2669: } else if (PyBytes_Check(encoded_string)) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 42: 2670: PyBytes_AsStringAndSize(encoded_string, &buffer, &len); call 0 returned 100% -: 2671: } -: 2672: 1185: 2673: *text = calloc(len+1,1); 1185: 2674: if (*text) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 1185: 2675: memcpy(*text, buffer, len); -: 2676: } else { #####: 2677: ImagingError_MemoryError(); call 0 never executed -: 2678: } 1185: 2679: if (bytes) { branch 0 taken 32% (fallthrough) branch 1 taken 68% 378: 2680: Py_DECREF(bytes); branch 0 taken 31% (fallthrough) branch 1 taken 69% call 2 returned 100% -: 2681: } -: 2682: -: 2683: return; -: 2684:} -: 2685: -: 2686: -: 2687:static PyObject* function _font_getmask called 108 returned 100% blocks executed 83% 108: 2688:_font_getmask(ImagingFontObject* self, PyObject* args) -: 2689:{ -: 2690: Imaging im; -: 2691: Imaging bitmap; -: 2692: int x, b; 108: 2693: int i=0; -: 2694: int status; -: 2695: Glyph* glyph; -: 2696: -: 2697: PyObject* encoded_string; -: 2698: -: 2699: unsigned char* text; 108: 2700: char* mode = ""; -: 2701: 108: 2702: if (!PyArg_ParseTuple(args, "O|s:getmask", &encoded_string, &mode)){ call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2703: return NULL; -: 2704: } -: 2705: 108: 2706: _font_text_asBytes(encoded_string, &text); call 0 returned 100% 108: 2707: if (!text) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2708: return NULL; -: 2709: } -: 2710: 216: 2711: im = ImagingNew(self->bitmap->mode, textwidth(self, text), self->ysize); call 0 returned 100% 108: 2712: if (!im) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 2713: free(text); #####: 2714: ImagingError_MemoryError(); call 0 never executed #####: 2715: return NULL; -: 2716: } -: 2717: 108: 2718: b = 0; 108: 2719: (void) ImagingFill(im, &b); call 0 returned 100% -: 2720: 108: 2721: b = self->baseline; 1024432: 2722: for (x = 0; text[i]; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 1024324: 2723: glyph = &self->glyphs[text[i]]; 1024324: 2724: bitmap = ImagingCrop( call 0 returned 100% -: 2725: self->bitmap, -: 2726: glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1 -: 2727: ); 1024324: 2728: if (!bitmap) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2729: goto failed; -: 2730: } 4097296: 2731: status = ImagingPaste( call 0 returned 100% -: 2732: im, bitmap, NULL, 4097296: 2733: glyph->dx0+x, glyph->dy0+b, glyph->dx1+x, glyph->dy1+b -: 2734: ); 1024324: 2735: ImagingDelete(bitmap); call 0 returned 100% 1024324: 2736: if (status < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2737: goto failed; -: 2738: } 1024324: 2739: x = x + glyph->dx; 1024324: 2740: b = b + glyph->dy; -: 2741: } 108: 2742: free(text); 108: 2743: return PyImagingNew(im); call 0 returned 100% -: 2744: -: 2745: failed: #####: 2746: free(text); #####: 2747: ImagingDelete(im); call 0 never executed #####: 2748: Py_RETURN_NONE; -: 2749:} -: 2750: -: 2751:static PyObject* function _font_getsize called 1079 returned 100% blocks executed 100% 1079: 2752:_font_getsize(ImagingFontObject* self, PyObject* args) -: 2753:{ -: 2754: unsigned char* text; -: 2755: PyObject* encoded_string; -: 2756: PyObject* val; -: 2757: 1079: 2758: if (!PyArg_ParseTuple(args, "O:getsize", &encoded_string)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2759: return NULL; -: 2760: } -: 2761: 1079: 2762: _font_text_asBytes(encoded_string, &text); call 0 returned 100% 1079: 2763: if (!text) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 2764: return NULL; -: 2765: } -: 2766: 1077: 2767: val = Py_BuildValue("ii", textwidth(self, text), self->ysize); call 0 returned 100% 1077: 2768: free(text); 1077: 2769: return val; -: 2770:} -: 2771: -: 2772:static struct PyMethodDef _font_methods[] = { -: 2773: {"getmask", (PyCFunction)_font_getmask, 1}, -: 2774: {"getsize", (PyCFunction)_font_getsize, 1}, -: 2775: {NULL, NULL} /* sentinel */ -: 2776:}; -: 2777: -: 2778:/* -------------------------------------------------------------------- */ -: 2779: -: 2780:static PyObject* function _draw_new called 400 returned 100% blocks executed 100% 400: 2781:_draw_new(PyObject* self_, PyObject* args) -: 2782:{ -: 2783: ImagingDrawObject *self; -: 2784: -: 2785: ImagingObject* imagep; 400: 2786: int blend = 0; 400: 2787: if (!PyArg_ParseTuple(args, "O!|i", &Imaging_Type, &imagep, &blend)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2788: return NULL; -: 2789: } -: 2790: 400: 2791: self = PyObject_New(ImagingDrawObject, &ImagingDraw_Type); call 0 returned 100% 400: 2792: if (self == NULL) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2793: return NULL; -: 2794: } -: 2795: -: 2796: /* keep a reference to the image object */ 400: 2797: Py_INCREF(imagep); 400: 2798: self->image = imagep; -: 2799: 400: 2800: self->ink[0] = self->ink[1] = self->ink[2] = self->ink[3] = 0; -: 2801: 400: 2802: self->blend = blend; -: 2803: 400: 2804: return (PyObject*) self; -: 2805:} -: 2806: -: 2807:static void function _draw_dealloc called 400 returned 100% blocks executed 100% 400: 2808:_draw_dealloc(ImagingDrawObject* self) -: 2809:{ 400: 2810: Py_XDECREF(self->image); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 90% (fallthrough) branch 3 taken 10% call 4 returned 100% 400: 2811: PyObject_Del(self); call 0 returned 100% 400: 2812:} -: 2813: -: 2814:extern Py_ssize_t PyPath_Flatten(PyObject* data, double **xy); -: 2815: -: 2816:static PyObject* function _draw_ink called 3290 returned 100% blocks executed 100% 3290: 2817:_draw_ink(ImagingDrawObject* self, PyObject* args) -: 2818:{ 3290: 2819: INT32 ink = 0; -: 2820: PyObject* color; 3290: 2821: if (!PyArg_ParseTuple(args, "O", &color)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2822: return NULL; -: 2823: } -: 2824: 3290: 2825: if (!getink(color, self->image->image, (char*) &ink)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2826: return NULL; -: 2827: } -: 2828: 3290: 2829: return PyLong_FromLong((int) ink); call 0 returned 100% -: 2830:} -: 2831: -: 2832:static PyObject* function _draw_arc called 12 returned 100% blocks executed 82% 12: 2833:_draw_arc(ImagingDrawObject* self, PyObject* args) -: 2834:{ -: 2835: double* xy; -: 2836: Py_ssize_t n; -: 2837: -: 2838: PyObject* data; -: 2839: int ink; 12: 2840: int width = 0; -: 2841: float start, end; 12: 2842: if (!PyArg_ParseTuple(args, "Offi|i", &data, &start, &end, &ink, &width)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2843: return NULL; -: 2844: } -: 2845: 12: 2846: n = PyPath_Flatten(data, &xy); call 0 returned 100% 12: 2847: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2848: return NULL; -: 2849: } 12: 2850: if (n != 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 2851: PyErr_SetString(PyExc_TypeError, must_be_two_coordinates); call 0 never executed #####: 2852: free(xy); #####: 2853: return NULL; -: 2854: } -: 2855: 60: 2856: n = ImagingDrawArc(self->image->image, call 0 returned 100% 24: 2857: (int) xy[0], (int) xy[1], 24: 2858: (int) xy[2], (int) xy[3], -: 2859: start, end, &ink, width, self->blend -: 2860: ); -: 2861: 12: 2862: free(xy); -: 2863: 12: 2864: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2865: return NULL; -: 2866: } -: 2867: 12: 2868: Py_INCREF(Py_None); 12: 2869: return Py_None; -: 2870:} -: 2871: -: 2872:static PyObject* function _draw_bitmap called 350 returned 100% blocks executed 82% 350: 2873:_draw_bitmap(ImagingDrawObject* self, PyObject* args) -: 2874:{ -: 2875: double *xy; -: 2876: Py_ssize_t n; -: 2877: -: 2878: PyObject *data; -: 2879: ImagingObject* bitmap; -: 2880: int ink; 350: 2881: if (!PyArg_ParseTuple(args, "OO!i", &data, &Imaging_Type, &bitmap, &ink)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2882: return NULL; -: 2883: } -: 2884: 350: 2885: n = PyPath_Flatten(data, &xy); call 0 returned 100% 350: 2886: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2887: return NULL; -: 2888: } 350: 2889: if (n != 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 2890: PyErr_SetString(PyExc_TypeError, call 0 never executed -: 2891: "coordinate list must contain exactly 1 coordinate" -: 2892: ); #####: 2893: free(xy); #####: 2894: return NULL; -: 2895: } -: 2896: 1400: 2897: n = ImagingDrawBitmap( call 0 returned 100% 1400: 2898: self->image->image, (int) xy[0], (int) xy[1], bitmap->image, -: 2899: &ink, self->blend -: 2900: ); -: 2901: 350: 2902: free(xy); -: 2903: 350: 2904: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2905: return NULL; -: 2906: } -: 2907: 350: 2908: Py_INCREF(Py_None); 350: 2909: return Py_None; -: 2910:} -: 2911: -: 2912:static PyObject* function _draw_chord called 20 returned 100% blocks executed 82% 20: 2913:_draw_chord(ImagingDrawObject* self, PyObject* args) -: 2914:{ -: 2915: double* xy; -: 2916: Py_ssize_t n; -: 2917: -: 2918: PyObject* data; -: 2919: int ink, fill; 20: 2920: int width = 0; -: 2921: float start, end; 20: 2922: if (!PyArg_ParseTuple(args, "Offii|i", call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2923: &data, &start, &end, &ink, &fill, &width)) { -: 2924: return NULL; -: 2925: } -: 2926: 20: 2927: n = PyPath_Flatten(data, &xy); call 0 returned 100% 20: 2928: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2929: return NULL; -: 2930: } 20: 2931: if (n != 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 2932: PyErr_SetString(PyExc_TypeError, must_be_two_coordinates); call 0 never executed #####: 2933: free(xy); #####: 2934: return NULL; -: 2935: } -: 2936: 100: 2937: n = ImagingDrawChord(self->image->image, call 0 returned 100% 40: 2938: (int) xy[0], (int) xy[1], 40: 2939: (int) xy[2], (int) xy[3], -: 2940: start, end, &ink, fill, width, self->blend -: 2941: ); -: 2942: 20: 2943: free(xy); -: 2944: 20: 2945: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2946: return NULL; -: 2947: } -: 2948: 20: 2949: Py_INCREF(Py_None); 20: 2950: return Py_None; -: 2951:} -: 2952: -: 2953:static PyObject* function _draw_ellipse called 2091 returned 100% blocks executed 82% 2091: 2954:_draw_ellipse(ImagingDrawObject* self, PyObject* args) -: 2955:{ -: 2956: double* xy; -: 2957: Py_ssize_t n; -: 2958: -: 2959: PyObject* data; -: 2960: int ink; 2091: 2961: int fill = 0; 2091: 2962: int width = 0; 2091: 2963: if (!PyArg_ParseTuple(args, "Oi|ii", &data, &ink, &fill, &width)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 2964: return NULL; -: 2965: } -: 2966: 2091: 2967: n = PyPath_Flatten(data, &xy); call 0 returned 100% 2091: 2968: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2969: return NULL; -: 2970: } 2091: 2971: if (n != 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 2972: PyErr_SetString(PyExc_TypeError, must_be_two_coordinates); call 0 never executed #####: 2973: free(xy); #####: 2974: return NULL; -: 2975: } -: 2976: 10455: 2977: n = ImagingDrawEllipse(self->image->image, call 0 returned 100% 4182: 2978: (int) xy[0], (int) xy[1], 4182: 2979: (int) xy[2], (int) xy[3], -: 2980: &ink, fill, width, self->blend -: 2981: ); -: 2982: 2091: 2983: free(xy); -: 2984: 2091: 2985: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 2986: return NULL; -: 2987: } -: 2988: 2091: 2989: Py_INCREF(Py_None); 2091: 2990: return Py_None; -: 2991:} -: 2992: -: 2993:static PyObject* function _draw_lines called 221 returned 100% blocks executed 90% 221: 2994:_draw_lines(ImagingDrawObject* self, PyObject* args) -: 2995:{ -: 2996: double *xy; -: 2997: Py_ssize_t i, n; -: 2998: -: 2999: PyObject *data; -: 3000: int ink; 221: 3001: int width = 0; 221: 3002: if (!PyArg_ParseTuple(args, "Oi|i", &data, &ink, &width)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3003: return NULL; -: 3004: } -: 3005: 221: 3006: n = PyPath_Flatten(data, &xy); call 0 returned 100% 221: 3007: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3008: return NULL; -: 3009: } -: 3010: 221: 3011: if (width <= 1) { branch 0 taken 27% (fallthrough) branch 1 taken 73% -: 3012: double *p = NULL; 163: 3013: for (i = 0; i < n-1; i++) { branch 0 taken 50% branch 1 taken 50% (fallthrough) 163: 3014: p = &xy[i+i]; 815: 3015: if (ImagingDrawLine( call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% 163: 3016: self->image->image, 652: 3017: (int) p[0], (int) p[1], (int) p[2], (int) p[3], -: 3018: &ink, self->blend) < 0) { #####: 3019: free(xy); #####: 3020: return NULL; -: 3021: } -: 3022: } 161: 3023: if (p) {/* draw last point */ branch 0 taken 99% (fallthrough) branch 1 taken 1% 480: 3024: ImagingDrawPoint( call 0 returned 100% 160: 3025: self->image->image, 320: 3026: (int) p[2], (int) p[3], -: 3027: &ink, self->blend -: 3028: ); -: 3029: } -: 3030: } else { 140: 3031: for (i = 0; i < n-1; i++) { branch 0 taken 70% branch 1 taken 30% (fallthrough) 140: 3032: double *p = &xy[i+i]; 700: 3033: if (ImagingDrawWideLine( call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% 140: 3034: self->image->image, 560: 3035: (int) p[0], (int) p[1], (int) p[2], (int) p[3], -: 3036: &ink, width, self->blend) < 0) { #####: 3037: free(xy); #####: 3038: return NULL; -: 3039: } -: 3040: } -: 3041: } -: 3042: 221: 3043: free(xy); -: 3044: 221: 3045: Py_INCREF(Py_None); 221: 3046: return Py_None; -: 3047:} -: 3048: -: 3049:static PyObject* function _draw_points called 2 returned 100% blocks executed 92% 2: 3050:_draw_points(ImagingDrawObject* self, PyObject* args) -: 3051:{ -: 3052: double *xy; -: 3053: Py_ssize_t i, n; -: 3054: -: 3055: PyObject *data; -: 3056: int ink; 2: 3057: if (!PyArg_ParseTuple(args, "Oi", &data, &ink)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3058: return NULL; -: 3059: } -: 3060: 2: 3061: n = PyPath_Flatten(data, &xy); call 0 returned 100% 2: 3062: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3063: return NULL; -: 3064: } -: 3065: 6: 3066: for (i = 0; i < n; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 6: 3067: double *p = &xy[i+i]; 6: 3068: if (ImagingDrawPoint(self->image->image, (int) p[0], (int) p[1], call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% -: 3069: &ink, self->blend) < 0) { #####: 3070: free(xy); #####: 3071: return NULL; -: 3072: } -: 3073: } -: 3074: 2: 3075: free(xy); -: 3076: 2: 3077: Py_INCREF(Py_None); 2: 3078: return Py_None; -: 3079:} -: 3080: -: 3081:#ifdef WITH_ARROW -: 3082: -: 3083:/* from outline.c */ -: 3084:extern ImagingOutline PyOutline_AsOutline(PyObject* outline); -: 3085: -: 3086:static PyObject* function _draw_outline called 8 returned 100% blocks executed 80% 8: 3087:_draw_outline(ImagingDrawObject* self, PyObject* args) -: 3088:{ -: 3089: ImagingOutline outline; -: 3090: -: 3091: PyObject* outline_; -: 3092: int ink; 8: 3093: int fill = 0; 8: 3094: if (!PyArg_ParseTuple(args, "Oi|i", &outline_, &ink, &fill)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3095: return NULL; -: 3096: } -: 3097: 8: 3098: outline = PyOutline_AsOutline(outline_); call 0 returned 100% 8: 3099: if (!outline) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 3100: PyErr_SetString(PyExc_TypeError, "expected outline object"); call 0 never executed #####: 3101: return NULL; -: 3102: } -: 3103: 8: 3104: if (ImagingDrawOutline(self->image->image, outline, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3105: &ink, fill, self->blend) < 0) { -: 3106: return NULL; -: 3107: } -: 3108: 8: 3109: Py_INCREF(Py_None); 8: 3110: return Py_None; -: 3111:} -: 3112: -: 3113:#endif -: 3114: -: 3115:static PyObject* function _draw_pieslice called 53 returned 100% blocks executed 82% 53: 3116:_draw_pieslice(ImagingDrawObject* self, PyObject* args) -: 3117:{ -: 3118: double* xy; -: 3119: Py_ssize_t n; -: 3120: -: 3121: PyObject* data; -: 3122: int ink, fill; 53: 3123: int width = 0; -: 3124: float start, end; 53: 3125: if (!PyArg_ParseTuple(args, "Offii|i", &data, &start, &end, &ink, &fill, &width)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3126: return NULL; -: 3127: } -: 3128: 53: 3129: n = PyPath_Flatten(data, &xy); call 0 returned 100% 53: 3130: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3131: return NULL; -: 3132: } 53: 3133: if (n != 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 3134: PyErr_SetString(PyExc_TypeError, must_be_two_coordinates); call 0 never executed #####: 3135: free(xy); #####: 3136: return NULL; -: 3137: } -: 3138: 265: 3139: n = ImagingDrawPieslice(self->image->image, call 0 returned 100% 106: 3140: (int) xy[0], (int) xy[1], 106: 3141: (int) xy[2], (int) xy[3], -: 3142: start, end, &ink, fill, width, self->blend -: 3143: ); -: 3144: 53: 3145: free(xy); -: 3146: 53: 3147: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3148: return NULL; -: 3149: } -: 3150: 53: 3151: Py_INCREF(Py_None); 53: 3152: return Py_None; -: 3153:} -: 3154: -: 3155:static PyObject* function _draw_polygon called 26 returned 100% blocks executed 80% 26: 3156:_draw_polygon(ImagingDrawObject* self, PyObject* args) -: 3157:{ -: 3158: double *xy; -: 3159: int *ixy; -: 3160: Py_ssize_t n, i; -: 3161: -: 3162: PyObject* data; -: 3163: int ink; 26: 3164: int fill = 0; 26: 3165: if (!PyArg_ParseTuple(args, "Oi|i", &data, &ink, &fill)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3166: return NULL; -: 3167: } -: 3168: 26: 3169: n = PyPath_Flatten(data, &xy); call 0 returned 100% 26: 3170: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3171: return NULL; -: 3172: } 26: 3173: if (n < 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 3174: PyErr_SetString(PyExc_TypeError, call 0 never executed -: 3175: "coordinate list must contain at least 2 coordinates" -: 3176: ); #####: 3177: free(xy); #####: 3178: return NULL; -: 3179: } -: 3180: -: 3181: /* Copy list of vertices to array */ 26: 3182: ixy = (int*) calloc(n, 2 * sizeof(int)); -: 3183: 169: 3184: for (i = 0; i < n; i++) { branch 0 taken 85% branch 1 taken 15% (fallthrough) 143: 3185: ixy[i+i] = (int) xy[i+i]; 143: 3186: ixy[i+i+1] = (int) xy[i+i+1]; -: 3187: } -: 3188: 26: 3189: free(xy); -: 3190: 26: 3191: if (ImagingDrawPolygon(self->image->image, n, ixy, call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% -: 3192: &ink, fill, self->blend) < 0) { #####: 3193: free(ixy); #####: 3194: return NULL; -: 3195: } -: 3196: 26: 3197: free(ixy); -: 3198: 26: 3199: Py_INCREF(Py_None); 26: 3200: return Py_None; -: 3201:} -: 3202: -: 3203:static PyObject* function _draw_rectangle called 147 returned 100% blocks executed 82% 147: 3204:_draw_rectangle(ImagingDrawObject* self, PyObject* args) -: 3205:{ -: 3206: double* xy; -: 3207: Py_ssize_t n; -: 3208: -: 3209: PyObject* data; -: 3210: int ink; 147: 3211: int fill = 0; 147: 3212: int width = 0; 147: 3213: if (!PyArg_ParseTuple(args, "Oi|ii", &data, &ink, &fill, &width)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3214: return NULL; -: 3215: } -: 3216: 147: 3217: n = PyPath_Flatten(data, &xy); call 0 returned 100% 147: 3218: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3219: return NULL; -: 3220: } 147: 3221: if (n != 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 3222: PyErr_SetString(PyExc_TypeError, must_be_two_coordinates); call 0 never executed #####: 3223: free(xy); #####: 3224: return NULL; -: 3225: } -: 3226: 735: 3227: n = ImagingDrawRectangle(self->image->image, call 0 returned 100% 294: 3228: (int) xy[0], (int) xy[1], 294: 3229: (int) xy[2], (int) xy[3], -: 3230: &ink, fill, width, self->blend -: 3231: ); -: 3232: 147: 3233: free(xy); -: 3234: 147: 3235: if (n < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3236: return NULL; -: 3237: } -: 3238: 147: 3239: Py_INCREF(Py_None); 147: 3240: return Py_None; -: 3241:} -: 3242: -: 3243:static struct PyMethodDef _draw_methods[] = { -: 3244:#ifdef WITH_IMAGEDRAW -: 3245: /* Graphics (ImageDraw) */ -: 3246: {"draw_lines", (PyCFunction)_draw_lines, 1}, -: 3247:#ifdef WITH_ARROW -: 3248: {"draw_outline", (PyCFunction)_draw_outline, 1}, -: 3249:#endif -: 3250: {"draw_polygon", (PyCFunction)_draw_polygon, 1}, -: 3251: {"draw_rectangle", (PyCFunction)_draw_rectangle, 1}, -: 3252: {"draw_points", (PyCFunction)_draw_points, 1}, -: 3253: {"draw_arc", (PyCFunction)_draw_arc, 1}, -: 3254: {"draw_bitmap", (PyCFunction)_draw_bitmap, 1}, -: 3255: {"draw_chord", (PyCFunction)_draw_chord, 1}, -: 3256: {"draw_ellipse", (PyCFunction)_draw_ellipse, 1}, -: 3257: {"draw_pieslice", (PyCFunction)_draw_pieslice, 1}, -: 3258: {"draw_ink", (PyCFunction)_draw_ink, 1}, -: 3259:#endif -: 3260: {NULL, NULL} /* sentinel */ -: 3261:}; -: 3262: -: 3263:#endif -: 3264: -: 3265: -: 3266:static PyObject* function pixel_access_new called 232282 returned 100% blocks executed 100% 232282: 3267:pixel_access_new(ImagingObject* imagep, PyObject* args) -: 3268:{ -: 3269: PixelAccessObject *self; -: 3270: 232282: 3271: int readonly = 0; 232282: 3272: if (!PyArg_ParseTuple(args, "|i", &readonly)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3273: return NULL; -: 3274: } -: 3275: 232282: 3276: self = PyObject_New(PixelAccessObject, &PixelAccess_Type); call 0 returned 100% 232282: 3277: if (self == NULL) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3278: return NULL; -: 3279: } -: 3280: -: 3281: /* keep a reference to the image object */ 232282: 3282: Py_INCREF(imagep); 232282: 3283: self->image = imagep; -: 3284: 232282: 3285: self->readonly = readonly; -: 3286: 232282: 3287: return (PyObject*) self; -: 3288:} -: 3289: -: 3290:static void function pixel_access_dealloc called 232282 returned 100% blocks executed 100% 232282: 3291:pixel_access_dealloc(PixelAccessObject* self) -: 3292:{ 232282: 3293: Py_XDECREF(self->image); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 1% (fallthrough) branch 3 taken 99% call 4 returned 100% 232282: 3294: PyObject_Del(self); call 0 returned 100% 232282: 3295:} -: 3296: -: 3297:static PyObject * function pixel_access_getitem called 219391 returned 100% blocks executed 100% 219391: 3298:pixel_access_getitem(PixelAccessObject *self, PyObject *xy) -: 3299:{ -: 3300: int x, y; 219391: 3301: if (_getxy(xy, &x, &y)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3302: return NULL; -: 3303: } -: 3304: 219391: 3305: return getpixel(self->image->image, self->image->access, x, y); call 0 returned 100% -: 3306:} -: 3307: -: 3308:static int function pixel_access_setitem called 266269 returned 100% blocks executed 81% 266269: 3309:pixel_access_setitem(PixelAccessObject *self, PyObject *xy, PyObject *color) -: 3310:{ 266269: 3311: Imaging im = self->image->image; -: 3312: char ink[4]; -: 3313: int x, y; -: 3314: 266269: 3315: if (self->readonly) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 3316: (void) ImagingError_ValueError(readonly); call 0 never executed #####: 3317: return -1; -: 3318: } -: 3319: 266269: 3320: if (_getxy(xy, &x, &y)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3321: return -1; -: 3322: } -: 3323: 266269: 3324: if (x < 0) { branch 0 taken 6% (fallthrough) branch 1 taken 94% 16384: 3325: x = im->xsize + x; -: 3326: } 266269: 3327: if (y < 0) { branch 0 taken 6% (fallthrough) branch 1 taken 94% 16384: 3328: y = im->ysize + y; -: 3329: } -: 3330: 266269: 3331: if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 0% (fallthrough) branch 7 taken 100% #####: 3332: PyErr_SetString(PyExc_IndexError, outside_image); call 0 never executed #####: 3333: return -1; -: 3334: } -: 3335: 266269: 3336: if (!color) {/* FIXME: raise exception? */ branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3337: return 0; -: 3338: } -: 3339: 266269: 3340: if (!getink(color, im, ink)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3341: return -1; -: 3342: } -: 3343: 266269: 3344: self->image->access->put_pixel(im, x, y, ink); call 0 returned 100% -: 3345: 266269: 3346: return 0; -: 3347:} -: 3348: -: 3349:/* -------------------------------------------------------------------- */ -: 3350:/* EFFECTS (experimental) */ -: 3351:/* -------------------------------------------------------------------- */ -: 3352: -: 3353:#ifdef WITH_EFFECTS -: 3354: -: 3355:static PyObject* function _effect_mandelbrot called 2 returned 100% blocks executed 100% 2: 3356:_effect_mandelbrot(ImagingObject* self, PyObject* args) -: 3357:{ 2: 3358: int xsize = 512; 2: 3359: int ysize = 512; -: 3360: double extent[4]; 2: 3361: int quality = 100; -: 3362: 2: 3363: extent[0] = -3; extent[1] = -2.5; 2: 3364: extent[2] = 2; extent[3] = 2.5; -: 3365: 2: 3366: if (!PyArg_ParseTuple(args, "|(ii)(dddd)i", &xsize, &ysize, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3367: &extent[0], &extent[1], &extent[2], &extent[3], -: 3368: &quality)) { -: 3369: return NULL; -: 3370: } -: 3371: 2: 3372: return PyImagingNew(ImagingEffectMandelbrot(xsize, ysize, extent, quality)); call 0 returned 100% call 1 returned 100% -: 3373:} -: 3374: -: 3375:static PyObject* function _effect_noise called 1 returned 100% blocks executed 100% 1: 3376:_effect_noise(ImagingObject* self, PyObject* args) -: 3377:{ -: 3378: int xsize, ysize; 1: 3379: float sigma = 128; 1: 3380: if (!PyArg_ParseTuple(args, "(ii)|f", &xsize, &ysize, &sigma)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3381: return NULL; -: 3382: } -: 3383: 1: 3384: return PyImagingNew(ImagingEffectNoise(xsize, ysize, sigma)); call 0 returned 100% call 1 returned 100% -: 3385:} -: 3386: -: 3387:static PyObject* function _effect_spread called 2 returned 100% blocks executed 100% 2: 3388:_effect_spread(ImagingObject* self, PyObject* args) -: 3389:{ -: 3390: int dist; -: 3391: 2: 3392: if (!PyArg_ParseTuple(args, "i", &dist)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3393: return NULL; -: 3394: } -: 3395: 2: 3396: return PyImagingNew(ImagingEffectSpread(self->image, dist)); call 0 returned 100% call 1 returned 100% -: 3397:} -: 3398: -: 3399:#endif -: 3400: -: 3401:/* -------------------------------------------------------------------- */ -: 3402:/* UTILITIES */ -: 3403:/* -------------------------------------------------------------------- */ -: 3404: -: 3405: -: 3406:static PyObject* function _getcodecstatus called 15 returned 100% blocks executed 80% 15: 3407:_getcodecstatus(PyObject* self, PyObject* args) -: 3408:{ -: 3409: int status; -: 3410: char* msg; -: 3411: 15: 3412: if (!PyArg_ParseTuple(args, "i", &status)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3413: return NULL; -: 3414: } -: 3415: 15: 3416: switch (status) { branch 0 taken 0% branch 1 taken 13% branch 2 taken 7% branch 3 taken 0% branch 4 taken 13% branch 5 taken 67% -: 3417: case IMAGING_CODEC_OVERRUN: -: 3418: msg = "buffer overrun"; break; -: 3419: case IMAGING_CODEC_BROKEN: #####: 3420: msg = "broken data stream"; break; -: 3421: case IMAGING_CODEC_UNKNOWN: 2: 3422: msg = "unrecognized data stream contents"; break; -: 3423: case IMAGING_CODEC_CONFIG: 1: 3424: msg = "codec configuration error"; break; -: 3425: case IMAGING_CODEC_MEMORY: #####: 3426: msg = "out of memory"; break; -: 3427: default: 2: 3428: Py_RETURN_NONE; -: 3429: } -: 3430: 13: 3431: return PyUnicode_FromString(msg); call 0 returned 100% -: 3432:} -: 3433: -: 3434:/* -------------------------------------------------------------------- */ -: 3435:/* DEBUGGING HELPERS */ -: 3436:/* -------------------------------------------------------------------- */ -: 3437: -: 3438: -: 3439:static PyObject* function _save_ppm called 21 returned 100% blocks executed 100% 21: 3440:_save_ppm(ImagingObject* self, PyObject* args) -: 3441:{ -: 3442: char* filename; -: 3443: 21: 3444: if (!PyArg_ParseTuple(args, "s", &filename)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3445: return NULL; -: 3446: } -: 3447: 21: 3448: if (!ImagingSavePPM(self->image, filename)) { call 0 returned 100% branch 1 taken 95% (fallthrough) branch 2 taken 5% -: 3449: return NULL; -: 3450: } -: 3451: 20: 3452: Py_INCREF(Py_None); 20: 3453: return Py_None; -: 3454:} -: 3455: -: 3456: -: 3457:/* -------------------------------------------------------------------- */ -: 3458: -: 3459:/* methods */ -: 3460: -: 3461:static struct PyMethodDef methods[] = { -: 3462: -: 3463: /* Put commonly used methods first */ -: 3464: {"getpixel", (PyCFunction)_getpixel, 1}, -: 3465: {"putpixel", (PyCFunction)_putpixel, 1}, -: 3466: -: 3467: {"pixel_access", (PyCFunction)pixel_access_new, 1}, -: 3468: -: 3469: /* Standard processing methods (Image) */ -: 3470: {"color_lut_3d", (PyCFunction)_color_lut_3d, 1}, -: 3471: {"convert", (PyCFunction)_convert, 1}, -: 3472: {"convert2", (PyCFunction)_convert2, 1}, -: 3473: {"convert_matrix", (PyCFunction)_convert_matrix, 1}, -: 3474: {"convert_transparent", (PyCFunction)_convert_transparent, 1}, -: 3475: {"copy", (PyCFunction)_copy, 1}, -: 3476: {"crop", (PyCFunction)_crop, 1}, -: 3477: {"expand", (PyCFunction)_expand_image, 1}, -: 3478: {"filter", (PyCFunction)_filter, 1}, -: 3479: {"histogram", (PyCFunction)_histogram, 1}, -: 3480: {"entropy", (PyCFunction)_entropy, 1}, -: 3481:#ifdef WITH_MODEFILTER -: 3482: {"modefilter", (PyCFunction)_modefilter, 1}, -: 3483:#endif -: 3484: {"offset", (PyCFunction)_offset, 1}, -: 3485: {"paste", (PyCFunction)_paste, 1}, -: 3486: {"point", (PyCFunction)_point, 1}, -: 3487: {"point_transform", (PyCFunction)_point_transform, 1}, -: 3488: {"putdata", (PyCFunction)_putdata, 1}, -: 3489:#ifdef WITH_QUANTIZE -: 3490: {"quantize", (PyCFunction)_quantize, 1}, -: 3491:#endif -: 3492:#ifdef WITH_RANKFILTER -: 3493: {"rankfilter", (PyCFunction)_rankfilter, 1}, -: 3494:#endif -: 3495: {"resize", (PyCFunction)_resize, 1}, -: 3496: {"reduce", (PyCFunction)_reduce, 1}, -: 3497: {"transpose", (PyCFunction)_transpose, 1}, -: 3498: {"transform2", (PyCFunction)_transform2, 1}, -: 3499: -: 3500: {"isblock", (PyCFunction)_isblock, 1}, -: 3501: -: 3502: {"getbbox", (PyCFunction)_getbbox, 1}, -: 3503: {"getcolors", (PyCFunction)_getcolors, 1}, -: 3504: {"getextrema", (PyCFunction)_getextrema, 1}, -: 3505: {"getprojection", (PyCFunction)_getprojection, 1}, -: 3506: -: 3507: {"getband", (PyCFunction)_getband, 1}, -: 3508: {"putband", (PyCFunction)_putband, 1}, -: 3509: {"split", (PyCFunction)_split, 1}, -: 3510: {"fillband", (PyCFunction)_fillband, 1}, -: 3511: -: 3512: {"setmode", (PyCFunction)im_setmode, 1}, -: 3513: -: 3514: {"getpalette", (PyCFunction)_getpalette, 1}, -: 3515: {"getpalettemode", (PyCFunction)_getpalettemode, 1}, -: 3516: {"putpalette", (PyCFunction)_putpalette, 1}, -: 3517: {"putpalettealpha", (PyCFunction)_putpalettealpha, 1}, -: 3518: {"putpalettealphas", (PyCFunction)_putpalettealphas, 1}, -: 3519: -: 3520:#ifdef WITH_IMAGECHOPS -: 3521: /* Channel operations (ImageChops) */ -: 3522: {"chop_invert", (PyCFunction)_chop_invert, 1}, -: 3523: {"chop_lighter", (PyCFunction)_chop_lighter, 1}, -: 3524: {"chop_darker", (PyCFunction)_chop_darker, 1}, -: 3525: {"chop_difference", (PyCFunction)_chop_difference, 1}, -: 3526: {"chop_multiply", (PyCFunction)_chop_multiply, 1}, -: 3527: {"chop_screen", (PyCFunction)_chop_screen, 1}, -: 3528: {"chop_add", (PyCFunction)_chop_add, 1}, -: 3529: {"chop_subtract", (PyCFunction)_chop_subtract, 1}, -: 3530: {"chop_add_modulo", (PyCFunction)_chop_add_modulo, 1}, -: 3531: {"chop_subtract_modulo", (PyCFunction)_chop_subtract_modulo, 1}, -: 3532: {"chop_and", (PyCFunction)_chop_and, 1}, -: 3533: {"chop_or", (PyCFunction)_chop_or, 1}, -: 3534: {"chop_xor", (PyCFunction)_chop_xor, 1}, -: 3535: {"chop_soft_light", (PyCFunction)_chop_soft_light, 1}, -: 3536: {"chop_hard_light", (PyCFunction)_chop_hard_light, 1}, -: 3537: {"chop_overlay", (PyCFunction)_chop_overlay, 1}, -: 3538: -: 3539:#endif -: 3540: -: 3541:#ifdef WITH_UNSHARPMASK -: 3542: /* Kevin Cazabon's unsharpmask extension */ -: 3543: {"gaussian_blur", (PyCFunction)_gaussian_blur, 1}, -: 3544: {"unsharp_mask", (PyCFunction)_unsharp_mask, 1}, -: 3545:#endif -: 3546: -: 3547: {"box_blur", (PyCFunction)_box_blur, 1}, -: 3548: -: 3549:#ifdef WITH_EFFECTS -: 3550: /* Special effects */ -: 3551: {"effect_spread", (PyCFunction)_effect_spread, 1}, -: 3552:#endif -: 3553: -: 3554: /* Misc. */ -: 3555: {"new_block", (PyCFunction)_new_block, 1}, -: 3556: -: 3557: {"save_ppm", (PyCFunction)_save_ppm, 1}, -: 3558: -: 3559: {NULL, NULL} /* sentinel */ -: 3560:}; -: 3561: -: 3562: -: 3563:/* attributes */ -: 3564: -: 3565:static PyObject* function _getattr_mode called 197101 returned 100% blocks executed 100% 197101: 3566:_getattr_mode(ImagingObject* self, void* closure) -: 3567:{ 197101: 3568: return PyUnicode_FromString(self->image->mode); call 0 returned 100% -: 3569:} -: 3570: -: 3571:static PyObject* function _getattr_size called 49421 returned 100% blocks executed 100% 49421: 3572:_getattr_size(ImagingObject* self, void* closure) -: 3573:{ 49421: 3574: return Py_BuildValue("ii", self->image->xsize, self->image->ysize); call 0 returned 100% -: 3575:} -: 3576: -: 3577:static PyObject* function _getattr_bands called 1706 returned 100% blocks executed 100% 1706: 3578:_getattr_bands(ImagingObject* self, void* closure) -: 3579:{ 1706: 3580: return PyLong_FromLong(self->image->bands); call 0 returned 100% -: 3581:} -: 3582: -: 3583:static PyObject* function _getattr_id called 9130 returned 100% blocks executed 100% 9130: 3584:_getattr_id(ImagingObject* self, void* closure) -: 3585:{ 9130: 3586: return PyLong_FromSsize_t((Py_ssize_t) self->image); call 0 returned 100% -: 3587:} -: 3588: -: 3589:static PyObject* function _getattr_ptr called 1 returned 100% blocks executed 100% 1: 3590:_getattr_ptr(ImagingObject* self, void* closure) -: 3591:{ 1: 3592: return PyCapsule_New(self->image, IMAGING_MAGIC, NULL); call 0 returned 100% -: 3593:} -: 3594: -: 3595:static PyObject* function _getattr_unsafe_ptrs called 118 returned 100% blocks executed 100% 118: 3596:_getattr_unsafe_ptrs(ImagingObject* self, void* closure) -: 3597:{ 118: 3598: return Py_BuildValue("(sn)(sn)(sn)", call 0 returned 100% 118: 3599: "image8", self->image->image8, -: 3600: "image32", self->image->image32, -: 3601: "image", self->image->image -: 3602: ); -: 3603:}; -: 3604: -: 3605: -: 3606:static struct PyGetSetDef getsetters[] = { -: 3607: { "mode", (getter) _getattr_mode }, -: 3608: { "size", (getter) _getattr_size }, -: 3609: { "bands", (getter) _getattr_bands }, -: 3610: { "id", (getter) _getattr_id }, -: 3611: { "ptr", (getter) _getattr_ptr }, -: 3612: { "unsafe_ptrs", (getter) _getattr_unsafe_ptrs }, -: 3613: { NULL } -: 3614:}; -: 3615: -: 3616:/* basic sequence semantics */ -: 3617: -: 3618:static Py_ssize_t function image_length called 730833 returned 100% blocks executed 100% 730833: 3619:image_length(ImagingObject *self) -: 3620:{ 730833: 3621: Imaging im = self->image; -: 3622: 730833: 3623: return (Py_ssize_t) im->xsize * im->ysize; -: 3624:} -: 3625: -: 3626:static PyObject * function image_item called 4304159 returned 100% blocks executed 100% 4304159: 3627:image_item(ImagingObject *self, Py_ssize_t i) -: 3628:{ -: 3629: int x, y; 4304159: 3630: Imaging im = self->image; -: 3631: 4304159: 3632: if (im->xsize > 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 4304158: 3633: x = i % im->xsize; 4304158: 3634: y = i / im->xsize; -: 3635: } else { -: 3636: x = y = 0; /* leave it to getpixel to raise an exception */ -: 3637: } -: 3638: 4304159: 3639: return getpixel(im, self->access, x, y); call 0 returned 100% -: 3640:} -: 3641: -: 3642:static PySequenceMethods image_as_sequence = { -: 3643: (lenfunc) image_length, /*sq_length*/ -: 3644: (binaryfunc) NULL, /*sq_concat*/ -: 3645: (ssizeargfunc) NULL, /*sq_repeat*/ -: 3646: (ssizeargfunc) image_item, /*sq_item*/ -: 3647: (ssizessizeargfunc) NULL, /*sq_slice*/ -: 3648: (ssizeobjargproc) NULL, /*sq_ass_item*/ -: 3649: (ssizessizeobjargproc) NULL, /*sq_ass_slice*/ -: 3650:}; -: 3651: -: 3652: -: 3653:/* type description */ -: 3654: -: 3655:static PyTypeObject Imaging_Type = { -: 3656: PyVarObject_HEAD_INIT(NULL, 0) -: 3657: "ImagingCore", /*tp_name*/ -: 3658: sizeof(ImagingObject), /*tp_size*/ -: 3659: 0, /*tp_itemsize*/ -: 3660: /* methods */ -: 3661: (destructor)_dealloc, /*tp_dealloc*/ -: 3662: 0, /*tp_print*/ -: 3663: 0, /*tp_getattr*/ -: 3664: 0, /*tp_setattr*/ -: 3665: 0, /*tp_compare*/ -: 3666: 0, /*tp_repr*/ -: 3667: 0, /*tp_as_number */ -: 3668: &image_as_sequence, /*tp_as_sequence */ -: 3669: 0, /*tp_as_mapping */ -: 3670: 0, /*tp_hash*/ -: 3671: 0, /*tp_call*/ -: 3672: 0, /*tp_str*/ -: 3673: 0, /*tp_getattro*/ -: 3674: 0, /*tp_setattro*/ -: 3675: 0, /*tp_as_buffer*/ -: 3676: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 3677: 0, /*tp_doc*/ -: 3678: 0, /*tp_traverse*/ -: 3679: 0, /*tp_clear*/ -: 3680: 0, /*tp_richcompare*/ -: 3681: 0, /*tp_weaklistoffset*/ -: 3682: 0, /*tp_iter*/ -: 3683: 0, /*tp_iternext*/ -: 3684: methods, /*tp_methods*/ -: 3685: 0, /*tp_members*/ -: 3686: getsetters, /*tp_getset*/ -: 3687:}; -: 3688: -: 3689:#ifdef WITH_IMAGEDRAW -: 3690: -: 3691:static PyTypeObject ImagingFont_Type = { -: 3692: PyVarObject_HEAD_INIT(NULL, 0) -: 3693: "ImagingFont", /*tp_name*/ -: 3694: sizeof(ImagingFontObject), /*tp_size*/ -: 3695: 0, /*tp_itemsize*/ -: 3696: /* methods */ -: 3697: (destructor)_font_dealloc, /*tp_dealloc*/ -: 3698: 0, /*tp_print*/ -: 3699: 0, /*tp_getattr*/ -: 3700: 0, /*tp_setattr*/ -: 3701: 0, /*tp_compare*/ -: 3702: 0, /*tp_repr*/ -: 3703: 0, /*tp_as_number */ -: 3704: 0, /*tp_as_sequence */ -: 3705: 0, /*tp_as_mapping */ -: 3706: 0, /*tp_hash*/ -: 3707: 0, /*tp_call*/ -: 3708: 0, /*tp_str*/ -: 3709: 0, /*tp_getattro*/ -: 3710: 0, /*tp_setattro*/ -: 3711: 0, /*tp_as_buffer*/ -: 3712: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 3713: 0, /*tp_doc*/ -: 3714: 0, /*tp_traverse*/ -: 3715: 0, /*tp_clear*/ -: 3716: 0, /*tp_richcompare*/ -: 3717: 0, /*tp_weaklistoffset*/ -: 3718: 0, /*tp_iter*/ -: 3719: 0, /*tp_iternext*/ -: 3720: _font_methods, /*tp_methods*/ -: 3721: 0, /*tp_members*/ -: 3722: 0, /*tp_getset*/ -: 3723:}; -: 3724: -: 3725:static PyTypeObject ImagingDraw_Type = { -: 3726: PyVarObject_HEAD_INIT(NULL, 0) -: 3727: "ImagingDraw", /*tp_name*/ -: 3728: sizeof(ImagingDrawObject), /*tp_size*/ -: 3729: 0, /*tp_itemsize*/ -: 3730: /* methods */ -: 3731: (destructor)_draw_dealloc, /*tp_dealloc*/ -: 3732: 0, /*tp_print*/ -: 3733: 0, /*tp_getattr*/ -: 3734: 0, /*tp_setattr*/ -: 3735: 0, /*tp_compare*/ -: 3736: 0, /*tp_repr*/ -: 3737: 0, /*tp_as_number */ -: 3738: 0, /*tp_as_sequence */ -: 3739: 0, /*tp_as_mapping */ -: 3740: 0, /*tp_hash*/ -: 3741: 0, /*tp_call*/ -: 3742: 0, /*tp_str*/ -: 3743: 0, /*tp_getattro*/ -: 3744: 0, /*tp_setattro*/ -: 3745: 0, /*tp_as_buffer*/ -: 3746: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 3747: 0, /*tp_doc*/ -: 3748: 0, /*tp_traverse*/ -: 3749: 0, /*tp_clear*/ -: 3750: 0, /*tp_richcompare*/ -: 3751: 0, /*tp_weaklistoffset*/ -: 3752: 0, /*tp_iter*/ -: 3753: 0, /*tp_iternext*/ -: 3754: _draw_methods, /*tp_methods*/ -: 3755: 0, /*tp_members*/ -: 3756: 0, /*tp_getset*/ -: 3757:}; -: 3758: -: 3759:#endif -: 3760: -: 3761:static PyMappingMethods pixel_access_as_mapping = { -: 3762: (lenfunc) NULL, /*mp_length*/ -: 3763: (binaryfunc) pixel_access_getitem, /*mp_subscript*/ -: 3764: (objobjargproc) pixel_access_setitem, /*mp_ass_subscript*/ -: 3765:}; -: 3766: -: 3767:/* type description */ -: 3768: -: 3769:static PyTypeObject PixelAccess_Type = { -: 3770: PyVarObject_HEAD_INIT(NULL, 0) -: 3771: "PixelAccess", sizeof(PixelAccessObject), 0, -: 3772: /* methods */ -: 3773: (destructor)pixel_access_dealloc, /*tp_dealloc*/ -: 3774: 0, /*tp_print*/ -: 3775: 0, /*tp_getattr*/ -: 3776: 0, /*tp_setattr*/ -: 3777: 0, /*tp_compare*/ -: 3778: 0, /*tp_repr*/ -: 3779: 0, /*tp_as_number */ -: 3780: 0, /*tp_as_sequence */ -: 3781: &pixel_access_as_mapping, /*tp_as_mapping */ -: 3782: 0 /*tp_hash*/ -: 3783:}; -: 3784: -: 3785:/* -------------------------------------------------------------------- */ -: 3786: -: 3787:static PyObject* function _get_stats called 20 returned 100% blocks executed 100% 20: 3788:_get_stats(PyObject* self, PyObject* args) -: 3789:{ -: 3790: PyObject* d; 20: 3791: ImagingMemoryArena arena = &ImagingDefaultArena; -: 3792: 20: 3793: if (!PyArg_ParseTuple(args, ":get_stats")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3794: return NULL; -: 3795: } -: 3796: 20: 3797: d = PyDict_New(); call 0 returned 100% 20: 3798: if ( ! d) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 3799: return NULL; -: 3800: } 20: 3801: PyDict_SetItemString(d, "new_count", call 0 returned 100% call 1 returned 100% 20: 3802: PyLong_FromLong(arena->stats_new_count)); 20: 3803: PyDict_SetItemString(d, "allocated_blocks", call 0 returned 100% call 1 returned 100% 20: 3804: PyLong_FromLong(arena->stats_allocated_blocks)); 20: 3805: PyDict_SetItemString(d, "reused_blocks", call 0 returned 100% call 1 returned 100% 20: 3806: PyLong_FromLong(arena->stats_reused_blocks)); 20: 3807: PyDict_SetItemString(d, "reallocated_blocks", call 0 returned 100% call 1 returned 100% 20: 3808: PyLong_FromLong(arena->stats_reallocated_blocks)); 20: 3809: PyDict_SetItemString(d, "freed_blocks", call 0 returned 100% call 1 returned 100% 20: 3810: PyLong_FromLong(arena->stats_freed_blocks)); 20: 3811: PyDict_SetItemString(d, "blocks_cached", call 0 returned 100% call 1 returned 100% 20: 3812: PyLong_FromLong(arena->blocks_cached)); 20: 3813: return d; -: 3814:} -: 3815: -: 3816:static PyObject* function _reset_stats called 5 returned 100% blocks executed 100% 5: 3817:_reset_stats(PyObject* self, PyObject* args) -: 3818:{ 5: 3819: ImagingMemoryArena arena = &ImagingDefaultArena; -: 3820: 5: 3821: if (!PyArg_ParseTuple(args, ":reset_stats")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3822: return NULL; -: 3823: } -: 3824: 5: 3825: arena->stats_new_count = 0; 5: 3826: arena->stats_allocated_blocks = 0; 5: 3827: arena->stats_reused_blocks = 0; 5: 3828: arena->stats_reallocated_blocks = 0; 5: 3829: arena->stats_freed_blocks = 0; -: 3830: 5: 3831: Py_INCREF(Py_None); 5: 3832: return Py_None; -: 3833:} -: 3834: -: 3835:static PyObject* function _get_alignment called 7 returned 100% blocks executed 100% 7: 3836:_get_alignment(PyObject* self, PyObject* args) -: 3837:{ 7: 3838: if (!PyArg_ParseTuple(args, ":get_alignment")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3839: return NULL; -: 3840: } -: 3841: 7: 3842: return PyLong_FromLong(ImagingDefaultArena.alignment); call 0 returned 100% -: 3843:} -: 3844: -: 3845:static PyObject* function _get_block_size called 5 returned 100% blocks executed 100% 5: 3846:_get_block_size(PyObject* self, PyObject* args) -: 3847:{ 5: 3848: if (!PyArg_ParseTuple(args, ":get_block_size")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3849: return NULL; -: 3850: } -: 3851: 5: 3852: return PyLong_FromLong(ImagingDefaultArena.block_size); call 0 returned 100% -: 3853:} -: 3854: -: 3855:static PyObject* function _get_blocks_max called 5 returned 100% blocks executed 100% 5: 3856:_get_blocks_max(PyObject* self, PyObject* args) -: 3857:{ 5: 3858: if (!PyArg_ParseTuple(args, ":get_blocks_max")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3859: return NULL; -: 3860: } -: 3861: 5: 3862: return PyLong_FromLong(ImagingDefaultArena.blocks_max); call 0 returned 100% -: 3863:} -: 3864: -: 3865:static PyObject* function _set_alignment called 22 returned 100% blocks executed 100% 22: 3866:_set_alignment(PyObject* self, PyObject* args) -: 3867:{ -: 3868: int alignment; 22: 3869: if (!PyArg_ParseTuple(args, "i:set_alignment", &alignment)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3870: return NULL; -: 3871: } -: 3872: 22: 3873: if (alignment < 1 || alignment > 128) { branch 0 taken 9% (fallthrough) branch 1 taken 91% 2: 3874: PyErr_SetString(PyExc_ValueError, "alignment should be from 1 to 128"); call 0 returned 100% 2: 3875: return NULL; -: 3876: } -: 3877: /* Is power of two */ 20: 3878: if (alignment & (alignment - 1)) { branch 0 taken 10% (fallthrough) branch 1 taken 90% 2: 3879: PyErr_SetString(PyExc_ValueError, "alignment should be power of two"); call 0 returned 100% 2: 3880: return NULL; -: 3881: } -: 3882: 18: 3883: ImagingDefaultArena.alignment = alignment; -: 3884: 18: 3885: Py_INCREF(Py_None); 18: 3886: return Py_None; -: 3887:} -: 3888: -: 3889:static PyObject* function _set_block_size called 24 returned 100% blocks executed 100% 24: 3890:_set_block_size(PyObject* self, PyObject* args) -: 3891:{ -: 3892: int block_size; 24: 3893: if (!PyArg_ParseTuple(args, "i:set_block_size", &block_size)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3894: return NULL; -: 3895: } -: 3896: 24: 3897: if (block_size <= 0) { branch 0 taken 8% (fallthrough) branch 1 taken 92% 2: 3898: PyErr_SetString(PyExc_ValueError, call 0 returned 100% -: 3899: "block_size should be greater than 0"); 2: 3900: return NULL; -: 3901: } -: 3902: 22: 3903: if (block_size & 0xfff) { branch 0 taken 9% (fallthrough) branch 1 taken 91% 2: 3904: PyErr_SetString(PyExc_ValueError, call 0 returned 100% -: 3905: "block_size should be multiple of 4096"); 2: 3906: return NULL; -: 3907: } -: 3908: 20: 3909: ImagingDefaultArena.block_size = block_size; -: 3910: 20: 3911: Py_INCREF(Py_None); 20: 3912: return Py_None; -: 3913:} -: 3914: -: 3915:static PyObject* function _set_blocks_max called 21 returned 100% blocks executed 71% 21: 3916:_set_blocks_max(PyObject* self, PyObject* args) -: 3917:{ -: 3918: int blocks_max; 21: 3919: if (!PyArg_ParseTuple(args, "i:set_blocks_max", &blocks_max)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3920: return NULL; -: 3921: } -: 3922: 21: 3923: if (blocks_max < 0) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 1: 3924: PyErr_SetString(PyExc_ValueError, call 0 returned 100% -: 3925: "blocks_max should be greater than 0"); 1: 3926: return NULL; -: 3927: } 20: 3928: else if ( blocks_max > SIZE_MAX/sizeof(ImagingDefaultArena.blocks_pool[0])) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 3929: PyErr_SetString(PyExc_ValueError, call 0 never executed -: 3930: "blocks_max is too large"); #####: 3931: return NULL; -: 3932: } -: 3933: -: 3934: 20: 3935: if ( ! ImagingMemorySetBlocksMax(&ImagingDefaultArena, blocks_max)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 3936: ImagingError_MemoryError(); call 0 never executed #####: 3937: return NULL; -: 3938: } -: 3939: 20: 3940: Py_INCREF(Py_None); 20: 3941: return Py_None; -: 3942:} -: 3943: -: 3944:static PyObject* function _clear_cache called 18 returned 100% blocks executed 100% 18: 3945:_clear_cache(PyObject* self, PyObject* args) -: 3946:{ 18: 3947: int i = 0; -: 3948: 18: 3949: if (!PyArg_ParseTuple(args, "|i:clear_cache", &i)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 3950: return NULL; -: 3951: } -: 3952: 18: 3953: ImagingMemoryClearCache(&ImagingDefaultArena, i); call 0 returned 100% -: 3954: 18: 3955: Py_INCREF(Py_None); 18: 3956: return Py_None; -: 3957:} -: 3958: -: 3959:/* -------------------------------------------------------------------- */ -: 3960: -: 3961:/* FIXME: this is something of a mess. Should replace this with -: 3962: pluggable codecs, but not before PIL 1.2 */ -: 3963: -: 3964:/* Decoders (in decode.c) */ -: 3965:extern PyObject* PyImaging_BcnDecoderNew(PyObject* self, PyObject* args); -: 3966:extern PyObject* PyImaging_BitDecoderNew(PyObject* self, PyObject* args); -: 3967:extern PyObject* PyImaging_FliDecoderNew(PyObject* self, PyObject* args); -: 3968:extern PyObject* PyImaging_GifDecoderNew(PyObject* self, PyObject* args); -: 3969:extern PyObject* PyImaging_HexDecoderNew(PyObject* self, PyObject* args); -: 3970:extern PyObject* PyImaging_JpegDecoderNew(PyObject* self, PyObject* args); -: 3971:extern PyObject* PyImaging_Jpeg2KDecoderNew(PyObject* self, PyObject* args); -: 3972:extern PyObject* PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args); -: 3973:extern PyObject* PyImaging_PackbitsDecoderNew(PyObject* self, PyObject* args); -: 3974:extern PyObject* PyImaging_PcdDecoderNew(PyObject* self, PyObject* args); -: 3975:extern PyObject* PyImaging_PcxDecoderNew(PyObject* self, PyObject* args); -: 3976:extern PyObject* PyImaging_RawDecoderNew(PyObject* self, PyObject* args); -: 3977:extern PyObject* PyImaging_SgiRleDecoderNew(PyObject* self, PyObject* args); -: 3978:extern PyObject* PyImaging_SunRleDecoderNew(PyObject* self, PyObject* args); -: 3979:extern PyObject* PyImaging_TgaRleDecoderNew(PyObject* self, PyObject* args); -: 3980:extern PyObject* PyImaging_XbmDecoderNew(PyObject* self, PyObject* args); -: 3981:extern PyObject* PyImaging_ZipDecoderNew(PyObject* self, PyObject* args); -: 3982: -: 3983:/* Encoders (in encode.c) */ -: 3984:extern PyObject* PyImaging_EpsEncoderNew(PyObject* self, PyObject* args); -: 3985:extern PyObject* PyImaging_GifEncoderNew(PyObject* self, PyObject* args); -: 3986:extern PyObject* PyImaging_JpegEncoderNew(PyObject* self, PyObject* args); -: 3987:extern PyObject* PyImaging_Jpeg2KEncoderNew(PyObject* self, PyObject* args); -: 3988:extern PyObject* PyImaging_PcxEncoderNew(PyObject* self, PyObject* args); -: 3989:extern PyObject* PyImaging_RawEncoderNew(PyObject* self, PyObject* args); -: 3990:extern PyObject* PyImaging_TgaRleEncoderNew(PyObject* self, PyObject* args); -: 3991:extern PyObject* PyImaging_XbmEncoderNew(PyObject* self, PyObject* args); -: 3992:extern PyObject* PyImaging_ZipEncoderNew(PyObject* self, PyObject* args); -: 3993:extern PyObject* PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args); -: 3994: -: 3995:/* Display support etc (in display.c) */ -: 3996:#ifdef _WIN32 -: 3997:extern PyObject* PyImaging_CreateWindowWin32(PyObject* self, PyObject* args); -: 3998:extern PyObject* PyImaging_DisplayWin32(PyObject* self, PyObject* args); -: 3999:extern PyObject* PyImaging_DisplayModeWin32(PyObject* self, PyObject* args); -: 4000:extern PyObject* PyImaging_GrabScreenWin32(PyObject* self, PyObject* args); -: 4001:extern PyObject* PyImaging_GrabClipboardWin32(PyObject* self, PyObject* args); -: 4002:extern PyObject* PyImaging_ListWindowsWin32(PyObject* self, PyObject* args); -: 4003:extern PyObject* PyImaging_EventLoopWin32(PyObject* self, PyObject* args); -: 4004:extern PyObject* PyImaging_DrawWmf(PyObject* self, PyObject* args); -: 4005:#endif -: 4006:#ifdef HAVE_XCB -: 4007:extern PyObject* PyImaging_GrabScreenX11(PyObject* self, PyObject* args); -: 4008:#endif -: 4009: -: 4010:/* Experimental path stuff (in path.c) */ -: 4011:extern PyObject* PyPath_Create(ImagingObject* self, PyObject* args); -: 4012: -: 4013:/* Experimental outline stuff (in outline.c) */ -: 4014:extern PyObject* PyOutline_Create(ImagingObject* self, PyObject* args); -: 4015: -: 4016:extern PyObject* PyImaging_Mapper(PyObject* self, PyObject* args); -: 4017:extern PyObject* PyImaging_MapBuffer(PyObject* self, PyObject* args); -: 4018: -: 4019:static PyMethodDef functions[] = { -: 4020: -: 4021: /* Object factories */ -: 4022: {"alpha_composite", (PyCFunction)_alpha_composite, 1}, -: 4023: {"blend", (PyCFunction)_blend, 1}, -: 4024: {"fill", (PyCFunction)_fill, 1}, -: 4025: {"new", (PyCFunction)_new, 1}, -: 4026: {"merge", (PyCFunction)_merge, 1}, -: 4027: -: 4028: /* Functions */ -: 4029: {"convert", (PyCFunction)_convert2, 1}, -: 4030: -: 4031: /* Codecs */ -: 4032: {"bcn_decoder", (PyCFunction)PyImaging_BcnDecoderNew, 1}, -: 4033: {"bit_decoder", (PyCFunction)PyImaging_BitDecoderNew, 1}, -: 4034: {"eps_encoder", (PyCFunction)PyImaging_EpsEncoderNew, 1}, -: 4035: {"fli_decoder", (PyCFunction)PyImaging_FliDecoderNew, 1}, -: 4036: {"gif_decoder", (PyCFunction)PyImaging_GifDecoderNew, 1}, -: 4037: {"gif_encoder", (PyCFunction)PyImaging_GifEncoderNew, 1}, -: 4038: {"hex_decoder", (PyCFunction)PyImaging_HexDecoderNew, 1}, -: 4039: {"hex_encoder", (PyCFunction)PyImaging_EpsEncoderNew, 1}, /* EPS=HEX! */ -: 4040:#ifdef HAVE_LIBJPEG -: 4041: {"jpeg_decoder", (PyCFunction)PyImaging_JpegDecoderNew, 1}, -: 4042: {"jpeg_encoder", (PyCFunction)PyImaging_JpegEncoderNew, 1}, -: 4043:#endif -: 4044:#ifdef HAVE_OPENJPEG -: 4045: {"jpeg2k_decoder", (PyCFunction)PyImaging_Jpeg2KDecoderNew, 1}, -: 4046: {"jpeg2k_encoder", (PyCFunction)PyImaging_Jpeg2KEncoderNew, 1}, -: 4047:#endif -: 4048:#ifdef HAVE_LIBTIFF -: 4049: {"libtiff_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, -: 4050: {"libtiff_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, -: 4051:#endif -: 4052: {"packbits_decoder", (PyCFunction)PyImaging_PackbitsDecoderNew, 1}, -: 4053: {"pcd_decoder", (PyCFunction)PyImaging_PcdDecoderNew, 1}, -: 4054: {"pcx_decoder", (PyCFunction)PyImaging_PcxDecoderNew, 1}, -: 4055: {"pcx_encoder", (PyCFunction)PyImaging_PcxEncoderNew, 1}, -: 4056: {"raw_decoder", (PyCFunction)PyImaging_RawDecoderNew, 1}, -: 4057: {"raw_encoder", (PyCFunction)PyImaging_RawEncoderNew, 1}, -: 4058: {"sgi_rle_decoder", (PyCFunction)PyImaging_SgiRleDecoderNew, 1}, -: 4059: {"sun_rle_decoder", (PyCFunction)PyImaging_SunRleDecoderNew, 1}, -: 4060: {"tga_rle_decoder", (PyCFunction)PyImaging_TgaRleDecoderNew, 1}, -: 4061: {"tga_rle_encoder", (PyCFunction)PyImaging_TgaRleEncoderNew, 1}, -: 4062: {"xbm_decoder", (PyCFunction)PyImaging_XbmDecoderNew, 1}, -: 4063: {"xbm_encoder", (PyCFunction)PyImaging_XbmEncoderNew, 1}, -: 4064:#ifdef HAVE_LIBZ -: 4065: {"zip_decoder", (PyCFunction)PyImaging_ZipDecoderNew, 1}, -: 4066: {"zip_encoder", (PyCFunction)PyImaging_ZipEncoderNew, 1}, -: 4067:#endif -: 4068: -: 4069: /* Memory mapping */ -: 4070:#ifdef WITH_MAPPING -: 4071:#ifdef _WIN32 -: 4072: {"map", (PyCFunction)PyImaging_Mapper, 1}, -: 4073:#endif -: 4074: {"map_buffer", (PyCFunction)PyImaging_MapBuffer, 1}, -: 4075:#endif -: 4076: -: 4077: /* Display support */ -: 4078:#ifdef _WIN32 -: 4079: {"display", (PyCFunction)PyImaging_DisplayWin32, 1}, -: 4080: {"display_mode", (PyCFunction)PyImaging_DisplayModeWin32, 1}, -: 4081: {"grabscreen_win32", (PyCFunction)PyImaging_GrabScreenWin32, 1}, -: 4082: {"grabclipboard_win32", (PyCFunction)PyImaging_GrabClipboardWin32, 1}, -: 4083: {"createwindow", (PyCFunction)PyImaging_CreateWindowWin32, 1}, -: 4084: {"eventloop", (PyCFunction)PyImaging_EventLoopWin32, 1}, -: 4085: {"listwindows", (PyCFunction)PyImaging_ListWindowsWin32, 1}, -: 4086: {"drawwmf", (PyCFunction)PyImaging_DrawWmf, 1}, -: 4087:#endif -: 4088:#ifdef HAVE_XCB -: 4089: {"grabscreen_x11", (PyCFunction)PyImaging_GrabScreenX11, 1}, -: 4090:#endif -: 4091: -: 4092: /* Utilities */ -: 4093: {"getcodecstatus", (PyCFunction)_getcodecstatus, 1}, -: 4094: -: 4095: /* Special effects (experimental) */ -: 4096:#ifdef WITH_EFFECTS -: 4097: {"effect_mandelbrot", (PyCFunction)_effect_mandelbrot, 1}, -: 4098: {"effect_noise", (PyCFunction)_effect_noise, 1}, -: 4099: {"linear_gradient", (PyCFunction)_linear_gradient, 1}, -: 4100: {"radial_gradient", (PyCFunction)_radial_gradient, 1}, -: 4101: {"wedge", (PyCFunction)_linear_gradient, 1}, /* Compatibility */ -: 4102:#endif -: 4103: -: 4104: /* Drawing support stuff */ -: 4105:#ifdef WITH_IMAGEDRAW -: 4106: {"font", (PyCFunction)_font_new, 1}, -: 4107: {"draw", (PyCFunction)_draw_new, 1}, -: 4108:#endif -: 4109: -: 4110: /* Experimental path stuff */ -: 4111:#ifdef WITH_IMAGEPATH -: 4112: {"path", (PyCFunction)PyPath_Create, 1}, -: 4113:#endif -: 4114: -: 4115: /* Experimental arrow graphics stuff */ -: 4116:#ifdef WITH_ARROW -: 4117: {"outline", (PyCFunction)PyOutline_Create, 1}, -: 4118:#endif -: 4119: -: 4120: /* Resource management */ -: 4121: {"get_stats", (PyCFunction)_get_stats, 1}, -: 4122: {"reset_stats", (PyCFunction)_reset_stats, 1}, -: 4123: {"get_alignment", (PyCFunction)_get_alignment, 1}, -: 4124: {"get_block_size", (PyCFunction)_get_block_size, 1}, -: 4125: {"get_blocks_max", (PyCFunction)_get_blocks_max, 1}, -: 4126: {"set_alignment", (PyCFunction)_set_alignment, 1}, -: 4127: {"set_block_size", (PyCFunction)_set_block_size, 1}, -: 4128: {"set_blocks_max", (PyCFunction)_set_blocks_max, 1}, -: 4129: {"clear_cache", (PyCFunction)_clear_cache, 1}, -: 4130: -: 4131: {NULL, NULL} /* sentinel */ -: 4132:}; -: 4133: -: 4134:static int function setup_module called 3 returned 100% blocks executed 100% 3: 4135:setup_module(PyObject* m) { 3: 4136: PyObject* d = PyModule_GetDict(m); call 0 returned 100% 3: 4137: const char* version = (char*)PILLOW_VERSION; -: 4138: -: 4139: /* Ready object types */ 3: 4140: if (PyType_Ready(&Imaging_Type) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 4141: return -1; -: 4142: } -: 4143: -: 4144:#ifdef WITH_IMAGEDRAW 3: 4145: if (PyType_Ready(&ImagingFont_Type) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 4146: return -1; -: 4147: } -: 4148: 3: 4149: if (PyType_Ready(&ImagingDraw_Type) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 4150: return -1; -: 4151: } -: 4152:#endif 3: 4153: if (PyType_Ready(&PixelAccess_Type) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 4154: return -1; -: 4155: } -: 4156: 3: 4157: ImagingAccessInit(); call 0 returned 100% -: 4158: -: 4159:#ifdef HAVE_LIBJPEG -: 4160: { -: 4161: extern const char* ImagingJpegVersion(void); 3: 4162: PyDict_SetItemString(d, "jpeglib_version", PyUnicode_FromString(ImagingJpegVersion())); call 0 returned 100% call 1 returned 100% call 2 returned 100% -: 4163: } -: 4164:#endif -: 4165: -: 4166:#ifdef HAVE_OPENJPEG -: 4167: { -: 4168: extern const char *ImagingJpeg2KVersion(void); 3: 4169: PyDict_SetItemString(d, "jp2klib_version", PyUnicode_FromString(ImagingJpeg2KVersion())); call 0 returned 100% call 1 returned 100% call 2 returned 100% -: 4170: } -: 4171:#endif -: 4172: -: 4173:#ifdef LIBJPEG_TURBO_VERSION 3: 4174: PyModule_AddObject(m, "HAVE_LIBJPEGTURBO", Py_True); call 0 returned 100% -: 4175: #define tostr1(a) #a -: 4176: #define tostr(a) tostr1(a) 3: 4177: PyDict_SetItemString(d, "libjpeg_turbo_version", PyUnicode_FromString(tostr(LIBJPEG_TURBO_VERSION))); call 0 returned 100% call 1 returned 100% -: 4178: #undef tostr -: 4179: #undef tostr1 -: 4180:#else -: 4181: PyModule_AddObject(m, "HAVE_LIBJPEGTURBO", Py_False); -: 4182:#endif -: 4183: -: 4184:#ifdef HAVE_LIBIMAGEQUANT 3: 4185: PyModule_AddObject(m, "HAVE_LIBIMAGEQUANT", Py_True); call 0 returned 100% -: 4186: { -: 4187: extern const char* ImagingImageQuantVersion(void); 3: 4188: PyDict_SetItemString(d, "imagequant_version", PyUnicode_FromString(ImagingImageQuantVersion())); call 0 returned 100% call 1 returned 100% call 2 returned 100% -: 4189: } -: 4190:#else -: 4191: PyModule_AddObject(m, "HAVE_LIBIMAGEQUANT", Py_False); -: 4192:#endif -: 4193: -: 4194:#ifdef HAVE_LIBZ -: 4195: /* zip encoding strategies */ 3: 4196: PyModule_AddIntConstant(m, "DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY); call 0 returned 100% 3: 4197: PyModule_AddIntConstant(m, "FILTERED", Z_FILTERED); call 0 returned 100% 3: 4198: PyModule_AddIntConstant(m, "HUFFMAN_ONLY", Z_HUFFMAN_ONLY); call 0 returned 100% 3: 4199: PyModule_AddIntConstant(m, "RLE", Z_RLE); call 0 returned 100% 3: 4200: PyModule_AddIntConstant(m, "FIXED", Z_FIXED); call 0 returned 100% -: 4201: { -: 4202: extern const char* ImagingZipVersion(void); 3: 4203: PyDict_SetItemString(d, "zlib_version", PyUnicode_FromString(ImagingZipVersion())); call 0 returned 100% call 1 returned 100% call 2 returned 100% -: 4204: } -: 4205:#endif -: 4206: -: 4207:#ifdef HAVE_LIBTIFF -: 4208: { -: 4209: extern const char * ImagingTiffVersion(void); -: 4210: PyDict_SetItemString(d, "libtiff_version", PyUnicode_FromString(ImagingTiffVersion())); -: 4211: -: 4212: // Test for libtiff 4.0 or later, excluding libtiff 3.9.6 and 3.9.7 -: 4213: PyObject* support_custom_tags; -: 4214:#if TIFFLIB_VERSION >= 20111221 && TIFFLIB_VERSION != 20120218 && TIFFLIB_VERSION != 20120922 -: 4215: support_custom_tags = Py_True; -: 4216:#else -: 4217: support_custom_tags = Py_False; -: 4218:#endif -: 4219: PyDict_SetItemString(d, "libtiff_support_custom_tags", support_custom_tags); -: 4220: } -: 4221:#endif -: 4222: -: 4223:#ifdef HAVE_XCB 3: 4224: PyModule_AddObject(m, "HAVE_XCB", Py_True); call 0 returned 100% -: 4225:#else -: 4226: PyModule_AddObject(m, "HAVE_XCB", Py_False); -: 4227:#endif -: 4228: 3: 4229: PyDict_SetItemString(d, "PILLOW_VERSION", PyUnicode_FromString(version)); call 0 returned 100% call 1 returned 100% -: 4230: 3: 4231: return 0; -: 4232:} -: 4233: -: 4234:PyMODINIT_FUNC function PyInit__imaging called 3 returned 100% blocks executed 100% 3: 4235:PyInit__imaging(void) { -: 4236: PyObject* m; -: 4237: -: 4238: static PyModuleDef module_def = { -: 4239: PyModuleDef_HEAD_INIT, -: 4240: "_imaging", /* m_name */ -: 4241: NULL, /* m_doc */ -: 4242: -1, /* m_size */ -: 4243: functions, /* m_methods */ -: 4244: }; -: 4245: 3: 4246: m = PyModule_Create(&module_def); call 0 returned 100% -: 4247: 3: 4248: if (setup_module(m) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 4249: return NULL; -: 4250: } -: 4251: 3: 4252: return m; -: 4253:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#TgaRleDecode.c.gcov -: 0:Source:src/libImaging/TgaRleDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/TgaRleDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/TgaRleDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for Targa RLE data. -: 6: * -: 7: * history: -: 8: * 97-01-04 fl created -: 9: * 98-09-11 fl don't one byte per pixel; take orientation into account -: 10: * -: 11: * Copyright (c) Fredrik Lundh 1997. -: 12: * Copyright (c) Secret Labs AB 1997-98. -: 13: * -: 14: * See the README file for information on usage and redistribution. -: 15: */ -: 16: -: 17: -: 18:#include "Imaging.h" -: 19: -: 20: -: 21:int function ImagingTgaRleDecode called 33 returned 100% blocks executed 90% 33: 22:ImagingTgaRleDecode(Imaging im, ImagingCodecState state, -: 23: UINT8* buf, Py_ssize_t bytes) -: 24:{ -: 25: int n, depth; -: 26: UINT8* ptr; -: 27: 33: 28: ptr = buf; -: 29: 33: 30: if (state->state == 0) { branch 0 taken 91% (fallthrough) branch 1 taken 9% -: 31: -: 32: /* check image orientation */ 30: 33: if (state->ystep < 0) { branch 0 taken 50% (fallthrough) branch 1 taken 50% 15: 34: state->y = state->ysize-1; 15: 35: state->ystep = -1; -: 36: } else { 15: 37: state->ystep = 1; -: 38: } -: 39: 30: 40: state->state = 1; -: 41: -: 42: } -: 43: 33: 44: depth = state->count; -: 45: -: 46: for (;;) { -: 47: 24577: 48: if (bytes < 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 49: return ptr - buf; -: 50: } -: 51: 24577: 52: if (ptr[0] & 0x80) { branch 0 taken 52% (fallthrough) branch 1 taken 48% -: 53: -: 54: /* Run (1 + pixelsize bytes) */ -: 55: 12885: 56: if (bytes < 1 + depth) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 57: break; -: 58: } -: 59: 12885: 60: n = depth * ((ptr[0] & 0x7f) + 1); -: 61: 12885: 62: if (state->x + n > state->bytes) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 63: state->errcode = IMAGING_CODEC_OVERRUN; #####: 64: return -1; -: 65: } -: 66: 12885: 67: if (depth == 1) { branch 0 taken 62% (fallthrough) branch 1 taken 38% 4948: 68: memset(state->buffer + state->x, ptr[1], n); -: 69: } else { -: 70: int i; 35423: 71: for (i = 0; i < n; i += depth) { branch 0 taken 82% branch 1 taken 18% (fallthrough) 70846: 72: memcpy(state->buffer + state->x + i, ptr+1, depth); -: 73: } -: 74: } -: 75: 12885: 76: ptr += 1 + depth; 12885: 77: bytes -= 1 + depth; -: 78: -: 79: } else { -: 80: -: 81: /* Literal (1+n+1 bytes block) */ 11692: 82: n = depth * (ptr[0] + 1); -: 83: 11692: 84: if (bytes < 1 + n) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 85: break; -: 86: } -: 87: 11689: 88: if (state->x + n > state->bytes) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 89: state->errcode = IMAGING_CODEC_OVERRUN; #####: 90: return -1; -: 91: } -: 92: 23378: 93: memcpy(state->buffer + state->x, ptr + 1, n); -: 94: 11689: 95: ptr += 1 + n; 11689: 96: bytes -= 1 + n; -: 97: -: 98: } -: 99: 24574: 100: state->x += n; -: 101: 24574: 102: if (state->x >= state->bytes) { branch 0 taken 94% branch 1 taken 6% (fallthrough) -: 103: -: 104: /* Got a full line, unpack it */ 4203: 105: state->shuffle((UINT8*) im->image[state->y + state->yoff] + call 0 returned 100% 2802: 106: state->xoff * im->pixelsize, state->buffer, -: 107: state->xsize); -: 108: 1401: 109: state->x = 0; -: 110: 1401: 111: state->y += state->ystep; -: 112: 1401: 113: if (state->y < 0 || state->y >= state->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 99% branch 3 taken 1% -: 114: /* End of file (errcode = 0) */ -: 115: return -1; -: 116: } -: 117: -: 118: } -: 119: -: 120: } -: 121: 3: 122: return ptr - buf; -: 123:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/#usr#include#powerpc64le-linux-gnu#bits#mathcalls.h.gcov -: 0:Source:/usr/include/powerpc64le-linux-gnu/bits/mathcalls.h -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Convert.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Convert.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* Prototype declarations for math functions; helper file for . -: 2: Copyright (C) 1996-2016 Free Software Foundation, Inc. -: 3: This file is part of the GNU C Library. -: 4: -: 5: The GNU C Library is free software; you can redistribute it and/or -: 6: modify it under the terms of the GNU Lesser General Public -: 7: License as published by the Free Software Foundation; either -: 8: version 2.1 of the License, or (at your option) any later version. -: 9: -: 10: The GNU C Library is distributed in the hope that it will be useful, -: 11: but WITHOUT ANY WARRANTY; without even the implied warranty of -: 12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -: 13: Lesser General Public License for more details. -: 14: -: 15: You should have received a copy of the GNU Lesser General Public -: 16: License along with the GNU C Library; if not, see -: 17: . */ -: 18: -: 19:/* NOTE: Because of the special way this file is used by , this -: 20: file must NOT be protected from multiple inclusion as header files -: 21: usually are. -: 22: -: 23: This file provides prototype declarations for the math functions. -: 24: Most functions are declared using the macro: -: 25: -: 26: __MATHCALL (NAME,[_r], (ARGS...)); -: 27: -: 28: This means there is a function `NAME' returning `double' and a function -: 29: `NAMEf' returning `float'. Each place `_Mdouble_' appears in the -: 30: prototype, that is actually `double' in the prototype for `NAME' and -: 31: `float' in the prototype for `NAMEf'. Reentrant variant functions are -: 32: called `NAME_r' and `NAMEf_r'. -: 33: -: 34: Functions returning other types like `int' are declared using the macro: -: 35: -: 36: __MATHDECL (TYPE, NAME,[_r], (ARGS...)); -: 37: -: 38: This is just like __MATHCALL but for a function returning `TYPE' -: 39: instead of `_Mdouble_'. In all of these cases, there is still -: 40: both a `NAME' and a `NAMEf' that takes `float' arguments. -: 41: -: 42: Note that there must be no whitespace before the argument passed for -: 43: NAME, to make token pasting work with -traditional. */ -: 44: -: 45:#ifndef _MATH_H -: 46:# error "Never include directly; include instead." -: 47:#endif -: 48: -: 49: -: 50:/* Trigonometric functions. */ -: 51: -: 52:_Mdouble_BEGIN_NAMESPACE -: 53:/* Arc cosine of X. */ -: 54:__MATHCALL (acos,, (_Mdouble_ __x)); -: 55:/* Arc sine of X. */ -: 56:__MATHCALL (asin,, (_Mdouble_ __x)); -: 57:/* Arc tangent of X. */ -: 58:__MATHCALL (atan,, (_Mdouble_ __x)); -: 59:/* Arc tangent of Y/X. */ -: 60:__MATHCALL (atan2,, (_Mdouble_ __y, _Mdouble_ __x)); -: 61: -: 62:/* Cosine of X. */ -: 63:__MATHCALL_VEC (cos,, (_Mdouble_ __x)); -: 64:/* Sine of X. */ -: 65:__MATHCALL_VEC (sin,, (_Mdouble_ __x)); -: 66:/* Tangent of X. */ -: 67:__MATHCALL (tan,, (_Mdouble_ __x)); -: 68: -: 69:/* Hyperbolic functions. */ -: 70: -: 71:/* Hyperbolic cosine of X. */ -: 72:__MATHCALL (cosh,, (_Mdouble_ __x)); -: 73:/* Hyperbolic sine of X. */ -: 74:__MATHCALL (sinh,, (_Mdouble_ __x)); -: 75:/* Hyperbolic tangent of X. */ -: 76:__MATHCALL (tanh,, (_Mdouble_ __x)); -: 77:_Mdouble_END_NAMESPACE -: 78: -: 79:#ifdef __USE_GNU -: 80:/* Cosine and sine of X. */ -: 81:__MATHDECL_VEC (void,sincos,, -: 82: (_Mdouble_ __x, _Mdouble_ *__sinx, _Mdouble_ *__cosx)); -: 83:#endif -: 84: -: 85:#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 -: 86:__BEGIN_NAMESPACE_C99 -: 87:/* Hyperbolic arc cosine of X. */ -: 88:__MATHCALL (acosh,, (_Mdouble_ __x)); -: 89:/* Hyperbolic arc sine of X. */ -: 90:__MATHCALL (asinh,, (_Mdouble_ __x)); -: 91:/* Hyperbolic arc tangent of X. */ -: 92:__MATHCALL (atanh,, (_Mdouble_ __x)); -: 93:__END_NAMESPACE_C99 -: 94:#endif -: 95: -: 96:/* Exponential and logarithmic functions. */ -: 97: -: 98:_Mdouble_BEGIN_NAMESPACE -: 99:/* Exponential function of X. */ -: 100:__MATHCALL_VEC (exp,, (_Mdouble_ __x)); -: 101: -: 102:/* Break VALUE into a normalized fraction and an integral power of 2. */ -: 103:__MATHCALL (frexp,, (_Mdouble_ __x, int *__exponent)); -: 104: -: 105:/* X times (two to the EXP power). */ -: 106:__MATHCALL (ldexp,, (_Mdouble_ __x, int __exponent)); -: 107: -: 108:/* Natural logarithm of X. */ -: 109:__MATHCALL_VEC (log,, (_Mdouble_ __x)); -: 110: -: 111:/* Base-ten logarithm of X. */ -: 112:__MATHCALL (log10,, (_Mdouble_ __x)); -: 113: -: 114:/* Break VALUE into integral and fractional parts. */ -: 115:__MATHCALL (modf,, (_Mdouble_ __x, _Mdouble_ *__iptr)) __nonnull ((2)); -: 116:_Mdouble_END_NAMESPACE -: 117: -: 118:#ifdef __USE_GNU -: 119:/* A function missing in all standards: compute exponent to base ten. */ -: 120:__MATHCALL (exp10,, (_Mdouble_ __x)); -: 121:/* Another name occasionally used. */ -: 122:__MATHCALL (pow10,, (_Mdouble_ __x)); -: 123:#endif -: 124: -: 125:#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 -: 126:__BEGIN_NAMESPACE_C99 -: 127:/* Return exp(X) - 1. */ -: 128:__MATHCALL (expm1,, (_Mdouble_ __x)); -: 129: -: 130:/* Return log(1 + X). */ -: 131:__MATHCALL (log1p,, (_Mdouble_ __x)); -: 132: -: 133:/* Return the base 2 signed integral exponent of X. */ -: 134:__MATHCALL (logb,, (_Mdouble_ __x)); -: 135:__END_NAMESPACE_C99 -: 136:#endif -: 137: -: 138:#ifdef __USE_ISOC99 -: 139:__BEGIN_NAMESPACE_C99 -: 140:/* Compute base-2 exponential of X. */ -: 141:__MATHCALL (exp2,, (_Mdouble_ __x)); -: 142: -: 143:/* Compute base-2 logarithm of X. */ -: 144:__MATHCALL (log2,, (_Mdouble_ __x)); -: 145:__END_NAMESPACE_C99 -: 146:#endif -: 147: -: 148: -: 149:/* Power functions. */ -: 150: -: 151:_Mdouble_BEGIN_NAMESPACE -: 152:/* Return X to the Y power. */ -: 153:__MATHCALL_VEC (pow,, (_Mdouble_ __x, _Mdouble_ __y)); -: 154: -: 155:/* Return the square root of X. */ -: 156:__MATHCALL (sqrt,, (_Mdouble_ __x)); -: 157:_Mdouble_END_NAMESPACE -: 158: -: 159:#if defined __USE_XOPEN || defined __USE_ISOC99 -: 160:__BEGIN_NAMESPACE_C99 -: 161:/* Return `sqrt(X*X + Y*Y)'. */ -: 162:__MATHCALL (hypot,, (_Mdouble_ __x, _Mdouble_ __y)); -: 163:__END_NAMESPACE_C99 -: 164:#endif -: 165: -: 166:#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 -: 167:__BEGIN_NAMESPACE_C99 -: 168:/* Return the cube root of X. */ -: 169:__MATHCALL (cbrt,, (_Mdouble_ __x)); -: 170:__END_NAMESPACE_C99 -: 171:#endif -: 172: -: 173: -: 174:/* Nearest integer, absolute value, and remainder functions. */ -: 175: -: 176:_Mdouble_BEGIN_NAMESPACE -: 177:/* Smallest integral value not less than X. */ -: 178:__MATHCALLX (ceil,, (_Mdouble_ __x), (__const__)); -: 179: -: 180:/* Absolute value of X. */ -: 181:__MATHCALLX (fabs,, (_Mdouble_ __x), (__const__)); -: 182: -: 183:/* Largest integer not greater than X. */ -: 184:__MATHCALLX (floor,, (_Mdouble_ __x), (__const__)); -: 185: -: 186:/* Floating-point modulo remainder of X/Y. */ -: 187:__MATHCALL (fmod,, (_Mdouble_ __x, _Mdouble_ __y)); -: 188: -: 189: -: 190:/* Return 0 if VALUE is finite or NaN, +1 if it -: 191: is +Infinity, -1 if it is -Infinity. */ -: 192:__MATHDECL_1 (int,__isinf,, (_Mdouble_ __value)) __attribute__ ((__const__)); -: 193: -: 194:/* Return nonzero if VALUE is finite and not NaN. */ -: 195:__MATHDECL_1 (int,__finite,, (_Mdouble_ __value)) __attribute__ ((__const__)); -: 196:_Mdouble_END_NAMESPACE -: 197: -: 198:#ifdef __USE_MISC -: 199:# if (!defined __cplusplus \ -: 200: || __cplusplus < 201103L /* isinf conflicts with C++11. */ \ -: 201: || __MATH_DECLARING_DOUBLE == 0) /* isinff or isinfl don't. */ -: 202:/* Return 0 if VALUE is finite or NaN, +1 if it -: 203: is +Infinity, -1 if it is -Infinity. */ -: 204:__MATHDECL_1 (int,isinf,, (_Mdouble_ __value)) __attribute__ ((__const__)); -: 205:# endif -: 206: -: 207:/* Return nonzero if VALUE is finite and not NaN. */ -: 208:__MATHDECL_1 (int,finite,, (_Mdouble_ __value)) __attribute__ ((__const__)); -: 209: -: 210:/* Return the remainder of X/Y. */ -: 211:__MATHCALL (drem,, (_Mdouble_ __x, _Mdouble_ __y)); -: 212: -: 213: -: 214:/* Return the fractional part of X after dividing out `ilogb (X)'. */ -: 215:__MATHCALL (significand,, (_Mdouble_ __x)); -: 216:#endif /* Use misc. */ -: 217: -: 218:#ifdef __USE_ISOC99 -: 219:__BEGIN_NAMESPACE_C99 -: 220:/* Return X with its signed changed to Y's. */ -: 221:__MATHCALLX (copysign,, (_Mdouble_ __x, _Mdouble_ __y), (__const__)); -: 222:__END_NAMESPACE_C99 -: 223:#endif -: 224: -: 225:#ifdef __USE_ISOC99 -: 226:__BEGIN_NAMESPACE_C99 -: 227:/* Return representation of qNaN for double type. */ -: 228:__MATHCALLX (nan,, (const char *__tagb), (__const__)); -: 229:__END_NAMESPACE_C99 -: 230:#endif -: 231: -: 232: -: 233:/* Return nonzero if VALUE is not a number. */ -: 234:__MATHDECL_1 (int,__isnan,, (_Mdouble_ __value)) __attribute__ ((__const__)); -: 235: -: 236:#if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K) -: 237:# if (!defined __cplusplus \ -: 238: || __cplusplus < 201103L /* isnan conflicts with C++11. */ \ -: 239: || __MATH_DECLARING_DOUBLE == 0) /* isnanf or isnanl don't. */ -: 240:/* Return nonzero if VALUE is not a number. */ -: 241:__MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__)); -: 242:# endif -: 243:#endif -: 244: -: 245:#if defined __USE_MISC || (defined __USE_XOPEN && __MATH_DECLARING_DOUBLE) -: 246:/* Bessel functions. */ -: 247:__MATHCALL (j0,, (_Mdouble_)); -: 248:__MATHCALL (j1,, (_Mdouble_)); -: 249:__MATHCALL (jn,, (int, _Mdouble_)); -: 250:__MATHCALL (y0,, (_Mdouble_)); -: 251:__MATHCALL (y1,, (_Mdouble_)); -: 252:__MATHCALL (yn,, (int, _Mdouble_)); -: 253:#endif -: 254: -: 255: -: 256:#if defined __USE_XOPEN || defined __USE_ISOC99 -: 257:__BEGIN_NAMESPACE_C99 -: 258:/* Error and gamma functions. */ -: 259:__MATHCALL (erf,, (_Mdouble_)); -: 260:__MATHCALL (erfc,, (_Mdouble_)); -: 261:__MATHCALL (lgamma,, (_Mdouble_)); -: 262:__END_NAMESPACE_C99 -: 263:#endif -: 264: -: 265:#ifdef __USE_ISOC99 -: 266:__BEGIN_NAMESPACE_C99 -: 267:/* True gamma function. */ -: 268:__MATHCALL (tgamma,, (_Mdouble_)); -: 269:__END_NAMESPACE_C99 -: 270:#endif -: 271: -: 272:#if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K) -: 273:/* Obsolete alias for `lgamma'. */ -: 274:__MATHCALL (gamma,, (_Mdouble_)); -: 275:#endif -: 276: -: 277:#ifdef __USE_MISC -: 278:/* Reentrant version of lgamma. This function uses the global variable -: 279: `signgam'. The reentrant version instead takes a pointer and stores -: 280: the value through it. */ -: 281:__MATHCALL (lgamma,_r, (_Mdouble_, int *__signgamp)); -: 282:#endif -: 283: -: 284: -: 285:#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 -: 286:__BEGIN_NAMESPACE_C99 -: 287:/* Return the integer nearest X in the direction of the -: 288: prevailing rounding mode. */ -: 289:__MATHCALL (rint,, (_Mdouble_ __x)); -: 290: -: 291:/* Return X + epsilon if X < Y, X - epsilon if X > Y. */ -: 292:__MATHCALLX (nextafter,, (_Mdouble_ __x, _Mdouble_ __y), (__const__)); -: 293:# if defined __USE_ISOC99 && !defined __LDBL_COMPAT -: 294:__MATHCALLX (nexttoward,, (_Mdouble_ __x, long double __y), (__const__)); -: 295:# endif -: 296: -: 297:/* Return the remainder of integer divison X / Y with infinite precision. */ -: 298:__MATHCALL (remainder,, (_Mdouble_ __x, _Mdouble_ __y)); -: 299: -: 300:# ifdef __USE_ISOC99 -: 301:/* Return X times (2 to the Nth power). */ -: 302:__MATHCALL (scalbn,, (_Mdouble_ __x, int __n)); -: 303:# endif -: 304: -: 305:/* Return the binary exponent of X, which must be nonzero. */ -: 306:__MATHDECL (int,ilogb,, (_Mdouble_ __x)); -: 307:#endif -: 308: -: 309:#ifdef __USE_ISOC99 -: 310:/* Return X times (2 to the Nth power). */ -: 311:__MATHCALL (scalbln,, (_Mdouble_ __x, long int __n)); -: 312: -: 313:/* Round X to integral value in floating-point format using current -: 314: rounding direction, but do not raise inexact exception. */ -: 315:__MATHCALL (nearbyint,, (_Mdouble_ __x)); -: 316: -: 317:/* Round X to nearest integral value, rounding halfway cases away from -: 318: zero. */ function round called 0 returned 0% blocks executed 0% #####: 319:__MATHCALLX (round,, (_Mdouble_ __x), (__const__)); -: 320: -: 321:/* Round X to the integral value in floating-point format nearest but -: 322: not larger in magnitude. */ -: 323:__MATHCALLX (trunc,, (_Mdouble_ __x), (__const__)); -: 324: -: 325:/* Compute remainder of X and Y and put in *QUO a value with sign of x/y -: 326: and magnitude congruent `mod 2^n' to the magnitude of the integral -: 327: quotient x/y, with n >= 3. */ -: 328:__MATHCALL (remquo,, (_Mdouble_ __x, _Mdouble_ __y, int *__quo)); -: 329: -: 330: -: 331:/* Conversion functions. */ -: 332: -: 333:/* Round X to nearest integral value according to current rounding -: 334: direction. */ -: 335:__MATHDECL (long int,lrint,, (_Mdouble_ __x)); -: 336:__extension__ -: 337:__MATHDECL (long long int,llrint,, (_Mdouble_ __x)); -: 338: -: 339:/* Round X to nearest integral value, rounding halfway cases away from -: 340: zero. */ -: 341:__MATHDECL (long int,lround,, (_Mdouble_ __x)); -: 342:__extension__ -: 343:__MATHDECL (long long int,llround,, (_Mdouble_ __x)); -: 344: -: 345: -: 346:/* Return positive difference between X and Y. */ -: 347:__MATHCALL (fdim,, (_Mdouble_ __x, _Mdouble_ __y)); -: 348: -: 349:/* Return maximum numeric value from X and Y. */ -: 350:__MATHCALLX (fmax,, (_Mdouble_ __x, _Mdouble_ __y), (__const__)); -: 351: -: 352:/* Return minimum numeric value from X and Y. */ -: 353:__MATHCALLX (fmin,, (_Mdouble_ __x, _Mdouble_ __y), (__const__)); -: 354: -: 355: -: 356:/* Classify given number. */ -: 357:__MATHDECL_1 (int, __fpclassify,, (_Mdouble_ __value)) -: 358: __attribute__ ((__const__)); -: 359: -: 360:/* Test for negative number. */ -: 361:__MATHDECL_1 (int, __signbit,, (_Mdouble_ __value)) -: 362: __attribute__ ((__const__)); -: 363: -: 364: -: 365:/* Multiply-add function computed as a ternary operation. */ -: 366:__MATHCALL (fma,, (_Mdouble_ __x, _Mdouble_ __y, _Mdouble_ __z)); -: 367:#endif /* Use ISO C99. */ -: 368: -: 369:#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 -: 370:__END_NAMESPACE_C99 -: 371:#endif -: 372: -: 373:#ifdef __USE_GNU -: 374:/* Test for signaling NaN. */ -: 375:__MATHDECL_1 (int, __issignaling,, (_Mdouble_ __value)) -: 376: __attribute__ ((__const__)); -: 377:#endif -: 378: -: 379:#if defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \ -: 380: && __MATH_DECLARING_DOUBLE \ -: 381: && !defined __USE_XOPEN2K8) -: 382:/* Return X times (2 to the Nth power). */ -: 383:__MATHCALL (scalb,, (_Mdouble_ __x, _Mdouble_ __n)); -: 384:#endif <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#ZipDecode.c.gcov -: 0:Source:src/libImaging/ZipDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/ZipDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/ZipDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for ZIP (deflated) image data. -: 6: * -: 7: * history: -: 8: * 1996-12-14 fl Created (for PNG) -: 9: * 1997-01-15 fl Prepared to read TIFF/ZIP -: 10: * 2001-11-19 fl PNG incomplete read patch (from Bernhard Herzog) -: 11: * -: 12: * Copyright (c) Fredrik Lundh 1996. -: 13: * Copyright (c) Secret Labs AB 1997-2001. -: 14: * -: 15: * See the README file for information on usage and redistribution. -: 16: */ -: 17: -: 18: -: 19:#include "Imaging.h" -: 20: -: 21:#ifdef HAVE_LIBZ -: 22: -: 23:#include "ZipCodecs.h" -: 24: -: 25:static const int OFFSET[] = { 7, 3, 3, 1, 1, 0, 0 }; -: 26:static const int STARTING_COL[] = { 0, 4, 0, 2, 0, 1, 0 }; -: 27:static const int STARTING_ROW[] = { 0, 0, 4, 0, 2, 0, 1 }; -: 28:static const int COL_INCREMENT[] = { 8, 8, 4, 4, 2, 2, 1 }; -: 29:static const int ROW_INCREMENT[] = { 8, 8, 8, 4, 4, 2, 2 }; -: 30: -: 31:/* Get the length in bytes of a scanline in the pass specified, -: 32: * for interlaced images */ -: 33:static int get_row_len(ImagingCodecState state, int pass) -: 34:{ 124: 35: int row_len = (state->xsize + OFFSET[pass]) / COL_INCREMENT[pass]; 124: 36: return ((row_len * state->bits) + 7) / 8; -: 37:} -: 38: -: 39:/* -------------------------------------------------------------------- */ -: 40:/* Decoder */ -: 41:/* -------------------------------------------------------------------- */ -: 42: -: 43:int function ImagingZipDecode called 1501 returned 100% blocks executed 80% 1501: 44:ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) -: 45:{ 1501: 46: ZIPSTATE* context = (ZIPSTATE*) state->context; -: 47: int err; -: 48: int n; -: 49: UINT8* ptr; -: 50: int i, bpp; -: 51: int row_len; -: 52: 1501: 53: if (!state->state) { branch 0 taken 68% (fallthrough) branch 1 taken 32% -: 54: -: 55: /* Initialization */ 1015: 56: if (context->mode == ZIP_PNG || context->mode == ZIP_PNG_PALETTE) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 1015: 57: context->prefix = 1; /* PNG */ -: 58: } -: 59: -: 60: /* overflow check for malloc */ 1015: 61: if (state->bytes > INT_MAX - 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 62: state->errcode = IMAGING_CODEC_MEMORY; #####: 63: return -1; -: 64: } -: 65: /* Expand standard buffer to make room for the (optional) filter -: 66: prefix, and allocate a buffer to hold the previous line */ 1015: 67: free(state->buffer); -: 68: /* malloc check ok, overflow checked above */ 1015: 69: state->buffer = (UINT8*) malloc(state->bytes+1); 1015: 70: context->previous = (UINT8*) malloc(state->bytes+1); 1015: 71: if (!state->buffer || !context->previous) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% #####: 72: state->errcode = IMAGING_CODEC_MEMORY; #####: 73: return -1; -: 74: } -: 75: 1015: 76: context->last_output = 0; -: 77: -: 78: /* Initialize to black */ 2030: 79: memset(context->previous, 0, state->bytes+1); -: 80: -: 81: /* Setup decompression context */ 1015: 82: context->z_stream.zalloc = (alloc_func) NULL; 1015: 83: context->z_stream.zfree = (free_func) NULL; 1015: 84: context->z_stream.opaque = (voidpf) NULL; -: 85: 1015: 86: err = inflateInit(&context->z_stream); call 0 returned 100% 1015: 87: if (err < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 88: state->errcode = IMAGING_CODEC_CONFIG; #####: 89: free(context->previous); #####: 90: context->previous = NULL; #####: 91: return -1; -: 92: } -: 93: 1015: 94: if (context->interlaced) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 15: 95: context->pass = 0; 15: 96: state->y = STARTING_ROW[context->pass]; -: 97: } -: 98: -: 99: /* Ready to decode */ 1015: 100: state->state = 1; -: 101: -: 102: } -: 103: 1501: 104: if (context->interlaced) { branch 0 taken 2% (fallthrough) branch 1 taken 98% 68: 105: row_len = get_row_len(state, context->pass); -: 106: } else { 1467: 107: row_len = state->bytes; -: 108: } -: 109: -: 110: /* Setup the source buffer */ 1501: 111: context->z_stream.next_in = buf; 1501: 112: context->z_stream.avail_in = bytes; -: 113: -: 114: /* Decompress what we've got this far */ 176563: 115: while (context->z_stream.avail_in > 0) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 116: 175050: 117: context->z_stream.next_out = state->buffer + context->last_output; 175050: 118: context->z_stream.avail_out = 175050: 119: row_len + context->prefix - context->last_output; -: 120: 175050: 121: err = inflate(&context->z_stream, Z_NO_FLUSH); call 0 returned 100% -: 122: 175050: 123: if (err < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 124: /* Something went wrong inside the compression library */ #####: 125: if (err == Z_DATA_ERROR) { branch 0 never executed branch 1 never executed #####: 126: state->errcode = IMAGING_CODEC_BROKEN; #####: 127: } else if (err == Z_MEM_ERROR) { branch 0 never executed branch 1 never executed #####: 128: state->errcode = IMAGING_CODEC_MEMORY; -: 129: } else { #####: 130: state->errcode = IMAGING_CODEC_CONFIG; -: 131: } #####: 132: free(context->previous); #####: 133: context->previous = NULL; #####: 134: inflateEnd(&context->z_stream); call 0 never executed #####: 135: return -1; -: 136: } -: 137: 175050: 138: n = row_len + context->prefix - context->z_stream.avail_out; -: 139: 175050: 140: if (n < row_len + context->prefix) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 580: 141: context->last_output = n; 580: 142: break; /* need more input data */ -: 143: } -: 144: -: 145: /* Apply predictor */ 174470: 146: switch (context->mode) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% -: 147: case ZIP_PNG: 174470: 148: switch (state->buffer[0]) { branch 0 taken 41% branch 1 taken 5% branch 2 taken 2% branch 3 taken 16% branch 4 taken 1% branch 5 taken 36% -: 149: case 0: -: 150: break; -: 151: case 1: -: 152: /* prior */ 8668: 153: bpp = (state->bits + 7) / 8; 11359273: 154: for (i = bpp+1; i <= row_len; i++) { branch 0 taken 99% branch 1 taken 1% 11350605: 155: state->buffer[i] += state->buffer[i-bpp]; -: 156: } -: 157: break; -: 158: case 2: -: 159: /* up */ 209240594: 160: for (i = 1; i <= row_len; i++) { branch 0 taken 99% branch 1 taken 1% 209240594: 161: state->buffer[i] += context->previous[i]; -: 162: } -: 163: break; -: 164: case 3: -: 165: /* average */ 2624: 166: bpp = (state->bits + 7) / 8; 10757: 167: for (i = 1; i <= bpp; i++) { branch 0 taken 76% branch 1 taken 24% (fallthrough) 8133: 168: state->buffer[i] += context->previous[i]/2; -: 169: } 2705611: 170: for (; i <= row_len; i++) { branch 0 taken 99% branch 1 taken 1% 5411222: 171: state->buffer[i] += 2705611: 172: (state->buffer[i-bpp] + context->previous[i])/2; -: 173: } -: 174: break; -: 175: case 4: -: 176: /* paeth filtering */ 27894: 177: bpp = (state->bits + 7) / 8; 106501: 178: for (i = 1; i <= bpp; i++) { branch 0 taken 74% branch 1 taken 26% (fallthrough) 78607: 179: state->buffer[i] += context->previous[i]; -: 180: } 61557676: 181: for (; i <= row_len; i++) { branch 0 taken 99% branch 1 taken 1% -: 182: int a, b, c; -: 183: int pa, pb, pc; -: 184: -: 185: /* fetch pixels */ 61557676: 186: a = state->buffer[i-bpp]; 61557676: 187: b = context->previous[i]; 61557676: 188: c = context->previous[i-bpp]; -: 189: -: 190: /* distances to surrounding pixels */ 61557676: 191: pa = abs(b - c); 61557676: 192: pb = abs(a - c); 61557676: 193: pc = abs(a + b - 2*c); -: 194: -: 195: /* pick predictor with the shortest distance */ 78979393: 196: state->buffer[i] += branch 0 taken 76% (fallthrough) branch 1 taken 24% branch 2 taken 80% (fallthrough) branch 3 taken 20% 46955093: 197: (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c; branch 0 taken 6% (fallthrough) branch 1 taken 94% -: 198: -: 199: } -: 200: break; -: 201: default: 3: 202: state->errcode = IMAGING_CODEC_UNKNOWN; 3: 203: free(context->previous); 3: 204: context->previous = NULL; 3: 205: inflateEnd(&context->z_stream); call 0 returned 100% 3: 206: return -1; -: 207: } -: 208: break; -: 209: case ZIP_TIFF_PREDICTOR: #####: 210: bpp = (state->bits + 7) / 8; #####: 211: for (i = bpp+1; i <= row_len; i++) { branch 0 never executed branch 1 never executed #####: 212: state->buffer[i] += state->buffer[i-bpp]; -: 213: } -: 214: break; -: 215: } -: 216: -: 217: /* Stuff data into the image */ 174467: 218: if (context->interlaced) { branch 0 taken 2% (fallthrough) branch 1 taken 98% 4230: 219: int col = STARTING_COL[context->pass]; 4230: 220: if (state->bits >= 8) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 221: /* Stuff pixels in their correct location, one by one */ 364500: 222: for (i = 0; i < row_len; i += ((state->bits + 7) / 8)) { branch 0 taken 99% branch 1 taken 1% 1093500: 223: state->shuffle((UINT8*) im->image[state->y] + call 0 returned 100% 364500: 224: col * im->pixelsize, 364500: 225: state->buffer + context->prefix + i, 1); 364500: 226: col += COL_INCREMENT[context->pass]; -: 227: } -: 228: } else { -: 229: /* Handle case with more than a pixel in each byte */ #####: 230: int row_bits = ((state->xsize + OFFSET[context->pass]) #####: 231: / COL_INCREMENT[context->pass]) * state->bits; #####: 232: for (i = 0; i < row_bits; i += state->bits) { branch 0 never executed branch 1 never executed #####: 233: UINT8 byte = *(state->buffer + context->prefix + (i / 8)); #####: 234: byte <<= (i % 8); #####: 235: state->shuffle((UINT8*) im->image[state->y] + call 0 never executed #####: 236: col * im->pixelsize, &byte, 1); #####: 237: col += COL_INCREMENT[context->pass]; -: 238: } -: 239: } -: 240: /* Find next valid scanline */ 4230: 241: state->y += ROW_INCREMENT[context->pass]; 8550: 242: while (state->y >= state->ysize || row_len <= 0) { branch 0 taken 2% branch 1 taken 98% (fallthrough) branch 2 taken 0% branch 3 taken 100% 105: 243: context->pass++; 105: 244: if (context->pass == 7) { branch 0 taken 14% (fallthrough) branch 1 taken 86% -: 245: /* Force exit below */ 15: 246: state->y = state->ysize; 15: 247: break; -: 248: } 90: 249: state->y = STARTING_ROW[context->pass]; 180: 250: row_len = get_row_len(state, context->pass); -: 251: /* Since we're moving to the "first" line, the previous line -: 252: * should be black to make filters work correctly */ 90: 253: memset(state->buffer, 0, state->bytes+1); -: 254: } -: 255: } else { 510711: 256: state->shuffle((UINT8*) im->image[state->y + state->yoff] + call 0 returned 100% 170237: 257: state->xoff * im->pixelsize, 170237: 258: state->buffer + context->prefix, -: 259: state->xsize); 170237: 260: state->y++; -: 261: } -: 262: -: 263: /* all inflate output has been consumed */ 174467: 264: context->last_output = 0; -: 265: 174467: 266: if (state->y >= state->ysize || err == Z_STREAM_END) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 0% (fallthrough) branch 3 taken 100% -: 267: -: 268: /* The image and the data should end simultaneously */ -: 269: /* if (state->y < state->ysize || err != Z_STREAM_END) -: 270: state->errcode = IMAGING_CODEC_BROKEN; */ -: 271: 906: 272: free(context->previous); 906: 273: context->previous = NULL; 906: 274: inflateEnd(&context->z_stream); call 0 returned 100% 906: 275: return -1; /* end of file (errcode=0) */ -: 276: -: 277: } -: 278: -: 279: /* Swap buffer pointers */ 173561: 280: ptr = state->buffer; 173561: 281: state->buffer = context->previous; 173561: 282: context->previous = ptr; -: 283: -: 284: } -: 285: 592: 286: return bytes; /* consumed all of it */ -: 287: -: 288:} -: 289: -: 290: function ImagingZipDecodeCleanup called 2032 returned 100% blocks executed 100% 2032: 291:int ImagingZipDecodeCleanup(ImagingCodecState state){ -: 292: /* called to free the decompression engine when the decode terminates -: 293: due to a corrupt or truncated image -: 294: */ 2032: 295: ZIPSTATE* context = (ZIPSTATE*) state->context; -: 296: -: 297: /* Clean up */ 2032: 298: if (context->previous) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 106: 299: inflateEnd(&context->z_stream); call 0 returned 100% 106: 300: free(context->previous); 106: 301: context->previous = NULL; -: 302: } 2032: 303: return -1; -: 304:} -: 305: -: 306:#endif <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#EpsEncode.c.gcov -: 0:Source:src/libImaging/EpsEncode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/EpsEncode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/EpsEncode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * encoder for EPS hex data -: 6: * -: 7: * history: -: 8: * 96-04-19 fl created -: 9: * 96-06-27 fl don't drop last block of encoded data -: 10: * -: 11: * notes: -: 12: * FIXME: rename to HexEncode.c ?? -: 13: * -: 14: * Copyright (c) Fredrik Lundh 1996. -: 15: * Copyright (c) Secret Labs AB 1997. -: 16: * -: 17: * See the README file for information on usage and redistribution. -: 18: */ -: 19: -: 20: -: 21:#include "Imaging.h" -: 22: -: 23: -: 24:int function ImagingEpsEncode called 81 returned 100% blocks executed 100% 81: 25:ImagingEpsEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) -: 26:{ -: 27: enum { HEXBYTE=1, NEWLINE }; 81: 28: const char *hex = "0123456789abcdef"; -: 29: 81: 30: UINT8* ptr = buf; -: 31: UINT8* in, i; -: 32: 81: 33: if (!state->state) { branch 0 taken 25% (fallthrough) branch 1 taken 75% 20: 34: state->state = HEXBYTE; 20: 35: state->xsize *= im->pixelsize; /* Hack! */ -: 36: } -: 37: 81: 38: in = (UINT8*) im->image[state->y]; -: 39: -: 40: for (;;) { -: 41: 2206269: 42: if (state->state == NEWLINE) { branch 0 taken 3% (fallthrough) branch 1 taken 97% 56563: 43: if (bytes < 1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 44: break; -: 45: } 56563: 46: *ptr++ = '\n'; 56563: 47: bytes--; 56563: 48: state->state = HEXBYTE; -: 49: } -: 50: 2206269: 51: if (bytes < 2) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 52: break; -: 53: } -: 54: 2206208: 55: i = in[state->x++]; 2206208: 56: *ptr++ = hex[(i>>4)&15]; 2206208: 57: *ptr++ = hex[i&15]; 2206208: 58: bytes -= 2; -: 59: -: 60: /* Skip junk bytes */ 2206208: 61: if (im->bands == 3 && (state->x & 3) == 3) { branch 0 taken 46% (fallthrough) branch 1 taken 54% branch 2 taken 33% (fallthrough) branch 3 taken 67% 340224: 62: state->x++; -: 63: } -: 64: 2206208: 65: if (++state->count >= 79/2) { branch 0 taken 3% (fallthrough) branch 1 taken 97% 56563: 66: state->state = NEWLINE; 56563: 67: state->count = 0; -: 68: } -: 69: 2206208: 70: if (state->x >= state->xsize) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 3544: 71: state->x = 0; 3544: 72: if (++state->y >= state->ysize) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 20: 73: state->errcode = IMAGING_CODEC_END; 20: 74: break; -: 75: } 3524: 76: in = (UINT8*) im->image[state->y]; -: 77: } -: 78: -: 79: } -: 80: 81: 81: return ptr - buf; -: 82: -: 83:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#QuantHash.c.gcov -: 0:Source:src/libImaging/QuantHash.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/QuantHash.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/QuantHash.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * hash tables used by the image quantizer -: 6: * -: 7: * history: -: 8: * 98-09-10 tjs Contributed -: 9: * 98-12-29 fl Added to PIL 1.0b1 -: 10: * -: 11: * Written by Toby J Sargeant . -: 12: * -: 13: * Copyright (c) 1998 by Toby J Sargeant -: 14: * Copyright (c) 1998 by Secret Labs AB -: 15: * -: 16: * See the README file for information on usage and redistribution. -: 17: */ -: 18: -: 19:#include -: 20:#include -: 21:#include -: 22:#include -: 23: -: 24:#include "QuantHash.h" -: 25: -: 26:typedef struct _HashNode { -: 27: struct _HashNode *next; -: 28: HashKey_t key; -: 29: HashVal_t value; -: 30:} HashNode; -: 31: -: 32:struct _HashTable { -: 33: HashNode **table; -: 34: uint32_t length; -: 35: uint32_t count; -: 36: HashFunc hashFunc; -: 37: HashCmpFunc cmpFunc; -: 38: void *userData; -: 39:}; -: 40: -: 41:#define MIN_LENGTH 11 -: 42:#define RESIZE_FACTOR 3 -: 43: -: 44:static int _hashtable_insert_node(HashTable *,HashNode *,int,int,CollisionFunc); -: 45: function hashtable_new called 24 returned 100% blocks executed 80% 24: 46:HashTable *hashtable_new(HashFunc hf,HashCmpFunc cf) { -: 47: HashTable *h; 24: 48: h=malloc(sizeof(HashTable)); 24: 49: if (!h) { return NULL; } branch 0 taken 100% (fallthrough) branch 1 taken 0% 24: 50: h->hashFunc=hf; 24: 51: h->cmpFunc=cf; 24: 52: h->length=MIN_LENGTH; 24: 53: h->count=0; 24: 54: h->userData=NULL; 24: 55: h->table=malloc(sizeof(HashNode *)*h->length); 24: 56: if (!h->table) { free(h); return NULL; } branch 0 taken 0% (fallthrough) branch 1 taken 100% 48: 57: memset (h->table,0,sizeof(HashNode *)*h->length); 24: 58: return h; -: 59:} -: 60: function _findPrime called 204 returned 100% blocks executed 92% 204: 61:static uint32_t _findPrime(uint32_t start,int dir) { -: 62: static int unit[]={0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0}; -: 63: uint32_t t; 568: 64: while (start>1) { branch 0 taken 100% branch 1 taken 0% (fallthrough) 364: 65: if (!unit[start&0x0f]) { branch 0 taken 56% (fallthrough) branch 1 taken 44% 160: 66: start+=dir; 160: 67: continue; -: 68: } 3338: 69: for (t=2;t=sqrt((double)start)) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 75: break; -: 76: } #####: 77: start+=dir; -: 78: } 204: 79: return start; -: 80:} -: 81: function _hashtable_rehash called 140 returned 100% blocks executed 90% 140: 82:static void _hashtable_rehash(HashTable *h,CollisionFunc cf,uint32_t newSize) { 140: 83: HashNode **oldTable=h->table; -: 84: uint32_t i; -: 85: HashNode *n,*nn; -: 86: uint32_t oldSize; 140: 87: oldSize=h->length; 140: 88: h->table=malloc(sizeof(HashNode *)*newSize); 140: 89: if (!h->table) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 90: h->table=oldTable; #####: 91: return; -: 92: } 140: 93: h->length=newSize; 140: 94: h->count=0; 280: 95: memset (h->table,0,sizeof(HashNode *)*h->length); 78728: 96: for (i=0;inext; 235904: 99: _hashtable_insert_node(h,n,0,0,cf); -: 100: } -: 101: } 140: 102: free(oldTable); -: 103:} -: 104: function _hashtable_resize called 137036 returned 100% blocks executed 100% 137036: 105:static void _hashtable_resize(HashTable *h) { -: 106: uint32_t newSize; -: 107: uint32_t oldSize; 137036: 108: oldSize=h->length; 137036: 109: newSize=oldSize; 137036: 110: if (h->count*RESIZE_FACTORlength) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 64: 111: newSize=_findPrime(h->length/2-1,-1); call 0 returned 100% 136972: 112: } else if (h->length*RESIZE_FACTORcount) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 140: 113: newSize=_findPrime(h->length*2+1,+1); call 0 returned 100% -: 114: } 137036: 115: if (newSizehashFunc(h,node->key)%h->length; call 0 returned 100% -: 123: HashNode **n,*nv; -: 124: int i; -: 125: 324142: 126: for (n=&(h->table[hash]);*n;n=&((*n)->next)) { branch 0 taken 47% branch 1 taken 53% (fallthrough) 153268: 127: nv=*n; 153268: 128: i=h->cmpFunc(h,nv->key,node->key); call 0 returned 100% 153268: 129: if (!i) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 130: if (cf) { branch 0 never executed branch 1 never executed #####: 131: nv->key=node->key; #####: 132: cf(h,&(nv->key),&(nv->value),node->key,node->value); call 0 never executed #####: 133: free(node); #####: 134: return 1; -: 135: } else { #####: 136: nv->key=node->key; #####: 137: nv->value=node->value; #####: 138: free(node); #####: 139: return 1; -: 140: } 153268: 141: } else if (i>0) { branch 0 taken 58% (fallthrough) branch 1 taken 42% -: 142: break; -: 143: } -: 144: } 235904: 145: if (!update) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 235904: 146: node->next=*n; 235904: 147: *n=node; 235904: 148: h->count++; 235904: 149: if (resize) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 150: _hashtable_resize(h); call 0 never executed -: 151: } -: 152: return 1; -: 153: } else { -: 154: return 0; -: 155: } -: 156:} -: 157: function _hashtable_insert called 137036 returned 100% blocks executed 100% 137036: 158:static int _hashtable_insert(HashTable *h,HashKey_t key,HashVal_t val,int resize,int update) { -: 159: HashNode **n,*nv; -: 160: HashNode *t; -: 161: int i; 137036: 162: uint32_t hash=h->hashFunc(h,key)%h->length; call 0 returned 100% -: 163: 278356: 164: for (n=&(h->table[hash]);*n;n=&((*n)->next)) { branch 0 taken 89% branch 1 taken 11% (fallthrough) 248150: 165: nv=*n; 248150: 166: i=h->cmpFunc(h,nv->key,key); call 0 returned 100% 248150: 167: if (!i) { branch 0 taken 28% (fallthrough) branch 1 taken 72% 68518: 168: nv->value=val; 68518: 169: return 1; 179632: 170: } else if (i>0) { branch 0 taken 79% (fallthrough) branch 1 taken 21% -: 171: break; -: 172: } -: 173: } 68518: 174: if (!update) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 68518: 175: t=malloc(sizeof(HashNode)); 68518: 176: if (!t) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 177: return 0; -: 178: } 68518: 179: t->next=*n; 68518: 180: *n=t; 68518: 181: t->key=key; 68518: 182: t->value=val; 68518: 183: h->count++; 68518: 184: if (resize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 68518: 185: _hashtable_resize(h); call 0 returned 100% -: 186: } -: 187: return 1; -: 188: } else { -: 189: return 0; -: 190: } -: 191:} -: 192: function hashtable_insert_or_update_computed called 679268 returned 100% blocks executed 94% 679268: 193:int hashtable_insert_or_update_computed(HashTable *h, -: 194: HashKey_t key, -: 195: ComputeFunc newFunc, -: 196: ComputeFunc existsFunc) { -: 197: HashNode **n,*nv; -: 198: HashNode *t; -: 199: int i; 679268: 200: uint32_t hash=h->hashFunc(h,key)%h->length; call 0 returned 100% -: 201: 1100518: 202: for (n=&(h->table[hash]);*n;n=&((*n)->next)) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 1069889: 203: nv=*n; 1069889: 204: i=h->cmpFunc(h,nv->key,key); call 0 returned 100% 1069889: 205: if (!i) { branch 0 taken 57% (fallthrough) branch 1 taken 43% 610750: 206: if (existsFunc) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 610750: 207: existsFunc(h,nv->key,&(nv->value)); call 0 returned 100% -: 208: } else { -: 209: return 0; -: 210: } 610750: 211: return 1; 459139: 212: } else if (i>0) { branch 0 taken 92% (fallthrough) branch 1 taken 8% -: 213: break; -: 214: } -: 215: } 68518: 216: t=malloc(sizeof(HashNode)); 68518: 217: if (!t) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 218: return 0; -: 219: } 68518: 220: t->key=key; 68518: 221: t->next=*n; 68518: 222: *n=t; 68518: 223: if (newFunc) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 68518: 224: newFunc(h,t->key,&(t->value)); call 0 returned 100% -: 225: } else { #####: 226: free(t); #####: 227: return 0; -: 228: } 68518: 229: h->count++; 68518: 230: _hashtable_resize(h); call 0 returned 100% 68518: 231: return 1; -: 232:} -: 233: function hashtable_insert called 137036 returned 100% blocks executed 100% 137036: 234:int hashtable_insert(HashTable *h,HashKey_t key,HashVal_t val) { 137036: 235: return _hashtable_insert(h,key,val,1,0); call 0 returned 100% -: 236:} -: 237: function hashtable_foreach_update called 0 returned 0% blocks executed 0% #####: 238:void hashtable_foreach_update(HashTable *h,IteratorUpdateFunc i,void *u) { -: 239: HashNode *n; -: 240: uint32_t x; -: 241: #####: 242: if (h->table) { branch 0 never executed branch 1 never executed #####: 243: for (x=0;xlength;x++) { branch 0 never executed branch 1 never executed #####: 244: for (n=h->table[x];n;n=n->next) { branch 0 never executed branch 1 never executed #####: 245: i(h,n->key,&(n->value),u); call 0 never executed -: 246: } -: 247: } -: 248: } #####: 249:} -: 250: function hashtable_foreach called 12 returned 100% blocks executed 100% 12: 251:void hashtable_foreach(HashTable *h,IteratorFunc i,void *u) { -: 252: HashNode *n; -: 253: uint32_t x; -: 254: 12: 255: if (h->table) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 39544: 256: for (x=0;xlength;x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 108062: 257: for (n=h->table[x];n;n=n->next) { branch 0 taken 63% branch 1 taken 37% (fallthrough) 68518: 258: i(h,n->key,n->value,u); call 0 returned 100% -: 259: } -: 260: } -: 261: } 12: 262:} -: 263: function hashtable_free called 24 returned 100% blocks executed 100% 24: 264:void hashtable_free(HashTable *h) { -: 265: HashNode *n,*nn; -: 266: uint32_t i; -: 267: 24: 268: if (h->table) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 79088: 269: for (i=0;ilength;i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 216124: 270: for (n=h->table[i];n;n=nn) { branch 0 taken 63% branch 1 taken 37% (fallthrough) 137036: 271: nn=n->next; 137036: 272: free(n); -: 273: } -: 274: } 24: 275: free(h->table); -: 276: } 24: 277: free(h); 24: 278:} -: 279: function hashtable_rehash_compute called 0 returned 0% blocks executed 0% #####: 280:void hashtable_rehash_compute(HashTable *h,CollisionFunc cf) { #####: 281: _hashtable_rehash(h,cf,h->length); call 0 never executed #####: 282:} -: 283: function hashtable_lookup called 1427054 returned 100% blocks executed 100% 1427054: 284:int hashtable_lookup(const HashTable *h,const HashKey_t key,HashVal_t *valp) { 1427054: 285: uint32_t hash=h->hashFunc(h,key)%h->length; call 0 returned 100% -: 286: HashNode *n; -: 287: int i; -: 288: 2104753: 289: for (n=h->table[hash];n;n=n->next) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 2074547: 290: i=h->cmpFunc(h,n->key,key); call 0 returned 100% 2074547: 291: if (!i) { branch 0 taken 65% (fallthrough) branch 1 taken 35% 1358536: 292: *valp=n->value; 1358536: 293: return 1; 716011: 294: } else if (i>0) { branch 0 taken 95% (fallthrough) branch 1 taken 5% -: 295: break; -: 296: } -: 297: } -: 298: return 0; -: 299:} -: 300: function hashtable_get_count called 679268 returned 100% blocks executed 100% 679268: 301:uint32_t hashtable_get_count(const HashTable *h) { 679268: 302: return h->count; -: 303:} -: 304: function hashtable_get_user_data called 4100384 returned 100% blocks executed 100% 4100384: 305:void *hashtable_get_user_data(const HashTable *h) { 4100384: 306: return h->userData; -: 307:} -: 308: function hashtable_set_user_data called 12 returned 100% blocks executed 100% 12: 309:void *hashtable_set_user_data(HashTable *h,void *data) { 12: 310: void *r=h->userData; 12: 311: h->userData=data; 12: 312: return r; -: 313:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Unpack.c.gcov -: 0:Source:src/libImaging/Unpack.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Unpack.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Unpack.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * code to unpack raw data from various file formats -: 6: * -: 7: * history: -: 8: * 1996-03-07 fl Created (from various decoders) -: 9: * 1996-04-19 fl Added band unpackers -: 10: * 1996-05-12 fl Published RGB unpackers -: 11: * 1996-05-27 fl Added nibble unpacker -: 12: * 1996-12-10 fl Added complete set of PNG unpackers -: 13: * 1996-12-29 fl Set alpha byte in RGB unpackers -: 14: * 1997-01-05 fl Added remaining TGA unpackers -: 15: * 1997-01-18 fl Added inverting band unpackers -: 16: * 1997-01-25 fl Added FlashPix unpackers -: 17: * 1997-05-31 fl Added floating point unpackers -: 18: * 1998-02-08 fl Added I unpacker -: 19: * 1998-07-01 fl Added YCbCr unpacker -: 20: * 1998-07-02 fl Added full set of integer unpackers -: 21: * 1998-12-29 fl Added mode field, I;16 unpackers -: 22: * 1998-12-30 fl Added RGBX modes -: 23: * 1999-02-04 fl Fixed I;16 unpackers -: 24: * 2003-05-13 fl Added L/RGB reversed unpackers -: 25: * 2003-09-26 fl Added LA/PA and RGBa->RGB unpackers -: 26: * -: 27: * Copyright (c) 1997-2003 by Secret Labs AB. -: 28: * Copyright (c) 1996-1997 by Fredrik Lundh. -: 29: * -: 30: * See the README file for information on usage and redistribution. -: 31: */ -: 32: -: 33:#include "Imaging.h" -: 34: -: 35:#define R 0 -: 36:#define G 1 -: 37:#define B 2 -: 38:#define X 3 -: 39: -: 40:#define A 3 -: 41: -: 42:#define C 0 -: 43:#define M 1 -: 44:#define Y 2 -: 45:#define K 3 -: 46: -: 47:/* byte-swapping macros */ -: 48: -: 49:#define C16N\ -: 50: (tmp[0]=in[0], tmp[1]=in[1]); -: 51:#define C16S\ -: 52: (tmp[1]=in[0], tmp[0]=in[1]); -: 53:#define C32N\ -: 54: (tmp[0]=in[0], tmp[1]=in[1], tmp[2]=in[2], tmp[3]=in[3]); -: 55:#define C32S\ -: 56: (tmp[3]=in[0], tmp[2]=in[1], tmp[1]=in[2], tmp[0]=in[3]); -: 57:#define C64N\ -: 58: (tmp[0]=in[0], tmp[1]=in[1], tmp[2]=in[2], tmp[3]=in[3],\ -: 59: tmp[4]=in[4], tmp[5]=in[5], tmp[6]=in[6], tmp[7]=in[7]); -: 60:#define C64S\ -: 61: (tmp[7]=in[0], tmp[6]=in[1], tmp[5]=in[2], tmp[4]=in[3],\ -: 62: tmp[3]=in[4], tmp[2]=in[5], tmp[1]=in[6], tmp[0]=in[7]); -: 63: -: 64:#ifdef WORDS_BIGENDIAN -: 65:#define C16B C16N -: 66:#define C16L C16S -: 67:#define C32B C32N -: 68:#define C32L C32S -: 69:#define C64B C64N -: 70:#define C64L C64S -: 71:#else -: 72:#define C16B C16S -: 73:#define C16L C16N -: 74:#define C32B C32S -: 75:#define C32L C32N -: 76:#define C64B C64S -: 77:#define C64L C64N -: 78:#endif -: 79: -: 80:/* bit-swapping */ -: 81: -: 82:static UINT8 BITFLIP[] = { -: 83: 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, -: 84: 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, -: 85: 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, -: 86: 180, 116, 244, 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, -: 87: 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, -: 88: 210, 50, 178, 114, 242, 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, -: 89: 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, 38, 166, 102, 230, 22, -: 90: 150, 86, 214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, -: 91: 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, -: 92: 225, 17, 145, 81, 209, 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, -: 93: 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, -: 94: 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, -: 95: 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, -: 96: 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, 11, 139, -: 97: 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, 7, -: 98: 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, -: 99: 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, -: 100: 255 -: 101:}; -: 102: -: 103:/* Unpack to "1" image */ -: 104: -: 105:static void function unpack1 called 282690 returned 100% blocks executed 100% 282690: 106:unpack1(UINT8* out, const UINT8* in, int pixels) -: 107:{ -: 108: /* bits (msb first, white is non-zero) */ 2319258: 109: while (pixels > 0) { branch 0 taken 86% branch 1 taken 14% (fallthrough) 1753878: 110: UINT8 byte = *in++; 1753878: 111: switch (pixels) { branch 0 taken 84% branch 1 taken 1% branch 2 taken 1% branch 3 taken 1% branch 4 taken 1% branch 5 taken 1% branch 6 taken 15% branch 7 taken 1% 1479482: 112: default: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; branch 0 taken 58% (fallthrough) branch 1 taken 42% 1480978: 113: case 7: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; branch 0 taken 55% (fallthrough) branch 1 taken 45% 1481466: 114: case 6: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; branch 0 taken 54% (fallthrough) branch 1 taken 46% 1481819: 115: case 5: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; branch 0 taken 57% (fallthrough) branch 1 taken 43% 1481932: 116: case 4: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; branch 0 taken 55% (fallthrough) branch 1 taken 45% 1484000: 117: case 3: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; branch 0 taken 55% (fallthrough) branch 1 taken 45% 1750581: 118: case 2: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; branch 0 taken 60% (fallthrough) branch 1 taken 40% 1753878: 119: case 1: *out++ = (byte & 128) ? 255 : 0; branch 0 taken 61% (fallthrough) branch 1 taken 39% -: 120: } 1753878: 121: pixels -= 8; -: 122: } 282690: 123:} -: 124: -: 125:static void function unpack1I called 2226 returned 100% blocks executed 100% 2226: 126:unpack1I(UINT8* out, const UINT8* in, int pixels) -: 127:{ -: 128: /* bits (msb first, white is zero) */ 148710: 129: while (pixels > 0) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 144258: 130: UINT8 byte = *in++; 144258: 131: switch (pixels) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% branch 4 taken 0% branch 5 taken 0% branch 6 taken 0% branch 7 taken 0% 144258: 132: default: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; branch 0 taken 75% (fallthrough) branch 1 taken 25% 144258: 133: case 7: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; branch 0 taken 75% (fallthrough) branch 1 taken 25% 144258: 134: case 6: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; branch 0 taken 75% (fallthrough) branch 1 taken 25% 144258: 135: case 5: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; branch 0 taken 75% (fallthrough) branch 1 taken 25% 144258: 136: case 4: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; branch 0 taken 75% (fallthrough) branch 1 taken 25% 144258: 137: case 3: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; branch 0 taken 75% (fallthrough) branch 1 taken 25% 144258: 138: case 2: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; branch 0 taken 75% (fallthrough) branch 1 taken 25% 144258: 139: case 1: *out++ = (byte & 128) ? 0 : 255; branch 0 taken 75% (fallthrough) branch 1 taken 25% -: 140: } 144258: 141: pixels -= 8; -: 142: } 2226: 143:} -: 144: -: 145:static void function unpack1R called 1162 returned 100% blocks executed 100% 1162: 146:unpack1R(UINT8* out, const UINT8* in, int pixels) -: 147:{ -: 148: /* bits (lsb first, white is non-zero) */ 129502: 149: while (pixels > 0) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 127178: 150: UINT8 byte = *in++; 127178: 151: switch (pixels) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% branch 4 taken 0% branch 5 taken 0% branch 6 taken 0% branch 7 taken 0% 127178: 152: default: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; branch 0 taken 67% (fallthrough) branch 1 taken 33% 127178: 153: case 7: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; branch 0 taken 67% (fallthrough) branch 1 taken 33% 127178: 154: case 6: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; branch 0 taken 67% (fallthrough) branch 1 taken 33% 127178: 155: case 5: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; branch 0 taken 67% (fallthrough) branch 1 taken 33% 127178: 156: case 4: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; branch 0 taken 67% (fallthrough) branch 1 taken 33% 127178: 157: case 3: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; branch 0 taken 67% (fallthrough) branch 1 taken 33% 127178: 158: case 2: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; branch 0 taken 67% (fallthrough) branch 1 taken 33% 127178: 159: case 1: *out++ = (byte & 1) ? 255 : 0; branch 0 taken 67% (fallthrough) branch 1 taken 33% -: 160: } 127178: 161: pixels -= 8; -: 162: } 1162: 163:} -: 164: -: 165:static void function unpack1IR called 2 returned 100% blocks executed 100% 2: 166:unpack1IR(UINT8* out, const UINT8* in, int pixels) -: 167:{ -: 168: /* bits (lsb first, white is zero) */ 6: 169: while (pixels > 0) { branch 0 taken 50% branch 1 taken 50% (fallthrough) 2: 170: UINT8 byte = *in++; 2: 171: switch (pixels) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% branch 4 taken 0% branch 5 taken 0% branch 6 taken 0% branch 7 taken 0% 2: 172: default: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; branch 0 taken 50% (fallthrough) branch 1 taken 50% 2: 173: case 7: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; branch 0 taken 50% (fallthrough) branch 1 taken 50% 2: 174: case 6: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; branch 0 taken 100% (fallthrough) branch 1 taken 0% 2: 175: case 5: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; branch 0 taken 50% (fallthrough) branch 1 taken 50% 2: 176: case 4: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; branch 0 taken 100% (fallthrough) branch 1 taken 0% 2: 177: case 3: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; branch 0 taken 50% (fallthrough) branch 1 taken 50% 2: 178: case 2: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; branch 0 taken 100% (fallthrough) branch 1 taken 0% 2: 179: case 1: *out++ = (byte & 1) ? 0 : 255; branch 0 taken 50% (fallthrough) branch 1 taken 50% -: 180: } 2: 181: pixels -= 8; -: 182: } 2: 183:} -: 184: -: 185:static void function unpack18 called 51 returned 100% blocks executed 100% 51: 186:unpack18(UINT8* out, const UINT8* in, int pixels) -: 187:{ -: 188: /* Unpack a '|b1' image, which is a numpy boolean. -: 189: 1 == true, 0==false, in bytes */ -: 190: -: 191: int i; 475: 192: for (i = 0; i < pixels; i++) { branch 0 taken 89% branch 1 taken 11% (fallthrough) 424: 193: out[i] = in[i] > 0 ? 255 : 0; branch 0 taken 71% (fallthrough) branch 1 taken 29% -: 194: } 51: 195:} -: 196: -: 197: -: 198: -: 199:/* Unpack to "L" image */ -: 200: -: 201:static void function unpackL2 called 129 returned 100% blocks executed 100% 129: 202:unpackL2(UINT8* out, const UINT8* in, int pixels) -: 203:{ -: 204: /* nibbles (msb first, white is non-zero) */ 4355: 205: while (pixels > 0) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 4097: 206: UINT8 byte = *in++; 4097: 207: switch (pixels) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% 4097: 208: default: *out++ = ((byte >> 6) & 0x03U) * 0x55U; byte <<= 2; 4097: 209: case 3: *out++ = ((byte >> 6) & 0x03U) * 0x55U; byte <<= 2; 4097: 210: case 2: *out++ = ((byte >> 6) & 0x03U) * 0x55U; byte <<= 2; 4097: 211: case 1: *out++ = ((byte >> 6) & 0x03U) * 0x55U; -: 212: } 4097: 213: pixels -= 4; -: 214: } 129: 215:} -: 216: -: 217:static void function unpackL2I called 129 returned 100% blocks executed 100% 129: 218:unpackL2I(UINT8* out, const UINT8* in, int pixels) -: 219:{ -: 220: /* nibbles (msb first, white is zero) */ 4355: 221: while (pixels > 0) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 4097: 222: UINT8 byte = *in++; 4097: 223: switch (pixels) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% 4097: 224: default: *out++ = 0xFFU - (UINT8)(((byte >> 6) & 0x03U) * 0x55U); byte <<= 2; 4097: 225: case 3: *out++ = 0xFFU - (UINT8)(((byte >> 6) & 0x03U) * 0x55U); byte <<= 2; 4097: 226: case 2: *out++ = 0xFFU - (UINT8)(((byte >> 6) & 0x03U) * 0x55U); byte <<= 2; 4097: 227: case 1: *out++ = 0xFFU - (UINT8)(((byte >> 6) & 0x03U) * 0x55U); -: 228: } 4097: 229: pixels -= 4; -: 230: } 129: 231:} -: 232: -: 233:static void function unpackL2R called 129 returned 100% blocks executed 100% 129: 234:unpackL2R(UINT8* out, const UINT8* in, int pixels) -: 235:{ -: 236: /* nibbles (bit order reversed, white is non-zero) */ 4355: 237: while (pixels > 0) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 4097: 238: UINT8 byte = *in++; 4097: 239: byte = BITFLIP[byte]; 4097: 240: switch (pixels) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% 4097: 241: default: *out++ = ((byte >> 6) & 0x03U) * 0x55U; byte <<= 2; 4097: 242: case 3: *out++ = ((byte >> 6) & 0x03U) * 0x55U; byte <<= 2; 4097: 243: case 2: *out++ = ((byte >> 6) & 0x03U) * 0x55U; byte <<= 2; 4097: 244: case 1: *out++ = ((byte >> 6) & 0x03U) * 0x55U; -: 245: } 4097: 246: pixels -= 4; -: 247: } 129: 248:} -: 249: -: 250:static void function unpackL2IR called 129 returned 100% blocks executed 100% 129: 251:unpackL2IR(UINT8* out, const UINT8* in, int pixels) -: 252:{ -: 253: /* nibbles (bit order reversed, white is zero) */ 4355: 254: while (pixels > 0) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 4097: 255: UINT8 byte = *in++; 4097: 256: byte = BITFLIP[byte]; 4097: 257: switch (pixels) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% 4097: 258: default: *out++ = 0xFFU - (UINT8)(((byte >> 6) & 0x03U) * 0x55U); byte <<= 2; 4097: 259: case 3: *out++ = 0xFFU - (UINT8)(((byte >> 6) & 0x03U) * 0x55U); byte <<= 2; 4097: 260: case 2: *out++ = 0xFFU - (UINT8)(((byte >> 6) & 0x03U) * 0x55U); byte <<= 2; 4097: 261: case 1: *out++ = 0xFFU - (UINT8)(((byte >> 6) & 0x03U) * 0x55U); -: 262: } 4097: 263: pixels -= 4; -: 264: } 129: 265:} -: 266: -: 267:static void function unpackL4 called 257 returned 100% blocks executed 100% 257: 268:unpackL4(UINT8* out, const UINT8* in, int pixels) -: 269:{ -: 270: /* nibbles (msb first, white is non-zero) */ 16900: 271: while (pixels > 0) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 16386: 272: UINT8 byte = *in++; 16386: 273: switch (pixels) { branch 0 taken 100% branch 1 taken 0% 16386: 274: default: *out++ = ((byte >> 4) & 0x0FU) * 0x11U; byte <<= 4; 16386: 275: case 1: *out++ = ((byte >> 4) & 0x0FU) * 0x11U; -: 276: } 16386: 277: pixels -= 2; -: 278: } 257: 279:} -: 280: -: 281:static void function unpackL4I called 129 returned 100% blocks executed 100% 129: 282:unpackL4I(UINT8* out, const UINT8* in, int pixels) -: 283:{ -: 284: /* nibbles (msb first, white is zero) */ 8452: 285: while (pixels > 0) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 8194: 286: UINT8 byte = *in++; 8194: 287: switch (pixels) { branch 0 taken 100% branch 1 taken 0% 8194: 288: default: *out++ = 0xFFU - (UINT8)(((byte >> 4) & 0x0FU) * 0x11U); byte <<= 4; 8194: 289: case 1: *out++ = 0xFFU - (UINT8)(((byte >> 4) & 0x0FU) * 0x11U); -: 290: } 8194: 291: pixels -= 2; -: 292: } 129: 293:} -: 294: -: 295:static void function unpackL4R called 129 returned 100% blocks executed 100% 129: 296:unpackL4R(UINT8* out, const UINT8* in, int pixels) -: 297:{ -: 298: /* nibbles (bit order reversed, white is non-zero) */ 8452: 299: while (pixels > 0) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 8194: 300: UINT8 byte = *in++; 8194: 301: byte = BITFLIP[byte]; 8194: 302: switch (pixels) { branch 0 taken 100% branch 1 taken 0% 8194: 303: default: *out++ = ((byte >> 4) & 0x0FU) * 0x11U; byte <<= 4; 8194: 304: case 1: *out++ = ((byte >> 4) & 0x0FU) * 0x11U; -: 305: } 8194: 306: pixels -= 2; -: 307: } 129: 308:} -: 309: -: 310:static void function unpackL4IR called 129 returned 100% blocks executed 100% 129: 311:unpackL4IR(UINT8* out, const UINT8* in, int pixels) -: 312:{ -: 313: /* nibbles (bit order reversed, white is zero) */ 8452: 314: while (pixels > 0) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 8194: 315: UINT8 byte = *in++; 8194: 316: byte = BITFLIP[byte]; 8194: 317: switch (pixels) { branch 0 taken 100% branch 1 taken 0% 8194: 318: default: *out++ = 0xFFU - (UINT8)(((byte >> 4) & 0x0FU) * 0x11U); byte <<= 4; 8194: 319: case 1: *out++ = 0xFFU - (UINT8)(((byte >> 4) & 0x0FU) * 0x11U); -: 320: } 8194: 321: pixels -= 2; -: 322: } 129: 323:} -: 324: -: 325:static void function unpackLA called 2769 returned 100% blocks executed 100% 2769: 326:unpackLA(UINT8* _out, const UINT8* in, int pixels) -: 327:{ -: 328: int i; -: 329: /* LA, pixel interleaved */ 368190: 330: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 365421: 331: UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], in[1]); 365421: 332: memcpy(_out, &iv, sizeof(iv)); 365421: 333: in += 2; _out += 4; -: 334: } 2769: 335:} -: 336: -: 337:static void function unpackLAL called 130 returned 100% blocks executed 100% 130: 338:unpackLAL(UINT8* _out, const UINT8* in, int pixels) -: 339:{ -: 340: int i; -: 341: /* LA, line interleaved */ 16520: 342: for (i = 0; i < pixels; i++, _out+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16390: 343: UINT32 iv = MAKE_UINT32(in[i], in[i], in[i], in[i+pixels]); 16390: 344: memcpy(_out, &iv, sizeof(iv)); -: 345: } 130: 346:} -: 347: -: 348:static void function unpackLI called 1 returned 100% blocks executed 100% 1: 349:unpackLI(UINT8* out, const UINT8* in, int pixels) -: 350:{ -: 351: /* negative */ -: 352: int i; 5: 353: for (i = 0; i < pixels; i++) { branch 0 taken 80% branch 1 taken 20% (fallthrough) 4: 354: out[i] = ~in[i]; -: 355: } 1: 356:} -: 357: -: 358:static void function unpackLR called 2 returned 100% blocks executed 100% 2: 359:unpackLR(UINT8* out, const UINT8* in, int pixels) -: 360:{ -: 361: int i; -: 362: /* RGB, bit reversed */ 10: 363: for (i = 0; i < pixels; i++) { branch 0 taken 80% branch 1 taken 20% (fallthrough) 8: 364: out[i] = BITFLIP[in[i]]; -: 365: } 2: 366:} -: 367: -: 368:static void function unpackL16 called 2 returned 100% blocks executed 100% 2: 369:unpackL16(UINT8* out, const UINT8* in, int pixels) -: 370:{ -: 371: /* int16 (upper byte, little endian) */ -: 372: int i; 8: 373: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 6: 374: out[i] = in[1]; 6: 375: in += 2; -: 376: } 2: 377:} -: 378: -: 379:static void function unpackL16B called 1154 returned 100% blocks executed 100% 1154: 380:unpackL16B(UINT8* out, const UINT8* in, int pixels) -: 381:{ -: 382: int i; -: 383: /* int16 (upper byte, big endian) */ 148616: 384: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 147462: 385: out[i] = in[0]; 147462: 386: in += 2; -: 387: } 1154: 388:} -: 389: -: 390: -: 391:/* Unpack to "P" image */ -: 392: -: 393:static void function unpackP1 called 891 returned 100% blocks executed 100% 891: 394:unpackP1(UINT8* out, const UINT8* in, int pixels) -: 395:{ -: 396: /* bits */ 12623: 397: while (pixels > 0) { branch 0 taken 92% branch 1 taken 8% (fallthrough) 10841: 398: UINT8 byte = *in++; 10841: 399: switch (pixels) { branch 0 taken 95% branch 1 taken 2% branch 2 taken 0% branch 3 taken 0% branch 4 taken 1% branch 5 taken 0% branch 6 taken 1% branch 7 taken 0% 10335: 400: default: *out++ = (byte >> 7) & 1; byte <<= 1; 10591: 401: case 7: *out++ = (byte >> 7) & 1; byte <<= 1; 10591: 402: case 6: *out++ = (byte >> 7) & 1; byte <<= 1; 10591: 403: case 5: *out++ = (byte >> 7) & 1; byte <<= 1; 10691: 404: case 4: *out++ = (byte >> 7) & 1; byte <<= 1; 10691: 405: case 3: *out++ = (byte >> 7) & 1; byte <<= 1; 10841: 406: case 2: *out++ = (byte >> 7) & 1; byte <<= 1; 10841: 407: case 1: *out++ = (byte >> 7) & 1; -: 408: } 10841: 409: pixels -= 8; -: 410: } 891: 411:} -: 412: -: 413:static void function unpackP2 called 194 returned 100% blocks executed 100% 194: 414:unpackP2(UINT8* out, const UINT8* in, int pixels) -: 415:{ -: 416: /* bit pairs */ 6535: 417: while (pixels > 0) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 6147: 418: UINT8 byte = *in++; 6147: 419: switch (pixels) { branch 0 taken 99% branch 1 taken 0% branch 2 taken 1% branch 3 taken 0% 6146: 420: default: *out++ = (byte >> 6) & 3; byte <<= 2; 6146: 421: case 3: *out++ = (byte >> 6) & 3; byte <<= 2; 6147: 422: case 2: *out++ = (byte >> 6) & 3; byte <<= 2; 6147: 423: case 1: *out++ = (byte >> 6) & 3; -: 424: } 6147: 425: pixels -= 4; -: 426: } 194: 427:} -: 428: -: 429:static void function unpackP4 called 21949 returned 100% blocks executed 100% 21949: 430:unpackP4(UINT8* out, const UINT8* in, int pixels) -: 431:{ -: 432: /* nibbles */ 7867084: 433: while (pixels > 0) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 7823186: 434: UINT8 byte = *in++; 7823186: 435: switch (pixels) { branch 0 taken 99% branch 1 taken 1% 7823058: 436: default: *out++ = (byte >> 4) & 15; byte <<= 4; 7823186: 437: case 1: *out++ = (byte >> 4) & 15; -: 438: } 7823186: 439: pixels -= 2; -: 440: } 21949: 441:} -: 442: -: 443:static void function unpackP2L called 0 returned 0% blocks executed 0% #####: 444:unpackP2L(UINT8* out, const UINT8* in, int pixels) -: 445:{ -: 446: int i, j, m, s; -: 447: /* bit layers */ #####: 448: m = 128; #####: 449: s = (pixels+7)/8; #####: 450: for (i = j = 0; i < pixels; i++) { branch 0 never executed branch 1 never executed #####: 451: out[i] = ((in[j] & m) ? 1 : 0) + ((in[j + s] & m) ? 2 : 0); branch 0 never executed branch 1 never executed #####: 452: if ((m >>= 1) == 0) { branch 0 never executed branch 1 never executed #####: 453: m = 128; #####: 454: j++; -: 455: } -: 456: } #####: 457:} -: 458: -: 459:static void function unpackP4L called 0 returned 0% blocks executed 0% #####: 460:unpackP4L(UINT8* out, const UINT8* in, int pixels) -: 461:{ -: 462: int i, j, m, s; -: 463: /* bit layers (trust the optimizer ;-) */ #####: 464: m = 128; #####: 465: s = (pixels+7)/8; #####: 466: for (i = j = 0; i < pixels; i++) { branch 0 never executed branch 1 never executed #####: 467: out[i] = ((in[j] & m) ? 1 : 0) + ((in[j + s] & m) ? 2 : 0) + branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed branch 4 never executed branch 5 never executed #####: 468: ((in[j + 2*s] & m) ? 4 : 0) + ((in[j + 3*s] & m) ? 8 : 0); #####: 469: if ((m >>= 1) == 0) { branch 0 never executed branch 1 never executed #####: 470: m = 128; #####: 471: j++; -: 472: } -: 473: } #####: 474:} -: 475: -: 476: -: 477:/* Unpack to "RGB" image */ -: 478: -: 479:void function ImagingUnpackRGB called 172112 returned 100% blocks executed 100% 172112: 480:ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels) -: 481:{ 172112: 482: int i = 0; -: 483: /* RGB triplets */ 152564539: 484: for (; i < pixels-1; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 485: UINT32 iv; 152392427: 486: memcpy(&iv, in, sizeof(iv)); 152392427: 487: iv |= MASK_UINT32_CHANNEL_3; 152392427: 488: memcpy(_out, &iv, sizeof(iv)); 152392427: 489: in += 3; _out += 4; -: 490: } 172112: 491: for (; i < pixels; i++) { branch 0 taken 50% branch 1 taken 50% (fallthrough) 172112: 492: UINT32 iv = MAKE_UINT32(in[0], in[1], in[2], 255); 172112: 493: memcpy(_out, &iv, sizeof(iv)); 172112: 494: in += 3; _out += 4; -: 495: } 172112: 496:} -: 497: -: 498:void function unpackRGB16L called 1 returned 100% blocks executed 100% 1: 499:unpackRGB16L(UINT8* _out, const UINT8* in, int pixels) -: 500:{ -: 501: int i; -: 502: /* 16-bit RGB triplets, little-endian order */ 3: 503: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 2: 504: UINT32 iv = MAKE_UINT32(in[1], in[3], in[5], 255); 2: 505: memcpy(_out, &iv, sizeof(iv)); 2: 506: in += 6; _out += 4; -: 507: } 1: 508:} -: 509: -: 510:void function unpackRGB16B called 764 returned 100% blocks executed 100% 764: 511:unpackRGB16B(UINT8* _out, const UINT8* in, int pixels) -: 512:{ -: 513: int i; -: 514: /* 16-bit RGB triplets, big-endian order */ 488448: 515: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 487684: 516: UINT32 iv = MAKE_UINT32(in[0], in[2], in[4], 255); 487684: 517: memcpy(_out, &iv, sizeof(iv)); 487684: 518: in += 6; _out += 4; -: 519: } 764: 520:} -: 521: -: 522:static void function unpackRGBL called 2092 returned 100% blocks executed 100% 2092: 523:unpackRGBL(UINT8* _out, const UINT8* in, int pixels) -: 524:{ -: 525: int i; -: 526: /* RGB, line interleaved */ 480882: 527: for (i = 0; i < pixels; i++, _out+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 478790: 528: UINT32 iv = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], 255); 478790: 529: memcpy(_out, &iv, sizeof(iv)); -: 530: } 2092: 531:} -: 532: -: 533:static void function unpackRGBR called 1 returned 100% blocks executed 100% 1: 534:unpackRGBR(UINT8* _out, const UINT8* in, int pixels) -: 535:{ -: 536: int i; -: 537: /* RGB, bit reversed */ 3: 538: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 2: 539: UINT32 iv = MAKE_UINT32(BITFLIP[in[0]], BITFLIP[in[1]], -: 540: BITFLIP[in[2]], 255); 2: 541: memcpy(_out, &iv, sizeof(iv)); 2: 542: in += 3; _out += 4; -: 543: } 1: 544:} -: 545: -: 546:void function ImagingUnpackBGR called 4369 returned 100% blocks executed 100% 4369: 547:ImagingUnpackBGR(UINT8* _out, const UINT8* in, int pixels) -: 548:{ -: 549: int i; -: 550: /* RGB, reversed bytes */ 2322186: 551: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 2317817: 552: UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], 255); 2317817: 553: memcpy(_out, &iv, sizeof(iv)); 2317817: 554: in += 3; _out += 4; -: 555: } 4369: 556:} -: 557: -: 558:void function ImagingUnpackRGB15 called 2 returned 100% blocks executed 100% 2: 559:ImagingUnpackRGB15(UINT8* out, const UINT8* in, int pixels) -: 560:{ -: 561: int i, pixel; -: 562: /* RGB, 5 bits per pixel */ 6: 563: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 4: 564: pixel = in[0] + (in[1] << 8); 4: 565: out[R] = (pixel & 31) * 255 / 31; 4: 566: out[G] = ((pixel>>5) & 31) * 255 / 31; 4: 567: out[B] = ((pixel>>10) & 31) * 255 / 31; 4: 568: out[A] = 255; 4: 569: out += 4; in += 2; -: 570: } 2: 571:} -: 572: -: 573:void function ImagingUnpackRGBA15 called 1 returned 100% blocks executed 100% 1: 574:ImagingUnpackRGBA15(UINT8* out, const UINT8* in, int pixels) -: 575:{ -: 576: int i, pixel; -: 577: /* RGB, 5/5/5/1 bits per pixel */ 3: 578: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 2: 579: pixel = in[0] + (in[1] << 8); 2: 580: out[R] = (pixel & 31) * 255 / 31; 2: 581: out[G] = ((pixel>>5) & 31) * 255 / 31; 2: 582: out[B] = ((pixel>>10) & 31) * 255 / 31; 2: 583: out[A] = (pixel>>15) * 255; 2: 584: out += 4; in += 2; -: 585: } 1: 586:} -: 587: -: 588:void function ImagingUnpackBGR15 called 66 returned 100% blocks executed 100% 66: 589:ImagingUnpackBGR15(UINT8* out, const UINT8* in, int pixels) -: 590:{ -: 591: int i, pixel; -: 592: /* RGB, reversed bytes, 5 bits per pixel */ 8198: 593: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 8132: 594: pixel = in[0] + (in[1] << 8); 8132: 595: out[B] = (pixel & 31) * 255 / 31; 8132: 596: out[G] = ((pixel>>5) & 31) * 255 / 31; 8132: 597: out[R] = ((pixel>>10) & 31) * 255 / 31; 8132: 598: out[A] = 255; 8132: 599: out += 4; in += 2; -: 600: } 66: 601:} -: 602: -: 603:void function ImagingUnpackBGRA15 called 1 returned 100% blocks executed 100% 1: 604:ImagingUnpackBGRA15(UINT8* out, const UINT8* in, int pixels) -: 605:{ -: 606: int i, pixel; -: 607: /* RGB, reversed bytes, 5/5/5/1 bits per pixel */ 3: 608: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 2: 609: pixel = in[0] + (in[1] << 8); 2: 610: out[B] = (pixel & 31) * 255 / 31; 2: 611: out[G] = ((pixel>>5) & 31) * 255 / 31; 2: 612: out[R] = ((pixel>>10) & 31) * 255 / 31; 2: 613: out[A] = (pixel>>15) * 255; 2: 614: out += 4; in += 2; -: 615: } 1: 616:} -: 617: -: 618:void function ImagingUnpackRGB16 called 1 returned 100% blocks executed 100% 1: 619:ImagingUnpackRGB16(UINT8* out, const UINT8* in, int pixels) -: 620:{ -: 621: int i, pixel; -: 622: /* RGB, 5/6/5 bits per pixel */ 3: 623: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 2: 624: pixel = in[0] + (in[1] << 8); 2: 625: out[R] = (pixel & 31) * 255 / 31; 2: 626: out[G] = ((pixel>>5) & 63) * 255 / 63; 2: 627: out[B] = ((pixel>>11) & 31) * 255 / 31; 2: 628: out[A] = 255; 2: 629: out += 4; in += 2; -: 630: } 1: 631:} -: 632: -: 633:void function ImagingUnpackBGR16 called 129 returned 100% blocks executed 100% 129: 634:ImagingUnpackBGR16(UINT8* out, const UINT8* in, int pixels) -: 635:{ -: 636: int i, pixel; -: 637: /* RGB, reversed bytes, 5/6/5 bits per pixel */ 16387: 638: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16258: 639: pixel = in[0] + (in[1] << 8); 16258: 640: out[B] = (pixel & 31) * 255 / 31; 16258: 641: out[G] = ((pixel>>5) & 63) * 255 / 63; 16258: 642: out[R] = ((pixel>>11) & 31) * 255 / 31; 16258: 643: out[A] = 255; 16258: 644: out += 4; in += 2; -: 645: } 129: 646:} -: 647: -: 648:void function ImagingUnpackRGB4B called 2 returned 100% blocks executed 100% 2: 649:ImagingUnpackRGB4B(UINT8* out, const UINT8* in, int pixels) -: 650:{ -: 651: int i, pixel; -: 652: /* RGB, 4 bits per pixel */ 6: 653: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 4: 654: pixel = in[0] + (in[1] << 8); 4: 655: out[R] = (pixel & 15) * 17; 4: 656: out[G] = ((pixel>>4) & 15) * 17; 4: 657: out[B] = ((pixel>>8) & 15) * 17; 4: 658: out[A] = 255; 4: 659: out += 4; in += 2; -: 660: } 2: 661:} -: 662: -: 663:void function ImagingUnpackRGBA4B called 1 returned 100% blocks executed 100% 1: 664:ImagingUnpackRGBA4B(UINT8* out, const UINT8* in, int pixels) -: 665:{ -: 666: int i, pixel; -: 667: /* RGBA, 4 bits per pixel */ 3: 668: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 2: 669: pixel = in[0] + (in[1] << 8); 2: 670: out[R] = (pixel & 15) * 17; 2: 671: out[G] = ((pixel>>4) & 15) * 17; 2: 672: out[B] = ((pixel>>8) & 15) * 17; 2: 673: out[A] = ((pixel>>12) & 15) * 17; 2: 674: out += 4; in += 2; -: 675: } 1: 676:} -: 677: -: 678:static void function ImagingUnpackBGRX called 1417 returned 100% blocks executed 100% 1417: 679:ImagingUnpackBGRX(UINT8* _out, const UINT8* in, int pixels) -: 680:{ -: 681: int i; -: 682: /* RGB, reversed bytes with padding */ 919901: 683: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 918484: 684: UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], 255); 918484: 685: memcpy(_out, &iv, sizeof(iv)); 918484: 686: in += 4; _out += 4; -: 687: } 1417: 688:} -: 689: -: 690:static void function ImagingUnpackXRGB called 2 returned 100% blocks executed 100% 2: 691:ImagingUnpackXRGB(UINT8* _out, const UINT8* in, int pixels) -: 692:{ -: 693: int i; -: 694: /* RGB, leading pad */ 8: 695: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 6: 696: UINT32 iv = MAKE_UINT32(in[1], in[2], in[3], 255); 6: 697: memcpy(_out, &iv, sizeof(iv)); 6: 698: in += 4; _out += 4; -: 699: } 2: 700:} -: 701: -: 702:static void function ImagingUnpackXBGR called 130 returned 100% blocks executed 100% 130: 703:ImagingUnpackXBGR(UINT8* _out, const UINT8* in, int pixels) -: 704:{ -: 705: int i; -: 706: /* RGB, reversed bytes, leading pad */ 16392: 707: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16262: 708: UINT32 iv = MAKE_UINT32(in[3], in[2], in[1], 255); 16262: 709: memcpy(_out, &iv, sizeof(iv)); 16262: 710: in += 4; _out += 4; -: 711: } 130: 712:} -: 713: -: 714:/* Unpack to "RGBA" image */ -: 715: -: 716:static void function unpackRGBALA called 1 returned 100% blocks executed 100% 1: 717:unpackRGBALA(UINT8* _out, const UINT8* in, int pixels) -: 718:{ -: 719: int i; -: 720: /* greyscale with alpha */ 4: 721: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 722: UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], in[1]); 3: 723: memcpy(_out, &iv, sizeof(iv)); 3: 724: in += 2; _out += 4; -: 725: } 1: 726:} -: 727: -: 728:static void function unpackRGBALA16B called 1 returned 100% blocks executed 100% 1: 729:unpackRGBALA16B(UINT8* _out, const UINT8* in, int pixels) -: 730:{ -: 731: int i; -: 732: /* 16-bit greyscale with alpha, big-endian */ 4: 733: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 734: UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], in[2]); 3: 735: memcpy(_out, &iv, sizeof(iv)); 3: 736: in += 4; _out += 4; -: 737: } 1: 738:} -: 739: -: 740:static void function unpackRGBa16L called 2 returned 100% blocks executed 100% 2: 741:unpackRGBa16L(UINT8* _out, const UINT8* in, int pixels) -: 742:{ -: 743: int i; -: 744: /* premultiplied 16-bit RGBA, little-endian */ 7: 745: for (i = 0; i < pixels; i++) { branch 0 taken 71% branch 1 taken 29% (fallthrough) 5: 746: int a = in[7]; -: 747: UINT32 iv; 5: 748: if ( ! a) { branch 0 taken 20% (fallthrough) branch 1 taken 80% 1: 749: iv = 0; 4: 750: } else if (a == 255) { branch 0 taken 25% (fallthrough) branch 1 taken 75% 1: 751: iv = MAKE_UINT32(in[1], in[3], in[5], a); -: 752: } else { 3: 753: iv = MAKE_UINT32(CLIP8(in[1] * 255 / a), branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 754: CLIP8(in[3] * 255 / a), -: 755: CLIP8(in[5] * 255 / a), a); -: 756: } 5: 757: memcpy(_out, &iv, sizeof(iv)); 5: 758: in += 8; _out += 4; -: 759: } 2: 760:} -: 761: -: 762:static void function unpackRGBa16B called 2 returned 100% blocks executed 100% 2: 763:unpackRGBa16B(UINT8* _out, const UINT8* in, int pixels) -: 764:{ -: 765: int i; -: 766: /* premultiplied 16-bit RGBA, big-endian */ 7: 767: for (i = 0; i < pixels; i++) { branch 0 taken 71% branch 1 taken 29% (fallthrough) 5: 768: int a = in[6]; -: 769: UINT32 iv; 5: 770: if ( ! a) { branch 0 taken 20% (fallthrough) branch 1 taken 80% 1: 771: iv = 0; 4: 772: } else if (a == 255) { branch 0 taken 25% (fallthrough) branch 1 taken 75% 1: 773: iv = MAKE_UINT32(in[0], in[2], in[4], a); -: 774: } else { 3: 775: iv = MAKE_UINT32(CLIP8(in[0] * 255 / a), branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 776: CLIP8(in[2] * 255 / a), -: 777: CLIP8(in[4] * 255 / a), a); -: 778: } 5: 779: memcpy(_out, &iv, sizeof(iv)); 5: 780: in += 8; _out += 4; -: 781: } 2: 782:} -: 783: -: 784:static void function unpackRGBa called 45 returned 100% blocks executed 100% 45: 785:unpackRGBa(UINT8* _out, const UINT8* in, int pixels) -: 786:{ -: 787: int i; -: 788: /* premultiplied RGBA */ 2416: 789: for (i = 0; i < pixels; i++) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 2371: 790: int a = in[3]; -: 791: UINT32 iv; 2371: 792: if ( ! a) { branch 0 taken 16% (fallthrough) branch 1 taken 84% 377: 793: iv = 0; 1994: 794: } else if (a == 255) { branch 0 taken 91% (fallthrough) branch 1 taken 9% 1814: 795: iv = MAKE_UINT32(in[0], in[1], in[2], a); -: 796: } else { 180: 797: iv = MAKE_UINT32(CLIP8(in[0] * 255 / a), branch 0 taken 23% (fallthrough) branch 1 taken 77% branch 2 taken 2% (fallthrough) branch 3 taken 98% branch 4 taken 28% (fallthrough) branch 5 taken 72% -: 798: CLIP8(in[1] * 255 / a), -: 799: CLIP8(in[2] * 255 / a), a); -: 800: } 2371: 801: memcpy(_out, &iv, sizeof(iv)); 2371: 802: in += 4; _out += 4; -: 803: } 45: 804:} -: 805: -: 806:static void function unpackRGBaskip1 called 1 returned 100% blocks executed 100% 1: 807:unpackRGBaskip1(UINT8* _out, const UINT8* in, int pixels) -: 808:{ -: 809: int i; 1: 810: UINT32* out = (UINT32*) _out; -: 811: /* premultiplied RGBA */ 4: 812: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 813: int a = in[3]; 3: 814: if ( ! a) { branch 0 taken 33% (fallthrough) branch 1 taken 67% 1: 815: out[i] = 0; 2: 816: } else if (a == 255) { branch 0 taken 50% (fallthrough) branch 1 taken 50% 1: 817: out[i] = MAKE_UINT32(in[0], in[1], in[2], a); -: 818: } else { 1: 819: out[i] = MAKE_UINT32(CLIP8(in[0] * 255 / a), branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 820: CLIP8(in[1] * 255 / a), -: 821: CLIP8(in[2] * 255 / a), a); -: 822: } 3: 823: in += 5; -: 824: } 1: 825:} -: 826: -: 827:static void function unpackRGBaskip2 called 1 returned 100% blocks executed 100% 1: 828:unpackRGBaskip2(UINT8* _out, const UINT8* in, int pixels) -: 829:{ -: 830: int i; 1: 831: UINT32* out = (UINT32*) _out; -: 832: /* premultiplied RGBA */ 4: 833: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 834: int a = in[3]; 3: 835: if ( ! a) { branch 0 taken 33% (fallthrough) branch 1 taken 67% 1: 836: out[i] = 0; 2: 837: } else if (a == 255) { branch 0 taken 50% (fallthrough) branch 1 taken 50% 1: 838: out[i] = MAKE_UINT32(in[0], in[1], in[2], a); -: 839: } else { 1: 840: out[i] = MAKE_UINT32(CLIP8(in[0] * 255 / a), branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 841: CLIP8(in[1] * 255 / a), -: 842: CLIP8(in[2] * 255 / a), a); -: 843: } 3: 844: in += 6; -: 845: } 1: 846:} -: 847: -: 848:static void function unpackBGRa called 2 returned 100% blocks executed 100% 2: 849:unpackBGRa(UINT8* _out, const UINT8* in, int pixels) -: 850:{ -: 851: int i; -: 852: /* premultiplied BGRA */ 7: 853: for (i = 0; i < pixels; i++) { branch 0 taken 71% branch 1 taken 29% (fallthrough) 5: 854: int a = in[3]; -: 855: UINT32 iv; 5: 856: if ( ! a) { branch 0 taken 20% (fallthrough) branch 1 taken 80% 1: 857: iv = 0; 4: 858: } else if (a == 255) { branch 0 taken 25% (fallthrough) branch 1 taken 75% 1: 859: iv = MAKE_UINT32(in[2], in[1], in[0], a); -: 860: } else { 3: 861: iv = MAKE_UINT32(CLIP8(in[2] * 255 / a), branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 862: CLIP8(in[1] * 255 / a), -: 863: CLIP8(in[0] * 255 / a), a); -: 864: } 5: 865: memcpy(_out, &iv, sizeof(iv)); 5: 866: in += 4; _out += 4; -: 867: } 2: 868:} -: 869: -: 870:static void function unpackRGBAI called 1 returned 100% blocks executed 100% 1: 871:unpackRGBAI(UINT8* out, const UINT8* in, int pixels) -: 872:{ -: 873: int i; -: 874: /* RGBA, inverted RGB bytes (FlashPix) */ 4: 875: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 876: out[R] = ~in[0]; 3: 877: out[G] = ~in[1]; 3: 878: out[B] = ~in[2]; 3: 879: out[A] = in[3]; 3: 880: out += 4; in += 4; -: 881: } 1: 882:} -: 883: -: 884:static void function unpackRGBAL called 5 returned 100% blocks executed 100% 5: 885:unpackRGBAL(UINT8* _out, const UINT8* in, int pixels) -: 886:{ -: 887: int i; -: 888: /* RGBA, line interleaved */ 209: 889: for (i = 0; i < pixels; i++, _out+=4) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 204: 890: UINT32 iv = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], -: 891: in[i+pixels+pixels+pixels]); 204: 892: memcpy(_out, &iv, sizeof(iv)); -: 893: } 5: 894:} -: 895: -: 896:void function unpackRGBA16L called 4 returned 100% blocks executed 100% 4: 897:unpackRGBA16L(UINT8* _out, const UINT8* in, int pixels) -: 898:{ -: 899: int i; -: 900: /* 16-bit RGBA, little-endian order */ 12: 901: for (i = 0; i < pixels; i++, _out+=4) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 8: 902: UINT32 iv = MAKE_UINT32(in[1], in[3], in[5], in[7]); 8: 903: memcpy(_out, &iv, sizeof(iv)); 8: 904: in += 8; -: 905: } 4: 906:} -: 907: -: 908:void function unpackRGBA16B called 195 returned 100% blocks executed 100% 195: 909:unpackRGBA16B(UINT8* _out, const UINT8* in, int pixels) -: 910:{ -: 911: int i; -: 912: /* 16-bit RGBA, big-endian order */ 24777: 913: for (i = 0; i < pixels; i++, _out+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 24582: 914: UINT32 iv = MAKE_UINT32(in[0], in[2], in[4], in[6]); 24582: 915: memcpy(_out, &iv, sizeof(iv)); 24582: 916: in += 8; -: 917: } 195: 918:} -: 919: -: 920:static void function unpackARGB called 602 returned 100% blocks executed 100% 602: 921:unpackARGB(UINT8* _out, const UINT8* in, int pixels) -: 922:{ -: 923: int i; -: 924: /* RGBA, leading pad */ 480608: 925: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 480006: 926: UINT32 iv = MAKE_UINT32(in[1], in[2], in[3], in[0]); 480006: 927: memcpy(_out, &iv, sizeof(iv)); 480006: 928: in += 4; _out += 4; -: 929: } 602: 930:} -: 931: -: 932:static void function unpackABGR called 2 returned 100% blocks executed 100% 2: 933:unpackABGR(UINT8* _out, const UINT8* in, int pixels) -: 934:{ -: 935: int i; -: 936: /* RGBA, reversed bytes */ 8: 937: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 6: 938: UINT32 iv = MAKE_UINT32(in[3], in[2], in[1], in[0]); 6: 939: memcpy(_out, &iv, sizeof(iv)); 6: 940: in += 4; _out += 4; -: 941: } 2: 942:} -: 943: -: 944:static void function unpackBGRA called 887 returned 100% blocks executed 100% 887: 945:unpackBGRA(UINT8* _out, const UINT8* in, int pixels) -: 946:{ -: 947: int i; -: 948: /* RGBA, reversed bytes */ 171920: 949: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 171033: 950: UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], in[3]); 171033: 951: memcpy(_out, &iv, sizeof(iv)); 171033: 952: in += 4; _out += 4; -: 953: } 887: 954:} -: 955: -: 956: -: 957:/* Unpack to "CMYK" image */ -: 958: -: 959:static void function unpackCMYKI called 1757 returned 100% blocks executed 100% 1757: 960:unpackCMYKI(UINT8* _out, const UINT8* in, int pixels) -: 961:{ -: 962: int i; -: 963: /* CMYK, inverted bytes (Photoshop 2.5) */ 168144: 964: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 166387: 965: UINT32 iv = ~MAKE_UINT32(in[0], in[1], in[2], in[3]); 166387: 966: memcpy(_out, &iv, sizeof(iv)); 166387: 967: in += 4; _out += 4; -: 968: } 1757: 969:} -: 970: -: 971:/* Unpack to "LAB" image */ -: 972:/* There are two representations of LAB images for whatever precision: -: 973: L: Uint (in PS, it's 0-100) -: 974: A: Int (in ps, -128 .. 128, or elsewhere 0..255, with 128 as middle. -: 975: Channels in PS display a 0 value as middle grey, -: 976: LCMS appears to use 128 as the 0 value for these channels) -: 977: B: Int (as above) -: 978: -: 979: Since we don't have any signed ints, we're going with the shifted versions -: 980: internally, and we'll unshift for saving and whatnot. -: 981:*/ -: 982:void function ImagingUnpackLAB called 415 returned 100% blocks executed 100% 415: 983:ImagingUnpackLAB(UINT8* out, const UINT8* in, int pixels) -: 984:{ -: 985: int i; -: 986: /* LAB triplets */ 49870: 987: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 49455: 988: out[0] = in[0]; 49455: 989: out[1] = in[1] ^ 128; /* signed in outside world */ 49455: 990: out[2] = in[2] ^ 128; 49455: 991: out[3] = 255; 49455: 992: out += 4; in += 3; -: 993: } 415: 994:} -: 995: -: 996:static void function unpackI16N_I16B called 1 returned 100% blocks executed 100% 1: 997:unpackI16N_I16B(UINT8* out, const UINT8* in, int pixels){ -: 998: int i; 1: 999: UINT8* tmp = (UINT8*) out; 4: 1000: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 1001: C16B; 3: 1002: in += 2; tmp += 2; -: 1003: } -: 1004: 1: 1005:} -: 1006:static void function unpackI16N_I16 called 2 returned 100% blocks executed 100% 2: 1007:unpackI16N_I16(UINT8* out, const UINT8* in, int pixels){ -: 1008: int i; 2: 1009: UINT8* tmp = (UINT8*) out; 8: 1010: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 6: 1011: C16L; 6: 1012: in += 2; tmp += 2; -: 1013: } 2: 1014:} -: 1015: -: 1016:static void function unpackI12_I16 called 101 returned 100% blocks executed 100% 101: 1017:unpackI12_I16(UINT8* out, const UINT8* in, int pixels){ -: 1018: /* Fillorder 1/MSB -> LittleEndian, for 12bit integer greyscale tiffs. -: 1019: -: 1020: According to the TIFF spec: -: 1021: -: 1022: FillOrder = 2 should be used only when BitsPerSample = 1 and -: 1023: the data is either uncompressed or compressed using CCITT 1D -: 1024: or 2D compression, to avoid potentially ambiguous situations. -: 1025: -: 1026: Yeah. I thought so. We'll see how well people read the spec. -: 1027: We've got several fillorder=2 modes in TiffImagePlugin.py -: 1028: -: 1029: There's no spec I can find. It appears that the in storage -: 1030: layout is: 00 80 00 ... -> (128 , 0 ...). The samples are -: 1031: stored in a single big bitian 12bit block, but need to be -: 1032: pulled out to little endian format to be stored in a 2 byte -: 1033: int. -: 1034: */ -: 1035: -: 1036: int i; -: 1037: UINT16 pixel; -: 1038:#ifdef WORDS_BIGENDIAN -: 1039: UINT8* tmp = (UINT8 *)&pixel; -: 1040:#endif 5102: 1041: for (i = 0; i < pixels-1; i+=2) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 5001: 1042: pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4); -: 1043:#ifdef WORDS_BIGENDIAN -: 1044: out[0] = tmp[1]; out[1] = tmp[0]; -: 1045:#else 5001: 1046: memcpy(out, &pixel, sizeof(pixel)); -: 1047:#endif -: 1048: 5001: 1049: out+=2; 5001: 1050: pixel = (((UINT16) (in[1] & 0x0F)) << 8) + in[2]; -: 1051:#ifdef WORDS_BIGENDIAN -: 1052: out[0] = tmp[1]; out[1] = tmp[0]; -: 1053:#else 5001: 1054: memcpy(out, &pixel, sizeof(pixel)); -: 1055:#endif -: 1056: 5001: 1057: in += 3; out+=2; -: 1058: } 101: 1059: if (i == pixels-1) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1: 1060: pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4); -: 1061:#ifdef WORDS_BIGENDIAN -: 1062: out[0] = tmp[1]; out[1] = tmp[0]; -: 1063:#else -: 1064: memcpy(out, &pixel, sizeof(pixel)); -: 1065:#endif -: 1066: } 101: 1067:} -: 1068: -: 1069: -: 1070:static void function copy1 called 366649 returned 100% blocks executed 100% 366649: 1071:copy1(UINT8* out, const UINT8* in, int pixels) -: 1072:{ -: 1073: /* L, P */ 733298: 1074: memcpy(out, in, pixels); 366649: 1075:} -: 1076: -: 1077:static void function copy2 called 145 returned 100% blocks executed 100% 145: 1078:copy2(UINT8* out, const UINT8* in, int pixels) -: 1079:{ -: 1080: /* I;16 */ 290: 1081: memcpy(out, in, pixels*2); 145: 1082:} -: 1083: -: 1084:static void function copy4 called 121933 returned 100% blocks executed 100% 121933: 1085:copy4(UINT8* out, const UINT8* in, int pixels) -: 1086:{ -: 1087: /* RGBA, CMYK quadruples */ 243866: 1088: memcpy(out, in, 4 * pixels); 121933: 1089:} -: 1090: -: 1091:static void function copy4skip1 called 3 returned 100% blocks executed 100% 3: 1092:copy4skip1(UINT8* _out, const UINT8* in, int pixels) -: 1093:{ -: 1094: int i; 12: 1095: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 9: 1096: memcpy(_out, in, 4); 9: 1097: in += 5; _out += 4; -: 1098: } 3: 1099:} -: 1100: -: 1101:static void function copy4skip2 called 3 returned 100% blocks executed 100% 3: 1102:copy4skip2(UINT8* _out, const UINT8* in, int pixels) -: 1103:{ -: 1104: int i; 12: 1105: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 9: 1106: memcpy(_out, in, 4); 9: 1107: in += 6; _out += 4; -: 1108: } 3: 1109:} -: 1110: -: 1111: -: 1112:/* Unpack to "I" and "F" images */ -: 1113: -: 1114:#define UNPACK_RAW(NAME, GET, INTYPE, OUTTYPE)\ -: 1115:static void NAME(UINT8* out_, const UINT8* in, int pixels)\ -: 1116:{\ -: 1117: int i;\ -: 1118: OUTTYPE* out = (OUTTYPE*) out_;\ -: 1119: for (i = 0; i < pixels; i++, in += sizeof(INTYPE)) {\ -: 1120: out[i] = (OUTTYPE) ((INTYPE) GET);\ -: 1121: }\ -: 1122:} -: 1123: -: 1124:#define UNPACK(NAME, COPY, INTYPE, OUTTYPE)\ -: 1125:static void NAME(UINT8* out_, const UINT8* in, int pixels)\ -: 1126:{\ -: 1127: int i;\ -: 1128: OUTTYPE* out = (OUTTYPE*) out_;\ -: 1129: INTYPE tmp_;\ -: 1130: UINT8* tmp = (UINT8*) &tmp_;\ -: 1131: for (i = 0; i < pixels; i++, in += sizeof(INTYPE)) {\ -: 1132: COPY;\ -: 1133: out[i] = (OUTTYPE) tmp_;\ -: 1134: }\ -: 1135:} -: 1136: function unpackI8 called 21 returned 100% blocks executed 100% 21: 1137:UNPACK_RAW(unpackI8, in[0], UINT8, INT32) branch 0 taken 91% branch 1 taken 9% (fallthrough) function unpackI8S called 1 returned 100% blocks executed 100% 1: 1138:UNPACK_RAW(unpackI8S, in[0], INT8, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackI16 called 1 returned 100% blocks executed 100% 1: 1139:UNPACK(unpackI16, C16L, UINT16, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackI16S called 31 returned 100% blocks executed 100% 31: 1140:UNPACK(unpackI16S, C16L, INT16, INT32) branch 0 taken 91% branch 1 taken 9% (fallthrough) function unpackI16B called 1685 returned 100% blocks executed 100% 1685: 1141:UNPACK(unpackI16B, C16B, UINT16, INT32) branch 0 taken 99% branch 1 taken 1% (fallthrough) function unpackI16BS called 1 returned 100% blocks executed 100% 1: 1142:UNPACK(unpackI16BS, C16B, INT16, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackI16N called 1 returned 100% blocks executed 100% 1: 1143:UNPACK(unpackI16N, C16N, UINT16, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackI16NS called 1 returned 100% blocks executed 100% 1: 1144:UNPACK(unpackI16NS, C16N, INT16, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackI32 called 21 returned 100% blocks executed 100% 21: 1145:UNPACK(unpackI32, C32L, UINT32, INT32) branch 0 taken 91% branch 1 taken 9% (fallthrough) function unpackI32S called 33 returned 100% blocks executed 100% 33: 1146:UNPACK(unpackI32S, C32L, INT32, INT32) branch 0 taken 97% branch 1 taken 3% (fallthrough) function unpackI32B called 1 returned 100% blocks executed 100% 1: 1147:UNPACK(unpackI32B, C32B, UINT32, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackI32BS called 1 returned 100% blocks executed 100% 1: 1148:UNPACK(unpackI32BS, C32B, INT32, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackI32N called 1 returned 100% blocks executed 100% 1: 1149:UNPACK(unpackI32N, C32N, UINT32, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackI32NS called 1 returned 100% blocks executed 100% 1: 1150:UNPACK(unpackI32NS, C32N, INT32, INT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) -: 1151: function unpackF8 called 1 returned 100% blocks executed 100% 1: 1152:UNPACK_RAW(unpackF8, in[0], UINT8, FLOAT32) branch 0 taken 80% branch 1 taken 20% (fallthrough) function unpackF8S called 1 returned 100% blocks executed 100% 1: 1153:UNPACK_RAW(unpackF8S, in[0], INT8, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF16 called 1 returned 100% blocks executed 100% 1: 1154:UNPACK(unpackF16, C16L, UINT16, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF16S called 1 returned 100% blocks executed 100% 1: 1155:UNPACK(unpackF16S, C16L, INT16, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF16B called 1 returned 100% blocks executed 100% 1: 1156:UNPACK(unpackF16B, C16B, UINT16, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF16BS called 1 returned 100% blocks executed 100% 1: 1157:UNPACK(unpackF16BS, C16B, INT16, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF16N called 1 returned 100% blocks executed 100% 1: 1158:UNPACK(unpackF16N, C16N, UINT16, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF16NS called 1 returned 100% blocks executed 100% 1: 1159:UNPACK(unpackF16NS, C16N, INT16, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF32 called 1 returned 100% blocks executed 100% 1: 1160:UNPACK(unpackF32, C32L, UINT32, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF32S called 1 returned 100% blocks executed 100% 1: 1161:UNPACK(unpackF32S, C32L, INT32, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF32B called 1 returned 100% blocks executed 100% 1: 1162:UNPACK(unpackF32B, C32B, UINT32, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF32BS called 1 returned 100% blocks executed 100% 1: 1163:UNPACK(unpackF32BS, C32B, INT32, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF32N called 1 returned 100% blocks executed 100% 1: 1164:UNPACK(unpackF32N, C32N, UINT32, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF32NS called 1 returned 100% blocks executed 100% 1: 1165:UNPACK(unpackF32NS, C32N, INT32, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF32F called 961 returned 100% blocks executed 100% 961: 1166:UNPACK(unpackF32F, C32L, FLOAT32, FLOAT32) branch 0 taken 99% branch 1 taken 1% (fallthrough) function unpackF32BF called 1 returned 100% blocks executed 100% 1: 1167:UNPACK(unpackF32BF, C32B, FLOAT32, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF32NF called 1 returned 100% blocks executed 100% 1: 1168:UNPACK(unpackF32NF, C32N, FLOAT32, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) -: 1169:#ifdef FLOAT64 function unpackF64F called 41 returned 100% blocks executed 100% 41: 1170:UNPACK(unpackF64F, C64L, FLOAT64, FLOAT32) branch 0 taken 91% branch 1 taken 9% (fallthrough) function unpackF64BF called 1 returned 100% blocks executed 100% 1: 1171:UNPACK(unpackF64BF, C64B, FLOAT64, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) function unpackF64NF called 1 returned 100% blocks executed 100% 1: 1172:UNPACK(unpackF64NF, C64N, FLOAT64, FLOAT32) branch 0 taken 67% branch 1 taken 33% (fallthrough) -: 1173:#endif -: 1174: -: 1175: -: 1176:/* Misc. unpackers */ -: 1177: -: 1178:static void function band0 called 6158 returned 100% blocks executed 100% 6158: 1179:band0(UINT8* out, const UINT8* in, int pixels) -: 1180:{ -: 1181: int i; -: 1182: /* band 0 only */ 835516: 1183: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 829358: 1184: out[0] = in[i]; 829358: 1185: out += 4; -: 1186: } 6158: 1187:} -: 1188: -: 1189:static void function band1 called 6158 returned 100% blocks executed 100% 6158: 1190:band1(UINT8* out, const UINT8* in, int pixels) -: 1191:{ -: 1192: int i; -: 1193: /* band 1 only */ 835516: 1194: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 829358: 1195: out[1] = in[i]; 829358: 1196: out += 4; -: 1197: } 6158: 1198:} -: 1199: -: 1200:static void function band2 called 6158 returned 100% blocks executed 100% 6158: 1201:band2(UINT8* out, const UINT8* in, int pixels) -: 1202:{ -: 1203: int i; -: 1204: /* band 2 only */ 835516: 1205: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 829358: 1206: out[2] = in[i]; 829358: 1207: out += 4; -: 1208: } 6158: 1209:} -: 1210: -: 1211:static void function band3 called 409 returned 100% blocks executed 100% 409: 1212:band3(UINT8* out, const UINT8* in, int pixels) -: 1213:{ -: 1214: /* band 3 only */ -: 1215: int i; 63186: 1216: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 62777: 1217: out[3] = in[i]; 62777: 1218: out += 4; -: 1219: } 409: 1220:} -: 1221: -: 1222:static void function band0I called 1 returned 100% blocks executed 100% 1: 1223:band0I(UINT8* out, const UINT8* in, int pixels) -: 1224:{ -: 1225: int i; -: 1226: /* band 0 only */ 4: 1227: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 1228: out[0] = ~in[i]; 3: 1229: out += 4; -: 1230: } 1: 1231:} -: 1232: -: 1233:static void function band1I called 1 returned 100% blocks executed 100% 1: 1234:band1I(UINT8* out, const UINT8* in, int pixels) -: 1235:{ -: 1236: int i; -: 1237: /* band 1 only */ 4: 1238: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 1239: out[1] = ~in[i]; 3: 1240: out += 4; -: 1241: } 1: 1242:} -: 1243: -: 1244:static void function band2I called 1 returned 100% blocks executed 100% 1: 1245:band2I(UINT8* out, const UINT8* in, int pixels) -: 1246:{ -: 1247: int i; -: 1248: /* band 2 only */ 4: 1249: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 1250: out[2] = ~in[i]; 3: 1251: out += 4; -: 1252: } 1: 1253:} -: 1254: -: 1255:static void function band3I called 1 returned 100% blocks executed 100% 1: 1256:band3I(UINT8* out, const UINT8* in, int pixels) -: 1257:{ -: 1258: /* band 3 only */ -: 1259: int i; 4: 1260: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 1261: out[3] = ~in[i]; 3: 1262: out += 4; -: 1263: } 1: 1264:} -: 1265: -: 1266:static struct { -: 1267: const char* mode; -: 1268: const char* rawmode; -: 1269: int bits; -: 1270: ImagingShuffler unpack; -: 1271:} unpackers[] = { -: 1272: -: 1273: /* raw mode syntax is ";" where "bits" defaults -: 1274: depending on mode (1 for "1", 8 for "P" and "L", etc), and -: 1275: "flags" should be given in alphabetical order. if both bits -: 1276: and flags have their default values, the ; should be left out */ -: 1277: -: 1278: /* flags: "I" inverted data; "R" reversed bit order; "B" big -: 1279: endian byte order (default is little endian); "L" line -: 1280: interleave, "S" signed, "F" floating point */ -: 1281: -: 1282: /* exception: rawmodes "I" and "F" are always native endian byte order */ -: 1283: -: 1284: /* bilevel */ -: 1285: {"1", "1", 1, unpack1}, -: 1286: {"1", "1;I", 1, unpack1I}, -: 1287: {"1", "1;R", 1, unpack1R}, -: 1288: {"1", "1;IR", 1, unpack1IR}, -: 1289: {"1", "1;8", 8, unpack18}, -: 1290: -: 1291: /* greyscale */ -: 1292: {"L", "L;2", 2, unpackL2}, -: 1293: {"L", "L;2I", 2, unpackL2I}, -: 1294: {"L", "L;2R", 2, unpackL2R}, -: 1295: {"L", "L;2IR", 2, unpackL2IR}, -: 1296: -: 1297: {"L", "L;4", 4, unpackL4}, -: 1298: {"L", "L;4I", 4, unpackL4I}, -: 1299: {"L", "L;4R", 4, unpackL4R}, -: 1300: {"L", "L;4IR", 4, unpackL4IR}, -: 1301: -: 1302: {"L", "L", 8, copy1}, -: 1303: {"L", "L;I", 8, unpackLI}, -: 1304: {"L", "L;R", 8, unpackLR}, -: 1305: {"L", "L;16", 16, unpackL16}, -: 1306: {"L", "L;16B", 16, unpackL16B}, -: 1307: -: 1308: /* greyscale w. alpha */ -: 1309: {"LA", "LA", 16, unpackLA}, -: 1310: {"LA", "LA;L", 16, unpackLAL}, -: 1311: -: 1312: /* greyscale w. alpha premultiplied */ -: 1313: {"La", "La", 16, unpackLA}, -: 1314: -: 1315: /* palette */ -: 1316: {"P", "P;1", 1, unpackP1}, -: 1317: {"P", "P;2", 2, unpackP2}, -: 1318: {"P", "P;2L", 2, unpackP2L}, -: 1319: {"P", "P;4", 4, unpackP4}, -: 1320: {"P", "P;4L", 4, unpackP4L}, -: 1321: {"P", "P", 8, copy1}, -: 1322: {"P", "P;R", 8, unpackLR}, -: 1323: -: 1324: /* palette w. alpha */ -: 1325: {"PA", "PA", 16, unpackLA}, -: 1326: {"PA", "PA;L", 16, unpackLAL}, -: 1327: -: 1328: /* true colour */ -: 1329: {"RGB", "RGB", 24, ImagingUnpackRGB}, -: 1330: {"RGB", "RGB;L", 24, unpackRGBL}, -: 1331: {"RGB", "RGB;R", 24, unpackRGBR}, -: 1332: {"RGB", "RGB;16L", 48, unpackRGB16L}, -: 1333: {"RGB", "RGB;16B", 48, unpackRGB16B}, -: 1334: {"RGB", "BGR", 24, ImagingUnpackBGR}, -: 1335: {"RGB", "RGB;15", 16, ImagingUnpackRGB15}, -: 1336: {"RGB", "BGR;15", 16, ImagingUnpackBGR15}, -: 1337: {"RGB", "RGB;16", 16, ImagingUnpackRGB16}, -: 1338: {"RGB", "BGR;16", 16, ImagingUnpackBGR16}, -: 1339: {"RGB", "RGB;4B", 16, ImagingUnpackRGB4B}, -: 1340: {"RGB", "BGR;5", 16, ImagingUnpackBGR15}, /* compat */ -: 1341: {"RGB", "RGBX", 32, copy4}, -: 1342: {"RGB", "RGBX;L", 32, unpackRGBAL}, -: 1343: {"RGB", "RGBA;L", 32, unpackRGBAL}, -: 1344: {"RGB", "BGRX", 32, ImagingUnpackBGRX}, -: 1345: {"RGB", "XRGB", 32, ImagingUnpackXRGB}, -: 1346: {"RGB", "XBGR", 32, ImagingUnpackXBGR}, -: 1347: {"RGB", "YCC;P", 24, ImagingUnpackYCC}, -: 1348: {"RGB", "R", 8, band0}, -: 1349: {"RGB", "G", 8, band1}, -: 1350: {"RGB", "B", 8, band2}, -: 1351: -: 1352: /* true colour w. alpha */ -: 1353: {"RGBA", "LA", 16, unpackRGBALA}, -: 1354: {"RGBA", "LA;16B", 32, unpackRGBALA16B}, -: 1355: {"RGBA", "RGBA", 32, copy4}, -: 1356: {"RGBA", "RGBAX", 40, copy4skip1}, -: 1357: {"RGBA", "RGBAXX", 48, copy4skip2}, -: 1358: {"RGBA", "RGBa", 32, unpackRGBa}, -: 1359: {"RGBA", "RGBaX", 40, unpackRGBaskip1}, -: 1360: {"RGBA", "RGBaXX", 48, unpackRGBaskip2}, -: 1361: {"RGBA", "RGBa;16L", 64, unpackRGBa16L}, -: 1362: {"RGBA", "RGBa;16B", 64, unpackRGBa16B}, -: 1363: {"RGBA", "BGRa", 32, unpackBGRa}, -: 1364: {"RGBA", "RGBA;I", 32, unpackRGBAI}, -: 1365: {"RGBA", "RGBA;L", 32, unpackRGBAL}, -: 1366: {"RGBA", "RGBA;15", 16, ImagingUnpackRGBA15}, -: 1367: {"RGBA", "BGRA;15", 16, ImagingUnpackBGRA15}, -: 1368: {"RGBA", "RGBA;4B", 16, ImagingUnpackRGBA4B}, -: 1369: {"RGBA", "RGBA;16L", 64, unpackRGBA16L}, -: 1370: {"RGBA", "RGBA;16B", 64, unpackRGBA16B}, -: 1371: {"RGBA", "BGRA", 32, unpackBGRA}, -: 1372: {"RGBA", "ARGB", 32, unpackARGB}, -: 1373: {"RGBA", "ABGR", 32, unpackABGR}, -: 1374: {"RGBA", "YCCA;P", 32, ImagingUnpackYCCA}, -: 1375: {"RGBA", "R", 8, band0}, -: 1376: {"RGBA", "G", 8, band1}, -: 1377: {"RGBA", "B", 8, band2}, -: 1378: {"RGBA", "A", 8, band3}, -: 1379: -: 1380:#ifdef WORDS_BIGENDIAN -: 1381: {"RGB", "RGB;16N", 48, unpackRGB16B}, -: 1382: {"RGBA", "RGBa;16N", 64, unpackRGBa16B}, -: 1383: {"RGBA", "RGBA;16N", 64, unpackRGBA16B}, -: 1384: {"RGBX", "RGBX;16N", 64, unpackRGBA16B}, -: 1385:#else -: 1386: {"RGB", "RGB;16N", 48, unpackRGB16L}, -: 1387: {"RGBA", "RGBa;16N", 64, unpackRGBa16L}, -: 1388: {"RGBA", "RGBA;16N", 64, unpackRGBA16L}, -: 1389: {"RGBX", "RGBX;16N", 64, unpackRGBA16B}, -: 1390:#endif -: 1391: -: 1392: /* true colour w. alpha premultiplied */ -: 1393: {"RGBa", "RGBa", 32, copy4}, -: 1394: {"RGBa", "BGRa", 32, unpackBGRA}, -: 1395: {"RGBa", "aRGB", 32, unpackARGB}, -: 1396: {"RGBa", "aBGR", 32, unpackABGR}, -: 1397: -: 1398: /* true colour w. padding */ -: 1399: {"RGBX", "RGB", 24, ImagingUnpackRGB}, -: 1400: {"RGBX", "RGB;L", 24, unpackRGBL}, -: 1401: {"RGBX", "RGB;16B", 48, unpackRGB16B}, -: 1402: {"RGBX", "BGR", 24, ImagingUnpackBGR}, -: 1403: {"RGBX", "RGB;15", 16, ImagingUnpackRGB15}, -: 1404: {"RGBX", "BGR;15", 16, ImagingUnpackBGR15}, -: 1405: {"RGBX", "RGB;4B", 16, ImagingUnpackRGB4B}, -: 1406: {"RGBX", "BGR;5", 16, ImagingUnpackBGR15}, /* compat */ -: 1407: {"RGBX", "RGBX", 32, copy4}, -: 1408: {"RGBX", "RGBXX", 40, copy4skip1}, -: 1409: {"RGBX", "RGBXXX", 48, copy4skip2}, -: 1410: {"RGBX", "RGBX;L", 32, unpackRGBAL}, -: 1411: {"RGBX", "RGBX;16L", 64, unpackRGBA16L}, -: 1412: {"RGBX", "RGBX;16B", 64, unpackRGBA16B}, -: 1413: {"RGBX", "BGRX", 32, ImagingUnpackBGRX}, -: 1414: {"RGBX", "XRGB", 32, ImagingUnpackXRGB}, -: 1415: {"RGBX", "XBGR", 32, ImagingUnpackXBGR}, -: 1416: {"RGBX", "YCC;P", 24, ImagingUnpackYCC}, -: 1417: {"RGBX", "R", 8, band0}, -: 1418: {"RGBX", "G", 8, band1}, -: 1419: {"RGBX", "B", 8, band2}, -: 1420: {"RGBX", "X", 8, band3}, -: 1421: -: 1422: /* colour separation */ -: 1423: {"CMYK", "CMYK", 32, copy4}, -: 1424: {"CMYK", "CMYKX", 40, copy4skip1}, -: 1425: {"CMYK", "CMYKXX", 48, copy4skip2}, -: 1426: {"CMYK", "CMYK;I", 32, unpackCMYKI}, -: 1427: {"CMYK", "CMYK;L", 32, unpackRGBAL}, -: 1428: {"CMYK", "CMYK;16L", 64, unpackRGBA16L}, -: 1429: {"CMYK", "CMYK;16B", 64, unpackRGBA16B}, -: 1430: {"CMYK", "C", 8, band0}, -: 1431: {"CMYK", "M", 8, band1}, -: 1432: {"CMYK", "Y", 8, band2}, -: 1433: {"CMYK", "K", 8, band3}, -: 1434: {"CMYK", "C;I", 8, band0I}, -: 1435: {"CMYK", "M;I", 8, band1I}, -: 1436: {"CMYK", "Y;I", 8, band2I}, -: 1437: {"CMYK", "K;I", 8, band3I}, -: 1438: -: 1439:#ifdef WORDS_BIGENDIAN -: 1440: {"CMYK", "CMYK;16N", 64, unpackRGBA16B}, -: 1441:#else -: 1442: {"CMYK", "CMYK;16N", 64, unpackRGBA16L}, -: 1443:#endif -: 1444: -: 1445: /* video (YCbCr) */ -: 1446: {"YCbCr", "YCbCr", 24, ImagingUnpackRGB}, -: 1447: {"YCbCr", "YCbCr;L", 24, unpackRGBL}, -: 1448: {"YCbCr", "YCbCrX", 32, copy4}, -: 1449: {"YCbCr", "YCbCrK", 32, copy4}, -: 1450: -: 1451: /* LAB Color */ -: 1452: {"LAB", "LAB", 24, ImagingUnpackLAB}, -: 1453: {"LAB", "L", 8, band0}, -: 1454: {"LAB", "A", 8, band1}, -: 1455: {"LAB", "B", 8, band2}, -: 1456: -: 1457: /* HSV Color */ -: 1458: {"HSV", "HSV", 24, ImagingUnpackRGB}, -: 1459: {"HSV", "H", 8, band0}, -: 1460: {"HSV", "S", 8, band1}, -: 1461: {"HSV", "V", 8, band2}, -: 1462: -: 1463: /* integer variations */ -: 1464: {"I", "I", 32, copy4}, -: 1465: {"I", "I;8", 8, unpackI8}, -: 1466: {"I", "I;8S", 8, unpackI8S}, -: 1467: {"I", "I;16", 16, unpackI16}, -: 1468: {"I", "I;16S", 16, unpackI16S}, -: 1469: {"I", "I;16B", 16, unpackI16B}, -: 1470: {"I", "I;16BS", 16, unpackI16BS}, -: 1471: {"I", "I;16N", 16, unpackI16N}, -: 1472: {"I", "I;16NS", 16, unpackI16NS}, -: 1473: {"I", "I;32", 32, unpackI32}, -: 1474: {"I", "I;32S", 32, unpackI32S}, -: 1475: {"I", "I;32B", 32, unpackI32B}, -: 1476: {"I", "I;32BS", 32, unpackI32BS}, -: 1477: {"I", "I;32N", 32, unpackI32N}, -: 1478: {"I", "I;32NS", 32, unpackI32NS}, -: 1479: -: 1480: /* floating point variations */ -: 1481: {"F", "F", 32, copy4}, -: 1482: {"F", "F;8", 8, unpackF8}, -: 1483: {"F", "F;8S", 8, unpackF8S}, -: 1484: {"F", "F;16", 16, unpackF16}, -: 1485: {"F", "F;16S", 16, unpackF16S}, -: 1486: {"F", "F;16B", 16, unpackF16B}, -: 1487: {"F", "F;16BS", 16, unpackF16BS}, -: 1488: {"F", "F;16N", 16, unpackF16N}, -: 1489: {"F", "F;16NS", 16, unpackF16NS}, -: 1490: {"F", "F;32", 32, unpackF32}, -: 1491: {"F", "F;32S", 32, unpackF32S}, -: 1492: {"F", "F;32B", 32, unpackF32B}, -: 1493: {"F", "F;32BS", 32, unpackF32BS}, -: 1494: {"F", "F;32N", 32, unpackF32N}, -: 1495: {"F", "F;32NS", 32, unpackF32NS}, -: 1496: {"F", "F;32F", 32, unpackF32F}, -: 1497: {"F", "F;32BF", 32, unpackF32BF}, -: 1498: {"F", "F;32NF", 32, unpackF32NF}, -: 1499:#ifdef FLOAT64 -: 1500: {"F", "F;64F", 64, unpackF64F}, -: 1501: {"F", "F;64BF", 64, unpackF64BF}, -: 1502: {"F", "F;64NF", 64, unpackF64NF}, -: 1503:#endif -: 1504: -: 1505: /* storage modes */ -: 1506: {"I;16", "I;16", 16, copy2}, -: 1507: {"I;16B", "I;16B", 16, copy2}, -: 1508: {"I;16L", "I;16L", 16, copy2}, -: 1509: -: 1510: {"I;16", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian. -: 1511: {"I;16L", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian. -: 1512: {"I;16B", "I;16N", 16, unpackI16N_I16B}, -: 1513: -: 1514: {"I;16", "I;12", 12, unpackI12_I16}, // 12 bit Tiffs stored in 16bits. -: 1515: -: 1516: {NULL} /* sentinel */ -: 1517:}; -: 1518: -: 1519: -: 1520:ImagingShuffler function ImagingFindUnpacker called 17246 returned 100% blocks executed 100% 17246: 1521:ImagingFindUnpacker(const char* mode, const char* rawmode, int* bits_out) -: 1522:{ -: 1523: int i; -: 1524: -: 1525: /* find a suitable pixel unpacker */ 164517: 1526: for (i = 0; unpackers[i].rawmode; i++) { branch 0 taken 100% branch 1 taken 0% (fallthrough) 199732: 1527: if (strcmp(unpackers[i].mode, mode) == 0 && branch 0 taken 21% (fallthrough) branch 1 taken 79% branch 2 taken 49% (fallthrough) branch 3 taken 51% 35215: 1528: strcmp(unpackers[i].rawmode, rawmode) == 0) { 17246: 1529: if (bits_out) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 17246: 1530: *bits_out = unpackers[i].bits; -: 1531: } 17246: 1532: return unpackers[i].unpack; -: 1533: } -: 1534: } -: 1535: -: 1536: /* FIXME: configure a general unpacker based on the type codes... */ -: 1537: -: 1538: return NULL; -: 1539:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#map.c.gcov -: 0:Source:src/map.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/map.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/map.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * -: 4: * standard memory mapping interface for the Imaging library -: 5: * -: 6: * history: -: 7: * 1998-03-05 fl added Win32 read mapping -: 8: * 1999-02-06 fl added "I;16" support -: 9: * 2003-04-21 fl added PyImaging_MapBuffer primitive -: 10: * -: 11: * Copyright (c) 1998-2003 by Secret Labs AB. -: 12: * Copyright (c) 2003 by Fredrik Lundh. -: 13: * -: 14: * See the README file for information on usage and redistribution. -: 15: */ -: 16: -: 17:/* -: 18: * FIXME: should move the memory mapping primitives into libImaging! -: 19: */ -: 20: -: 21:#include "Python.h" -: 22: -: 23:#include "libImaging/Imaging.h" -: 24: -: 25:/* compatibility wrappers (defined in _imaging.c) */ -: 26:extern int PyImaging_CheckBuffer(PyObject* buffer); -: 27:extern int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view); -: 28: -: 29:/* -------------------------------------------------------------------- */ -: 30:/* Standard mapper */ -: 31: -: 32:typedef struct { -: 33: PyObject_HEAD -: 34: char* base; -: 35: int size; -: 36: int offset; -: 37:#ifdef _WIN32 -: 38: HANDLE hFile; -: 39: HANDLE hMap; -: 40:#endif -: 41:} ImagingMapperObject; -: 42: -: 43:static PyTypeObject ImagingMapperType; -: 44: -: 45:ImagingMapperObject* function PyImaging_MapperNew called 0 returned 0% blocks executed 0% #####: 46:PyImaging_MapperNew(const char* filename, int readonly) -: 47:{ -: 48: ImagingMapperObject *mapper; -: 49: #####: 50: if (PyType_Ready(&ImagingMapperType) < 0) { call 0 never executed branch 1 never executed branch 2 never executed -: 51: return NULL; -: 52: } -: 53: #####: 54: mapper = PyObject_New(ImagingMapperObject, &ImagingMapperType); call 0 never executed #####: 55: if (mapper == NULL) { branch 0 never executed branch 1 never executed -: 56: return NULL; -: 57: } -: 58: #####: 59: mapper->base = NULL; #####: 60: mapper->size = mapper->offset = 0; -: 61: -: 62:#ifdef _WIN32 -: 63: mapper->hFile = (HANDLE)-1; -: 64: mapper->hMap = (HANDLE)-1; -: 65: -: 66: /* FIXME: currently supports readonly mappings only */ -: 67: mapper->hFile = CreateFile( -: 68: filename, -: 69: GENERIC_READ, -: 70: FILE_SHARE_READ, -: 71: NULL, OPEN_EXISTING, -: 72: FILE_ATTRIBUTE_NORMAL, -: 73: NULL); -: 74: if (mapper->hFile == (HANDLE)-1) { -: 75: PyErr_SetString(PyExc_OSError, "cannot open file"); -: 76: Py_DECREF(mapper); -: 77: return NULL; -: 78: } -: 79: -: 80: mapper->hMap = CreateFileMapping( -: 81: mapper->hFile, NULL, -: 82: PAGE_READONLY, -: 83: 0, 0, NULL); -: 84: if (mapper->hMap == (HANDLE)-1) { -: 85: CloseHandle(mapper->hFile); -: 86: PyErr_SetString(PyExc_OSError, "cannot map file"); -: 87: Py_DECREF(mapper); -: 88: return NULL; -: 89: } -: 90: -: 91: mapper->base = (char*) MapViewOfFile( -: 92: mapper->hMap, -: 93: FILE_MAP_READ, -: 94: 0, 0, 0); -: 95: -: 96: mapper->size = GetFileSize(mapper->hFile, 0); -: 97:#endif -: 98: #####: 99: return mapper; -: 100:} -: 101: -: 102:static void function mapping_dealloc called 0 returned 0% blocks executed 0% #####: 103:mapping_dealloc(ImagingMapperObject* mapper) -: 104:{ -: 105:#ifdef _WIN32 -: 106: if (mapper->base != 0) { -: 107: UnmapViewOfFile(mapper->base); -: 108: } -: 109: if (mapper->hMap != (HANDLE)-1) { -: 110: CloseHandle(mapper->hMap); -: 111: } -: 112: if (mapper->hFile != (HANDLE)-1) { -: 113: CloseHandle(mapper->hFile); -: 114: } -: 115: mapper->base = 0; -: 116: mapper->hMap = mapper->hFile = (HANDLE)-1; -: 117:#endif #####: 118: PyObject_Del(mapper); call 0 never executed #####: 119:} -: 120: -: 121:/* -------------------------------------------------------------------- */ -: 122:/* standard file operations */ -: 123: -: 124:static PyObject* function mapping_read called 0 returned 0% blocks executed 0% #####: 125:mapping_read(ImagingMapperObject* mapper, PyObject* args) -: 126:{ -: 127: PyObject* buf; -: 128: #####: 129: int size = -1; #####: 130: if (!PyArg_ParseTuple(args, "|i", &size)) { call 0 never executed branch 1 never executed branch 2 never executed -: 131: return NULL; -: 132: } -: 133: -: 134: /* check size */ #####: 135: if (size < 0 || mapper->offset + size > mapper->size) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 136: size = mapper->size - mapper->offset; -: 137: } #####: 138: if (size < 0) { branch 0 never executed branch 1 never executed #####: 139: size = 0; -: 140: } -: 141: #####: 142: buf = PyBytes_FromStringAndSize(NULL, size); call 0 never executed #####: 143: if (!buf) { branch 0 never executed branch 1 never executed -: 144: return NULL; -: 145: } -: 146: #####: 147: if (size > 0) { branch 0 never executed branch 1 never executed #####: 148: memcpy(PyBytes_AsString(buf), mapper->base + mapper->offset, size); call 0 never executed #####: 149: mapper->offset += size; -: 150: } -: 151: -: 152: return buf; -: 153:} -: 154: -: 155:static PyObject* function mapping_seek called 0 returned 0% blocks executed 0% #####: 156:mapping_seek(ImagingMapperObject* mapper, PyObject* args) -: 157:{ -: 158: int offset; #####: 159: int whence = 0; #####: 160: if (!PyArg_ParseTuple(args, "i|i", &offset, &whence)) { call 0 never executed branch 1 never executed branch 2 never executed -: 161: return NULL; -: 162: } -: 163: #####: 164: switch (whence) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed -: 165: case 0: /* SEEK_SET */ #####: 166: mapper->offset = offset; #####: 167: break; -: 168: case 1: /* SEEK_CUR */ #####: 169: mapper->offset += offset; #####: 170: break; -: 171: case 2: /* SEEK_END */ #####: 172: mapper->offset = mapper->size + offset; #####: 173: break; -: 174: default: -: 175: /* FIXME: raise ValueError? */ -: 176: break; -: 177: } -: 178: #####: 179: Py_INCREF(Py_None); #####: 180: return Py_None; -: 181:} -: 182: -: 183:/* -------------------------------------------------------------------- */ -: 184:/* map entire image */ -: 185: -: 186:extern PyObject*PyImagingNew(Imaging im); -: 187: -: 188:static void function ImagingDestroyMap called 0 returned 0% blocks executed 0% #####: 189:ImagingDestroyMap(Imaging im) -: 190:{ #####: 191: return; /* nothing to do! */ -: 192:} -: 193: -: 194:static PyObject* function mapping_readimage called 0 returned 0% blocks executed 0% #####: 195:mapping_readimage(ImagingMapperObject* mapper, PyObject* args) -: 196:{ -: 197: int y, size; -: 198: Imaging im; -: 199: -: 200: char* mode; -: 201: int xsize; -: 202: int ysize; -: 203: int stride; -: 204: int orientation; #####: 205: if (!PyArg_ParseTuple(args, "s(ii)ii", &mode, &xsize, &ysize, call 0 never executed branch 1 never executed branch 2 never executed -: 206: &stride, &orientation)) { -: 207: return NULL; -: 208: } -: 209: #####: 210: if (stride <= 0) { branch 0 never executed branch 1 never executed -: 211: /* FIXME: maybe we should call ImagingNewPrologue instead */ #####: 212: if (!strcmp(mode, "L") || !strcmp(mode, "P")) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed branch 4 never executed branch 5 never executed branch 6 never executed branch 7 never executed #####: 213: stride = xsize; #####: 214: } else if (!strcmp(mode, "I;16") || !strcmp(mode, "I;16B")) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 215: stride = xsize * 2; -: 216: } else { #####: 217: stride = xsize * 4; -: 218: } -: 219: } -: 220: #####: 221: size = ysize * stride; -: 222: #####: 223: if (mapper->offset + size > mapper->size) { branch 0 never executed branch 1 never executed #####: 224: PyErr_SetString(PyExc_OSError, "image file truncated"); call 0 never executed #####: 225: return NULL; -: 226: } -: 227: #####: 228: im = ImagingNewPrologue(mode, xsize, ysize); call 0 never executed #####: 229: if (!im) { branch 0 never executed branch 1 never executed -: 230: return NULL; -: 231: } -: 232: -: 233: /* setup file pointers */ #####: 234: if (orientation > 0) { branch 0 never executed branch 1 never executed #####: 235: for (y = 0; y < ysize; y++) { branch 0 never executed branch 1 never executed #####: 236: im->image[y] = mapper->base + mapper->offset + y * stride; -: 237: } -: 238: } else { #####: 239: for (y = 0; y < ysize; y++) { branch 0 never executed branch 1 never executed #####: 240: im->image[ysize-y-1] = mapper->base + mapper->offset + y * stride; -: 241: } -: 242: } -: 243: #####: 244: im->destroy = ImagingDestroyMap; -: 245: #####: 246: mapper->offset += size; -: 247: #####: 248: return PyImagingNew(im); call 0 never executed -: 249:} -: 250: -: 251:static struct PyMethodDef methods[] = { -: 252: /* standard file interface */ -: 253: {"read", (PyCFunction)mapping_read, 1}, -: 254: {"seek", (PyCFunction)mapping_seek, 1}, -: 255: /* extensions */ -: 256: {"readimage", (PyCFunction)mapping_readimage, 1}, -: 257: {NULL, NULL} /* sentinel */ -: 258:}; -: 259: -: 260:static PyTypeObject ImagingMapperType = { -: 261: PyVarObject_HEAD_INIT(NULL, 0) -: 262: "ImagingMapper", /*tp_name*/ -: 263: sizeof(ImagingMapperObject), /*tp_size*/ -: 264: 0, /*tp_itemsize*/ -: 265: /* methods */ -: 266: (destructor)mapping_dealloc, /*tp_dealloc*/ -: 267: 0, /*tp_print*/ -: 268: 0, /*tp_getattr*/ -: 269: 0, /*tp_setattr*/ -: 270: 0, /*tp_compare*/ -: 271: 0, /*tp_repr*/ -: 272: 0, /*tp_as_number */ -: 273: 0, /*tp_as_sequence */ -: 274: 0, /*tp_as_mapping */ -: 275: 0, /*tp_hash*/ -: 276: 0, /*tp_call*/ -: 277: 0, /*tp_str*/ -: 278: 0, /*tp_getattro*/ -: 279: 0, /*tp_setattro*/ -: 280: 0, /*tp_as_buffer*/ -: 281: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 282: 0, /*tp_doc*/ -: 283: 0, /*tp_traverse*/ -: 284: 0, /*tp_clear*/ -: 285: 0, /*tp_richcompare*/ -: 286: 0, /*tp_weaklistoffset*/ -: 287: 0, /*tp_iter*/ -: 288: 0, /*tp_iternext*/ -: 289: methods, /*tp_methods*/ -: 290: 0, /*tp_members*/ -: 291: 0, /*tp_getset*/ -: 292:}; -: 293: -: 294:PyObject* function PyImaging_Mapper called 0 returned 0% blocks executed 0% #####: 295:PyImaging_Mapper(PyObject* self, PyObject* args) -: 296:{ -: 297: char* filename; #####: 298: if (!PyArg_ParseTuple(args, "s", &filename)) { call 0 never executed branch 1 never executed branch 2 never executed -: 299: return NULL; -: 300: } -: 301: #####: 302: return (PyObject*) PyImaging_MapperNew(filename, 1); call 0 never executed -: 303:} -: 304: -: 305:/* -------------------------------------------------------------------- */ -: 306:/* Buffer mapper */ -: 307: -: 308:typedef struct ImagingBufferInstance { -: 309: struct ImagingMemoryInstance im; -: 310: PyObject* target; -: 311: Py_buffer view; -: 312:} ImagingBufferInstance; -: 313: -: 314:static void function mapping_destroy_buffer called 106 returned 100% blocks executed 100% 106: 315:mapping_destroy_buffer(Imaging im) -: 316:{ 106: 317: ImagingBufferInstance* buffer = (ImagingBufferInstance*) im; -: 318: 106: 319: PyBuffer_Release(&buffer->view); call 0 returned 100% 106: 320: Py_XDECREF(buffer->target); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 42% (fallthrough) branch 3 taken 58% call 4 returned 100% 106: 321:} -: 322: -: 323:PyObject* function PyImaging_MapBuffer called 107 returned 100% blocks executed 77% 107: 324:PyImaging_MapBuffer(PyObject* self, PyObject* args) -: 325:{ -: 326: Py_ssize_t y, size; -: 327: Imaging im; -: 328: -: 329: PyObject* target; -: 330: Py_buffer view; -: 331: char* mode; -: 332: char* codec; -: 333: Py_ssize_t offset; -: 334: int xsize, ysize; -: 335: int stride; -: 336: int ystep; -: 337: 107: 338: if (!PyArg_ParseTuple(args, "O(ii)sn(sii)", &target, &xsize, &ysize, call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 339: &codec, &offset, &mode, &stride, &ystep)) { -: 340: return NULL; -: 341: } -: 342: 107: 343: if (!PyImaging_CheckBuffer(target)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 344: PyErr_SetString(PyExc_TypeError, "expected string or buffer"); call 0 never executed #####: 345: return NULL; -: 346: } -: 347: 107: 348: if (stride <= 0) { branch 0 taken 79% (fallthrough) branch 1 taken 21% 85: 349: if (!strcmp(mode, "L") || !strcmp(mode, "P")) { branch 0 taken 64% (fallthrough) branch 1 taken 36% branch 2 taken 36% (fallthrough) branch 3 taken 64% branch 4 taken 26% (fallthrough) branch 5 taken 74% branch 6 taken 26% (fallthrough) branch 7 taken 74% 62: 350: stride = xsize; 23: 351: } else if (!strncmp(mode, "I;16", 4)) { branch 0 taken 78% (fallthrough) branch 1 taken 22% 18: 352: stride = xsize * 2; -: 353: } else { 5: 354: stride = xsize * 4; -: 355: } -: 356: } -: 357: 107: 358: if (stride > 0 && ysize > PY_SSIZE_T_MAX / stride) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 0% (fallthrough) branch 3 taken 100% #####: 359: PyErr_SetString(PyExc_MemoryError, "Integer overflow in ysize"); call 0 never executed #####: 360: return NULL; -: 361: } -: 362: 107: 363: size = (Py_ssize_t) ysize * stride; -: 364: 107: 365: if (offset > PY_SSIZE_T_MAX - size) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 366: PyErr_SetString(PyExc_MemoryError, "Integer overflow in offset"); call 0 never executed #####: 367: return NULL; -: 368: } -: 369: -: 370: /* check buffer size */ 107: 371: if (PyImaging_GetBuffer(target, &view) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 372: return NULL; -: 373: } -: 374: 107: 375: if (view.len < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 376: PyErr_SetString(PyExc_ValueError, "buffer has negative size"); call 0 never executed #####: 377: PyBuffer_Release(&view); call 0 never executed #####: 378: return NULL; -: 379: } 107: 380: if (offset + size > view.len) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1: 381: PyErr_SetString(PyExc_ValueError, "buffer is not large enough"); call 0 returned 100% 1: 382: PyBuffer_Release(&view); call 0 returned 100% 1: 383: return NULL; -: 384: } -: 385: 106: 386: im = ImagingNewPrologueSubtype( call 0 returned 100% -: 387: mode, xsize, ysize, sizeof(ImagingBufferInstance)); 106: 388: if (!im) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 389: PyBuffer_Release(&view); call 0 never executed #####: 390: return NULL; -: 391: } -: 392: -: 393: /* setup file pointers */ 106: 394: if (ystep > 0) { branch 0 taken 35% (fallthrough) branch 1 taken 65% 48947: 395: for (y = 0; y < ysize; y++) { branch 0 taken 99% branch 1 taken 1% 48947: 396: im->image[y] = (char*)view.buf + offset + y * stride; -: 397: } -: 398: } else { 2157: 399: for (y = 0; y < ysize; y++) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 2157: 400: im->image[ysize-y-1] = (char*)view.buf + offset + y * stride; -: 401: } -: 402: } -: 403: 106: 404: im->destroy = mapping_destroy_buffer; -: 405: 106: 406: Py_INCREF(target); 106: 407: ((ImagingBufferInstance*) im)->target = target; 106: 408: ((ImagingBufferInstance*) im)->view = view; -: 409: 106: 410: return PyImagingNew(im); call 0 returned 100% -: 411:} -: 412: <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#_imagingcms.c.gcov -: 0:Source:src/_imagingcms.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/_imagingcms.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/_imagingcms.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * pyCMS -: 3: * a Python / PIL interface to the littleCMS ICC Color Management System -: 4: * Copyright (C) 2002-2003 Kevin Cazabon -: 5: * kevin@cazabon.com -: 6: * http://www.cazabon.com -: 7: * Adapted/reworked for PIL by Fredrik Lundh -: 8: * Copyright (c) 2009 Fredrik Lundh -: 9: * Updated to LCMS2 -: 10: * Copyright (c) 2013 Eric Soroos -: 11: * -: 12: * pyCMS home page: http://www.cazabon.com/pyCMS -: 13: * littleCMS home page: http://www.littlecms.com -: 14: * (littleCMS is Copyright (C) 1998-2001 Marti Maria) -: 15: * -: 16: * Originally released under LGPL. Graciously donated to PIL in -: 17: * March 2009, for distribution under the standard PIL license -: 18: */ -: 19: -: 20:#define COPYRIGHTINFO "\ -: 21:pyCMS\n\ -: 22:a Python / PIL interface to the littleCMS ICC Color Management System\n\ -: 23:Copyright (C) 2002-2003 Kevin Cazabon\n\ -: 24:kevin@cazabon.com\n\ -: 25:http://www.cazabon.com\n\ -: 26:" -: 27: -: 28:#define PY_SSIZE_T_CLEAN -: 29:#include "Python.h" // Include before wchar.h so _GNU_SOURCE is set -: 30:#include "wchar.h" -: 31:#include "datetime.h" -: 32: -: 33:#include "lcms2.h" -: 34:#include "libImaging/Imaging.h" -: 35: -: 36:#define PYCMSVERSION "1.0.0 pil" -: 37: -: 38:/* version history */ -: 39: -: 40:/* -: 41: 1.0.0 pil Integrating littleCMS2 -: 42: 0.1.0 pil integration & refactoring -: 43: 0.0.2 alpha: Minor updates, added interfaces to littleCMS features, Jan 6, 2003 -: 44: - fixed some memory holes in how transforms/profiles were created and passed back to Python -: 45: due to improper destructor setup for PyCObjects -: 46: - added buildProofTransformFromOpenProfiles() function -: 47: - eliminated some code redundancy, centralizing several common tasks with internal functions -: 48: -: 49: 0.0.1 alpha: First public release Dec 26, 2002 -: 50: -: 51:*/ -: 52: -: 53:/* known to-do list with current version: -: 54: -: 55: Verify that PILmode->littleCMStype conversion in findLCMStype is correct for all -: 56: PIL modes (it probably isn't for the more obscure ones) -: 57: -: 58: Add support for creating custom RGB profiles on the fly -: 59: Add support for checking presence of a specific tag in a profile -: 60: Add support for other littleCMS features as required -: 61: -: 62:*/ -: 63: -: 64:/* -: 65: INTENT_PERCEPTUAL 0 -: 66: INTENT_RELATIVE_COLORIMETRIC 1 -: 67: INTENT_SATURATION 2 -: 68: INTENT_ABSOLUTE_COLORIMETRIC 3 -: 69:*/ -: 70: -: 71:/* -------------------------------------------------------------------- */ -: 72:/* wrapper classes */ -: 73: -: 74:/* a profile represents the ICC characteristics for a specific device */ -: 75: -: 76:typedef struct { -: 77: PyObject_HEAD -: 78: cmsHPROFILE profile; -: 79:} CmsProfileObject; -: 80: -: 81:static PyTypeObject CmsProfile_Type; -: 82: -: 83:#define CmsProfile_Check(op) (Py_TYPE(op) == &CmsProfile_Type) -: 84: -: 85:static PyObject* -: 86:cms_profile_new(cmsHPROFILE profile) -: 87:{ -: 88: CmsProfileObject* self; -: 89: 73: 90: self = PyObject_New(CmsProfileObject, &CmsProfile_Type); call 0 returned 100% call 1 returned 100% call 2 returned 100% 73: 91: if (!self) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 92: return NULL; -: 93: } -: 94: 73: 95: self->profile = profile; -: 96: -: 97: return (PyObject*) self; -: 98:} -: 99: -: 100:static PyObject* function cms_profile_open called 25 returned 100% blocks executed 100% 25: 101:cms_profile_open(PyObject* self, PyObject* args) -: 102:{ -: 103: cmsHPROFILE hProfile; -: 104: -: 105: char* sProfile; 25: 106: if (!PyArg_ParseTuple(args, "s:profile_open", &sProfile)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 107: return NULL; -: 108: } -: 109: 25: 110: hProfile = cmsOpenProfileFromFile(sProfile, "r"); call 0 returned 100% 25: 111: if (!hProfile) { branch 0 taken 8% (fallthrough) branch 1 taken 92% 2: 112: PyErr_SetString(PyExc_OSError, "cannot open profile file"); call 0 returned 100% 2: 113: return NULL; -: 114: } -: 115: 23: 116: return cms_profile_new(hProfile); -: 117:} -: 118: -: 119:static PyObject* function cms_profile_fromstring called 4 returned 100% blocks executed 82% 4: 120:cms_profile_fromstring(PyObject* self, PyObject* args) -: 121:{ -: 122: cmsHPROFILE hProfile; -: 123: -: 124: char* pProfile; -: 125: Py_ssize_t nProfile; 4: 126: if (!PyArg_ParseTuple(args, "y#:profile_frombytes", &pProfile, &nProfile)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 127: return NULL; -: 128: } -: 129: 4: 130: hProfile = cmsOpenProfileFromMem(pProfile, nProfile); call 0 returned 100% 4: 131: if (!hProfile) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 132: PyErr_SetString(PyExc_OSError, "cannot open profile from string"); call 0 never executed #####: 133: return NULL; -: 134: } -: 135: 4: 136: return cms_profile_new(hProfile); -: 137:} -: 138: -: 139:static PyObject* function cms_profile_tobytes called 44 returned 100% blocks executed 63% 44: 140:cms_profile_tobytes(PyObject* self, PyObject* args) -: 141:{ 44: 142: char *pProfile =NULL; -: 143: cmsUInt32Number nProfile; -: 144: PyObject* CmsProfile; -: 145: -: 146: cmsHPROFILE *profile; -: 147: -: 148: PyObject* ret; 44: 149: if (!PyArg_ParseTuple(args, "O", &CmsProfile)){ call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 150: return NULL; -: 151: } -: 152: 44: 153: profile = ((CmsProfileObject*)CmsProfile)->profile; -: 154: 44: 155: if (!cmsSaveProfileToMem(profile, pProfile, &nProfile)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 156: PyErr_SetString(PyExc_OSError, "Could not determine profile size"); call 0 never executed #####: 157: return NULL; -: 158: } -: 159: 44: 160: pProfile = (char*)malloc(nProfile); 44: 161: if (!pProfile) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 162: PyErr_SetString(PyExc_OSError, "Out of Memory"); call 0 never executed #####: 163: return NULL; -: 164: } -: 165: 44: 166: if (!cmsSaveProfileToMem(profile, pProfile, &nProfile)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 167: PyErr_SetString(PyExc_OSError, "Could not get profile"); call 0 never executed #####: 168: free(pProfile); #####: 169: return NULL; -: 170: } -: 171: 44: 172: ret = PyBytes_FromStringAndSize(pProfile, (Py_ssize_t)nProfile); call 0 returned 100% -: 173: 44: 174: free(pProfile); 44: 175: return ret; -: 176:} -: 177: -: 178:static void function cms_profile_dealloc called 73 returned 100% blocks executed 100% 73: 179:cms_profile_dealloc(CmsProfileObject* self) -: 180:{ 73: 181: (void) cmsCloseProfile(self->profile); call 0 returned 100% 73: 182: PyObject_Del(self); call 0 returned 100% 73: 183:} -: 184: -: 185:/* a transform represents the mapping between two profiles */ -: 186: -: 187:typedef struct { -: 188: PyObject_HEAD -: 189: char mode_in[8]; -: 190: char mode_out[8]; -: 191: cmsHTRANSFORM transform; -: 192:} CmsTransformObject; -: 193: -: 194:static PyTypeObject CmsTransform_Type; -: 195: -: 196:#define CmsTransform_Check(op) (Py_TYPE(op) == &CmsTransform_Type) -: 197: -: 198:static PyObject* function cms_transform_new called 40 returned 100% blocks executed 100% 40: 199:cms_transform_new(cmsHTRANSFORM transform, char* mode_in, char* mode_out) -: 200:{ -: 201: CmsTransformObject* self; -: 202: 40: 203: self = PyObject_New(CmsTransformObject, &CmsTransform_Type); call 0 returned 100% 40: 204: if (!self) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 205: return NULL; -: 206: } -: 207: 40: 208: self->transform = transform; -: 209: 80: 210: strcpy(self->mode_in, mode_in); 80: 211: strcpy(self->mode_out, mode_out); -: 212: 40: 213: return (PyObject*) self; -: 214:} -: 215: -: 216:static void function cms_transform_dealloc called 40 returned 100% blocks executed 100% 40: 217:cms_transform_dealloc(CmsTransformObject* self) -: 218:{ 40: 219: cmsDeleteTransform(self->transform); call 0 returned 100% 40: 220: PyObject_Del(self); call 0 returned 100% 40: 221:} -: 222: -: 223:/* -------------------------------------------------------------------- */ -: 224:/* internal functions */ -: 225: -: 226:static cmsUInt32Number function findLCMStype called 80 returned 100% blocks executed 85% 80: 227:findLCMStype(char* PILmode) -: 228:{ 80: 229: if (strcmp(PILmode, "RGB") == 0) { branch 0 taken 73% (fallthrough) branch 1 taken 28% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 58% (fallthrough) branch 7 taken 43% -: 230: return TYPE_RGBA_8; -: 231: } 46: 232: else if (strcmp(PILmode, "RGBA") == 0) { branch 0 taken 74% (fallthrough) branch 1 taken 26% -: 233: return TYPE_RGBA_8; -: 234: } 34: 235: else if (strcmp(PILmode, "RGBX") == 0) { branch 0 taken 65% (fallthrough) branch 1 taken 35% -: 236: return TYPE_RGBA_8; -: 237: } 22: 238: else if (strcmp(PILmode, "RGBA;16B") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 239: return TYPE_RGBA_16; -: 240: } 22: 241: else if (strcmp(PILmode, "CMYK") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 242: return TYPE_CMYK_8; -: 243: } 22: 244: else if (strcmp(PILmode, "L") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 245: return TYPE_GRAY_8; -: 246: } 22: 247: else if (strcmp(PILmode, "L;16") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 248: return TYPE_GRAY_16; -: 249: } 22: 250: else if (strcmp(PILmode, "L;16B") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 251: return TYPE_GRAY_16_SE; -: 252: } 22: 253: else if (strcmp(PILmode, "YCCA") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 254: return TYPE_YCbCr_8; -: 255: } 22: 256: else if (strcmp(PILmode, "YCC") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed branch 4 never executed branch 5 never executed branch 6 taken 100% (fallthrough) branch 7 taken 0% -: 257: return TYPE_YCbCr_8; -: 258: } 22: 259: else if (strcmp(PILmode, "LAB") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 0% (fallthrough) branch 7 taken 100% -: 260: // LabX equivalent like ALab, but not reversed -- no #define in lcms2 -: 261: return (COLORSPACE_SH(PT_LabV2)|CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)); -: 262: } -: 263: -: 264: else { -: 265: /* take a wild guess... but you probably should fail instead. */ #####: 266: return TYPE_GRAY_8; /* so there's no buffer overrun... */ -: 267: } -: 268:} -: 269: -: 270:#define Cms_Min(a, b) ((a) < (b) ? (a) : (b)) -: 271: -: 272:static int function pyCMSgetAuxChannelChannel called 66 returned 100% blocks executed 45% 66: 273:pyCMSgetAuxChannelChannel (cmsUInt32Number format, int auxChannelNdx) -: 274:{ 66: 275: int numColors = T_CHANNELS(format); 66: 276: int numExtras = T_EXTRA(format); -: 277: 66: 278: if (T_SWAPFIRST(format) && T_DOSWAP(format)) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 279: // reverse order, before anything but last extra is shifted last #####: 280: if (auxChannelNdx == numExtras - 1) { branch 0 never executed branch 1 never executed #####: 281: return numColors + numExtras - 1; -: 282: } else { #####: 283: return numExtras - 2 - auxChannelNdx; -: 284: } -: 285: } 66: 286: else if (T_SWAPFIRST(format)) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 287: // in order, after color channels, but last extra is shifted to first #####: 288: if (auxChannelNdx == numExtras - 1) { branch 0 never executed branch 1 never executed -: 289: return 0; -: 290: } else { #####: 291: return numColors + 1 + auxChannelNdx; -: 292: } -: 293: } 66: 294: else if (T_DOSWAP(format)) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 295: // reverse order, before anything #####: 296: return numExtras - 1 - auxChannelNdx; -: 297: } -: 298: else { -: 299: // in order, after color channels 66: 300: return numColors + auxChannelNdx; -: 301: } -: 302:} -: 303: -: 304:static void function pyCMScopyAux called 40 returned 100% blocks executed 100% 40: 305:pyCMScopyAux (cmsHTRANSFORM hTransform, Imaging imDst, const Imaging imSrc) -: 306:{ -: 307: cmsUInt32Number dstLCMSFormat; -: 308: cmsUInt32Number srcLCMSFormat; -: 309: int numSrcExtras; -: 310: int numDstExtras; -: 311: int numExtras; -: 312: int ySize; -: 313: int xSize; -: 314: int channelSize; -: 315: int srcChunkSize; -: 316: int dstChunkSize; -: 317: int e; -: 318: -: 319: // trivially copied 40: 320: if (imDst == imSrc) { branch 0 taken 83% (fallthrough) branch 1 taken 18% -: 321: return; -: 322: } -: 323: 33: 324: dstLCMSFormat = cmsGetTransformOutputFormat(hTransform); call 0 returned 100% 33: 325: srcLCMSFormat = cmsGetTransformInputFormat(hTransform); call 0 returned 100% -: 326: -: 327: // currently, all Pillow formats are chunky formats, but check it anyway 33: 328: if (T_PLANAR(dstLCMSFormat) || T_PLANAR(srcLCMSFormat)) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 329: return; -: 330: } -: 331: -: 332: // copy only if channel format is identical, except OPTIMIZED is ignored as it -: 333: // does not affect the aux channel 33: 334: if (T_FLOAT(dstLCMSFormat) != T_FLOAT(srcLCMSFormat) branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 335: || T_FLAVOR(dstLCMSFormat) != T_FLAVOR(srcLCMSFormat) branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 336: || T_ENDIAN16(dstLCMSFormat) != T_ENDIAN16(srcLCMSFormat) branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 337: || T_BYTES(dstLCMSFormat) != T_BYTES(srcLCMSFormat)) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 338: return; -: 339: } -: 340: 33: 341: numSrcExtras = T_EXTRA(srcLCMSFormat); 33: 342: numDstExtras = T_EXTRA(dstLCMSFormat); 33: 343: numExtras = Cms_Min(numSrcExtras, numDstExtras); 33: 344: ySize = Cms_Min(imSrc->ysize, imDst->ysize); 33: 345: xSize = Cms_Min(imSrc->xsize, imDst->xsize); 33: 346: channelSize = T_BYTES(dstLCMSFormat); 33: 347: srcChunkSize = (T_CHANNELS(srcLCMSFormat) + T_EXTRA(srcLCMSFormat)) * channelSize; 33: 348: dstChunkSize = (T_CHANNELS(dstLCMSFormat) + T_EXTRA(dstLCMSFormat)) * channelSize; -: 349: 66: 350: for (e = 0; e < numExtras; ++e) { branch 0 taken 50% branch 1 taken 50% (fallthrough) -: 351: int y; 33: 352: int dstChannel = pyCMSgetAuxChannelChannel(dstLCMSFormat, e); call 0 returned 100% 33: 353: int srcChannel = pyCMSgetAuxChannelChannel(srcLCMSFormat, e); -: 354: 4139: 355: for (y = 0; y < ySize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) -: 356: int x; 4106: 357: char* pDstExtras = imDst->image[y] + dstChannel * channelSize; 4106: 358: const char* pSrcExtras = imSrc->image[y] + srcChannel * channelSize; -: 359: 528494: 360: for (x = 0; x < xSize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 1048776: 361: memcpy(pDstExtras + x * dstChunkSize, pSrcExtras + x * srcChunkSize, channelSize); -: 362: } -: 363: } -: 364: } -: 365:} -: 366: -: 367:static int function pyCMSdoTransform called 40 returned 100% blocks executed 100% 40: 368:pyCMSdoTransform(Imaging im, Imaging imOut, cmsHTRANSFORM hTransform) -: 369:{ -: 370: int i; -: 371: 40: 372: if (im->xsize > imOut->xsize || im->ysize > imOut->ysize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 373: return -1; -: 374: } -: 375: 40: 376: Py_BEGIN_ALLOW_THREADS -: 377: -: 378: // transform color channels only 5042: 379: for (i = 0; i < im->ysize; i++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 5002: 380: cmsDoTransform(hTransform, im->image[i], imOut->image[i], im->xsize); call 0 returned 100% -: 381: } -: 382: -: 383: // lcms by default does nothing to the auxiliary channels leaving those -: 384: // unchanged. To do "the right thing" here, i.e. maintain identical results -: 385: // with and without inPlace, we replicate those channels to the output. -: 386: // -: 387: // As of lcms 2.8, a new cmsFLAGS_COPY_ALPHA flag is introduced which would -: 388: // do the same thing automagically. Unfortunately, lcms2.8 is not yet widely -: 389: // enough available on all platforms, so we polyfill it here for now. 40: 390: pyCMScopyAux(hTransform, imOut, im); call 0 returned 100% -: 391: 40: 392: Py_END_ALLOW_THREADS call 0 returned 100% -: 393: 40: 394: return 0; -: 395:} -: 396: -: 397:static cmsHTRANSFORM function _buildTransform called 39 returned 100% blocks executed 88% 39: 398:_buildTransform(cmsHPROFILE hInputProfile, cmsHPROFILE hOutputProfile, char *sInMode, char *sOutMode, int iRenderingIntent, cmsUInt32Number cmsFLAGS) -: 399:{ -: 400: cmsHTRANSFORM hTransform; -: 401: 39: 402: Py_BEGIN_ALLOW_THREADS call 0 returned 100% -: 403: -: 404: /* create the transform */ 39: 405: hTransform = cmsCreateTransform(hInputProfile, call 0 returned 100% call 1 returned 100% call 2 returned 100% -: 406: findLCMStype(sInMode), -: 407: hOutputProfile, -: 408: findLCMStype(sOutMode), -: 409: iRenderingIntent, cmsFLAGS); -: 410: 39: 411: Py_END_ALLOW_THREADS call 0 returned 100% -: 412: 39: 413: if (!hTransform) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 414: PyErr_SetString(PyExc_ValueError, "cannot build transform"); call 0 never executed -: 415: } -: 416: 39: 417: return hTransform; /* if NULL, an exception is set */ -: 418:} -: 419: -: 420:static cmsHTRANSFORM function _buildProofTransform called 1 returned 100% blocks executed 88% 1: 421:_buildProofTransform(cmsHPROFILE hInputProfile, cmsHPROFILE hOutputProfile, cmsHPROFILE hProofProfile, char *sInMode, char *sOutMode, int iRenderingIntent, int iProofIntent, cmsUInt32Number cmsFLAGS) -: 422:{ -: 423: cmsHTRANSFORM hTransform; -: 424: 1: 425: Py_BEGIN_ALLOW_THREADS call 0 returned 100% -: 426: -: 427: /* create the transform */ 1: 428: hTransform = cmsCreateProofingTransform(hInputProfile, call 0 returned 100% call 1 returned 100% call 2 returned 100% -: 429: findLCMStype(sInMode), -: 430: hOutputProfile, -: 431: findLCMStype(sOutMode), -: 432: hProofProfile, -: 433: iRenderingIntent, -: 434: iProofIntent, -: 435: cmsFLAGS); -: 436: 1: 437: Py_END_ALLOW_THREADS call 0 returned 100% -: 438: 1: 439: if (!hTransform) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 440: PyErr_SetString(PyExc_ValueError, "cannot build proof transform"); call 0 never executed -: 441: } -: 442: 1: 443: return hTransform; /* if NULL, an exception is set */ -: 444:} -: 445: -: 446:/* -------------------------------------------------------------------- */ -: 447:/* Python callable functions */ -: 448: -: 449:static PyObject * function buildTransform called 39 returned 100% blocks executed 100% 39: 450:buildTransform(PyObject *self, PyObject *args) { -: 451: CmsProfileObject *pInputProfile; -: 452: CmsProfileObject *pOutputProfile; -: 453: char *sInMode; -: 454: char *sOutMode; 39: 455: int iRenderingIntent = 0; 39: 456: int cmsFLAGS = 0; -: 457: 39: 458: cmsHTRANSFORM transform = NULL; -: 459: 39: 460: if (!PyArg_ParseTuple(args, "O!O!ss|ii:buildTransform", &CmsProfile_Type, &pInputProfile, &CmsProfile_Type, &pOutputProfile, &sInMode, &sOutMode, &iRenderingIntent, &cmsFLAGS)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 461: return NULL; -: 462: } -: 463: 39: 464: transform = _buildTransform(pInputProfile->profile, pOutputProfile->profile, sInMode, sOutMode, iRenderingIntent, cmsFLAGS); call 0 returned 100% -: 465: 39: 466: if (!transform) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 467: return NULL; -: 468: } -: 469: 39: 470: return cms_transform_new(transform, sInMode, sOutMode); call 0 returned 100% -: 471:} -: 472: -: 473:static PyObject * function buildProofTransform called 1 returned 100% blocks executed 100% 1: 474:buildProofTransform(PyObject *self, PyObject *args) -: 475:{ -: 476: CmsProfileObject *pInputProfile; -: 477: CmsProfileObject *pOutputProfile; -: 478: CmsProfileObject *pProofProfile; -: 479: char *sInMode; -: 480: char *sOutMode; 1: 481: int iRenderingIntent = 0; 1: 482: int iProofIntent = 0; 1: 483: int cmsFLAGS = 0; -: 484: 1: 485: cmsHTRANSFORM transform = NULL; -: 486: 1: 487: if (!PyArg_ParseTuple(args, "O!O!O!ss|iii:buildProofTransform", &CmsProfile_Type, &pInputProfile, &CmsProfile_Type, &pOutputProfile, &CmsProfile_Type, &pProofProfile, &sInMode, &sOutMode, &iRenderingIntent, &iProofIntent, &cmsFLAGS)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 488: return NULL; -: 489: } -: 490: 1: 491: transform = _buildProofTransform(pInputProfile->profile, pOutputProfile->profile, pProofProfile->profile, sInMode, sOutMode, iRenderingIntent, iProofIntent, cmsFLAGS); call 0 returned 100% -: 492: 1: 493: if (!transform) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 494: return NULL; -: 495: } -: 496: 1: 497: return cms_transform_new(transform, sInMode, sOutMode); call 0 returned 100% -: 498: -: 499:} -: 500: -: 501:static PyObject * function cms_transform_apply called 40 returned 100% blocks executed 100% 40: 502:cms_transform_apply(CmsTransformObject *self, PyObject *args) -: 503:{ -: 504: Py_ssize_t idIn; -: 505: Py_ssize_t idOut; -: 506: Imaging im; -: 507: Imaging imOut; -: 508: -: 509: int result; -: 510: 40: 511: if (!PyArg_ParseTuple(args, "nn:apply", &idIn, &idOut)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 512: return NULL; -: 513: } -: 514: 40: 515: im = (Imaging) idIn; 40: 516: imOut = (Imaging) idOut; -: 517: 40: 518: result = pyCMSdoTransform(im, imOut, self->transform); call 0 returned 100% -: 519: 40: 520: return Py_BuildValue("i", result); call 0 returned 100% -: 521:} -: 522: -: 523:/* -------------------------------------------------------------------- */ -: 524:/* Python-Callable On-The-Fly profile creation functions */ -: 525: -: 526:static PyObject * function createProfile called 46 returned 100% blocks executed 73% 46: 527:createProfile(PyObject *self, PyObject *args) -: 528:{ -: 529: char *sColorSpace; -: 530: cmsHPROFILE hProfile; 46: 531: cmsFloat64Number dColorTemp = 0.0; -: 532: cmsCIExyY whitePoint; -: 533: cmsBool result; -: 534: 46: 535: if (!PyArg_ParseTuple(args, "s|d:createProfile", &sColorSpace, &dColorTemp)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 536: return NULL; -: 537: } -: 538: 46: 539: if (strcmp(sColorSpace, "LAB") == 0) { branch 0 taken 33% (fallthrough) branch 1 taken 67% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 33% (fallthrough) branch 7 taken 67% 15: 540: if (dColorTemp > 0.0) { branch 0 taken 13% (fallthrough) branch 1 taken 87% 2: 541: result = cmsWhitePointFromTemp(&whitePoint, dColorTemp); call 0 returned 100% 2: 542: if (!result) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 543: PyErr_SetString(PyExc_ValueError, "ERROR: Could not calculate white point from color temperature provided, must be float in degrees Kelvin"); call 0 never executed #####: 544: return NULL; -: 545: } 2: 546: hProfile = cmsCreateLab2Profile(&whitePoint); call 0 returned 100% -: 547: } else { 13: 548: hProfile = cmsCreateLab2Profile(NULL); call 0 returned 100% -: 549: } -: 550: } 31: 551: else if (strcmp(sColorSpace, "XYZ") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed branch 4 never executed branch 5 never executed branch 6 taken 0% (fallthrough) branch 7 taken 100% #####: 552: hProfile = cmsCreateXYZProfile(); call 0 never executed -: 553: } 31: 554: else if (strcmp(sColorSpace, "sRGB") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 31: 555: hProfile = cmsCreate_sRGBProfile(); call 0 returned 100% -: 556: } -: 557: else { -: 558: hProfile = NULL; -: 559: } -: 560: 46: 561: if (!hProfile) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 562: PyErr_SetString(PyExc_ValueError, "failed to create requested color space"); call 0 never executed #####: 563: return NULL; -: 564: } -: 565: 46: 566: return cms_profile_new(hProfile); -: 567:} -: 568: -: 569:/* -------------------------------------------------------------------- */ -: 570:/* profile methods */ -: 571: -: 572:static PyObject * function cms_profile_is_intent_supported called 3 returned 100% blocks executed 100% 3: 573:cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args) -: 574:{ -: 575: cmsBool result; -: 576: -: 577: int intent; -: 578: int direction; 3: 579: if (!PyArg_ParseTuple(args, "ii:is_intent_supported", &intent, &direction)) { call 0 returned 100% branch 1 taken 67% (fallthrough) branch 2 taken 33% -: 580: return NULL; -: 581: } -: 582: 2: 583: result = cmsIsIntentSupported(self->profile, intent, direction); call 0 returned 100% -: 584: -: 585: /* printf("cmsIsIntentSupported(%p, %d, %d) => %d\n", self->profile, intent, direction, result); */ -: 586: 2: 587: return PyLong_FromLong(result != 0); call 0 returned 100% -: 588:} -: 589: -: 590:#ifdef _WIN32 -: 591: -: 592:#ifdef _WIN64 -: 593:#define F_HANDLE "K" -: 594:#else -: 595:#define F_HANDLE "k" -: 596:#endif -: 597: -: 598:static PyObject * -: 599:cms_get_display_profile_win32(PyObject* self, PyObject* args) -: 600:{ -: 601: char filename[MAX_PATH]; -: 602: cmsUInt32Number filename_size; -: 603: BOOL ok; -: 604: -: 605: HANDLE handle = 0; -: 606: int is_dc = 0; -: 607: if (!PyArg_ParseTuple(args, "|" F_HANDLE "i:get_display_profile", &handle, &is_dc)) { -: 608: return NULL; -: 609: } -: 610: -: 611: filename_size = sizeof(filename); -: 612: -: 613: if (is_dc) { -: 614: ok = GetICMProfile((HDC) handle, &filename_size, filename); -: 615: } else { -: 616: HDC dc = GetDC((HWND) handle); -: 617: ok = GetICMProfile(dc, &filename_size, filename); -: 618: ReleaseDC((HWND) handle, dc); -: 619: } -: 620: -: 621: if (ok) { -: 622: return PyUnicode_FromStringAndSize(filename, filename_size-1); -: 623: } -: 624: -: 625: Py_INCREF(Py_None); -: 626: return Py_None; -: 627:} -: 628:#endif -: 629: -: 630:/* -------------------------------------------------------------------- */ -: 631:/* Helper functions. */ -: 632: -: 633:static PyObject* function _profile_read_mlu.isra.6 called 25 returned 100% blocks executed 81% 25: 634:_profile_read_mlu(CmsProfileObject* self, cmsTagSignature info) -: 635:{ -: 636: PyObject *uni; 25: 637: char *lc = "en"; 25: 638: char *cc = cmsNoCountry; -: 639: cmsMLU *mlu; -: 640: cmsUInt32Number len; -: 641: wchar_t *buf; -: 642: 25: 643: if (!cmsIsTag(self->profile, info)) { call 0 returned 100% branch 1 taken 20% (fallthrough) branch 2 taken 80% 5: 644: Py_INCREF(Py_None); -: 645: return Py_None; -: 646: } -: 647: 20: 648: mlu = cmsReadTag(self->profile, info); call 0 returned 100% 20: 649: if (!mlu) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 650: Py_INCREF(Py_None); -: 651: return Py_None; -: 652: } -: 653: 20: 654: len = cmsMLUgetWide(mlu, lc, cc, NULL, 0); call 0 returned 100% 20: 655: if (len == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 656: Py_INCREF(Py_None); -: 657: return Py_None; -: 658: } -: 659: 20: 660: buf = malloc(len); 20: 661: if (!buf) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 662: PyErr_SetString(PyExc_OSError, "Out of Memory"); call 0 never executed -: 663: return NULL; -: 664: } -: 665: /* Just in case the next call fails. */ 20: 666: buf[0] = '\0'; -: 667: 20: 668: cmsMLUgetWide(mlu, lc, cc, buf, len); call 0 returned 100% -: 669: // buf contains additional junk after \0 20: 670: uni = PyUnicode_FromWideChar(buf, wcslen(buf)); call 0 returned 100% call 1 returned 100% 20: 671: free(buf); -: 672: -: 673: return uni; -: 674:} -: 675: -: 676: -: 677:static PyObject* function _profile_read_int_as_string called 6 returned 100% blocks executed 100% 6: 678:_profile_read_int_as_string(cmsUInt32Number nr) -: 679:{ -: 680: PyObject* ret; -: 681: char buf[5]; 6: 682: buf[0] = (char) ((nr >> 24) & 0xff); 6: 683: buf[1] = (char) ((nr >> 16) & 0xff); 6: 684: buf[2] = (char) ((nr >> 8) & 0xff); 6: 685: buf[3] = (char) (nr & 0xff); 6: 686: buf[4] = 0; -: 687: 6: 688: ret = PyUnicode_DecodeASCII(buf, 4, NULL); call 0 returned 100% 6: 689: return ret; -: 690:} -: 691: -: 692: -: 693:static PyObject* function _profile_read_signature.isra.5 called 4 returned 100% blocks executed 89% 4: 694:_profile_read_signature(CmsProfileObject* self, cmsTagSignature info) -: 695:{ -: 696: unsigned int *sig; -: 697: 4: 698: if (!cmsIsTag(self->profile, info)) { call 0 returned 100% branch 1 taken 75% (fallthrough) branch 2 taken 25% 3: 699: Py_INCREF(Py_None); -: 700: return Py_None; -: 701: } -: 702: 1: 703: sig = (unsigned int *) cmsReadTag(self->profile, info); call 0 returned 100% 1: 704: if (!sig) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 705: Py_INCREF(Py_None); -: 706: return Py_None; -: 707: } -: 708: 1: 709: return _profile_read_int_as_string(*sig); call 0 returned 100% -: 710:} -: 711: -: 712:static PyObject* function _xyz_py called 9 returned 100% blocks executed 100% 9: 713:_xyz_py(cmsCIEXYZ* XYZ) -: 714:{ -: 715: cmsCIExyY xyY; 9: 716: cmsXYZ2xyY(&xyY, XYZ); call 0 returned 100% 9: 717: return Py_BuildValue("((d,d,d),(d,d,d))", XYZ->X, XYZ->Y, XYZ->Z, xyY.x, xyY.y, xyY.Y); call 0 returned 100% -: 718:} -: 719: -: 720:static PyObject* function _xyz3_py called 1 returned 100% blocks executed 100% 1: 721:_xyz3_py(cmsCIEXYZ* XYZ) -: 722:{ -: 723: cmsCIExyY xyY[3]; 1: 724: cmsXYZ2xyY(&xyY[0], &XYZ[0]); call 0 returned 100% 1: 725: cmsXYZ2xyY(&xyY[1], &XYZ[1]); call 0 returned 100% 1: 726: cmsXYZ2xyY(&xyY[2], &XYZ[2]); call 0 returned 100% -: 727: 1: 728: return Py_BuildValue("(((d,d,d),(d,d,d),(d,d,d)),((d,d,d),(d,d,d),(d,d,d)))", call 0 returned 100% -: 729: XYZ[0].X, XYZ[0].Y, XYZ[0].Z, -: 730: XYZ[1].X, XYZ[1].Y, XYZ[1].Z, -: 731: XYZ[2].X, XYZ[2].Y, XYZ[2].Z, -: 732: xyY[0].x, xyY[0].y, xyY[0].Y, -: 733: xyY[1].x, xyY[1].y, xyY[1].Y, -: 734: xyY[2].x, xyY[2].y, xyY[2].Y); -: 735:} -: 736: -: 737:static PyObject* function _profile_read_ciexyz.isra.3 called 7 returned 100% blocks executed 82% 7: 738:_profile_read_ciexyz(CmsProfileObject* self, cmsTagSignature info, int multi) -: 739:{ -: 740: cmsCIEXYZ* XYZ; -: 741: 7: 742: if (!cmsIsTag(self->profile, info)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 743: Py_INCREF(Py_None); -: 744: return Py_None; -: 745: } -: 746: 7: 747: XYZ = (cmsCIEXYZ*) cmsReadTag(self->profile, info); call 0 returned 100% 7: 748: if (!XYZ) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 749: Py_INCREF(Py_None); -: 750: return Py_None; -: 751: } 7: 752: if (multi) { branch 0 taken 14% (fallthrough) branch 1 taken 86% 1: 753: return _xyz3_py(XYZ); call 0 returned 100% -: 754: } else { 6: 755: return _xyz_py(XYZ); call 0 returned 100% -: 756: } -: 757:} -: 758: -: 759:static PyObject* function _profile_read_ciexyy_triple.isra.0 called 1 returned 100% blocks executed 56% 1: 760:_profile_read_ciexyy_triple(CmsProfileObject* self, cmsTagSignature info) -: 761:{ -: 762: cmsCIExyYTRIPLE* triple; -: 763: 1: 764: if (!cmsIsTag(self->profile, info)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 1: 765: Py_INCREF(Py_None); -: 766: return Py_None; -: 767: } -: 768: #####: 769: triple = (cmsCIExyYTRIPLE*) cmsReadTag(self->profile, info); call 0 never executed #####: 770: if (!triple) { branch 0 never executed branch 1 never executed #####: 771: Py_INCREF(Py_None); -: 772: return Py_None; -: 773: } -: 774: -: 775: /* Note: lcms does all the heavy lifting and error checking (nr of -: 776: channels == 3). */ #####: 777: return Py_BuildValue("((d,d,d),(d,d,d),(d,d,d)),", call 0 never executed -: 778: triple->Red.x, triple->Red.y, triple->Red.Y, -: 779: triple->Green.x, triple->Green.y, triple->Green.Y, -: 780: triple->Blue.x, triple->Blue.y, triple->Blue.Y); -: 781:} -: 782: -: 783:static PyObject* function _profile_read_named_color_list.isra.2 called 2 returned 100% blocks executed 24% 2: 784:_profile_read_named_color_list(CmsProfileObject* self, cmsTagSignature info) -: 785:{ -: 786: cmsNAMEDCOLORLIST* ncl; -: 787: int i, n; -: 788: char name[cmsMAX_PATH]; -: 789: PyObject* result; -: 790: 2: 791: if (!cmsIsTag(self->profile, info)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 2: 792: Py_INCREF(Py_None); -: 793: return Py_None; -: 794: } -: 795: #####: 796: ncl = (cmsNAMEDCOLORLIST*) cmsReadTag(self->profile, info); call 0 never executed #####: 797: if (ncl == NULL) { branch 0 never executed branch 1 never executed #####: 798: Py_INCREF(Py_None); -: 799: return Py_None; -: 800: } -: 801: #####: 802: n = cmsNamedColorCount(ncl); call 0 never executed #####: 803: result = PyList_New(n); call 0 never executed #####: 804: if (!result) { branch 0 never executed branch 1 never executed #####: 805: Py_INCREF(Py_None); -: 806: return Py_None; -: 807: } -: 808: #####: 809: for (i = 0; i < n; i++) { branch 0 never executed branch 1 never executed -: 810: PyObject* str; #####: 811: cmsNamedColorInfo(ncl, i, name, NULL, NULL, NULL, NULL); call 0 never executed #####: 812: str = PyUnicode_FromString(name); call 0 never executed #####: 813: if (str == NULL) { branch 0 never executed branch 1 never executed #####: 814: Py_DECREF(result); branch 0 never executed branch 1 never executed call 2 never executed #####: 815: Py_INCREF(Py_None); -: 816: return Py_None; -: 817: } #####: 818: PyList_SET_ITEM(result, i, str); -: 819: } -: 820: -: 821: return result; -: 822:} -: 823: function _calculate_rgb_primaries.isra.4 called 3 returned 100% blocks executed 100% 3: 824:static cmsBool _calculate_rgb_primaries(CmsProfileObject* self, cmsCIEXYZTRIPLE* result) -: 825:{ 3: 826: double input[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; -: 827: cmsHPROFILE hXYZ; -: 828: cmsHTRANSFORM hTransform; -: 829: -: 830: /* https://littlecms2.blogspot.com/2009/07/less-is-more.html */ -: 831: -: 832: // double array of RGB values with max on each identity 3: 833: hXYZ = cmsCreateXYZProfile(); call 0 returned 100% 3: 834: if (hXYZ == NULL) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 835: return 0; -: 836: } -: 837: -: 838: // transform from our profile to XYZ using doubles for highest precision 3: 839: hTransform = cmsCreateTransform(self->profile, TYPE_RGB_DBL, call 0 returned 100% -: 840: hXYZ, TYPE_XYZ_DBL, -: 841: INTENT_RELATIVE_COLORIMETRIC, -: 842: cmsFLAGS_NOCACHE | cmsFLAGS_NOOPTIMIZE); 3: 843: cmsCloseProfile(hXYZ); call 0 returned 100% 3: 844: if (hTransform == NULL) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 845: return 0; -: 846: } -: 847: 3: 848: cmsDoTransform(hTransform, (void*) input, result, 3); call 0 returned 100% 3: 849: cmsDeleteTransform(hTransform); call 0 returned 100% -: 850: return 1; -: 851:} -: 852: function _check_intent called 24 returned 100% blocks executed 100% 24: 853:static cmsBool _check_intent(int clut, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number UsedDirection) -: 854:{ 24: 855: if (clut) { branch 0 taken 50% (fallthrough) branch 1 taken 50% 12: 856: return cmsIsCLUT(hProfile, Intent, UsedDirection); call 0 returned 100% -: 857: } -: 858: else { 12: 859: return cmsIsIntentSupported(hProfile, Intent, UsedDirection); call 0 returned 100% -: 860: } -: 861:} -: 862: -: 863:#define INTENTS 200 -: 864: -: 865:static PyObject* function _is_intent_supported.isra.1 called 2 returned 100% blocks executed 66% 2: 866:_is_intent_supported(CmsProfileObject* self, int clut) -: 867:{ -: 868: PyObject* result; -: 869: int n; -: 870: int i; -: 871: cmsUInt32Number intent_ids[INTENTS]; -: 872: char *intent_descs[INTENTS]; -: 873: 2: 874: result = PyDict_New(); call 0 returned 100% 2: 875: if (result == NULL) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 876: Py_INCREF(Py_None); -: 877: return Py_None; -: 878: } -: 879: -: 880: 2: 881: n = cmsGetSupportedIntents(INTENTS, call 0 returned 100% -: 882: intent_ids, -: 883: intent_descs); 22: 884: for (i = 0; i < n; i++) { branch 0 taken 91% branch 1 taken 9% (fallthrough) 20: 885: int intent = (int) intent_ids[i]; -: 886: PyObject* id; -: 887: PyObject* entry; -: 888: -: 889: /* Only valid for ICC Intents (otherwise we read invalid memory in lcms cmsio1.c). */ 20: 890: if (!(intent == INTENT_PERCEPTUAL || intent == INTENT_RELATIVE_COLORIMETRIC branch 0 taken 60% (fallthrough) branch 1 taken 40% -: 891: || intent == INTENT_SATURATION || intent == INTENT_ABSOLUTE_COLORIMETRIC)) { 12: 892: continue; -: 893: } -: 894: 8: 895: id = PyLong_FromLong((long) intent); call 0 returned 100% 24: 896: entry = Py_BuildValue("(OOO)", branch 0 taken 50% (fallthrough) branch 1 taken 50% branch 2 taken 50% (fallthrough) branch 3 taken 50% branch 4 taken 0% (fallthrough) branch 5 taken 100% call 6 returned 100% 8: 897: _check_intent(clut, self->profile, intent, LCMS_USED_AS_INPUT) ? Py_True : Py_False, call 0 returned 100% 8: 898: _check_intent(clut, self->profile, intent, LCMS_USED_AS_OUTPUT) ? Py_True : Py_False, call 0 returned 100% 8: 899: _check_intent(clut, self->profile, intent, LCMS_USED_AS_PROOF) ? Py_True : Py_False); call 0 returned 100% 8: 900: if (id == NULL || entry == NULL) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% #####: 901: Py_XDECREF(id); branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed call 4 never executed #####: 902: Py_XDECREF(entry); branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed call 4 never executed #####: 903: Py_XDECREF(result); branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed call 4 never executed #####: 904: Py_INCREF(Py_None); -: 905: return Py_None; -: 906: } 8: 907: PyDict_SetItem(result, id, entry); call 0 returned 100% -: 908: } -: 909: return result; -: 910:} -: 911: -: 912:/* -------------------------------------------------------------------- */ -: 913:/* Python interface setup */ -: 914: -: 915:static PyMethodDef pyCMSdll_methods[] = { -: 916: -: 917: {"profile_open", cms_profile_open, 1}, -: 918: {"profile_frombytes", cms_profile_fromstring, 1}, -: 919: {"profile_fromstring", cms_profile_fromstring, 1}, -: 920: {"profile_tobytes", cms_profile_tobytes, 1}, -: 921: -: 922: /* profile and transform functions */ -: 923: {"buildTransform", buildTransform, 1}, -: 924: {"buildProofTransform", buildProofTransform, 1}, -: 925: {"createProfile", createProfile, 1}, -: 926: -: 927: /* platform specific tools */ -: 928:#ifdef _WIN32 -: 929: {"get_display_profile_win32", cms_get_display_profile_win32, 1}, -: 930:#endif -: 931: -: 932: {NULL, NULL} -: 933:}; -: 934: -: 935:static struct PyMethodDef cms_profile_methods[] = { -: 936: {"is_intent_supported", (PyCFunction) cms_profile_is_intent_supported, 1}, -: 937: {NULL, NULL} /* sentinel */ -: 938:}; -: 939: -: 940:static PyObject* function cms_profile_getattr_rendering_intent called 3 returned 100% blocks executed 100% 3: 941:cms_profile_getattr_rendering_intent(CmsProfileObject* self, void* closure) -: 942:{ 3: 943: return PyLong_FromLong(cmsGetHeaderRenderingIntent(self->profile)); call 0 returned 100% call 1 returned 100% -: 944:} -: 945: -: 946:/* New-style unicode interfaces. */ -: 947:static PyObject* function cms_profile_getattr_copyright called 3 returned 100% blocks executed 100% 3: 948:cms_profile_getattr_copyright(CmsProfileObject* self, void* closure) -: 949:{ 3: 950: return _profile_read_mlu(self, cmsSigCopyrightTag); call 0 returned 100% -: 951:} -: 952: -: 953:static PyObject* function cms_profile_getattr_target called 1 returned 100% blocks executed 100% 1: 954:cms_profile_getattr_target(CmsProfileObject* self, void* closure) -: 955:{ 1: 956: return _profile_read_mlu(self, cmsSigCharTargetTag); call 0 returned 100% -: 957:} -: 958: -: 959:static PyObject* function cms_profile_getattr_manufacturer called 6 returned 100% blocks executed 100% 6: 960:cms_profile_getattr_manufacturer(CmsProfileObject* self, void* closure) -: 961:{ 6: 962: return _profile_read_mlu(self, cmsSigDeviceMfgDescTag); call 0 returned 100% -: 963:} -: 964: -: 965:static PyObject* function cms_profile_getattr_model called 7 returned 100% blocks executed 100% 7: 966:cms_profile_getattr_model(CmsProfileObject* self, void* closure) -: 967:{ 7: 968: return _profile_read_mlu(self, cmsSigDeviceModelDescTag); call 0 returned 100% -: 969:} -: 970: -: 971:static PyObject* function cms_profile_getattr_profile_description called 6 returned 100% blocks executed 100% 6: 972:cms_profile_getattr_profile_description(CmsProfileObject* self, void* closure) -: 973:{ 6: 974: return _profile_read_mlu(self, cmsSigProfileDescriptionTag); call 0 returned 100% -: 975:} -: 976: -: 977:static PyObject* function cms_profile_getattr_screening_description called 1 returned 100% blocks executed 100% 1: 978:cms_profile_getattr_screening_description(CmsProfileObject* self, void* closure) -: 979:{ 1: 980: return _profile_read_mlu(self, cmsSigScreeningDescTag); call 0 returned 100% -: 981:} -: 982: -: 983:static PyObject* function cms_profile_getattr_viewing_condition called 1 returned 100% blocks executed 100% 1: 984:cms_profile_getattr_viewing_condition(CmsProfileObject* self, void* closure) -: 985:{ 1: 986: return _profile_read_mlu(self, cmsSigViewingCondDescTag); call 0 returned 100% -: 987:} -: 988: -: 989:static PyObject* function cms_profile_getattr_creation_date called 1 returned 100% blocks executed 80% 1: 990:cms_profile_getattr_creation_date(CmsProfileObject* self, void* closure) -: 991:{ -: 992: cmsBool result; -: 993: struct tm ct; -: 994: 1: 995: result = cmsGetHeaderCreationDateTime(self->profile, &ct); call 0 returned 100% 1: 996: if (! result) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 997: Py_INCREF(Py_None); #####: 998: return Py_None; -: 999: } -: 1000: 1: 1001: return PyDateTime_FromDateAndTime(1900 + ct.tm_year, ct.tm_mon, ct.tm_mday, call 0 returned 100% -: 1002: ct.tm_hour, ct.tm_min, ct.tm_sec, 0); -: 1003:} -: 1004: -: 1005:static PyObject* function cms_profile_getattr_version called 1 returned 100% blocks executed 100% 1: 1006:cms_profile_getattr_version(CmsProfileObject* self, void* closure) -: 1007:{ 1: 1008: cmsFloat64Number version = cmsGetProfileVersion(self->profile); call 0 returned 100% 1: 1009: return PyFloat_FromDouble(version); call 0 returned 100% -: 1010:} -: 1011: -: 1012:static PyObject* function cms_profile_getattr_icc_version called 1 returned 100% blocks executed 100% 1: 1013:cms_profile_getattr_icc_version(CmsProfileObject* self, void* closure) -: 1014:{ 1: 1015: return PyLong_FromLong((long) cmsGetEncodedICCversion(self->profile)); call 0 returned 100% call 1 returned 100% -: 1016:} -: 1017: -: 1018:static PyObject* function cms_profile_getattr_attributes called 1 returned 100% blocks executed 100% 1: 1019:cms_profile_getattr_attributes(CmsProfileObject* self, void* closure) -: 1020:{ -: 1021: cmsUInt64Number attr; 1: 1022: cmsGetHeaderAttributes(self->profile, &attr); call 0 returned 100% -: 1023: /* This works just as well on Windows (LLP64), 32-bit Linux -: 1024: (ILP32) and 64-bit Linux (LP64) systems. */ 1: 1025: return PyLong_FromUnsignedLongLong((unsigned long long) attr); call 0 returned 100% -: 1026:} -: 1027: -: 1028:static PyObject* function cms_profile_getattr_header_flags called 1 returned 100% blocks executed 100% 1: 1029:cms_profile_getattr_header_flags(CmsProfileObject* self, void* closure) -: 1030:{ 1: 1031: cmsUInt32Number flags = cmsGetHeaderFlags(self->profile); call 0 returned 100% 1: 1032: return PyLong_FromLong(flags); call 0 returned 100% -: 1033:} -: 1034: -: 1035:static PyObject* function cms_profile_getattr_header_manufacturer called 1 returned 100% blocks executed 100% 1: 1036:cms_profile_getattr_header_manufacturer(CmsProfileObject* self, void* closure) -: 1037:{ 1: 1038: return _profile_read_int_as_string(cmsGetHeaderManufacturer(self->profile)); call 0 returned 100% call 1 returned 100% -: 1039:} -: 1040: -: 1041:static PyObject* function cms_profile_getattr_header_model called 1 returned 100% blocks executed 100% 1: 1042:cms_profile_getattr_header_model(CmsProfileObject* self, void* closure) -: 1043:{ 1: 1044: return _profile_read_int_as_string(cmsGetHeaderModel(self->profile)); call 0 returned 100% call 1 returned 100% -: 1045:} -: 1046: -: 1047:static PyObject* function cms_profile_getattr_device_class called 1 returned 100% blocks executed 100% 1: 1048:cms_profile_getattr_device_class(CmsProfileObject* self, void* closure) -: 1049:{ 1: 1050: return _profile_read_int_as_string(cmsGetDeviceClass(self->profile)); call 0 returned 100% call 1 returned 100% -: 1051:} -: 1052: -: 1053:static PyObject* function cms_profile_getattr_connection_space called 1 returned 100% blocks executed 100% 1: 1054:cms_profile_getattr_connection_space(CmsProfileObject* self, void* closure) -: 1055:{ 1: 1056: return _profile_read_int_as_string(cmsGetPCS(self->profile)); call 0 returned 100% call 1 returned 100% -: 1057:} -: 1058: -: 1059:static PyObject* function cms_profile_getattr_xcolor_space called 1 returned 100% blocks executed 100% 1: 1060:cms_profile_getattr_xcolor_space(CmsProfileObject* self, void* closure) -: 1061:{ 1: 1062: return _profile_read_int_as_string(cmsGetColorSpace(self->profile)); call 0 returned 100% call 1 returned 100% -: 1063:} -: 1064: -: 1065:static PyObject* function cms_profile_getattr_profile_id called 1 returned 100% blocks executed 100% 1: 1066:cms_profile_getattr_profile_id(CmsProfileObject* self, void* closure) -: 1067:{ -: 1068: cmsUInt8Number id[16]; 1: 1069: cmsGetHeaderProfileID(self->profile, id); call 0 returned 100% 1: 1070: return PyBytes_FromStringAndSize((char *) id, 16); call 0 returned 100% -: 1071:} -: 1072: -: 1073:static PyObject* function cms_profile_getattr_is_matrix_shaper called 1 returned 100% blocks executed 100% 1: 1074:cms_profile_getattr_is_matrix_shaper(CmsProfileObject* self, void* closure) -: 1075:{ 1: 1076: return PyBool_FromLong((long) cmsIsMatrixShaper(self->profile)); call 0 returned 100% call 1 returned 100% -: 1077:} -: 1078: -: 1079:static PyObject* function cms_profile_getattr_technology called 1 returned 100% blocks executed 100% 1: 1080:cms_profile_getattr_technology(CmsProfileObject* self, void* closure) -: 1081:{ 1: 1082: return _profile_read_signature(self, cmsSigTechnologyTag); call 0 returned 100% -: 1083:} -: 1084: -: 1085:static PyObject* function cms_profile_getattr_colorimetric_intent called 1 returned 100% blocks executed 100% 1: 1086:cms_profile_getattr_colorimetric_intent(CmsProfileObject* self, void* closure) -: 1087:{ 1: 1088: return _profile_read_signature(self, cmsSigColorimetricIntentImageStateTag); call 0 returned 100% -: 1089:} -: 1090: -: 1091:static PyObject* function cms_profile_getattr_perceptual_rendering_intent_gamut called 1 returned 100% blocks executed 100% 1: 1092:cms_profile_getattr_perceptual_rendering_intent_gamut(CmsProfileObject* self, void* closure) -: 1093:{ 1: 1094: return _profile_read_signature(self, cmsSigPerceptualRenderingIntentGamutTag); call 0 returned 100% -: 1095:} -: 1096: -: 1097:static PyObject* function cms_profile_getattr_saturation_rendering_intent_gamut called 1 returned 100% blocks executed 100% 1: 1098:cms_profile_getattr_saturation_rendering_intent_gamut(CmsProfileObject* self, void* closure) -: 1099:{ 1: 1100: return _profile_read_signature(self, cmsSigSaturationRenderingIntentGamutTag); call 0 returned 100% -: 1101:} -: 1102: -: 1103:static PyObject* function cms_profile_getattr_red_colorant called 1 returned 100% blocks executed 80% 1: 1104:cms_profile_getattr_red_colorant(CmsProfileObject* self, void* closure) -: 1105:{ 1: 1106: if (!cmsIsMatrixShaper(self->profile)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 1107: Py_INCREF(Py_None); #####: 1108: return Py_None; -: 1109: } 1: 1110: return _profile_read_ciexyz(self, cmsSigRedColorantTag, 0); call 0 returned 100% -: 1111:} -: 1112: -: 1113: -: 1114:static PyObject* function cms_profile_getattr_green_colorant called 1 returned 100% blocks executed 80% 1: 1115:cms_profile_getattr_green_colorant(CmsProfileObject* self, void* closure) -: 1116:{ 1: 1117: if (!cmsIsMatrixShaper(self->profile)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 1118: Py_INCREF(Py_None); #####: 1119: return Py_None; -: 1120: } 1: 1121: return _profile_read_ciexyz(self, cmsSigGreenColorantTag, 0); call 0 returned 100% -: 1122:} -: 1123: -: 1124: -: 1125:static PyObject* function cms_profile_getattr_blue_colorant called 1 returned 100% blocks executed 80% 1: 1126:cms_profile_getattr_blue_colorant(CmsProfileObject* self, void* closure) -: 1127:{ 1: 1128: if (!cmsIsMatrixShaper(self->profile)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 1129: Py_INCREF(Py_None); #####: 1130: return Py_None; -: 1131: } 1: 1132: return _profile_read_ciexyz(self, cmsSigBlueColorantTag, 0); call 0 returned 100% -: 1133:} -: 1134: -: 1135:static PyObject* function cms_profile_getattr_media_white_point_temperature called 1 returned 100% blocks executed 73% 1: 1136:cms_profile_getattr_media_white_point_temperature(CmsProfileObject *self, void* closure) -: 1137:{ -: 1138: cmsCIEXYZ* XYZ; -: 1139: cmsCIExyY xyY; -: 1140: cmsFloat64Number tempK; 1: 1141: cmsTagSignature info = cmsSigMediaWhitePointTag; -: 1142: cmsBool result; -: 1143: 1: 1144: if (!cmsIsTag(self->profile, info)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 1145: Py_INCREF(Py_None); #####: 1146: return Py_None; -: 1147: } -: 1148: 1: 1149: XYZ = (cmsCIEXYZ*) cmsReadTag(self->profile, info); call 0 returned 100% 1: 1150: if (!XYZ) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1151: Py_INCREF(Py_None); #####: 1152: return Py_None; -: 1153: } 1: 1154: if (XYZ == NULL || XYZ->X == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% #####: 1155: Py_INCREF(Py_None); #####: 1156: return Py_None; -: 1157: } -: 1158: 1: 1159: cmsXYZ2xyY(&xyY, XYZ); call 0 returned 100% 1: 1160: result = cmsTempFromWhitePoint(&tempK, &xyY); call 0 returned 100% 1: 1161: if (!result) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1162: Py_INCREF(Py_None); #####: 1163: return Py_None; -: 1164: } 1: 1165: return PyFloat_FromDouble(tempK); call 0 returned 100% -: 1166:} -: 1167: -: 1168:static PyObject* function cms_profile_getattr_media_white_point called 1 returned 100% blocks executed 100% 1: 1169:cms_profile_getattr_media_white_point(CmsProfileObject* self, void* closure) -: 1170:{ 1: 1171: return _profile_read_ciexyz(self, cmsSigMediaWhitePointTag, 0); call 0 returned 100% -: 1172:} -: 1173: -: 1174: -: 1175:static PyObject* function cms_profile_getattr_media_black_point called 1 returned 100% blocks executed 100% 1: 1176:cms_profile_getattr_media_black_point(CmsProfileObject* self, void* closure) -: 1177:{ 1: 1178: return _profile_read_ciexyz(self, cmsSigMediaBlackPointTag, 0); call 0 returned 100% -: 1179:} -: 1180: -: 1181:static PyObject* function cms_profile_getattr_luminance called 1 returned 100% blocks executed 100% 1: 1182:cms_profile_getattr_luminance(CmsProfileObject* self, void* closure) -: 1183:{ 1: 1184: return _profile_read_ciexyz(self, cmsSigLuminanceTag, 0); call 0 returned 100% -: 1185:} -: 1186: -: 1187:static PyObject* function cms_profile_getattr_chromatic_adaptation called 1 returned 100% blocks executed 100% 1: 1188:cms_profile_getattr_chromatic_adaptation(CmsProfileObject* self, void* closure) -: 1189:{ 1: 1190: return _profile_read_ciexyz(self, cmsSigChromaticAdaptationTag, 1); call 0 returned 100% -: 1191:} -: 1192: -: 1193:static PyObject* function cms_profile_getattr_chromaticity called 1 returned 100% blocks executed 100% 1: 1194:cms_profile_getattr_chromaticity(CmsProfileObject* self, void* closure) -: 1195:{ 1: 1196: return _profile_read_ciexyy_triple(self, cmsSigChromaticityTag); call 0 returned 100% -: 1197:} -: 1198: -: 1199:static PyObject* function cms_profile_getattr_red_primary called 1 returned 100% blocks executed 86% 1: 1200:cms_profile_getattr_red_primary(CmsProfileObject* self, void* closure) -: 1201:{ 1: 1202: cmsBool result = 0; -: 1203: cmsCIEXYZTRIPLE primaries; -: 1204: 1: 1205: if (cmsIsMatrixShaper(self->profile)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 1: 1206: result = _calculate_rgb_primaries(self, &primaries); call 0 returned 100% -: 1207: } 1: 1208: if (! result) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1209: Py_INCREF(Py_None); #####: 1210: return Py_None; -: 1211: } -: 1212: 1: 1213: return _xyz_py(&primaries.Red); call 0 returned 100% -: 1214:} -: 1215: -: 1216:static PyObject* function cms_profile_getattr_green_primary called 1 returned 100% blocks executed 86% 1: 1217:cms_profile_getattr_green_primary(CmsProfileObject* self, void* closure) -: 1218:{ 1: 1219: cmsBool result = 0; -: 1220: cmsCIEXYZTRIPLE primaries; -: 1221: 1: 1222: if (cmsIsMatrixShaper(self->profile)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 1: 1223: result = _calculate_rgb_primaries(self, &primaries); call 0 returned 100% -: 1224: } 1: 1225: if (! result) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1226: Py_INCREF(Py_None); #####: 1227: return Py_None; -: 1228: } -: 1229: 1: 1230: return _xyz_py(&primaries.Green); call 0 returned 100% -: 1231:} -: 1232: -: 1233:static PyObject* function cms_profile_getattr_blue_primary called 1 returned 100% blocks executed 86% 1: 1234:cms_profile_getattr_blue_primary(CmsProfileObject* self, void* closure) -: 1235:{ 1: 1236: cmsBool result = 0; -: 1237: cmsCIEXYZTRIPLE primaries; -: 1238: 1: 1239: if (cmsIsMatrixShaper(self->profile)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 1: 1240: result = _calculate_rgb_primaries(self, &primaries); call 0 returned 100% -: 1241: } 1: 1242: if (! result) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1243: Py_INCREF(Py_None); #####: 1244: return Py_None; -: 1245: } -: 1246: 1: 1247: return _xyz_py(&primaries.Blue); call 0 returned 100% -: 1248:} -: 1249: -: 1250:static PyObject* function cms_profile_getattr_colorant_table called 1 returned 100% blocks executed 100% 1: 1251:cms_profile_getattr_colorant_table(CmsProfileObject* self, void* closure) -: 1252:{ 1: 1253: return _profile_read_named_color_list(self, cmsSigColorantTableTag); call 0 returned 100% -: 1254:} -: 1255: -: 1256:static PyObject* function cms_profile_getattr_colorant_table_out called 1 returned 100% blocks executed 100% 1: 1257:cms_profile_getattr_colorant_table_out(CmsProfileObject* self, void* closure) -: 1258:{ 1: 1259: return _profile_read_named_color_list(self, cmsSigColorantTableOutTag); call 0 returned 100% -: 1260:} -: 1261: -: 1262:static PyObject* function cms_profile_getattr_is_intent_supported called 1 returned 100% blocks executed 100% 1: 1263:cms_profile_getattr_is_intent_supported (CmsProfileObject* self, void* closure) -: 1264:{ 1: 1265: return _is_intent_supported(self, 0); call 0 returned 100% -: 1266:} -: 1267: -: 1268:static PyObject* function cms_profile_getattr_is_clut called 1 returned 100% blocks executed 100% 1: 1269:cms_profile_getattr_is_clut (CmsProfileObject* self, void* closure) -: 1270:{ 1: 1271: return _is_intent_supported(self, 1); call 0 returned 100% -: 1272:} -: 1273: -: 1274:static const char* function _illu_map called 1 returned 100% blocks executed 27% 1: 1275:_illu_map(int i) -: 1276:{ 1: 1277: switch(i) { branch 0 taken 0% branch 1 taken 100% branch 2 taken 0% branch 3 taken 0% branch 4 taken 0% branch 5 taken 0% branch 6 taken 0% branch 7 taken 0% branch 8 taken 0% branch 9 taken 0% -: 1278: case 0: -: 1279: return "unknown"; -: 1280: case 1: #####: 1281: return "D50"; -: 1282: case 2: 1: 1283: return "D65"; -: 1284: case 3: #####: 1285: return "D93"; -: 1286: case 4: #####: 1287: return "F2"; -: 1288: case 5: #####: 1289: return "D55"; -: 1290: case 6: #####: 1291: return "A"; -: 1292: case 7: #####: 1293: return "E"; -: 1294: case 8: #####: 1295: return "F8"; -: 1296: default: #####: 1297: return NULL; -: 1298: } -: 1299:} -: 1300: -: 1301:static PyObject* function cms_profile_getattr_icc_measurement_condition called 1 returned 100% blocks executed 83% 1: 1302:cms_profile_getattr_icc_measurement_condition (CmsProfileObject* self, void* closure) -: 1303:{ -: 1304: cmsICCMeasurementConditions* mc; 1: 1305: cmsTagSignature info = cmsSigMeasurementTag; -: 1306: const char *geo; -: 1307: 1: 1308: if (!cmsIsTag(self->profile, info)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 1309: Py_INCREF(Py_None); #####: 1310: return Py_None; -: 1311: } -: 1312: 1: 1313: mc = (cmsICCMeasurementConditions*) cmsReadTag(self->profile, info); call 0 returned 100% 1: 1314: if (!mc) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1315: Py_INCREF(Py_None); #####: 1316: return Py_None; -: 1317: } -: 1318: 1: 1319: if (mc->Geometry == 1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1320: geo = "45/0, 0/45"; 1: 1321: } else if (mc->Geometry == 2) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1322: geo = "0d, d/0"; -: 1323: } else { 1: 1324: geo = "unknown"; -: 1325: } -: 1326: 2: 1327: return Py_BuildValue("{s:i,s:(ddd),s:s,s:d,s:s}", call 0 returned 100% call 1 returned 100% -: 1328: "observer", mc->Observer, -: 1329: "backing", mc->Backing.X, mc->Backing.Y, mc->Backing.Z, -: 1330: "geo", geo, -: 1331: "flare", mc->Flare, 1: 1332: "illuminant_type", _illu_map(mc->IlluminantType)); -: 1333:} -: 1334: -: 1335:static PyObject* function cms_profile_getattr_icc_viewing_condition called 1 returned 100% blocks executed 44% 1: 1336:cms_profile_getattr_icc_viewing_condition (CmsProfileObject* self, void* closure) -: 1337:{ -: 1338: cmsICCViewingConditions* vc; 1: 1339: cmsTagSignature info = cmsSigViewingConditionsTag; -: 1340: 1: 1341: if (!cmsIsTag(self->profile, info)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 1: 1342: Py_INCREF(Py_None); 1: 1343: return Py_None; -: 1344: } -: 1345: #####: 1346: vc = (cmsICCViewingConditions*) cmsReadTag(self->profile, info); call 0 never executed #####: 1347: if (!vc) { branch 0 never executed branch 1 never executed #####: 1348: Py_INCREF(Py_None); #####: 1349: return Py_None; -: 1350: } -: 1351: #####: 1352: return Py_BuildValue("{s:(ddd),s:(ddd),s:s}", call 0 never executed call 1 never executed -: 1353: "illuminant", vc->IlluminantXYZ.X, vc->IlluminantXYZ.Y, vc->IlluminantXYZ.Z, -: 1354: "surround", vc->SurroundXYZ.X, vc->SurroundXYZ.Y, vc->SurroundXYZ.Z, #####: 1355: "illuminant_type", _illu_map(vc->IlluminantType)); -: 1356:} -: 1357: -: 1358: -: 1359:static struct PyGetSetDef cms_profile_getsetters[] = { -: 1360: /* New style interfaces. */ -: 1361: { "rendering_intent", (getter) cms_profile_getattr_rendering_intent }, -: 1362: { "creation_date", (getter) cms_profile_getattr_creation_date }, -: 1363: { "copyright", (getter) cms_profile_getattr_copyright }, -: 1364: { "target", (getter) cms_profile_getattr_target }, -: 1365: { "manufacturer", (getter) cms_profile_getattr_manufacturer }, -: 1366: { "model", (getter) cms_profile_getattr_model }, -: 1367: { "profile_description", (getter) cms_profile_getattr_profile_description }, -: 1368: { "screening_description", (getter) cms_profile_getattr_screening_description }, -: 1369: { "viewing_condition", (getter) cms_profile_getattr_viewing_condition }, -: 1370: { "version", (getter) cms_profile_getattr_version }, -: 1371: { "icc_version", (getter) cms_profile_getattr_icc_version }, -: 1372: { "attributes", (getter) cms_profile_getattr_attributes }, -: 1373: { "header_flags", (getter) cms_profile_getattr_header_flags }, -: 1374: { "header_manufacturer", (getter) cms_profile_getattr_header_manufacturer }, -: 1375: { "header_model", (getter) cms_profile_getattr_header_model }, -: 1376: { "device_class", (getter) cms_profile_getattr_device_class }, -: 1377: { "connection_space", (getter) cms_profile_getattr_connection_space }, -: 1378: { "xcolor_space", (getter) cms_profile_getattr_xcolor_space }, -: 1379: { "profile_id", (getter) cms_profile_getattr_profile_id }, -: 1380: { "is_matrix_shaper", (getter) cms_profile_getattr_is_matrix_shaper }, -: 1381: { "technology", (getter) cms_profile_getattr_technology }, -: 1382: { "colorimetric_intent", (getter) cms_profile_getattr_colorimetric_intent }, -: 1383: { "perceptual_rendering_intent_gamut", (getter) cms_profile_getattr_perceptual_rendering_intent_gamut }, -: 1384: { "saturation_rendering_intent_gamut", (getter) cms_profile_getattr_saturation_rendering_intent_gamut }, -: 1385: { "red_colorant", (getter) cms_profile_getattr_red_colorant }, -: 1386: { "green_colorant", (getter) cms_profile_getattr_green_colorant }, -: 1387: { "blue_colorant", (getter) cms_profile_getattr_blue_colorant }, -: 1388: { "red_primary", (getter) cms_profile_getattr_red_primary }, -: 1389: { "green_primary", (getter) cms_profile_getattr_green_primary }, -: 1390: { "blue_primary", (getter) cms_profile_getattr_blue_primary }, -: 1391: { "media_white_point_temperature", (getter) cms_profile_getattr_media_white_point_temperature }, -: 1392: { "media_white_point", (getter) cms_profile_getattr_media_white_point }, -: 1393: { "media_black_point", (getter) cms_profile_getattr_media_black_point }, -: 1394: { "luminance", (getter) cms_profile_getattr_luminance }, -: 1395: { "chromatic_adaptation", (getter) cms_profile_getattr_chromatic_adaptation }, -: 1396: { "chromaticity", (getter) cms_profile_getattr_chromaticity }, -: 1397: { "colorant_table", (getter) cms_profile_getattr_colorant_table }, -: 1398: { "colorant_table_out", (getter) cms_profile_getattr_colorant_table_out }, -: 1399: { "intent_supported", (getter) cms_profile_getattr_is_intent_supported }, -: 1400: { "clut", (getter) cms_profile_getattr_is_clut }, -: 1401: { "icc_measurement_condition", (getter) cms_profile_getattr_icc_measurement_condition }, -: 1402: { "icc_viewing_condition", (getter) cms_profile_getattr_icc_viewing_condition }, -: 1403: -: 1404: { NULL } -: 1405:}; -: 1406: -: 1407: -: 1408:static PyTypeObject CmsProfile_Type = { -: 1409: PyVarObject_HEAD_INIT(NULL, 0) -: 1410: "PIL._imagingcms.CmsProfile", /*tp_name */ -: 1411: sizeof(CmsProfileObject), 0,/*tp_basicsize, tp_itemsize */ -: 1412: /* methods */ -: 1413: (destructor) cms_profile_dealloc, /*tp_dealloc*/ -: 1414: 0, /*tp_print*/ -: 1415: 0, /*tp_getattr*/ -: 1416: 0, /*tp_setattr*/ -: 1417: 0, /*tp_compare*/ -: 1418: 0, /*tp_repr*/ -: 1419: 0, /*tp_as_number */ -: 1420: 0, /*tp_as_sequence */ -: 1421: 0, /*tp_as_mapping */ -: 1422: 0, /*tp_hash*/ -: 1423: 0, /*tp_call*/ -: 1424: 0, /*tp_str*/ -: 1425: 0, /*tp_getattro*/ -: 1426: 0, /*tp_setattro*/ -: 1427: 0, /*tp_as_buffer*/ -: 1428: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 1429: 0, /*tp_doc*/ -: 1430: 0, /*tp_traverse*/ -: 1431: 0, /*tp_clear*/ -: 1432: 0, /*tp_richcompare*/ -: 1433: 0, /*tp_weaklistoffset*/ -: 1434: 0, /*tp_iter*/ -: 1435: 0, /*tp_iternext*/ -: 1436: cms_profile_methods, /*tp_methods*/ -: 1437: 0, /*tp_members*/ -: 1438: cms_profile_getsetters, /*tp_getset*/ -: 1439:}; -: 1440: -: 1441:static struct PyMethodDef cms_transform_methods[] = { -: 1442: {"apply", (PyCFunction) cms_transform_apply, 1}, -: 1443: {NULL, NULL} /* sentinel */ -: 1444:}; -: 1445: -: 1446:static PyObject* function cms_transform_getattr_inputMode called 0 returned 0% blocks executed 0% #####: 1447:cms_transform_getattr_inputMode(CmsTransformObject* self, void* closure) -: 1448:{ #####: 1449: return PyUnicode_FromString(self->mode_in); call 0 never executed -: 1450:} -: 1451: -: 1452:static PyObject* function cms_transform_getattr_outputMode called 0 returned 0% blocks executed 0% #####: 1453:cms_transform_getattr_outputMode(CmsTransformObject* self, void* closure) -: 1454:{ #####: 1455: return PyUnicode_FromString(self->mode_out); call 0 never executed -: 1456:} -: 1457: -: 1458:static struct PyGetSetDef cms_transform_getsetters[] = { -: 1459: { "inputMode", (getter) cms_transform_getattr_inputMode }, -: 1460: { "outputMode", (getter) cms_transform_getattr_outputMode }, -: 1461: { NULL } -: 1462:}; -: 1463: -: 1464:static PyTypeObject CmsTransform_Type = { -: 1465: PyVarObject_HEAD_INIT(NULL, 0) -: 1466: "CmsTransform", sizeof(CmsTransformObject), 0, -: 1467: /* methods */ -: 1468: (destructor) cms_transform_dealloc, /*tp_dealloc*/ -: 1469: 0, /*tp_print*/ -: 1470: 0, /*tp_getattr*/ -: 1471: 0, /*tp_setattr*/ -: 1472: 0, /*tp_compare*/ -: 1473: 0, /*tp_repr*/ -: 1474: 0, /*tp_as_number */ -: 1475: 0, /*tp_as_sequence */ -: 1476: 0, /*tp_as_mapping */ -: 1477: 0, /*tp_hash*/ -: 1478: 0, /*tp_call*/ -: 1479: 0, /*tp_str*/ -: 1480: 0, /*tp_getattro*/ -: 1481: 0, /*tp_setattro*/ -: 1482: 0, /*tp_as_buffer*/ -: 1483: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 1484: 0, /*tp_doc*/ -: 1485: 0, /*tp_traverse*/ -: 1486: 0, /*tp_clear*/ -: 1487: 0, /*tp_richcompare*/ -: 1488: 0, /*tp_weaklistoffset*/ -: 1489: 0, /*tp_iter*/ -: 1490: 0, /*tp_iternext*/ -: 1491: cms_transform_methods, /*tp_methods*/ -: 1492: 0, /*tp_members*/ -: 1493: cms_transform_getsetters, /*tp_getset*/ -: 1494:}; -: 1495: -: 1496:static int function setup_module called 3 returned 100% blocks executed 100% 3: 1497:setup_module(PyObject* m) { -: 1498: PyObject *d; -: 1499: PyObject *v; -: 1500: int vn; -: 1501: 3: 1502: d = PyModule_GetDict(m); call 0 returned 100% -: 1503: 3: 1504: CmsProfile_Type.tp_new = PyType_GenericNew; -: 1505: -: 1506: /* Ready object types */ 3: 1507: PyType_Ready(&CmsProfile_Type); call 0 returned 100% 3: 1508: PyType_Ready(&CmsTransform_Type); call 0 returned 100% -: 1509: 3: 1510: Py_INCREF(&CmsProfile_Type); 3: 1511: PyModule_AddObject(m, "CmsProfile", (PyObject *)&CmsProfile_Type); call 0 returned 100% -: 1512: 3: 1513: d = PyModule_GetDict(m); call 0 returned 100% -: 1514: -: 1515: /* this check is also in PIL.features.pilinfo() */ -: 1516:#if LCMS_VERSION < 2070 3: 1517: vn = LCMS_VERSION; -: 1518:#else -: 1519: vn = cmsGetEncodedCMMversion(); -: 1520:#endif -: 1521: if (vn % 10) { -: 1522: v = PyUnicode_FromFormat("%d.%d.%d", vn / 1000, (vn / 10) % 100, vn % 10); -: 1523: } else { 3: 1524: v = PyUnicode_FromFormat("%d.%d", vn / 1000, (vn / 10) % 100); call 0 returned 100% -: 1525: } 3: 1526: PyDict_SetItemString(d, "littlecms_version", v); call 0 returned 100% -: 1527: 3: 1528: return 0; -: 1529:} -: 1530: -: 1531:PyMODINIT_FUNC function PyInit__imagingcms called 3 returned 100% blocks executed 100% 3: 1532:PyInit__imagingcms(void) { -: 1533: PyObject* m; -: 1534: -: 1535: static PyModuleDef module_def = { -: 1536: PyModuleDef_HEAD_INIT, -: 1537: "_imagingcms", /* m_name */ -: 1538: NULL, /* m_doc */ -: 1539: -1, /* m_size */ -: 1540: pyCMSdll_methods, /* m_methods */ -: 1541: }; -: 1542: 3: 1543: m = PyModule_Create(&module_def); call 0 returned 100% -: 1544: 3: 1545: if (setup_module(m) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 1546: return NULL; -: 1547: } -: 1548: 3: 1549: PyDateTime_IMPORT; call 0 returned 100% -: 1550: 3: 1551: return m; -: 1552:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#TgaRleEncode.c.gcov -: 0:Source:src/libImaging/TgaRleEncode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/TgaRleEncode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/TgaRleEncode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1: -: 2:#include "Imaging.h" -: 3: -: 4:#include -: 5:#include -: 6: -: 7: -: 8:static int comparePixels(const UINT8* buf, int x, int bytesPerPixel) -: 9:{ 329175: 10: buf += x * bytesPerPixel; 329175: 11: return memcmp(buf, buf + bytesPerPixel, bytesPerPixel) == 0; -: 12:} -: 13: -: 14: -: 15:int function ImagingTgaRleEncode called 26 returned 100% blocks executed 100% 26: 16:ImagingTgaRleEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) -: 17:{ -: 18: UINT8* dst; -: 19: int bytesPerPixel; -: 20: 26: 21: if (state->state == 0) { branch 0 taken 77% (fallthrough) branch 1 taken 23% 20: 22: if (state->ystep < 0) { branch 0 taken 60% (fallthrough) branch 1 taken 40% 12: 23: state->ystep = -1; 12: 24: state->y = state->ysize - 1; -: 25: } else { 8: 26: state->ystep = 1; -: 27: } -: 28: 20: 29: state->state = 1; -: 30: } -: 31: 26: 32: dst = buf; 26: 33: bytesPerPixel = (state->bits + 7) / 8; -: 34: -: 35: while (1) { -: 36: int flushCount; -: 37: -: 38: /* -: 39: * state->count is the numbers of bytes in the packet, -: 40: * excluding the 1-byte descriptor. -: 41: */ 35468: 42: if (state->count == 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 43: UINT8* row; -: 44: UINT8 descriptor; -: 45: int startX; -: 46: -: 47: assert(state->x <= state->xsize); -: 48: -: 49: /* Make sure we have space for the descriptor. */ 35456: 50: if (bytes < 1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 51: break; -: 52: } -: 53: 35456: 54: if (state->x == state->xsize) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 1680: 55: state->x = 0; -: 56: 1680: 57: state->y += state->ystep; 1680: 58: if (state->y < 0 || state->y >= state->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% 20: 59: state->errcode = IMAGING_CODEC_END; 20: 60: break; -: 61: } -: 62: } -: 63: 35436: 64: if (state->x == 0) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 3360: 65: state->shuffle( call 0 returned 100% -: 66: state->buffer, 1680: 67: (UINT8*)im->image[state->y + state->yoff] 1680: 68: + state->xoff * im->pixelsize, -: 69: state->xsize); -: 70: } -: 71: 35436: 72: row = state->buffer; -: 73: -: 74: /* Start with a raw packet for 1 px. */ 35436: 75: descriptor = 0; 35436: 76: startX = state->x; 35436: 77: state->count = bytesPerPixel; -: 78: 35436: 79: if (state->x + 1 < state->xsize) { branch 0 taken 98% (fallthrough) branch 1 taken 2% -: 80: int maxLookup; -: 81: int isRaw; -: 82: 69796: 83: isRaw = !comparePixels(row, state->x, bytesPerPixel); 34898: 84: ++state->x; -: 85: -: 86: /* -: 87: * A packet can contain up to 128 pixels; -: 88: * 2 are already behind (state->x points to -: 89: * the second one). -: 90: */ 34898: 91: maxLookup = state->x + 126; -: 92: /* A packet must not span multiple rows. */ 34898: 93: if (maxLookup > state->xsize - 1) { branch 0 taken 57% (fallthrough) branch 1 taken 43% 19998: 94: maxLookup = state->xsize - 1; -: 95: } -: 96: 34898: 97: if (isRaw) { branch 0 taken 52% (fallthrough) branch 1 taken 48% 222311: 98: while (state->x < maxLookup) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 442218: 99: if (!comparePixels(row, state->x, bytesPerPixel)) { branch 0 taken 93% (fallthrough) branch 1 taken 7% 205726: 100: ++state->x; -: 101: } else { -: 102: /* Two identical pixels will go to RLE packet. */ 15383: 103: --state->x; 15383: 104: break; -: 105: } -: 106: } -: 107: 16585: 108: state->count += (state->x - startX) * bytesPerPixel; -: 109: } else { -: 110: descriptor |= 0x80; -: 111: 73340: 112: while (state->x < maxLookup) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 146336: 113: if (comparePixels(row, state->x, bytesPerPixel)) { branch 0 taken 75% (fallthrough) branch 1 taken 25% 55027: 114: ++state->x; -: 115: } else { -: 116: break; -: 117: } -: 118: } -: 119: } -: 120: } -: 121: -: 122: /* -: 123: * state->x currently points to the last pixel to be -: 124: * included in the packet. The pixel count in the -: 125: * descriptor is 1 less than actual number of pixels in -: 126: * the packet, that is, state->x == startX if we encode -: 127: * only 1 pixel. -: 128: */ 35436: 129: descriptor += state->x - startX; 35436: 130: *dst++ = descriptor; 35436: 131: --bytes; -: 132: -: 133: /* Advance to past-the-last encoded pixel. */ 35436: 134: ++state->x; -: 135: } -: 136: -: 137: assert(bytes >= 0); -: 138: assert(state->count > 0); -: 139: assert(state->x > 0); -: 140: assert(state->count <= state->x * bytesPerPixel); -: 141: 35448: 142: if (bytes == 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 143: break; -: 144: } -: 145: 35442: 146: flushCount = state->count; 35442: 147: if (flushCount > bytes) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 6: 148: flushCount = bytes; -: 149: } -: 150: 106326: 151: memcpy( -: 152: dst, 70884: 153: state->buffer + (state->x * bytesPerPixel - state->count), -: 154: flushCount); 35442: 155: dst += flushCount; 35442: 156: bytes -= flushCount; -: 157: 35442: 158: state->count -= flushCount; 35442: 159: } -: 160: 26: 161: return dst - buf; -: 162:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Fill.c.gcov -: 0:Source:src/libImaging/Fill.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Fill.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Fill.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * fill image with constant pixel value -: 6: * -: 7: * history: -: 8: * 95-11-26 fl moved from Imaging.c -: 9: * 96-05-17 fl added radial fill, renamed wedge to linear -: 10: * 98-06-23 fl changed ImageFill signature -: 11: * -: 12: * Copyright (c) Secret Labs AB 1997-98. All rights reserved. -: 13: * Copyright (c) Fredrik Lundh 1995-96. -: 14: * -: 15: * See the README file for information on usage and redistribution. -: 16: */ -: 17: -: 18: -: 19:#include "Imaging.h" -: 20: -: 21:#include "math.h" -: 22: -: 23:Imaging function ImagingFill called 15960 returned 100% blocks executed 100% 15960: 24:ImagingFill(Imaging im, const void* colour) -: 25:{ -: 26: int x, y; -: 27: ImagingSectionCookie cookie; -: 28: 15960: 29: if (im->type == IMAGING_TYPE_SPECIAL) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 30: /* use generic API */ 67: 31: ImagingAccess access = ImagingAccessNew(im); call 0 returned 100% 67: 32: if (access) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 208: 33: for (y = 0; y < im->ysize; y++) { branch 0 taken 76% (fallthrough) branch 1 taken 24% 10752: 34: for (x = 0; x < im->xsize; x++) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 10752: 35: access->put_pixel(im, x, y, colour); call 0 returned 100% -: 36: } -: 37: } -: 38: ImagingAccessDelete(im, access); -: 39: } else { -: 40: /* wipe the image */ 1: 41: for (y = 0; y < im->ysize; y++) { branch 0 taken 50% branch 1 taken 50% 2: 42: memset(im->image[y], 0, im->linesize); -: 43: } -: 44: } -: 45: } else { 15893: 46: INT32 c = 0L; 15893: 47: ImagingSectionEnter(&cookie); call 0 returned 100% 31786: 48: memcpy(&c, colour, im->pixelsize); 15893: 49: if (im->image32 && c != 0L) { branch 0 taken 8% (fallthrough) branch 1 taken 92% branch 2 taken 40% (fallthrough) branch 3 taken 60% 118857: 50: for (y = 0; y < im->ysize; y++) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 120196328: 51: for (x = 0; x < im->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 120196328: 52: im->image32[y][x] = c; -: 53: } -: 54: } -: 55: } else { 15370: 56: unsigned char cc = (unsigned char) *(UINT8*) colour; 411627: 57: for (y = 0; y < im->ysize; y++) { branch 0 taken 96% branch 1 taken 4% (fallthrough) 792514: 58: memset(im->image[y], cc, im->linesize); -: 59: } -: 60: } 15893: 61: ImagingSectionLeave(&cookie); call 0 returned 100% -: 62: } -: 63: 15960: 64: return im; -: 65:} -: 66: -: 67:Imaging function ImagingFillLinearGradient called 12 returned 100% blocks executed 100% 12: 68:ImagingFillLinearGradient(const char *mode) -: 69:{ -: 70: Imaging im; -: 71: int y; -: 72: 12: 73: if (strlen(mode) != 1) { branch 0 taken 8% (fallthrough) branch 1 taken 92% 1: 74: return (Imaging) ImagingError_ModeError(); call 0 returned 100% -: 75: } -: 76: 11: 77: im = ImagingNewDirty(mode, 256, 256); call 0 returned 100% 11: 78: if (!im) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 79: return NULL; -: 80: } -: 81: 2816: 82: for (y = 0; y < 256; y++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 5632: 83: memset(im->image8[y], (unsigned char) y, 256); -: 84: } -: 85: -: 86: return im; -: 87:} -: 88: -: 89:Imaging function ImagingFillRadialGradient called 3 returned 100% blocks executed 100% 3: 90:ImagingFillRadialGradient(const char *mode) -: 91:{ -: 92: Imaging im; -: 93: int x, y; -: 94: int d; -: 95: 3: 96: if (strlen(mode) != 1) { branch 0 taken 33% (fallthrough) branch 1 taken 67% 1: 97: return (Imaging) ImagingError_ModeError(); call 0 returned 100% -: 98: } -: 99: 2: 100: im = ImagingNewDirty(mode, 256, 256); call 0 returned 100% 2: 101: if (!im) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 102: return NULL; -: 103: } -: 104: 512: 105: for (y = 0; y < 256; y++) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 131072: 106: for (x = 0; x < 256; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 131072: 107: d = (int) sqrt((double) ((x-128)*(x-128) + (y-128)*(y-128)) * 2.0); 131072: 108: if (d >= 255) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 10: 109: im->image8[y][x] = 255; -: 110: } else { 131062: 111: im->image8[y][x] = d; -: 112: } -: 113: } -: 114: } -: 115: -: 116: return im; -: 117:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Copy.c.gcov -: 0:Source:src/libImaging/Copy.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Copy.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Copy.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * copy image -: 6: * -: 7: * history: -: 8: * 95-11-26 fl Moved from Imaging.c -: 9: * 97-05-12 fl Added ImagingCopy2 -: 10: * 97-08-28 fl Allow imOut == NULL in ImagingCopy2 -: 11: * -: 12: * Copyright (c) Fredrik Lundh 1995-97. -: 13: * Copyright (c) Secret Labs AB 1997. -: 14: * -: 15: * See the README file for details on usage and redistribution. -: 16: */ -: 17: -: 18: -: 19:#include "Imaging.h" -: 20: -: 21: -: 22:static Imaging function _copy called 2788 returned 100% blocks executed 80% 2788: 23:_copy(Imaging imOut, Imaging imIn) -: 24:{ -: 25: ImagingSectionCookie cookie; -: 26: int y; -: 27: 2788: 28: if (!imIn) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 29: return (Imaging) ImagingError_ValueError(NULL); call 0 never executed -: 30: } -: 31: 2788: 32: imOut = ImagingNew2Dirty(imIn->mode, imOut, imIn); call 0 returned 100% 2788: 33: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 34: return NULL; -: 35: } -: 36: 2788: 37: ImagingCopyPalette(imOut, imIn); call 0 returned 100% -: 38: 2788: 39: ImagingSectionEnter(&cookie); call 0 returned 100% 2788: 40: if (imIn->block != NULL && imOut->block != NULL) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed #####: 41: memcpy(imOut->block, imIn->block, imIn->ysize * imIn->linesize); -: 42: } else { 420544: 43: for (y = 0; y < imIn->ysize; y++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 841088: 44: memcpy(imOut->image[y], imIn->image[y], imIn->linesize); -: 45: } -: 46: } 2788: 47: ImagingSectionLeave(&cookie); call 0 returned 100% -: 48: 2788: 49: return imOut; -: 50:} -: 51: -: 52:Imaging function ImagingCopy called 2576 returned 100% blocks executed 100% 2576: 53:ImagingCopy(Imaging imIn) -: 54:{ 2576: 55: return _copy(NULL, imIn); call 0 returned 100% -: 56:} -: 57: -: 58:Imaging function ImagingCopy2 called 212 returned 100% blocks executed 100% 212: 59:ImagingCopy2(Imaging imOut, Imaging imIn) -: 60:{ 212: 61: return _copy(imOut, imIn); call 0 returned 100% -: 62:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#AlphaComposite.c.gcov -: 0:Source:src/libImaging/AlphaComposite.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/AlphaComposite.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/AlphaComposite.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * Alpha composite imSrc over imDst. -: 6: * https://en.wikipedia.org/wiki/Alpha_compositing -: 7: * -: 8: * See the README file for details on usage and redistribution. -: 9: */ -: 10: -: 11: -: 12:#include "Imaging.h" -: 13: -: 14:#define PRECISION_BITS 7 -: 15: -: 16:typedef struct -: 17:{ -: 18: UINT8 r; -: 19: UINT8 g; -: 20: UINT8 b; -: 21: UINT8 a; -: 22:} rgba8; -: 23: -: 24: -: 25: -: 26:Imaging function ImagingAlphaComposite called 6 returned 100% blocks executed 91% 6: 27:ImagingAlphaComposite(Imaging imDst, Imaging imSrc) -: 28:{ -: 29: Imaging imOut; -: 30: int x, y; -: 31: -: 32: /* Check arguments */ 12: 33: if (!imDst || !imSrc || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% 12: 34: strcmp(imDst->mode, "RGBA") || branch 0 taken 100% (fallthrough) branch 1 taken 0% 12: 35: imDst->type != IMAGING_TYPE_UINT8 || branch 0 taken 0% (fallthrough) branch 1 taken 100% 6: 36: imDst->bands != 4) { #####: 37: return ImagingError_ModeError(); call 0 never executed -: 38: } -: 39: 12: 40: if (strcmp(imDst->mode, imSrc->mode) || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 6: 41: imDst->type != imSrc->type || 6: 42: imDst->bands != imSrc->bands || branch 0 taken 100% (fallthrough) branch 1 taken 0% 6: 43: imDst->xsize != imSrc->xsize || branch 0 taken 0% (fallthrough) branch 1 taken 100% 6: 44: imDst->ysize != imSrc->ysize) { #####: 45: return ImagingError_Mismatch(); call 0 never executed -: 46: } -: 47: 6: 48: imOut = ImagingNewDirty(imDst->mode, imDst->xsize, imDst->ysize); call 0 returned 100% 6: 49: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 50: return NULL; -: 51: } -: 52: 580: 53: for (y = 0; y < imDst->ysize; y++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 580: 54: rgba8* dst = (rgba8*) imDst->image[y]; 580: 55: rgba8* src = (rgba8*) imSrc->image[y]; 580: 56: rgba8* out = (rgba8*) imOut->image[y]; -: 57: 64852: 58: for (x = 0; x < imDst->xsize; x ++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 64272: 59: if (src->a == 0) { branch 0 taken 5% (fallthrough) branch 1 taken 95% -: 60: // Copy 4 bytes at once. 3300: 61: *out = *dst; -: 62: } else { -: 63: // Integer implementation with increased precision. -: 64: // Each variable has extra meaningful bits. -: 65: // Divisions are rounded. -: 66: -: 67: UINT32 tmpr, tmpg, tmpb; 60972: 68: UINT32 blend = dst->a * (255 - src->a); 60972: 69: UINT32 outa255 = src->a * 255 + blend; -: 70: // There we use 7 bits for precision. -: 71: // We could use more, but we go beyond 32 bits. 60972: 72: UINT32 coef1 = src->a * 255 * 255 * (1<r * coef1 + dst->r * coef2; 60972: 76: tmpg = src->g * coef1 + dst->g * coef2; 60972: 77: tmpb = src->b * coef1 + dst->b * coef2; 60972: 78: out->r = SHIFTFORDIV255(tmpr + (0x80<> PRECISION_BITS; 60972: 79: out->g = SHIFTFORDIV255(tmpg + (0x80<> PRECISION_BITS; 60972: 80: out->b = SHIFTFORDIV255(tmpb + (0x80<> PRECISION_BITS; 60972: 81: out->a = SHIFTFORDIV255(outa255 + 0x80); -: 82: } -: 83: 64272: 84: dst++; src++; out++; -: 85: } -: 86: -: 87: } -: 88: -: 89: return imOut; -: 90:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Blend.c.gcov -: 0:Source:src/libImaging/Blend.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Blend.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Blend.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * interpolate between two existing images -: 6: * -: 7: * history: -: 8: * 96-03-20 fl Created -: 9: * 96-05-18 fl Simplified blend expression -: 10: * 96-10-05 fl Fixed expression bug, special case for interpolation -: 11: * -: 12: * Copyright (c) Fredrik Lundh 1996. -: 13: * Copyright (c) Secret Labs AB 1997. -: 14: * -: 15: * See the README file for details on usage and redistribution. -: 16: */ -: 17: -: 18: -: 19:#include "Imaging.h" -: 20: -: 21: -: 22:Imaging function ImagingBlend called 19 returned 100% blocks executed 64% 19: 23:ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha) -: 24:{ -: 25: Imaging imOut; -: 26: int x, y; -: 27: -: 28: /* Check arguments */ 19: 29: if (!imIn1 || !imIn2 || imIn1->type != IMAGING_TYPE_UINT8 branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% 19: 30: || imIn1->palette || strcmp(imIn1->mode, "1") == 0 branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% branch 4 taken 100% (fallthrough) branch 5 taken 0% 19: 31: || imIn2->palette || strcmp(imIn2->mode, "1") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% branch 4 taken 0% (fallthrough) branch 5 taken 100% #####: 32: return ImagingError_ModeError(); call 0 never executed -: 33: } -: 34: 19: 35: if (imIn1->type != imIn2->type || branch 0 taken 100% (fallthrough) branch 1 taken 0% 19: 36: imIn1->bands != imIn2->bands || branch 0 taken 100% (fallthrough) branch 1 taken 0% 19: 37: imIn1->xsize != imIn2->xsize || branch 0 taken 0% (fallthrough) branch 1 taken 100% 19: 38: imIn1->ysize != imIn2->ysize) { #####: 39: return ImagingError_Mismatch(); call 0 never executed -: 40: } -: 41: -: 42: /* Shortcuts */ 19: 43: if (alpha == 0.0) { branch 0 taken 21% (fallthrough) branch 1 taken 79% 4: 44: return ImagingCopy(imIn1); call 0 returned 100% 15: 45: } else if (alpha == 1.0) { branch 0 taken 27% (fallthrough) branch 1 taken 73% 4: 46: return ImagingCopy(imIn2); call 0 returned 100% -: 47: } -: 48: 11: 49: imOut = ImagingNewDirty(imIn1->mode, imIn1->xsize, imIn1->ysize); call 0 returned 100% 11: 50: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 51: return NULL; -: 52: } -: 53: 11: 54: if (alpha >= 0 && alpha <= 1.0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% -: 55: /* Interpolate between bands */ 1253: 56: for (y = 0; y < imIn1->ysize; y++) { branch 0 taken 99% branch 1 taken 1% 1253: 57: UINT8* in1 = (UINT8*) imIn1->image[y]; 1253: 58: UINT8* in2 = (UINT8*) imIn2->image[y]; 1253: 59: UINT8* out = (UINT8*) imOut->image[y]; 581929: 60: for (x = 0; x < imIn1->linesize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 1161352: 61: out[x] = (UINT8) 580676: 62: ((int) in1[x] + alpha * ((int) in2[x] - (int) in1[x])); -: 63: } -: 64: } -: 65: } else { -: 66: /* Extrapolation; must make sure to clip resulting values */ #####: 67: for (y = 0; y < imIn1->ysize; y++) { branch 0 never executed branch 1 never executed #####: 68: UINT8* in1 = (UINT8*) imIn1->image[y]; #####: 69: UINT8* in2 = (UINT8*) imIn2->image[y]; #####: 70: UINT8* out = (UINT8*) imOut->image[y]; #####: 71: for (x = 0; x < imIn1->linesize; x++) { branch 0 never executed branch 1 never executed #####: 72: float temp = (float) #####: 73: ((int) in1[x] + alpha * ((int) in2[x] - (int) in1[x])); #####: 74: if (temp <= 0.0) { branch 0 never executed branch 1 never executed #####: 75: out[x] = 0; #####: 76: } else if (temp >= 255.0) { branch 0 never executed branch 1 never executed #####: 77: out[x] = 255; -: 78: } else { #####: 79: out[x] = (UINT8) temp; -: 80: } -: 81: } -: 82: } -: 83: } -: 84: -: 85: return imOut; -: 86:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#XbmEncode.c.gcov -: 0:Source:src/libImaging/XbmEncode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/XbmEncode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/XbmEncode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * encoder for Xbm data -: 6: * -: 7: * history: -: 8: * 96-11-01 fl created -: 9: * -: 10: * Copyright (c) Fredrik Lundh 1996. -: 11: * Copyright (c) Secret Labs AB 1997. -: 12: * -: 13: * See the README file for information on usage and redistribution. -: 14: */ -: 15: -: 16: -: 17:#include "Imaging.h" -: 18: -: 19: -: 20:int function ImagingXbmEncode called 13 returned 100% blocks executed 96% 13: 21:ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) -: 22:{ 13: 23: const char *hex = "0123456789abcdef"; -: 24: 13: 25: UINT8* ptr = buf; -: 26: int i, n; -: 27: 13: 28: if (!state->state) { branch 0 taken 31% (fallthrough) branch 1 taken 69% -: 29: -: 30: /* 8 pixels are stored in no more than 6 bytes */ 4: 31: state->bytes = 6*(state->xsize+7)/8; -: 32: 4: 33: state->state = 1; -: 34: -: 35: } -: 36: 13: 37: if (bytes < state->bytes) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 38: state->errcode = IMAGING_CODEC_MEMORY; #####: 39: return 0; -: 40: } -: 41: -: 42: ptr = buf; -: 43: 1393: 44: while (bytes >= state->bytes) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 45: 2768: 46: state->shuffle(state->buffer, call 0 returned 100% 1384: 47: (UINT8*) im->image[state->y + state->yoff] + 1384: 48: state->xoff * im->pixelsize, state->xsize); -: 49: 1384: 50: if (state->y < state->ysize-1) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 51: -: 52: /* any line but the last */ 130971: 53: for (n = 0; n < state->xsize; n += 8) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 54: 130971: 55: i = state->buffer[n/8]; -: 56: 130971: 57: *ptr++ = '0'; 130971: 58: *ptr++ = 'x'; 130971: 59: *ptr++ = hex[(i>>4)&15]; 130971: 60: *ptr++ = hex[i&15]; 130971: 61: *ptr++ = ','; 130971: 62: bytes -= 5; -: 63: 130971: 64: if (++state->count >= 79/5) { branch 0 taken 7% (fallthrough) branch 1 taken 93% 8730: 65: *ptr++ = '\n'; 8730: 66: bytes--; 8730: 67: state->count = 0; -: 68: } -: 69: -: 70: } -: 71: 1380: 72: state->y++; -: 73: -: 74: } else { -: 75: -: 76: /* last line */ 173: 77: for (n = 0; n < state->xsize; n += 8) { branch 0 taken 98% branch 1 taken 2% (fallthrough) -: 78: 173: 79: i = state->buffer[n/8]; -: 80: 173: 81: *ptr++ = '0'; 173: 82: *ptr++ = 'x'; 173: 83: *ptr++ = hex[(i>>4)&15]; 173: 84: *ptr++ = hex[i&15]; -: 85: 173: 86: if (n < state->xsize-8) { branch 0 taken 98% (fallthrough) branch 1 taken 2% 169: 87: *ptr++ = ','; 169: 88: if (++state->count >= 79/5) { branch 0 taken 7% (fallthrough) branch 1 taken 93% 11: 89: *ptr++ = '\n'; 11: 90: bytes--; 11: 91: state->count = 0; -: 92: } -: 93: } else { 4: 94: *ptr++ = '\n'; -: 95: } -: 96: 173: 97: bytes -= 5; -: 98: -: 99: } -: 100: 4: 101: state->errcode = IMAGING_CODEC_END; 4: 102: break; -: 103: } -: 104: } -: 105: 13: 106: return ptr - buf; -: 107:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#ModeFilter.c.gcov -: 0:Source:src/libImaging/ModeFilter.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/ModeFilter.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/ModeFilter.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * mode filter -: 6: * -: 7: * history: -: 8: * 2002-06-08 fl Created (based on code from IFUNC95) -: 9: * 2004-10-05 fl Rewritten; use a simpler brute-force algorithm -: 10: * -: 11: * Copyright (c) Secret Labs AB 2002-2004. All rights reserved. -: 12: * -: 13: * See the README file for information on usage and redistribution. -: 14: */ -: 15: -: 16:#include "Imaging.h" -: 17: -: 18:Imaging function ImagingModeFilter called 20 returned 100% blocks executed 97% 20: 19:ImagingModeFilter(Imaging im, int size) -: 20:{ -: 21: Imaging imOut; -: 22: int x, y, i; -: 23: int xx, yy; -: 24: int maxcount; -: 25: UINT8 maxpixel; -: 26: int histogram[256]; -: 27: 20: 28: if (!im || im->bands != 1 || im->type != IMAGING_TYPE_UINT8) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 0% (fallthrough) branch 5 taken 100% #####: 29: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 30: } -: 31: 20: 32: imOut = ImagingNewDirty(im->mode, im->xsize, im->ysize); call 0 returned 100% 20: 33: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 34: return NULL; -: 35: } -: 36: 20: 37: size = size / 2; -: 38: 1080: 39: for (y = 0; y < imOut->ysize; y++) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 1060: 40: UINT8* out = &IMAGING_PIXEL_L(imOut, 0, y); 132240: 41: for (x = 0; x < imOut->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 42: -: 43: /* calculate histogram over current area */ -: 44: -: 45: /* FIXME: brute force! to improve, update the histogram -: 46: incrementally. may also add a "frequent list", like in -: 47: the old implementation, but I'm not sure that's worth -: 48: the added complexity... */ -: 49: 131180: 50: memset(histogram, 0, sizeof(histogram)); 524720: 51: for (yy = y - size; yy <= y + size; yy++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 393540: 52: if (yy >= 0 && yy < imOut->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 99% (fallthrough) branch 3 taken 1% 391420: 53: UINT8* in = &IMAGING_PIXEL_L(im, 0, yy); 1565680: 54: for (xx = x - size; xx <= x + size; xx++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 1174260: 55: if (xx >= 0 && xx < imOut->xsize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 99% (fallthrough) branch 3 taken 1% 1167980: 56: histogram[in[xx]]++; -: 57: } -: 58: } -: 59: } -: 60: } -: 61: -: 62: /* find most frequent pixel value in this region */ 131180: 63: maxpixel = 0; 131180: 64: maxcount = histogram[maxpixel]; 33582080: 65: for (i = 1; i < 256; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 33450900: 66: if (histogram[i] > maxcount) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 188823: 67: maxcount = histogram[i]; 188823: 68: maxpixel = (UINT8) i; -: 69: } -: 70: } -: 71: 131180: 72: if (maxcount > 2) { branch 0 taken 47% (fallthrough) branch 1 taken 53% 61560: 73: out[x] = maxpixel; -: 74: } else { 69620: 75: out[x] = IMAGING_PIXEL_L(im, x, y); -: 76: } -: 77: -: 78: } -: 79: -: 80: } -: 81: 20: 82: ImagingCopyPalette(imOut, im); call 0 returned 100% -: 83: 20: 84: return imOut; -: 85:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Convert.c.gcov -: 0:Source:src/libImaging/Convert.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Convert.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Convert.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * convert images -: 6: * -: 7: * history: -: 8: * 1995-06-15 fl created -: 9: * 1995-11-28 fl added some "RGBA" and "CMYK" conversions -: 10: * 1996-04-22 fl added "1" conversions (same as "L") -: 11: * 1996-05-05 fl added palette conversions (hack) -: 12: * 1996-07-23 fl fixed "1" conversions to zero/non-zero convention -: 13: * 1996-11-01 fl fixed "P" to "L" and "RGB" to "1" conversions -: 14: * 1996-12-29 fl set alpha byte in RGB converters -: 15: * 1997-05-12 fl added ImagingConvert2 -: 16: * 1997-05-30 fl added floating point support -: 17: * 1997-08-27 fl added "P" to "1" and "P" to "F" conversions -: 18: * 1998-01-11 fl added integer support -: 19: * 1998-07-01 fl added "YCbCr" support -: 20: * 1998-07-02 fl added "RGBX" conversions (sort of) -: 21: * 1998-07-04 fl added floyd-steinberg dithering -: 22: * 1998-07-12 fl changed "YCrCb" to "YCbCr" (!) -: 23: * 1998-12-29 fl added basic "I;16" and "I;16B" conversions -: 24: * 1999-02-03 fl added "RGBa", and "BGR" conversions (experimental) -: 25: * 2003-09-26 fl added "LA" and "PA" conversions (experimental) -: 26: * 2005-05-05 fl fixed "P" to "1" threshold -: 27: * 2005-12-08 fl fixed palette memory leak in topalette -: 28: * -: 29: * Copyright (c) 1997-2005 by Secret Labs AB. -: 30: * Copyright (c) 1995-1997 by Fredrik Lundh. -: 31: * -: 32: * See the README file for details on usage and redistribution. -: 33: */ -: 34: -: 35: -: 36:#include "Imaging.h" -: 37: -: 38:#define MAX(a, b) (a)>(b) ? (a) : (b) -: 39:#define MIN(a, b) (a)<(b) ? (a) : (b) -: 40: -: 41:#define CLIP16(v) ((v) <= -32768 ? -32768 : (v) >= 32767 ? 32767 : (v)) -: 42: -: 43:/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ -: 44:#define L(rgb)\ -: 45: ((INT32) (rgb)[0]*299 + (INT32) (rgb)[1]*587 + (INT32) (rgb)[2]*114) -: 46:#define L24(rgb)\ -: 47: ((rgb)[0]*19595 + (rgb)[1]*38470 + (rgb)[2]*7471 + 0x8000) -: 48: -: 49: -: 50:#ifndef round -: 51:double round(double x) { #####: 52: return floor(x+0.5); -: 53:} -: 54:#endif -: 55: -: 56:/* ------------------- */ -: 57:/* 1 (bit) conversions */ -: 58:/* ------------------- */ -: 59: -: 60:static void function bit2l called 833 returned 100% blocks executed 100% 833: 61:bit2l(UINT8* out, const UINT8* in, int xsize) -: 62:{ -: 63: int x; 132930: 64: for (x = 0; x < xsize; x++) branch 0 taken 99% branch 1 taken 1% (fallthrough) 132097: 65: *out++ = (*in++ != 0) ? 255 : 0; branch 0 taken 33% (fallthrough) branch 1 taken 67% 833: 66:} -: 67: -: 68:static void function bit2rgb called 512 returned 100% blocks executed 100% 512: 69:bit2rgb(UINT8* out, const UINT8* in, int xsize) -: 70:{ -: 71: int x; 57856: 72: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 57344: 73: UINT8 v = (*in++ != 0) ? 255 : 0; branch 0 taken 65% (fallthrough) branch 1 taken 35% 57344: 74: *out++ = v; 57344: 75: *out++ = v; 57344: 76: *out++ = v; 57344: 77: *out++ = 255; -: 78: } 512: 79:} -: 80: -: 81:static void function bit2cmyk called 128 returned 100% blocks executed 100% 128: 82:bit2cmyk(UINT8* out, const UINT8* in, int xsize) -: 83:{ -: 84: int x; 16512: 85: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 86: *out++ = 0; 16384: 87: *out++ = 0; 16384: 88: *out++ = 0; 16384: 89: *out++ = (*in++ != 0) ? 0 : 255; branch 0 taken 67% (fallthrough) branch 1 taken 33% -: 90: } 128: 91:} -: 92: -: 93:static void function bit2ycbcr called 128 returned 100% blocks executed 100% 128: 94:bit2ycbcr(UINT8* out, const UINT8* in, int xsize) -: 95:{ -: 96: int x; 16512: 97: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 98: *out++ = (*in++ != 0) ? 255 : 0; branch 0 taken 67% (fallthrough) branch 1 taken 33% 16384: 99: *out++ = 128; 16384: 100: *out++ = 128; 16384: 101: *out++ = 255; -: 102: } 128: 103:} -: 104: -: 105:static void function bit2hsv called 128 returned 100% blocks executed 100% 128: 106:bit2hsv(UINT8* out, const UINT8* in, int xsize) -: 107:{ -: 108: int x; 16512: 109: for (x = 0; x < xsize; x++, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 110: UINT8 v = (*in++ != 0) ? 255 : 0; branch 0 taken 67% (fallthrough) branch 1 taken 33% 16384: 111: out[0] = 0; 16384: 112: out[1] = 0; 16384: 113: out[2] = v; 16384: 114: out[3] = 255; -: 115: } 128: 116:} -: 117: -: 118:/* ----------------- */ -: 119:/* RGB/L conversions */ -: 120:/* ----------------- */ -: 121: -: 122:static void function l2bit called 1 returned 100% blocks executed 83% 1: 123:l2bit(UINT8* out, const UINT8* in, int xsize) -: 124:{ -: 125: int x; 2: 126: for (x = 0; x < xsize; x++) { branch 0 taken 50% branch 1 taken 50% (fallthrough) 1: 127: *out++ = (*in++ >= 128) ? 255 : 0; branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 128: } 1: 129:} -: 130: -: 131:static void function lA2la called 75106 returned 100% blocks executed 100% 75106: 132:lA2la(UINT8* out, const UINT8* in, int xsize) -: 133:{ -: 134: int x; -: 135: unsigned int alpha, pixel, tmp; 37132631: 136: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 37057525: 137: alpha = in[3]; 37057525: 138: pixel = MULDIV255(in[0], alpha, tmp); 37057525: 139: *out++ = (UINT8) pixel; 37057525: 140: *out++ = (UINT8) pixel; 37057525: 141: *out++ = (UINT8) pixel; 37057525: 142: *out++ = (UINT8) alpha; -: 143: } 75106: 144:} -: 145: -: 146:/* RGBa -> RGBA conversion to remove premultiplication -: 147: Needed for correct transforms/resizing on RGBA images */ -: 148:static void function la2lA called 20827 returned 100% blocks executed 100% 20827: 149:la2lA(UINT8* out, const UINT8* in, int xsize) -: 150:{ -: 151: int x; -: 152: unsigned int alpha, pixel; 3420108: 153: for (x = 0; x < xsize; x++, in+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 3399281: 154: alpha = in[3]; 3399281: 155: if (alpha == 255 || alpha == 0) { branch 0 taken 48% (fallthrough) branch 1 taken 52% branch 2 taken 1% (fallthrough) branch 3 taken 99% 1779933: 156: pixel = in[0]; -: 157: } else { 1619348: 158: pixel = CLIP8((255 * in[0]) / alpha); branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 159: } 3399281: 160: *out++ = (UINT8) pixel; 3399281: 161: *out++ = (UINT8) pixel; 3399281: 162: *out++ = (UINT8) pixel; 3399281: 163: *out++ = (UINT8) alpha; -: 164: } 20827: 165:} -: 166: -: 167:static void function l2la called 523 returned 100% blocks executed 100% 523: 168:l2la(UINT8* out, const UINT8* in, int xsize) -: 169:{ -: 170: int x; 148690: 171: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% branch 2 taken 99% branch 3 taken 1% (fallthrough) 147527: 172: UINT8 v = *in++; 147527: 173: *out++ = v; 147527: 174: *out++ = v; 147527: 175: *out++ = v; 147527: 176: *out++ = 255; -: 177: } 523: 178:} -: 179: -: 180:static void function l2rgb called 5392 returned 100% blocks executed 100% 5392: 181:l2rgb(UINT8* out, const UINT8* in, int xsize) -: 182:{ -: 183: int x; 1866626: 184: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 1861234: 185: UINT8 v = *in++; 1861234: 186: *out++ = v; 1861234: 187: *out++ = v; 1861234: 188: *out++ = v; 1861234: 189: *out++ = 255; -: 190: } 5392: 191:} -: 192: -: 193:static void function l2hsv called 256 returned 100% blocks executed 100% 256: 194:l2hsv(UINT8* out, const UINT8* in, int xsize) -: 195:{ -: 196: int x; 33024: 197: for (x = 0; x < xsize; x++, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 32768: 198: UINT8 v = *in++; 32768: 199: out[0] = 0; 32768: 200: out[1] = 0; 32768: 201: out[2] = v; 32768: 202: out[3] = 255; -: 203: } 256: 204:} -: 205: -: 206:static void function la2l called 1024 returned 100% blocks executed 100% 1024: 207:la2l(UINT8* out, const UINT8* in, int xsize) -: 208:{ -: 209: int x; 132096: 210: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 131072: 211: *out++ = in[0]; -: 212: } 1024: 213:} -: 214: -: 215:static void function la2rgb called 896 returned 100% blocks executed 100% 896: 216:la2rgb(UINT8* out, const UINT8* in, int xsize) -: 217:{ -: 218: int x; 115584: 219: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 114688: 220: UINT8 v = in[0]; 114688: 221: *out++ = v; 114688: 222: *out++ = v; 114688: 223: *out++ = v; 114688: 224: *out++ = in[3]; -: 225: } 896: 226:} -: 227: -: 228:static void function la2hsv called 128 returned 100% blocks executed 100% 128: 229:la2hsv(UINT8* out, const UINT8* in, int xsize) -: 230:{ -: 231: int x; 16512: 232: for (x = 0; x < xsize; x++, in += 4, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 233: UINT8 v = in[0]; 16384: 234: out[0] = 0; 16384: 235: out[1] = 0; 16384: 236: out[2] = v; 16384: 237: out[3] = in[3]; -: 238: } 128: 239:} -: 240: -: 241:static void function rgb2bit called 0 returned 0% blocks executed 0% #####: 242:rgb2bit(UINT8* out, const UINT8* in, int xsize) -: 243:{ -: 244: int x; #####: 245: for (x = 0; x < xsize; x++, in += 4) { branch 0 never executed branch 1 never executed -: 246: /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ #####: 247: *out++ = (L(in) >= 128000) ? 255 : 0; branch 0 never executed branch 1 never executed -: 248: } #####: 249:} -: 250: -: 251:static void function rgb2l called 5049 returned 100% blocks executed 100% 5049: 252:rgb2l(UINT8* out, const UINT8* in, int xsize) -: 253:{ -: 254: int x; 1502590: 255: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 256: /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ 1497541: 257: *out++ = L24(in) >> 16; -: 258: } 5049: 259:} -: 260: -: 261:static void function rgb2la called 840 returned 100% blocks executed 100% 840: 262:rgb2la(UINT8* out, const UINT8* in, int xsize) -: 263:{ -: 264: int x; 108360: 265: for (x = 0; x < xsize; x++, in += 4, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 266: /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ 107520: 267: out[0] = out[1] = out[2] = L24(in) >> 16; 107520: 268: out[3] = 255; -: 269: } 840: 270:} -: 271: -: 272:static void function rgb2i called 1512 returned 100% blocks executed 100% 1512: 273:rgb2i(UINT8* out_, const UINT8* in, int xsize) -: 274:{ -: 275: int x; 191976: 276: for (x = 0; x < xsize; x++, in += 4, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 190464: 277: INT32 v = L24(in) >> 16; 190464: 278: memcpy(out_, &v, sizeof(v)); -: 279: } 1512: 280:} -: 281: -: 282:static void function rgb2f called 1480 returned 100% blocks executed 100% 1480: 283:rgb2f(UINT8* out_, const UINT8* in, int xsize) -: 284:{ -: 285: int x; 190920: 286: for (x = 0; x < xsize; x++, in += 4, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 189440: 287: FLOAT32 v = (float) L(in) / 1000.0F; 189440: 288: memcpy(out_, &v, sizeof(v)); -: 289: } 1480: 290:} -: 291: -: 292:static void function rgb2bgr15 called 128 returned 100% blocks executed 100% 128: 293:rgb2bgr15(UINT8* out_, const UINT8* in, int xsize) -: 294:{ -: 295: int x; 16512: 296: for (x = 0; x < xsize; x++, in += 4, out_ += 2) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 49152: 297: UINT16 v = 16384: 298: ((((UINT16)in[0])<<7)&0x7c00) + 16384: 299: ((((UINT16)in[1])<<2)&0x03e0) + 16384: 300: ((((UINT16)in[2])>>3)&0x001f); 16384: 301: memcpy(out_, &v, sizeof(v)); -: 302: } 128: 303:} -: 304: -: 305:static void function rgb2bgr16 called 0 returned 0% blocks executed 0% #####: 306:rgb2bgr16(UINT8* out_, const UINT8* in, int xsize) -: 307:{ -: 308: int x; #####: 309: for (x = 0; x < xsize; x++, in += 4, out_ += 2) { branch 0 never executed branch 1 never executed #####: 310: UINT16 v = #####: 311: ((((UINT16)in[0])<<8)&0xf800) + #####: 312: ((((UINT16)in[1])<<3)&0x07e0) + #####: 313: ((((UINT16)in[2])>>3)&0x001f); #####: 314: memcpy(out_, &v, sizeof(v)); -: 315: } #####: 316:} -: 317: -: 318:static void function rgb2bgr24 called 0 returned 0% blocks executed 0% #####: 319:rgb2bgr24(UINT8* out, const UINT8* in, int xsize) -: 320:{ -: 321: int x; #####: 322: for (x = 0; x < xsize; x++, in += 4) { branch 0 never executed branch 1 never executed #####: 323: *out++ = in[2]; #####: 324: *out++ = in[1]; #####: 325: *out++ = in[0]; -: 326: } #####: 327:} -: 328: -: 329:static void function rgb2hsv_row called 150528 returned 100% blocks executed 100% 150528: 330:rgb2hsv_row(UINT8* out, const UINT8* in) -: 331:{ // following colorsys.py -: 332: float h,s,rc,gc,bc,cr; -: 333: UINT8 maxc,minc; -: 334: UINT8 r, g, b; -: 335: UINT8 uh,us,uv; -: 336: 150528: 337: r = in[0]; 150528: 338: g = in[1]; 150528: 339: b = in[2]; 150528: 340: maxc = MAX(r,MAX(g,b)); branch 0 taken 27% (fallthrough) branch 1 taken 73% 150528: 341: minc = MIN(r,MIN(g,b)); branch 0 taken 64% (fallthrough) branch 1 taken 36% 150528: 342: uv = maxc; 150528: 343: if (minc == maxc){ branch 0 taken 97% (fallthrough) branch 1 taken 3% -: 344: uh = 0; -: 345: us = 0; -: 346: } else { 145485: 347: cr = (float)(maxc-minc); 145485: 348: s = cr/(float)maxc; 145485: 349: rc = ((float)(maxc-r))/cr; 145485: 350: gc = ((float)(maxc-g))/cr; 145485: 351: bc = ((float)(maxc-b))/cr; 145485: 352: if (r == maxc) { branch 0 taken 39% (fallthrough) branch 1 taken 61% 56561: 353: h = bc-gc; 88924: 354: } else if (g == maxc) { branch 0 taken 7% (fallthrough) branch 1 taken 93% 6569: 355: h = 2.0 + rc-bc; -: 356: } else { 82355: 357: h = 4.0 + gc-rc; -: 358: } -: 359: // incorrect hue happens if h/6 is negative. 145485: 360: h = fmod((h/6.0 + 1.0), 1.0); -: 361: 145485: 362: uh = (UINT8)CLIP8((int)(h*255.0)); branch 0 taken 96% (fallthrough) branch 1 taken 4% branch 2 taken 100% (fallthrough) branch 3 taken 0% 145485: 363: us = (UINT8)CLIP8((int)(s*255.0)); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 364: } 150528: 365: out[0] = uh; 150528: 366: out[1] = us; 150528: 367: out[2] = uv; 150528: 368:} -: 369: -: 370:static void function rgb2hsv called 800 returned 100% blocks executed 100% 800: 371:rgb2hsv(UINT8* out, const UINT8* in, int xsize) -: 372:{ -: 373: int x; 102176: 374: for (x = 0; x < xsize; x++, in += 4, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 101376: 375: rgb2hsv_row(out, in); call 0 returned 100% 101376: 376: out[3] = in[3]; -: 377: } 800: 378:} -: 379: -: 380: -: 381: -: 382:static void function hsv2rgb called 1696 returned 100% blocks executed 100% 1696: 383:hsv2rgb(UINT8* out, const UINT8* in, int xsize) -: 384:{ // following colorsys.py -: 385: -: 386: int p,q,t; -: 387: UINT8 up,uq,ut; -: 388: int i, x; -: 389: float f, fs; -: 390: UINT8 h,s,v; -: 391: 217760: 392: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 216064: 393: h = in[0]; 216064: 394: s = in[1]; 216064: 395: v = in[2]; -: 396: 216064: 397: if (s==0){ branch 0 taken 1% (fallthrough) branch 1 taken 99% 506: 398: *out++ = v; 506: 399: *out++ = v; 506: 400: *out++ = v; -: 401: } else { 215558: 402: i = floor((float)h * 6.0 / 255.0); // 0 - 6 215558: 403: f = (float)h * 6.0 / 255.0 - (float)i; // 0-1 : remainder. 215558: 404: fs = ((float)s)/255.0; -: 405: 215558: 406: p = round((float)v * (1.0-fs)); 215558: 407: q = round((float)v * (1.0-fs*f)); 215558: 408: t = round((float)v * (1.0-fs*(1.0-f))); 215558: 409: up = (UINT8)CLIP8(p); branch 0 taken 98% (fallthrough) branch 1 taken 2% branch 2 taken 100% (fallthrough) branch 3 taken 0% 215558: 410: uq = (UINT8)CLIP8(q); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% 215558: 411: ut = (UINT8)CLIP8(t); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 412: 215558: 413: switch (i%6) { branch 0 taken 27% branch 1 taken 1% branch 2 taken 1% branch 3 taken 35% branch 4 taken 26% branch 5 taken 10% branch 6 taken 0% -: 414: case 0: 58630: 415: *out++ = v; 58630: 416: *out++ = ut; 58630: 417: *out++ = up; 58630: 418: break; -: 419: case 1: 1910: 420: *out++ = uq; 1910: 421: *out++ = v; 1910: 422: *out++ = up; 1910: 423: break; -: 424: case 2: 3014: 425: *out++ = up; 3014: 426: *out++ = v; 3014: 427: *out++ = ut; 3014: 428: break; -: 429: case 3: 75724: 430: *out++ = up; 75724: 431: *out++ = uq; 75724: 432: *out++ = v; 75724: 433: break; -: 434: case 4: 55608: 435: *out++ = ut; 55608: 436: *out++ = up; 55608: 437: *out++ = v; 55608: 438: break; -: 439: case 5: 20672: 440: *out++ = v; 20672: 441: *out++ = up; 20672: 442: *out++ = uq; 20672: 443: break; -: 444: -: 445: } -: 446: } 216064: 447: *out++ = in[3]; -: 448: } 1696: 449:} -: 450: -: 451: -: 452: -: 453:/* ---------------- */ -: 454:/* RGBA conversions */ -: 455:/* ---------------- */ -: 456: -: 457:static void function rgb2rgba called 3340 returned 100% blocks executed 100% 3340: 458:rgb2rgba(UINT8* out, const UINT8* in, int xsize) -: 459:{ -: 460: int x; 462892: 461: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 459552: 462: *out++ = *in++; 459552: 463: *out++ = *in++; 459552: 464: *out++ = *in++; 459552: 465: *out++ = 255; in++; -: 466: } 3340: 467:} -: 468: -: 469:static void function rgba2la called 512 returned 100% blocks executed 100% 512: 470:rgba2la(UINT8* out, const UINT8* in, int xsize) -: 471:{ -: 472: int x; 66048: 473: for (x = 0; x < xsize; x++, in += 4, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 474: /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ 65536: 475: out[0] = out[1] = out[2] = L24(in) >> 16; 65536: 476: out[3] = in[3]; -: 477: } 512: 478:} -: 479: -: 480:static void function rgba2rgb called 5744 returned 100% blocks executed 100% 5744: 481:rgba2rgb(UINT8* out, const UINT8* in, int xsize) -: 482:{ -: 483: int x; 4247636: 484: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 4241892: 485: *out++ = *in++; 4241892: 486: *out++ = *in++; 4241892: 487: *out++ = *in++; 4241892: 488: *out++ = 255; in++; -: 489: } 5744: 490:} -: 491: -: 492:static void function rgbA2rgba called 78896 returned 100% blocks executed 100% 78896: 493:rgbA2rgba(UINT8* out, const UINT8* in, int xsize) -: 494:{ -: 495: int x; -: 496: unsigned int alpha, tmp; 39281569: 497: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 39202673: 498: alpha = in[3]; 39202673: 499: *out++ = MULDIV255(*in++, alpha, tmp); 39202673: 500: *out++ = MULDIV255(*in++, alpha, tmp); 39202673: 501: *out++ = MULDIV255(*in++, alpha, tmp); 39202673: 502: *out++ = *in++; -: 503: } 78896: 504:} -: 505: -: 506:/* RGBa -> RGBA conversion to remove premultiplication -: 507: Needed for correct transforms/resizing on RGBA images */ -: 508:static void function rgba2rgbA called 21983 returned 100% blocks executed 100% 21983: 509:rgba2rgbA(UINT8* out, const UINT8* in, int xsize) -: 510:{ -: 511: int x; -: 512: unsigned int alpha; 3559028: 513: for (x = 0; x < xsize; x++, in+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 3537045: 514: alpha = in[3]; 3537045: 515: if (alpha == 255 || alpha == 0) { branch 0 taken 46% (fallthrough) branch 1 taken 54% branch 2 taken 1% (fallthrough) branch 3 taken 99% 1916339: 516: *out++ = in[0]; 1916339: 517: *out++ = in[1]; 1916339: 518: *out++ = in[2]; -: 519: } else { 1620706: 520: *out++ = CLIP8((255 * in[0]) / alpha); branch 0 taken 99% (fallthrough) branch 1 taken 1% 1620706: 521: *out++ = CLIP8((255 * in[1]) / alpha); branch 0 taken 99% (fallthrough) branch 1 taken 1% 1620706: 522: *out++ = CLIP8((255 * in[2]) / alpha); branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 523: } 3537045: 524: *out++ = in[3]; -: 525: } 21983: 526:} -: 527: -: 528:/* -: 529: * Conversion of RGB + single transparent color to RGBA, -: 530: * where any pixel that matches the color will have the -: 531: * alpha channel set to 0 -: 532: */ -: 533: -: 534:static void function rgbT2rgba called 576 returned 100% blocks executed 100% 576: 535:rgbT2rgba(UINT8* out, int xsize, int r, int g, int b) -: 536:{ -: 537:#ifdef WORDS_BIGENDIAN -: 538: UINT32 trns = ((r & 0xff)<<24) | ((g & 0xff)<<16) | ((b & 0xff)<<8) | 0xff; -: 539: UINT32 repl = trns & 0xffffff00; -: 540:#else 576: 541: UINT32 trns = (0xff <<24) | ((b & 0xff)<<16) | ((g & 0xff)<<8) | (r & 0xff); 576: 542: UINT32 repl = trns & 0x00ffffff; -: 543:#endif -: 544: -: 545: int i; -: 546: 45632: 547: for (i=0; i < xsize; i++ ,out += sizeof(trns)) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 548: UINT32 v; 45056: 549: memcpy(&v, out, sizeof(v)); 45056: 550: if (v==trns) { branch 0 taken 16% (fallthrough) branch 1 taken 84% -: 551: memcpy(out, &repl, sizeof(repl)); -: 552: } -: 553: } 576: 554:} -: 555: -: 556: -: 557:/* ---------------- */ -: 558:/* CMYK conversions */ -: 559:/* ---------------- */ -: 560: -: 561:static void function l2cmyk called 389 returned 100% blocks executed 100% 389: 562:l2cmyk(UINT8* out, const UINT8* in, int xsize) -: 563:{ -: 564: int x; 49576: 565: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 49187: 566: *out++ = 0; 49187: 567: *out++ = 0; 49187: 568: *out++ = 0; 49187: 569: *out++ = ~(*in++); -: 570: } 389: 571:} -: 572: -: 573:static void function la2cmyk called 128 returned 100% blocks executed 100% 128: 574:la2cmyk(UINT8* out, const UINT8* in, int xsize) -: 575:{ -: 576: int x; 16512: 577: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 578: *out++ = 0; 16384: 579: *out++ = 0; 16384: 580: *out++ = 0; 16384: 581: *out++ = ~(in[0]); -: 582: } 128: 583:} -: 584: -: 585:static void function rgb2cmyk called 1024 returned 100% blocks executed 100% 1024: 586:rgb2cmyk(UINT8* out, const UINT8* in, int xsize) -: 587:{ -: 588: int x; 164864: 589: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) branch 2 taken 99% branch 3 taken 1% (fallthrough) branch 4 taken 99% branch 5 taken 1% (fallthrough) -: 590: /* Note: no undercolour removal */ 163840: 591: *out++ = ~(*in++); 163840: 592: *out++ = ~(*in++); 163840: 593: *out++ = ~(*in++); 163840: 594: *out++ = 0; in++; -: 595: } 1024: 596:} -: 597: -: 598:static void function cmyk2rgb called 1408 returned 100% blocks executed 100% 1408: 599:cmyk2rgb(UINT8* out, const UINT8* in, int xsize) -: 600:{ -: 601: int x, nk, tmp; 181632: 602: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 180224: 603: nk = 255 - in[3]; 180224: 604: out[0] = CLIP8(nk - MULDIV255(in[0], nk, tmp)); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% 180224: 605: out[1] = CLIP8(nk - MULDIV255(in[1], nk, tmp)); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% 180224: 606: out[2] = CLIP8(nk - MULDIV255(in[2], nk, tmp)); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% 180224: 607: out[3] = 255; 180224: 608: out += 4; 180224: 609: in += 4; -: 610: } 1408: 611:} -: 612: -: 613:static void function cmyk2hsv called 128 returned 100% blocks executed 100% 128: 614:cmyk2hsv(UINT8* out, const UINT8* in, int xsize) -: 615:{ -: 616: int x, nk, tmp; 16512: 617: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 618: nk = 255 - in[3]; 16384: 619: out[0] = CLIP8(nk - MULDIV255(in[0], nk, tmp)); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% 16384: 620: out[1] = CLIP8(nk - MULDIV255(in[1], nk, tmp)); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% 16384: 621: out[2] = CLIP8(nk - MULDIV255(in[2], nk, tmp)); branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% 16384: 622: rgb2hsv_row(out, out); call 0 returned 100% 16384: 623: out[3] = 255; 16384: 624: out += 4; 16384: 625: in += 4; -: 626: } 128: 627:} -: 628: -: 629:/* ------------- */ -: 630:/* I conversions */ -: 631:/* ------------- */ -: 632: -: 633:static void function bit2i called 256 returned 100% blocks executed 100% 256: 634:bit2i(UINT8* out_, const UINT8* in, int xsize) -: 635:{ -: 636: int x; 32896: 637: for (x = 0; x < xsize; x++, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 32640: 638: INT32 v = (*in++ != 0) ? 255 : 0; branch 0 taken 69% (fallthrough) branch 1 taken 31% 32640: 639: memcpy(out_, &v, sizeof(v)); -: 640: } 256: 641:} -: 642: -: 643:static void function l2i called 617345 returned 100% blocks executed 100% 617345: 644:l2i(UINT8* out_, const UINT8* in, int xsize) -: 645:{ -: 646: int x; 191584602: 647: for (x = 0; x < xsize; x++, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 190967257: 648: INT32 v = *in++; 190967257: 649: memcpy(out_, &v, sizeof(v)); -: 650: } 617345: 651:} -: 652: -: 653:static void function i2l called 313825 returned 100% blocks executed 100% 313825: 654:i2l(UINT8* out, const UINT8* in_, int xsize) -: 655:{ -: 656: int x; 96871322: 657: for (x = 0; x < xsize; x++, out++, in_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 658: INT32 v; 96557497: 659: memcpy(&v, in_, sizeof(v)); 96557497: 660: if (v <= 0) { branch 0 taken 86% (fallthrough) branch 1 taken 14% 82876779: 661: *out = 0; 13680718: 662: } else if (v >= 255) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 18918: 663: *out = 255; -: 664: } else { 13661800: 665: *out = (UINT8) v; -: 666: } -: 667: } 313825: 668:} -: 669: -: 670:static void function i2f called 326 returned 100% blocks executed 100% 326: 671:i2f(UINT8* out_, const UINT8* in_, int xsize) -: 672:{ -: 673: int x; 37196: 674: for (x = 0; x < xsize; x++, in_ += 4, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 675: INT32 i; -: 676: FLOAT32 f; 36870: 677: memcpy(&i, in_, sizeof(i)); 36870: 678: f = i; 36870: 679: memcpy(out_, &f, sizeof(f)); -: 680: } 326: 681:} -: 682: -: 683:static void function i2rgb called 513 returned 100% blocks executed 100% 513: 684:i2rgb(UINT8* out, const UINT8* in_, int xsize) -: 685:{ -: 686: int x; 513: 687: INT32* in = (INT32*) in_; 57858: 688: for (x = 0; x < xsize; x++, in++, out+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 57345: 689: if (*in <= 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 110: 690: out[0] = out[1] = out[2] = 0; 57235: 691: } else if (*in >= 255) { branch 0 taken 2% (fallthrough) branch 1 taken 98% 1121: 692: out[0] = out[1] = out[2] = 255; -: 693: } else { 56114: 694: out[0] = out[1] = out[2] = (UINT8) *in; -: 695: } 57345: 696: out[3] = 255; -: 697: } 513: 698:} -: 699: -: 700:static void function i2hsv called 128 returned 100% blocks executed 89% 128: 701:i2hsv(UINT8* out, const UINT8* in_, int xsize) -: 702:{ -: 703: int x; 128: 704: INT32* in = (INT32*) in_; 16512: 705: for (x = 0; x < xsize; x++, in++, out+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 706: out[0] = 0; 16384: 707: out[1] = 0; 16384: 708: if (*in <= 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 709: out[2] = 0; 16384: 710: } else if (*in >= 255) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1: 711: out[2] = 255; -: 712: } else { 16383: 713: out[2] = (UINT8) *in; -: 714: } 16384: 715: out[3] = 255; -: 716: } 128: 717:} -: 718: -: 719:/* ------------- */ -: 720:/* F conversions */ -: 721:/* ------------- */ -: 722: -: 723:static void function bit2f called 128 returned 100% blocks executed 100% 128: 724:bit2f(UINT8* out_, const UINT8* in, int xsize) -: 725:{ -: 726: int x; 16512: 727: for (x = 0; x < xsize; x++, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 728: FLOAT32 f = (*in++ != 0) ? 255.0F : 0.0F; branch 0 taken 67% (fallthrough) branch 1 taken 33% 16384: 729: memcpy(out_, &f, sizeof(f)); -: 730: } 128: 731:} -: 732: -: 733:static void function l2f called 1037 returned 100% blocks executed 100% 1037: 734:l2f(UINT8* out_, const UINT8* in, int xsize) -: 735:{ -: 736: int x; 328760: 737: for (x = 0; x < xsize; x++, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 327723: 738: FLOAT32 f = (FLOAT32) *in++; 327723: 739: memcpy(out_, &f, sizeof(f)); -: 740: } 1037: 741:} -: 742: -: 743:static void function f2l called 5905 returned 100% blocks executed 100% 5905: 744:f2l(UINT8* out, const UINT8* in_, int xsize) -: 745:{ -: 746: int x; 1281663: 747: for (x = 0; x < xsize; x++, out++, in_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 748: FLOAT32 v; 1275758: 749: memcpy(&v, in_, sizeof(v)); 1275758: 750: if (v <= 0.0) { branch 0 taken 83% (fallthrough) branch 1 taken 17% 1055550: 751: *out = 0; 220208: 752: } else if (v >= 255.0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 12: 753: *out = 255; -: 754: } else { 220196: 755: *out = (UINT8) v; -: 756: } -: 757: } 5905: 758:} -: 759: -: 760:static void function f2i called 129 returned 100% blocks executed 100% 129: 761:f2i(UINT8* out_, const UINT8* in_, int xsize) -: 762:{ -: 763: int x; 16514: 764: for (x = 0; x < xsize; x++, in_ += 4, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 765: FLOAT32 f; -: 766: INT32 i; 16385: 767: memcpy(&f, in_, sizeof(f)); 16385: 768: i = f; 16385: 769: memcpy(out_, &i, sizeof(i)); -: 770: } 129: 771:} -: 772: -: 773:/* ----------------- */ -: 774:/* YCbCr conversions */ -: 775:/* ----------------- */ -: 776: -: 777:/* See ConvertYCbCr.c for RGB/YCbCr tables */ -: 778: -: 779:static void function l2ycbcr called 389 returned 100% blocks executed 100% 389: 780:l2ycbcr(UINT8* out, const UINT8* in, int xsize) -: 781:{ -: 782: int x; 49576: 783: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 49187: 784: *out++ = *in++; 49187: 785: *out++ = 128; 49187: 786: *out++ = 128; 49187: 787: *out++ = 255; -: 788: } 389: 789:} -: 790: -: 791:static void function la2ycbcr called 128 returned 100% blocks executed 100% 128: 792:la2ycbcr(UINT8* out, const UINT8* in, int xsize) -: 793:{ -: 794: int x; 16512: 795: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 796: *out++ = in[0]; 16384: 797: *out++ = 128; 16384: 798: *out++ = 128; 16384: 799: *out++ = 255; -: 800: } 128: 801:} -: 802: -: 803:static void function ycbcr2l called 128 returned 100% blocks executed 100% 128: 804:ycbcr2l(UINT8* out, const UINT8* in, int xsize) -: 805:{ -: 806: int x; 16512: 807: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 808: *out++ = in[0]; -: 809: } 128: 810:} -: 811: -: 812:static void function ycbcr2la called 128 returned 100% blocks executed 100% 128: 813:ycbcr2la(UINT8* out, const UINT8* in, int xsize) -: 814:{ -: 815: int x; 16512: 816: for (x = 0; x < xsize; x++, in += 4, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 817: out[0] = out[1] = out[2] = in[0]; 16384: 818: out[3] = 255; -: 819: } 128: 820:} -: 821: -: 822:/* ------------------------- */ -: 823:/* I;16 (16-bit) conversions */ -: 824:/* ------------------------- */ -: 825: -: 826:static void function I_I16L called 544 returned 100% blocks executed 100% 544: 827:I_I16L(UINT8* out, const UINT8* in_, int xsize) -: 828:{ -: 829: int x, v; 54816: 830: for (x = 0; x < xsize; x++, in_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 831: INT32 i; 54272: 832: memcpy(&i, in_, sizeof(i)); 54272: 833: v = CLIP16(i); branch 0 taken 100% (fallthrough) branch 1 taken 0% 54272: 834: *out++ = (UINT8) v; 54272: 835: *out++ = (UINT8) (v >> 8); -: 836: } 544: 837:} -: 838: -: 839:static void function I_I16B called 256 returned 100% blocks executed 100% 256: 840:I_I16B(UINT8* out, const UINT8* in_, int xsize) -: 841:{ -: 842: int x, v; 20736: 843: for (x = 0; x < xsize; x++, in_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 844: INT32 i; 20480: 845: memcpy(&i, in_, sizeof(i)); 20480: 846: v = CLIP16(i); branch 0 taken 100% (fallthrough) branch 1 taken 0% 20480: 847: *out++ = (UINT8) (v >> 8); 20480: 848: *out++ = (UINT8) v; -: 849: } 256: 850:} -: 851: -: 852: -: 853:static void function I16L_I called 452 returned 100% blocks executed 100% 452: 854:I16L_I(UINT8* out_, const UINT8* in, int xsize) -: 855:{ -: 856: int x; 31956: 857: for (x = 0; x < xsize; x++, in += 2, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 31504: 858: INT32 v = in[0] + ((int) in[1] << 8); 31504: 859: memcpy(out_, &v, sizeof(v)); -: 860: } 452: 861:} -: 862: -: 863: -: 864:static void function I16B_I called 32 returned 100% blocks executed 100% 32: 865:I16B_I(UINT8* out_, const UINT8* in, int xsize) -: 866:{ -: 867: int x; 1056: 868: for (x = 0; x < xsize; x++, in += 2, out_ += 4) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 1024: 869: INT32 v = in[1] + ((int) in[0] << 8); 1024: 870: memcpy(out_, &v, sizeof(v)); -: 871: } 32: 872:} -: 873: -: 874:static void function I16L_F called 64 returned 100% blocks executed 100% 64: 875:I16L_F(UINT8* out_, const UINT8* in, int xsize) -: 876:{ -: 877: int x; 4160: 878: for (x = 0; x < xsize; x++, in += 2, out_ += 4) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 4096: 879: FLOAT32 v = in[0] + ((int) in[1] << 8); 4096: 880: memcpy(out_, &v, sizeof(v)); -: 881: } 64: 882:} -: 883: -: 884: -: 885:static void function I16B_F called 0 returned 0% blocks executed 0% #####: 886:I16B_F(UINT8* out_, const UINT8* in, int xsize) -: 887:{ -: 888: int x; #####: 889: for (x = 0; x < xsize; x++, in += 2, out_ += 4) { branch 0 never executed branch 1 never executed #####: 890: FLOAT32 v = in[1] + ((int) in[0] << 8); #####: 891: memcpy(out_, &v, sizeof(v)); -: 892: } #####: 893:} -: 894: -: 895:static void function L_I16L called 0 returned 0% blocks executed 0% #####: 896:L_I16L(UINT8* out, const UINT8* in, int xsize) -: 897:{ -: 898: int x; #####: 899: for (x = 0; x < xsize; x++, in++) { branch 0 never executed branch 1 never executed #####: 900: *out++ = *in; #####: 901: *out++ = 0; -: 902: } #####: 903:} -: 904: -: 905:static void function L_I16B called 0 returned 0% blocks executed 0% #####: 906:L_I16B(UINT8* out, const UINT8* in, int xsize) -: 907:{ -: 908: int x; #####: 909: for (x = 0; x < xsize; x++, in++) { branch 0 never executed branch 1 never executed #####: 910: *out++ = 0; #####: 911: *out++ = *in; -: 912: } #####: 913:} -: 914: -: 915:static void function I16L_L called 288 returned 100% blocks executed 86% 288: 916:I16L_L(UINT8* out, const UINT8* in, int xsize) -: 917:{ -: 918: int x; 34080: 919: for (x = 0; x < xsize; x++, in += 2) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 33792: 920: if (in[1] != 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 921: *out++ = 255; -: 922: } else { 33792: 923: *out++ = in[0]; -: 924: } -: 925: } 288: 926:} -: 927: -: 928:static void function I16B_L called 32 returned 100% blocks executed 86% 32: 929:I16B_L(UINT8* out, const UINT8* in, int xsize) -: 930:{ -: 931: int x; 1056: 932: for (x = 0; x < xsize; x++, in += 2) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 1024: 933: if (in[0] != 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 934: *out++ = 255; -: 935: } else { 1024: 936: *out++ = in[1]; -: 937: } -: 938: } 32: 939:} -: 940: -: 941:static struct { -: 942: const char* from; -: 943: const char* to; -: 944: ImagingShuffler convert; -: 945:} converters[] = { -: 946: -: 947: { "1", "L", bit2l }, -: 948: { "1", "I", bit2i }, -: 949: { "1", "F", bit2f }, -: 950: { "1", "RGB", bit2rgb }, -: 951: { "1", "RGBA", bit2rgb }, -: 952: { "1", "RGBX", bit2rgb }, -: 953: { "1", "CMYK", bit2cmyk }, -: 954: { "1", "YCbCr", bit2ycbcr }, -: 955: { "1", "HSV", bit2hsv }, -: 956: -: 957: { "L", "1", l2bit }, -: 958: { "L", "LA", l2la }, -: 959: { "L", "I", l2i }, -: 960: { "L", "F", l2f }, -: 961: { "L", "RGB", l2rgb }, -: 962: { "L", "RGBA", l2rgb }, -: 963: { "L", "RGBX", l2rgb }, -: 964: { "L", "CMYK", l2cmyk }, -: 965: { "L", "YCbCr", l2ycbcr }, -: 966: { "L", "HSV", l2hsv }, -: 967: -: 968: { "LA", "L", la2l }, -: 969: { "LA", "La", lA2la }, -: 970: { "LA", "RGB", la2rgb }, -: 971: { "LA", "RGBA", la2rgb }, -: 972: { "LA", "RGBX", la2rgb }, -: 973: { "LA", "CMYK", la2cmyk }, -: 974: { "LA", "YCbCr", la2ycbcr }, -: 975: { "LA", "HSV", la2hsv }, -: 976: -: 977: { "La", "LA", la2lA }, -: 978: -: 979: { "I", "L", i2l }, -: 980: { "I", "F", i2f }, -: 981: { "I", "RGB", i2rgb }, -: 982: { "I", "RGBA", i2rgb }, -: 983: { "I", "RGBX", i2rgb }, -: 984: { "I", "HSV", i2hsv }, -: 985: -: 986: { "F", "L", f2l }, -: 987: { "F", "I", f2i }, -: 988: -: 989: { "RGB", "1", rgb2bit }, -: 990: { "RGB", "L", rgb2l }, -: 991: { "RGB", "LA", rgb2la }, -: 992: { "RGB", "I", rgb2i }, -: 993: { "RGB", "F", rgb2f }, -: 994: { "RGB", "BGR;15", rgb2bgr15 }, -: 995: { "RGB", "BGR;16", rgb2bgr16 }, -: 996: { "RGB", "BGR;24", rgb2bgr24 }, -: 997: { "RGB", "RGBA", rgb2rgba }, -: 998: { "RGB", "RGBX", rgb2rgba }, -: 999: { "RGB", "CMYK", rgb2cmyk }, -: 1000: { "RGB", "YCbCr", ImagingConvertRGB2YCbCr }, -: 1001: { "RGB", "HSV", rgb2hsv }, -: 1002: -: 1003: { "RGBA", "1", rgb2bit }, -: 1004: { "RGBA", "L", rgb2l }, -: 1005: { "RGBA", "LA", rgba2la }, -: 1006: { "RGBA", "I", rgb2i }, -: 1007: { "RGBA", "F", rgb2f }, -: 1008: { "RGBA", "RGB", rgba2rgb }, -: 1009: { "RGBA", "RGBa", rgbA2rgba }, -: 1010: { "RGBA", "RGBX", rgb2rgba }, -: 1011: { "RGBA", "CMYK", rgb2cmyk }, -: 1012: { "RGBA", "YCbCr", ImagingConvertRGB2YCbCr }, -: 1013: { "RGBA", "HSV", rgb2hsv }, -: 1014: -: 1015: { "RGBa", "RGBA", rgba2rgbA }, -: 1016: -: 1017: { "RGBX", "1", rgb2bit }, -: 1018: { "RGBX", "L", rgb2l }, -: 1019: { "RGBX", "LA", rgb2la }, -: 1020: { "RGBX", "I", rgb2i }, -: 1021: { "RGBX", "F", rgb2f }, -: 1022: { "RGBX", "RGB", rgba2rgb }, -: 1023: { "RGBX", "CMYK", rgb2cmyk }, -: 1024: { "RGBX", "YCbCr", ImagingConvertRGB2YCbCr }, -: 1025: { "RGBX", "HSV", rgb2hsv }, -: 1026: -: 1027: { "CMYK", "RGB", cmyk2rgb }, -: 1028: { "CMYK", "RGBA", cmyk2rgb }, -: 1029: { "CMYK", "RGBX", cmyk2rgb }, -: 1030: { "CMYK", "HSV", cmyk2hsv }, -: 1031: -: 1032: { "YCbCr", "L", ycbcr2l }, -: 1033: { "YCbCr", "LA", ycbcr2la }, -: 1034: { "YCbCr", "RGB", ImagingConvertYCbCr2RGB }, -: 1035: -: 1036: { "HSV", "RGB", hsv2rgb }, -: 1037: -: 1038: { "I", "I;16", I_I16L }, -: 1039: { "I;16", "I", I16L_I }, -: 1040: { "L", "I;16", L_I16L }, -: 1041: { "I;16", "L", I16L_L }, -: 1042: -: 1043: { "I", "I;16L", I_I16L }, -: 1044: { "I;16L", "I", I16L_I }, -: 1045: { "I", "I;16B", I_I16B }, -: 1046: { "I;16B", "I", I16B_I }, -: 1047: -: 1048: { "L", "I;16L", L_I16L }, -: 1049: { "I;16L", "L", I16L_L }, -: 1050: { "L", "I;16B", L_I16B }, -: 1051: { "I;16B", "L", I16B_L }, -: 1052: -: 1053: { "I;16", "F", I16L_F }, -: 1054: { "I;16L", "F", I16L_F }, -: 1055: { "I;16B", "F", I16B_F }, -: 1056: -: 1057: { NULL } -: 1058:}; -: 1059: -: 1060:/* FIXME: translate indexed versions to pointer versions below this line */ -: 1061: -: 1062:/* ------------------- */ -: 1063:/* Palette conversions */ -: 1064:/* ------------------- */ -: 1065: -: 1066:static void function p2bit called 128 returned 100% blocks executed 100% 128: 1067:p2bit(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1068:{ -: 1069: int x; -: 1070: /* FIXME: precalculate greyscale palette? */ 16512: 1071: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1072: *out++ = (L(&palette[in[x]*4]) >= 128000) ? 255 : 0; branch 0 taken 69% (fallthrough) branch 1 taken 31% -: 1073: } 128: 1074:} -: 1075: -: 1076:static void function pa2bit called 128 returned 100% blocks executed 100% 128: 1077:pa2bit(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1078:{ -: 1079: int x; -: 1080: /* FIXME: precalculate greyscale palette? */ 16512: 1081: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1082: *out++ = (L(&palette[in[0]*4]) >= 128000) ? 255 : 0; branch 0 taken 69% (fallthrough) branch 1 taken 31% -: 1083: } 128: 1084:} -: 1085: -: 1086:static void function p2l called 9276 returned 100% blocks executed 100% 9276: 1087:p2l(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1088:{ -: 1089: int x; -: 1090: /* FIXME: precalculate greyscale palette? */ 2493970: 1091: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 2484694: 1092: *out++ = L(&palette[in[x]*4]) / 1000; -: 1093: } 9276: 1094:} -: 1095: -: 1096:static void function pa2l called 128 returned 100% blocks executed 100% 128: 1097:pa2l(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1098:{ -: 1099: int x; -: 1100: /* FIXME: precalculate greyscale palette? */ 16512: 1101: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1102: *out++ = L(&palette[in[0]*4]) / 1000; -: 1103: } 128: 1104:} -: 1105: -: 1106:static void function p2pa called 129 returned 100% blocks executed 100% 129: 1107:p2pa(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1108:{ -: 1109: int x; 16514: 1110: for (x = 0; x < xsize; x++, in++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16385: 1111: const UINT8* rgba = &palette[in[0]]; 16385: 1112: *out++ = in[0]; 16385: 1113: *out++ = in[0]; 16385: 1114: *out++ = in[0]; 16385: 1115: *out++ = rgba[3]; -: 1116: } 129: 1117:} -: 1118: -: 1119:static void function p2la called 256 returned 100% blocks executed 100% 256: 1120:p2la(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1121:{ -: 1122: int x; -: 1123: /* FIXME: precalculate greyscale palette? */ 33024: 1124: for (x = 0; x < xsize; x++, out+=4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 32768: 1125: const UINT8* rgba = &palette[*in++ * 4]; 32768: 1126: out[0] = out[1] = out[2] = L(rgba) / 1000; 32768: 1127: out[3] = rgba[3]; -: 1128: } 256: 1129:} -: 1130: -: 1131:static void function pa2la called 128 returned 100% blocks executed 100% 128: 1132:pa2la(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1133:{ -: 1134: int x; -: 1135: /* FIXME: precalculate greyscale palette? */ 16512: 1136: for (x = 0; x < xsize; x++, in += 4, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1137: out[0] = out[1] = out[2] = L(&palette[in[0]*4]) / 1000; 16384: 1138: out[3] = in[3]; -: 1139: } 128: 1140:} -: 1141: -: 1142:static void function p2i called 128 returned 100% blocks executed 100% 128: 1143:p2i(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette) -: 1144:{ -: 1145: int x; 16512: 1146: for (x = 0; x < xsize; x++, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1147: INT32 v = L(&palette[in[x]*4]) / 1000; 16384: 1148: memcpy(out_, &v, sizeof(v)); -: 1149: } 128: 1150:} -: 1151: -: 1152:static void function pa2i called 128 returned 100% blocks executed 100% 128: 1153:pa2i(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette) -: 1154:{ -: 1155: int x; 128: 1156: INT32* out = (INT32*) out_; 16512: 1157: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1158: *out++ = L(&palette[in[0]*4]) / 1000; -: 1159: } 128: 1160:} -: 1161: -: 1162:static void function p2f called 128 returned 100% blocks executed 100% 128: 1163:p2f(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette) -: 1164:{ -: 1165: int x; 16512: 1166: for (x = 0; x < xsize; x++, out_ += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1167: FLOAT32 v = L(&palette[in[x]*4]) / 1000.0F; 16384: 1168: memcpy(out_, &v, sizeof(v)); -: 1169: } 128: 1170:} -: 1171: -: 1172:static void function pa2f called 128 returned 100% blocks executed 100% 128: 1173:pa2f(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette) -: 1174:{ -: 1175: int x; 128: 1176: FLOAT32* out = (FLOAT32*) out_; 16512: 1177: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1178: *out++ = (float) L(&palette[in[0]*4]) / 1000.0F; -: 1179: } 128: 1180:} -: 1181: -: 1182:static void function p2rgb called 31696 returned 100% blocks executed 100% 31696: 1183:p2rgb(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1184:{ -: 1185: int x; 9528336: 1186: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) branch 2 taken 99% branch 3 taken 1% (fallthrough) branch 4 taken 99% branch 5 taken 1% (fallthrough) 9496384: 1187: const UINT8* rgb = &palette[*in++ * 4]; 9496384: 1188: *out++ = rgb[0]; 9496384: 1189: *out++ = rgb[1]; 9496384: 1190: *out++ = rgb[2]; 9496384: 1191: *out++ = 255; -: 1192: } 31696: 1193:} -: 1194: -: 1195:static void function pa2rgb called 512 returned 100% blocks executed 100% 512: 1196:pa2rgb(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1197:{ -: 1198: int x; 99072: 1199: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) branch 2 taken 99% branch 3 taken 1% (fallthrough) branch 4 taken 99% branch 5 taken 1% (fallthrough) 98304: 1200: const UINT8* rgb = &palette[in[0] * 4]; 98304: 1201: *out++ = rgb[0]; 98304: 1202: *out++ = rgb[1]; 98304: 1203: *out++ = rgb[2]; 98304: 1204: *out++ = 255; -: 1205: } 512: 1206:} -: 1207: -: 1208:static void function p2hsv called 128 returned 100% blocks executed 100% 128: 1209:p2hsv(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1210:{ -: 1211: int x; 16512: 1212: for (x = 0; x < xsize; x++, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1213: const UINT8* rgb = &palette[*in++ * 4]; 16384: 1214: rgb2hsv_row(out, rgb); call 0 returned 100% 16384: 1215: out[3] = 255; -: 1216: } 128: 1217:} -: 1218: -: 1219:static void function pa2hsv called 128 returned 100% blocks executed 100% 128: 1220:pa2hsv(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1221:{ -: 1222: int x; 16512: 1223: for (x = 0; x < xsize; x++, in += 4, out += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 1224: const UINT8* rgb = &palette[in[0] * 4]; 16384: 1225: rgb2hsv_row(out, rgb); call 0 returned 100% 16384: 1226: out[3] = 255; -: 1227: } 128: 1228:} -: 1229: -: 1230:static void function p2rgba called 73064 returned 100% blocks executed 100% 73064: 1231:p2rgba(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1232:{ -: 1233: int x; 18106192: 1234: for (x = 0; x < xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 18033128: 1235: const UINT8* rgba = &palette[*in++ * 4]; 18033128: 1236: *out++ = rgba[0]; 18033128: 1237: *out++ = rgba[1]; 18033128: 1238: *out++ = rgba[2]; 18033128: 1239: *out++ = rgba[3]; -: 1240: } 73064: 1241:} -: 1242: -: 1243:static void function pa2rgba called 256 returned 100% blocks executed 100% 256: 1244:pa2rgba(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1245:{ -: 1246: int x; 33024: 1247: for (x = 0; x < xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 32768: 1248: const UINT8* rgb = &palette[in[0] * 4]; 32768: 1249: *out++ = rgb[0]; 32768: 1250: *out++ = rgb[1]; 32768: 1251: *out++ = rgb[2]; 32768: 1252: *out++ = in[3]; -: 1253: } 256: 1254:} -: 1255: -: 1256:static void function p2cmyk called 128 returned 100% blocks executed 100% 128: 1257:p2cmyk(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1258:{ -: 1259: p2rgb(out, in, xsize, palette); 128: 1260: rgb2cmyk(out, out, xsize); 128: 1261:} -: 1262: -: 1263:static void function pa2cmyk called 128 returned 100% blocks executed 100% 128: 1264:pa2cmyk(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1265:{ -: 1266: pa2rgb(out, in, xsize, palette); 128: 1267: rgb2cmyk(out, out, xsize); 128: 1268:} -: 1269: -: 1270:static void function p2ycbcr called 128 returned 100% blocks executed 100% 128: 1271:p2ycbcr(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1272:{ 128: 1273: p2rgb(out, in, xsize, palette); 128: 1274: ImagingConvertRGB2YCbCr(out, out, xsize); call 0 returned 100% 128: 1275:} -: 1276: -: 1277:static void function pa2ycbcr called 128 returned 100% blocks executed 100% 128: 1278:pa2ycbcr(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) -: 1279:{ 128: 1280: pa2rgb(out, in, xsize, palette); 128: 1281: ImagingConvertRGB2YCbCr(out, out, xsize); call 0 returned 100% 128: 1282:} -: 1283: -: 1284:static Imaging function frompalette called 696 returned 100% blocks executed 99% 696: 1285:frompalette(Imaging imOut, Imaging imIn, const char *mode) -: 1286:{ -: 1287: ImagingSectionCookie cookie; -: 1288: int alpha; -: 1289: int y; -: 1290: void (*convert)(UINT8*, const UINT8*, int, const UINT8*); -: 1291: -: 1292: /* Map palette image to L, RGB, RGBA, or CMYK */ -: 1293: 696: 1294: if (!imIn->palette) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1295: return (Imaging) ImagingError_ValueError("no palette"); call 0 never executed -: 1296: } -: 1297: 696: 1298: alpha = !strcmp(imIn->mode, "PA"); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 2% (fallthrough) branch 3 taken 98% -: 1299: 696: 1300: if (strcmp(mode, "1") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% branch 2 taken 1% (fallthrough) branch 3 taken 99% 2: 1301: convert = alpha ? pa2bit : p2bit; branch 0 taken 50% (fallthrough) branch 1 taken 50% 694: 1302: } else if (strcmp(mode, "L") == 0) { branch 0 taken 11% (fallthrough) branch 1 taken 89% branch 2 taken 11% (fallthrough) branch 3 taken 89% 74: 1303: convert = alpha ? pa2l : p2l; branch 0 taken 99% (fallthrough) branch 1 taken 1% 620: 1304: } else if (strcmp(mode, "LA") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 1% (fallthrough) branch 5 taken 99% 3: 1305: convert = alpha ? pa2la : p2la; branch 0 taken 67% (fallthrough) branch 1 taken 33% 617: 1306: } else if (strcmp(mode, "PA") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% branch 2 taken 67% (fallthrough) branch 3 taken 33% branch 4 taken 99% (fallthrough) branch 5 taken 1% -: 1307: convert = p2pa; 615: 1308: } else if (strcmp(mode, "I") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% branch 2 taken 1% (fallthrough) branch 3 taken 99% 2: 1309: convert = alpha ? pa2i : p2i; branch 0 taken 50% (fallthrough) branch 1 taken 50% 613: 1310: } else if (strcmp(mode, "F") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% branch 2 taken 1% (fallthrough) branch 3 taken 99% 2: 1311: convert = alpha ? pa2f : p2f; branch 0 taken 50% (fallthrough) branch 1 taken 50% 611: 1312: } else if (strcmp(mode, "RGB") == 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 38% (fallthrough) branch 7 taken 62% 231: 1313: convert = alpha ? pa2rgb : p2rgb; branch 0 taken 98% (fallthrough) branch 1 taken 2% 380: 1314: } else if (strcmp(mode, "RGBA") == 0) { branch 0 taken 98% (fallthrough) branch 1 taken 2% 371: 1315: convert = alpha ? pa2rgba : p2rgba; branch 0 taken 99% (fallthrough) branch 1 taken 1% 9: 1316: } else if (strcmp(mode, "RGBX") == 0) { branch 0 taken 22% (fallthrough) branch 1 taken 78% 2: 1317: convert = alpha ? pa2rgba : p2rgba; branch 0 taken 50% (fallthrough) branch 1 taken 50% 7: 1318: } else if (strcmp(mode, "CMYK") == 0) { branch 0 taken 29% (fallthrough) branch 1 taken 71% 2: 1319: convert = alpha ? pa2cmyk : p2cmyk; branch 0 taken 50% (fallthrough) branch 1 taken 50% 5: 1320: } else if (strcmp(mode, "YCbCr") == 0) { branch 0 taken 40% (fallthrough) branch 1 taken 60% 2: 1321: convert = alpha ? pa2ycbcr : p2ycbcr; branch 0 taken 50% (fallthrough) branch 1 taken 50% 3: 1322: } else if (strcmp(mode, "HSV") == 0) { branch 0 taken 67% (fallthrough) branch 1 taken 33% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 67% (fallthrough) branch 7 taken 33% 2: 1323: convert = alpha ? pa2hsv : p2hsv; branch 0 taken 50% (fallthrough) branch 1 taken 50% -: 1324: } else { 1: 1325: return (Imaging) ImagingError_ValueError("conversion not supported"); call 0 returned 100% -: 1326: } -: 1327: 695: 1328: imOut = ImagingNew2Dirty(mode, imOut, imIn); call 0 returned 100% 695: 1329: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1330: return NULL; -: 1331: } -: 1332: 695: 1333: ImagingSectionEnter(&cookie); 117676: 1334: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 233962: 1335: (*convert)((UINT8*) imOut->image[y], (UINT8*) imIn->image[y], call 0 returned 100% 116981: 1336: imIn->xsize, imIn->palette->palette); -: 1337: } 695: 1338: ImagingSectionLeave(&cookie); call 0 returned 100% -: 1339: 695: 1340: return imOut; -: 1341:} -: 1342: -: 1343:#if defined(_MSC_VER) -: 1344:#pragma optimize("", off) -: 1345:#endif -: 1346:static Imaging function topalette called 130 returned 100% blocks executed 88% 130: 1347:topalette(Imaging imOut, Imaging imIn, const char *mode, ImagingPalette inpalette, int dither) -: 1348:{ -: 1349: ImagingSectionCookie cookie; -: 1350: int alpha; -: 1351: int x, y; 130: 1352: ImagingPalette palette = inpalette;; -: 1353: -: 1354: /* Map L or RGB/RGBX/RGBA to palette image */ 130: 1355: if (strcmp(imIn->mode, "L") != 0 && strncmp(imIn->mode, "RGB", 3) != 0) { branch 0 taken 13% (fallthrough) branch 1 taken 87% branch 2 taken 88% (fallthrough) branch 3 taken 12% branch 4 taken 35% (fallthrough) branch 5 taken 65% 40: 1356: return (Imaging) ImagingError_ValueError("conversion not supported"); call 0 returned 100% -: 1357: } -: 1358: 90: 1359: alpha = !strcmp(mode, "PA"); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 40% (fallthrough) branch 3 taken 60% -: 1360: 90: 1361: if (palette == NULL) { branch 0 taken 94% (fallthrough) branch 1 taken 6% -: 1362: /* FIXME: make user configurable */ 85: 1363: if (imIn->bands == 1) { branch 0 taken 18% (fallthrough) branch 1 taken 82% 15: 1364: palette = ImagingPaletteNew("RGB"); /* Initialised to grey ramp */ call 0 returned 100% -: 1365: } else { 70: 1366: palette = ImagingPaletteNewBrowser(); /* Standard colour cube */ call 0 returned 100% -: 1367: } -: 1368: } -: 1369: 90: 1370: if (!palette) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1371: return (Imaging) ImagingError_ValueError("no palette"); call 0 never executed -: 1372: } -: 1373: 90: 1374: imOut = ImagingNew2Dirty(mode, imOut, imIn); call 0 returned 100% 90: 1375: if (!imOut) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1376: if (palette != inpalette) { branch 0 never executed branch 1 never executed #####: 1377: ImagingPaletteDelete(palette); call 0 never executed -: 1378: } -: 1379: return NULL; -: 1380: } -: 1381: 90: 1382: ImagingPaletteDelete(imOut->palette); call 0 returned 100% 90: 1383: imOut->palette = ImagingPaletteDuplicate(palette); call 0 returned 100% -: 1384: 90: 1385: if (imIn->bands == 1) { branch 0 taken 17% (fallthrough) branch 1 taken 83% -: 1386: /* greyscale image */ -: 1387: -: 1388: /* Greyscale palette: copy data as is */ 15: 1389: ImagingSectionEnter(&cookie); 2940: 1390: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 2925: 1391: if (alpha) { branch 0 taken 22% (fallthrough) branch 1 taken 78% 640: 1392: l2la((UINT8*) imOut->image[y], (UINT8*) imIn->image[y], imIn->xsize); -: 1393: } else { 2285: 1394: memcpy(imOut->image[y], imIn->image[y], imIn->linesize); -: 1395: } -: 1396: } 15: 1397: ImagingSectionLeave(&cookie); call 0 returned 100% -: 1398: -: 1399: } else { -: 1400: /* colour image */ -: 1401: -: 1402: /* Create mapping cache */ 75: 1403: if (ImagingPaletteCachePrepare(palette) < 0) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 1404: ImagingDelete(imOut); call 0 never executed #####: 1405: if (palette != inpalette) { branch 0 never executed branch 1 never executed #####: 1406: ImagingPaletteDelete(palette); call 0 never executed -: 1407: } -: 1408: return NULL; -: 1409: } -: 1410: 75: 1411: if (dither) { branch 0 taken 97% (fallthrough) branch 1 taken 3% -: 1412: /* floyd-steinberg dither */ -: 1413: -: 1414: int* errors; 73: 1415: errors = calloc(imIn->xsize + 1, sizeof(int) * 3); 73: 1416: if (!errors) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1417: ImagingDelete(imOut); call 0 never executed #####: 1418: return ImagingError_MemoryError(); call 0 never executed -: 1419: } -: 1420: -: 1421: /* Map each pixel to the nearest palette entry */ 73: 1422: ImagingSectionEnter(&cookie); 5643: 1423: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) -: 1424: int r, r0, r1, r2; -: 1425: int g, g0, g1, g2; -: 1426: int b, b0, b1, b2; 5570: 1427: UINT8* in = (UINT8*) imIn->image[y]; 5570: 1428: UINT8* out = alpha ? (UINT8*) imOut->image32[y] : imOut->image8[y]; branch 0 taken 41% (fallthrough) branch 1 taken 59% 5570: 1429: int* e = errors; -: 1430: 5570: 1431: r = r0 = r1 = 0; 5570: 1432: g = g0 = g1 = 0; 5570: 1433: b = b0 = b1 = b2 = 0; -: 1434: 748404: 1435: for (x = 0; x < imIn->xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 1436: int d2; -: 1437: INT16* cache; -: 1438: 742834: 1439: r = CLIP8(in[0] + (r + e[3+0])/16); branch 0 taken 92% (fallthrough) branch 1 taken 8% 742834: 1440: g = CLIP8(in[1] + (g + e[3+1])/16); branch 0 taken 86% (fallthrough) branch 1 taken 14% 742834: 1441: b = CLIP8(in[2] + (b + e[3+2])/16); branch 0 taken 87% (fallthrough) branch 1 taken 13% -: 1442: -: 1443: /* get closest colour */ 742834: 1444: cache = &ImagingPaletteCache(palette, r, g, b); 742834: 1445: if (cache[0] == 0x100) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 5999: 1446: ImagingPaletteCacheUpdate(palette, r, g, b); call 0 returned 100% -: 1447: } 742834: 1448: if (alpha) { branch 0 taken 40% (fallthrough) branch 1 taken 60% 294912: 1449: out[x*4] = out[x*4+1] = out[x*4+2] = (UINT8) cache[0]; 294912: 1450: out[x*4+3] = 255; -: 1451: } else { 447922: 1452: out[x] = (UINT8) cache[0]; -: 1453: } -: 1454: 742834: 1455: r -= (int) palette->palette[cache[0]*4]; 742834: 1456: g -= (int) palette->palette[cache[0]*4+1]; 742834: 1457: b -= (int) palette->palette[cache[0]*4+2]; -: 1458: -: 1459: /* propagate errors (don't ask ;-) */ 742834: 1460: r2 = r; d2 = r + r; r += d2; e[0] = r + r0; 742834: 1461: r += d2; r0 = r + r1; r1 = r2; r += d2; 742834: 1462: g2 = g; d2 = g + g; g += d2; e[1] = g + g0; 742834: 1463: g += d2; g0 = g + g1; g1 = g2; g += d2; 742834: 1464: b2 = b; d2 = b + b; b += d2; e[2] = b + b0; 742834: 1465: b += d2; b0 = b + b1; b1 = b2; b += d2; -: 1466: 742834: 1467: e += 3; -: 1468: -: 1469: } -: 1470: 5570: 1471: e[0] = b0; 5570: 1472: e[1] = b1; 5570: 1473: e[2] = b2; -: 1474: -: 1475: } 73: 1476: ImagingSectionLeave(&cookie); call 0 returned 100% 73: 1477: free(errors); -: 1478: -: 1479: } else { -: 1480: -: 1481: /* closest colour */ 2: 1482: ImagingSectionEnter(&cookie); 258: 1483: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) -: 1484: int r, g, b; 256: 1485: UINT8* in = (UINT8*) imIn->image[y]; 256: 1486: UINT8* out = alpha ? (UINT8*) imOut->image32[y] : imOut->image8[y]; branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 1487: 33024: 1488: for (x = 0; x < imIn->xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 1489: INT16* cache; -: 1490: 32768: 1491: r = in[0]; g = in[1]; b = in[2]; -: 1492: -: 1493: /* get closest colour */ 32768: 1494: cache = &ImagingPaletteCache(palette, r, g, b); 32768: 1495: if (cache[0] == 0x100) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 191: 1496: ImagingPaletteCacheUpdate(palette, r, g, b); call 0 returned 100% -: 1497: } 32768: 1498: if (alpha) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1499: out[x*4] = out[x*4+1] = out[x*4+2] = (UINT8) cache[0]; #####: 1500: out[x*4+3] = 255; -: 1501: } else { 32768: 1502: out[x] = (UINT8) cache[0]; -: 1503: } -: 1504: } -: 1505: } 2: 1506: ImagingSectionLeave(&cookie); call 0 returned 100% -: 1507: -: 1508: } 75: 1509: if (inpalette != palette) { branch 0 taken 93% (fallthrough) branch 1 taken 7% 70: 1510: ImagingPaletteCacheDelete(palette); call 0 returned 100% -: 1511: } -: 1512: } -: 1513: 90: 1514: if (inpalette != palette) { branch 0 taken 94% (fallthrough) branch 1 taken 6% 85: 1515: ImagingPaletteDelete(palette); call 0 returned 100% -: 1516: } -: 1517: -: 1518: return imOut; -: 1519:} -: 1520: -: 1521:static Imaging function tobilevel.isra.0 called 55 returned 100% blocks executed 95% 55: 1522:tobilevel(Imaging imOut, Imaging imIn, int dither) -: 1523:{ -: 1524: ImagingSectionCookie cookie; -: 1525: int x, y; -: 1526: int* errors; -: 1527: -: 1528: /* Map L or RGB to dithered 1 image */ 55: 1529: if (strcmp(imIn->mode, "L") != 0 && strcmp(imIn->mode, "RGB") != 0) { branch 0 taken 18% (fallthrough) branch 1 taken 82% branch 2 taken 84% (fallthrough) branch 3 taken 16% branch 4 taken 57% (fallthrough) branch 5 taken 43% branch 6 taken 100% (fallthrough) branch 7 taken 0% branch 8 taken 100% (fallthrough) branch 9 taken 0% branch 10 taken 48% (fallthrough) branch 11 taken 52% 22: 1530: return (Imaging) ImagingError_ValueError("conversion not supported"); call 0 returned 100% -: 1531: } -: 1532: 33: 1533: imOut = ImagingNew2Dirty("1", imOut, imIn); call 0 returned 100% 33: 1534: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1535: return NULL; -: 1536: } -: 1537: 33: 1538: errors = calloc(imIn->xsize + 1, sizeof(int)); 33: 1539: if (!errors) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1540: ImagingDelete(imOut); call 0 never executed #####: 1541: return ImagingError_MemoryError(); call 0 never executed -: 1542: } -: 1543: 33: 1544: if (imIn->bands == 1) { branch 0 taken 27% (fallthrough) branch 1 taken 73% -: 1545: -: 1546: /* map each pixel to black or white, using error diffusion */ 9: 1547: ImagingSectionEnter(&cookie); 2529: 1548: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) -: 1549: int l, l0, l1, l2, d2; 2520: 1550: UINT8* in = (UINT8*) imIn->image[y]; 2520: 1551: UINT8* out = imOut->image8[y]; -: 1552: 2520: 1553: l = l0 = l1 = 0; -: 1554: 2068102: 1555: for (x = 0; x < imIn->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 1556: -: 1557: /* pick closest colour */ 2065582: 1558: l = CLIP8(in[x] + (l + errors[x+1])/16); branch 0 taken 99% (fallthrough) branch 1 taken 1% 2065582: 1559: out[x] = (l > 128) ? 255 : 0; branch 0 taken 67% (fallthrough) branch 1 taken 33% -: 1560: -: 1561: /* propagate errors */ 2065582: 1562: l -= (int) out[x]; 2065582: 1563: l2 = l; d2 = l + l; l += d2; errors[x] = l + l0; 2065582: 1564: l += d2; l0 = l + l1; l1 = l2; l += d2; -: 1565: } -: 1566: 2520: 1567: errors[x] = l0; -: 1568: -: 1569: } 9: 1570: ImagingSectionLeave(&cookie); call 0 returned 100% -: 1571: -: 1572: } else { -: 1573: -: 1574: /* map each pixel to black or white, using error diffusion */ 24: 1575: ImagingSectionEnter(&cookie); 1432: 1576: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 98% branch 2 taken 2% (fallthrough) -: 1577: int l, l0, l1, l2, d2; 1408: 1578: UINT8* in = (UINT8*) imIn->image[y]; 1408: 1579: UINT8* out = imOut->image8[y]; -: 1580: 1408: 1581: l = l0 = l1 = 0; -: 1582: 181632: 1583: for (x = 0; x < imIn->xsize; x++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 1584: -: 1585: /* pick closest colour */ 180224: 1586: l = CLIP8(L(in)/1000 + (l + errors[x+1])/16); branch 0 taken 99% (fallthrough) branch 1 taken 1% 180224: 1587: out[x] = (l > 128) ? 255 : 0; branch 0 taken 67% (fallthrough) branch 1 taken 33% -: 1588: -: 1589: /* propagate errors */ 180224: 1590: l -= (int) out[x]; 180224: 1591: l2 = l; d2 = l + l; l += d2; errors[x] = l + l0; 180224: 1592: l += d2; l0 = l + l1; l1 = l2; l += d2; -: 1593: -: 1594: } -: 1595: 1408: 1596: errors[x] = l0; -: 1597: -: 1598: } 24: 1599: ImagingSectionLeave(&cookie); call 0 returned 100% -: 1600: } -: 1601: 33: 1602: free(errors); -: 1603: -: 1604: return imOut; -: 1605:} -: 1606:#if defined(_MSC_VER) -: 1607:#pragma optimize("", on) -: 1608:#endif -: 1609: -: 1610:static Imaging function convert called 7902 returned 100% blocks executed 91% 7902: 1611:convert(Imaging imOut, Imaging imIn, const char *mode, -: 1612: ImagingPalette palette, int dither) -: 1613:{ -: 1614: ImagingSectionCookie cookie; -: 1615: ImagingShuffler convert; -: 1616: int y; -: 1617: 7902: 1618: if (!imIn) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1619: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 1620: } -: 1621: 7902: 1622: if (!mode) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 1623: /* Map palette image to full depth */ #####: 1624: if (!imIn->palette) { branch 0 never executed branch 1 never executed #####: 1625: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 1626: } #####: 1627: mode = imIn->palette->mode; -: 1628: } else { -: 1629: /* Same mode? */ 7902: 1630: if (!strcmp(imIn->mode, mode)) { branch 0 taken 2% (fallthrough) branch 1 taken 98% 192: 1631: return ImagingCopy2(imOut, imIn); call 0 returned 100% -: 1632: } -: 1633: } -: 1634: -: 1635: -: 1636: /* test for special conversions */ -: 1637: 7710: 1638: if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "PA") == 0) { branch 0 taken 9% (fallthrough) branch 1 taken 91% branch 2 taken 91% (fallthrough) branch 3 taken 9% branch 4 taken 1% (fallthrough) branch 5 taken 99% branch 6 taken 100% (fallthrough) branch 7 taken 0% branch 8 taken 1% (fallthrough) branch 9 taken 99% 696: 1639: return frompalette(imOut, imIn, mode); call 0 returned 100% -: 1640: } -: 1641: 7014: 1642: if (strcmp(mode, "P") == 0 || strcmp(mode, "PA") == 0) { branch 0 taken 2% (fallthrough) branch 1 taken 98% branch 2 taken 99% (fallthrough) branch 3 taken 1% branch 4 taken 1% (fallthrough) branch 5 taken 99% branch 6 taken 100% (fallthrough) branch 7 taken 0% branch 8 taken 1% (fallthrough) branch 9 taken 99% 130: 1643: return topalette(imOut, imIn, mode, palette, dither); call 0 returned 100% -: 1644: } -: 1645: 6884: 1646: if (dither && strcmp(mode, "1") == 0) { branch 0 taken 97% (fallthrough) branch 1 taken 3% branch 2 taken 1% (fallthrough) branch 3 taken 99% branch 4 taken 99% (fallthrough) branch 5 taken 1% 55: 1647: return tobilevel(imOut, imIn, dither); call 0 returned 100% -: 1648: } -: 1649: -: 1650: -: 1651: /* standard conversion machinery */ -: 1652: -: 1653: convert = NULL; -: 1654: 166498: 1655: for (y = 0; converters[y].from; y++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 190540: 1656: if (!strcmp(imIn->mode, converters[y].from) && branch 0 taken 10% (fallthrough) branch 1 taken 90% branch 2 taken 39% (fallthrough) branch 3 taken 61% 17350: 1657: !strcmp(mode, converters[y].to)) { 6692: 1658: convert = converters[y].convert; 6692: 1659: break; -: 1660: } -: 1661: } -: 1662: 6829: 1663: if (!convert) { branch 0 taken 2% (fallthrough) branch 1 taken 98% -: 1664:#ifdef notdef -: 1665: return (Imaging) ImagingError_ValueError("conversion not supported"); -: 1666:#else -: 1667: static char buf[256]; -: 1668: /* FIXME: may overflow if mode is too large */ 274: 1669: sprintf(buf, "conversion from %s to %s not supported", imIn->mode, mode); 137: 1670: return (Imaging) ImagingError_ValueError(buf); call 0 returned 100% -: 1671:#endif -: 1672: } -: 1673: 6692: 1674: imOut = ImagingNew2Dirty(mode, imOut, imIn); call 0 returned 100% 6692: 1675: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1676: return NULL; -: 1677: } -: 1678: 6692: 1679: ImagingSectionEnter(&cookie); 1181390: 1680: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 1174698: 1681: (*convert)((UINT8*) imOut->image[y], (UINT8*) imIn->image[y], call 0 returned 100% -: 1682: imIn->xsize); -: 1683: } 6692: 1684: ImagingSectionLeave(&cookie); call 0 returned 100% -: 1685: 6692: 1686: return imOut; -: 1687:} -: 1688: -: 1689:Imaging function ImagingConvert called 7902 returned 100% blocks executed 100% 7902: 1690:ImagingConvert(Imaging imIn, const char *mode, -: 1691: ImagingPalette palette, int dither) -: 1692:{ 7902: 1693: return convert(NULL, imIn, mode, palette, dither); call 0 returned 100% -: 1694:} -: 1695: -: 1696:Imaging function ImagingConvert2 called 0 returned 0% blocks executed 0% #####: 1697:ImagingConvert2(Imaging imOut, Imaging imIn) -: 1698:{ #####: 1699: return convert(imOut, imIn, imOut->mode, NULL, 0); call 0 never executed -: 1700:} -: 1701: -: 1702: -: 1703:Imaging function ImagingConvertTransparent called 8 returned 100% blocks executed 95% 8: 1704:ImagingConvertTransparent(Imaging imIn, const char *mode, -: 1705: int r, int g, int b) -: 1706:{ -: 1707: ImagingSectionCookie cookie; -: 1708: ImagingShuffler convert; 8: 1709: Imaging imOut = NULL; -: 1710: int y; -: 1711: 8: 1712: if (!imIn){ branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 1713: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 1714: } -: 1715: 22: 1716: if (!((strcmp(imIn->mode, "RGB") == 0 || branch 0 taken 25% (fallthrough) branch 1 taken 75% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 75% (fallthrough) branch 7 taken 25% branch 8 taken 67% (fallthrough) branch 9 taken 33% branch 10 taken 0% (fallthrough) branch 11 taken 100% 10: 1717: strcmp(imIn->mode, "1") == 0 || branch 0 taken 33% (fallthrough) branch 1 taken 67% branch 2 taken 50% (fallthrough) branch 3 taken 50% 6: 1718: strcmp(imIn->mode, "I") == 0 || branch 0 taken 50% (fallthrough) branch 1 taken 50% branch 2 taken 100% (fallthrough) branch 3 taken 0% 2: 1719: strcmp(imIn->mode, "L") == 0) branch 0 taken 100% (fallthrough) branch 1 taken 0% 8: 1720: && strcmp(mode, "RGBA") == 0)) -: 1721:#ifdef notdef -: 1722: { -: 1723: return (Imaging) ImagingError_ValueError("conversion not supported"); -: 1724: } -: 1725:#else -: 1726: { -: 1727: static char buf[256]; -: 1728: /* FIXME: may overflow if mode is too large */ #####: 1729: sprintf(buf, "conversion from %s to %s not supported in convert_transparent", imIn->mode, mode); #####: 1730: return (Imaging) ImagingError_ValueError(buf); call 0 never executed -: 1731: } -: 1732:#endif -: 1733: 8: 1734: if (strcmp(imIn->mode, "RGB") == 0) { branch 0 taken 25% (fallthrough) branch 1 taken 75% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 75% (fallthrough) branch 7 taken 25% -: 1735: convert = rgb2rgba; -: 1736: } else { 6: 1737: if (strcmp(imIn->mode, "1") == 0) { branch 0 taken 33% (fallthrough) branch 1 taken 67% branch 2 taken 67% (fallthrough) branch 3 taken 33% -: 1738: convert = bit2rgb; 4: 1739: } else if (strcmp(imIn->mode, "I") == 0) { branch 0 taken 50% (fallthrough) branch 1 taken 50% branch 2 taken 50% (fallthrough) branch 3 taken 50% -: 1740: convert = i2rgb; -: 1741: } else { 2: 1742: convert = l2rgb; -: 1743: } -: 1744: g = b = r; -: 1745: } -: 1746: 8: 1747: imOut = ImagingNew2Dirty(mode, imOut, imIn); call 0 returned 100% 8: 1748: if (!imOut){ branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 1749: return NULL; -: 1750: } -: 1751: 8: 1752: ImagingSectionEnter(&cookie); 584: 1753: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 576: 1754: (*convert)((UINT8*) imOut->image[y], (UINT8*) imIn->image[y], call 0 returned 100% -: 1755: imIn->xsize); 576: 1756: rgbT2rgba((UINT8*) imOut->image[y], imIn->xsize, r, g, b); call 0 returned 100% -: 1757: } 8: 1758: ImagingSectionLeave(&cookie); call 0 returned 100% -: 1759: 8: 1760: return imOut; -: 1761: -: 1762:} -: 1763: -: 1764:Imaging function ImagingConvertInPlace called 6 returned 100% blocks executed 100% 6: 1765:ImagingConvertInPlace(Imaging imIn, const char* mode) -: 1766:{ -: 1767: ImagingSectionCookie cookie; -: 1768: ImagingShuffler convert; -: 1769: int y; -: 1770: -: 1771: /* limited support for inplace conversion */ 6: 1772: if (strcmp(imIn->mode, "L") == 0 && strcmp(mode, "1") == 0) { branch 0 taken 33% (fallthrough) branch 1 taken 67% branch 2 taken 33% (fallthrough) branch 3 taken 67% branch 4 taken 50% (fallthrough) branch 5 taken 50% branch 6 taken 50% (fallthrough) branch 7 taken 50% -: 1773: convert = l2bit; 5: 1774: } else if (strcmp(imIn->mode, "1") == 0 && strcmp(mode, "L") == 0) { branch 0 taken 20% (fallthrough) branch 1 taken 80% branch 2 taken 20% (fallthrough) branch 3 taken 80% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 0% (fallthrough) branch 7 taken 100% -: 1775: convert = bit2l; -: 1776: } else { 4: 1777: return ImagingError_ModeError(); call 0 returned 100% -: 1778: } -: 1779: 2: 1780: ImagingSectionEnter(&cookie); 4: 1781: for (y = 0; y < imIn->ysize; y++) { call 0 returned 100% branch 1 taken 50% branch 2 taken 50% (fallthrough) 2: 1782: (*convert)((UINT8*) imIn->image[y], (UINT8*) imIn->image[y], call 0 returned 100% -: 1783: imIn->xsize); -: 1784: } 2: 1785: ImagingSectionLeave(&cookie); call 0 returned 100% -: 1786: 2: 1787: return imIn; -: 1788:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Chops.c.gcov -: 0:Source:src/libImaging/Chops.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Chops.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Chops.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * basic channel operations -: 6: * -: 7: * history: -: 8: * 1996-03-28 fl Created -: 9: * 1996-08-13 fl Added and/or/xor for "1" images -: 10: * 1996-12-14 fl Added add_modulo, sub_modulo -: 11: * 2005-09-10 fl Fixed output values from and/or/xor -: 12: * -: 13: * Copyright (c) 1996 by Fredrik Lundh. -: 14: * Copyright (c) 1997 by Secret Labs AB. -: 15: * -: 16: * See the README file for details on usage and redistribution. -: 17: */ -: 18: -: 19: -: 20:#include "Imaging.h" -: 21: -: 22:#define CHOP(operation)\ -: 23: int x, y;\ -: 24: Imaging imOut;\ -: 25: imOut = create(imIn1, imIn2, NULL);\ -: 26: if (!imOut) {\ -: 27: return NULL;\ -: 28: }\ -: 29: for (y = 0; y < imOut->ysize; y++) {\ -: 30: UINT8* out = (UINT8*) imOut->image[y];\ -: 31: UINT8* in1 = (UINT8*) imIn1->image[y];\ -: 32: UINT8* in2 = (UINT8*) imIn2->image[y];\ -: 33: for (x = 0; x < imOut->linesize; x++) {\ -: 34: int temp = operation;\ -: 35: if (temp <= 0) {\ -: 36: out[x] = 0;\ -: 37: } else if (temp >= 255) {\ -: 38: out[x] = 255;\ -: 39: } else {\ -: 40: out[x] = temp;\ -: 41: }\ -: 42: }\ -: 43: }\ -: 44: return imOut; -: 45: -: 46:#define CHOP2(operation, mode)\ -: 47: int x, y;\ -: 48: Imaging imOut;\ -: 49: imOut = create(imIn1, imIn2, mode);\ -: 50: if (!imOut) {\ -: 51: return NULL;\ -: 52: }\ -: 53: for (y = 0; y < imOut->ysize; y++) {\ -: 54: UINT8* out = (UINT8*) imOut->image[y];\ -: 55: UINT8* in1 = (UINT8*) imIn1->image[y];\ -: 56: UINT8* in2 = (UINT8*) imIn2->image[y];\ -: 57: for (x = 0; x < imOut->linesize; x++) {\ -: 58: out[x] = operation;\ -: 59: }\ -: 60: }\ -: 61: return imOut; -: 62: -: 63:static Imaging function create called 146 returned 100% blocks executed 88% 146: 64:create(Imaging im1, Imaging im2, char* mode) -: 65:{ -: 66: int xsize, ysize; -: 67: 146: 68: if (!im1 || !im2 || im1->type != IMAGING_TYPE_UINT8 || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 25% (fallthrough) branch 7 taken 75% 36: 69: (mode != NULL && (strcmp(im1->mode, "1") || strcmp(im2->mode, "1")))) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 0% (fallthrough) branch 7 taken 100% #####: 70: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 71: } 292: 72: if (im1->type != im2->type || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% 146: 73: im1->bands != im2->bands) { #####: 74: return (Imaging) ImagingError_Mismatch(); call 0 never executed -: 75: } -: 76: 146: 77: xsize = (im1->xsize < im2->xsize) ? im1->xsize : im2->xsize; 146: 78: ysize = (im1->ysize < im2->ysize) ? im1->ysize : im2->ysize; -: 79: 146: 80: return ImagingNewDirty(im1->mode, xsize, ysize); call 0 returned 100% -: 81:} -: 82: -: 83:Imaging function ImagingChopLighter called 3 returned 100% blocks executed 100% 3: 84:ImagingChopLighter(Imaging imIn1, Imaging imIn2) -: 85:{ 3: 86: CHOP((in1[x] > in2[x]) ? in1[x] : in2[x]); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 30% (fallthrough) branch 4 taken 70% branch 5 taken 30% (fallthrough) branch 6 taken 70% branch 7 taken 34% (fallthrough) branch 8 taken 66% branch 9 taken 99% branch 10 taken 1% (fallthrough) branch 11 taken 99% branch 12 taken 1% (fallthrough) -: 87:} -: 88: -: 89:Imaging function ImagingChopDarker called 3 returned 100% blocks executed 100% 3: 90:ImagingChopDarker(Imaging imIn1, Imaging imIn2) -: 91:{ 3: 92: CHOP((in1[x] < in2[x]) ? in1[x] : in2[x]); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 1% (fallthrough) branch 4 taken 99% branch 5 taken 60% (fallthrough) branch 6 taken 40% branch 7 taken 55% (fallthrough) branch 8 taken 45% branch 9 taken 99% branch 10 taken 1% (fallthrough) branch 11 taken 99% branch 12 taken 1% (fallthrough) -: 93:} -: 94: -: 95:Imaging function ImagingChopDifference called 3 returned 100% blocks executed 100% 3: 96:ImagingChopDifference(Imaging imIn1, Imaging imIn2) -: 97:{ 3: 98: CHOP(abs((int) in1[x] - (int) in2[x])); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 69% (fallthrough) branch 4 taken 31% branch 5 taken 2% (fallthrough) branch 6 taken 98% branch 7 taken 99% branch 8 taken 1% (fallthrough) branch 9 taken 99% branch 10 taken 1% (fallthrough) -: 99:} -: 100: -: 101:Imaging function ImagingChopMultiply called 4 returned 100% blocks executed 100% 4: 102:ImagingChopMultiply(Imaging imIn1, Imaging imIn2) -: 103:{ 4: 104: CHOP((int) in1[x] * (int) in2[x] / 255); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 44% (fallthrough) branch 4 taken 56% branch 5 taken 41% (fallthrough) branch 6 taken 59% branch 7 taken 99% branch 8 taken 1% (fallthrough) branch 9 taken 99% branch 10 taken 1% (fallthrough) -: 105:} -: 106: -: 107:Imaging function ImagingChopScreen called 2 returned 100% blocks executed 100% 2: 108:ImagingChopScreen(Imaging imIn1, Imaging imIn2) -: 109:{ 2: 110: CHOP(255 - ((int) (255 - in1[x]) * (int) (255 - in2[x])) / 255); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 45% (fallthrough) branch 4 taken 55% branch 5 taken 42% (fallthrough) branch 6 taken 58% branch 7 taken 99% branch 8 taken 1% (fallthrough) branch 9 taken 99% branch 10 taken 1% (fallthrough) -: 111:} -: 112: -: 113:Imaging function ImagingChopAdd called 6 returned 100% blocks executed 100% 6: 114:ImagingChopAdd(Imaging imIn1, Imaging imIn2, float scale, int offset) -: 115:{ 6: 116: CHOP(((int) in1[x] + (int) in2[x]) / scale + offset); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 13% (fallthrough) branch 4 taken 87% branch 5 taken 39% (fallthrough) branch 6 taken 61% branch 7 taken 99% branch 8 taken 1% (fallthrough) branch 9 taken 99% branch 10 taken 1% (fallthrough) -: 117:} -: 118: -: 119:Imaging function ImagingChopSubtract called 6 returned 100% blocks executed 100% 6: 120:ImagingChopSubtract(Imaging imIn1, Imaging imIn2, float scale, int offset) -: 121:{ 6: 122: CHOP(((int) in1[x] - (int) in2[x]) / scale + offset); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 50% (fallthrough) branch 4 taken 50% branch 5 taken 1% (fallthrough) branch 6 taken 99% branch 7 taken 99% branch 8 taken 1% (fallthrough) branch 9 taken 99% branch 10 taken 1% (fallthrough) -: 123:} -: 124: -: 125:Imaging function ImagingChopAnd called 12 returned 100% blocks executed 100% 12: 126:ImagingChopAnd(Imaging imIn1, Imaging imIn2) -: 127:{ 12: 128: CHOP2((in1[x] && in2[x]) ? 255 : 0, "1"); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 50% (fallthrough) branch 4 taken 50% branch 5 taken 50% (fallthrough) branch 6 taken 50% branch 7 taken 50% branch 8 taken 50% (fallthrough) branch 9 taken 50% branch 10 taken 50% (fallthrough) -: 129:} -: 130: -: 131:Imaging function ImagingChopOr called 12 returned 100% blocks executed 100% 12: 132:ImagingChopOr(Imaging imIn1, Imaging imIn2) -: 133:{ 12: 134: CHOP2((in1[x] || in2[x]) ? 255 : 0, "1"); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 50% (fallthrough) branch 4 taken 50% branch 5 taken 50% (fallthrough) branch 6 taken 50% branch 7 taken 50% branch 8 taken 50% (fallthrough) branch 9 taken 50% branch 10 taken 50% (fallthrough) -: 135:} -: 136: -: 137:Imaging function ImagingChopXor called 12 returned 100% blocks executed 100% 12: 138:ImagingChopXor(Imaging imIn1, Imaging imIn2) -: 139:{ 12: 140: CHOP2(((in1[x] != 0) ^ (in2[x] != 0)) ? 255 : 0, "1"); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 50% (fallthrough) branch 4 taken 50% branch 5 taken 50% branch 6 taken 50% (fallthrough) branch 7 taken 50% branch 8 taken 50% (fallthrough) -: 141:} -: 142: -: 143:Imaging function ImagingChopAddModulo called 3 returned 100% blocks executed 100% 3: 144:ImagingChopAddModulo(Imaging imIn1, Imaging imIn2) -: 145:{ 3: 146: CHOP2(in1[x] + in2[x], NULL); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 99% branch 4 taken 1% (fallthrough) branch 5 taken 99% branch 6 taken 1% (fallthrough) -: 147:} -: 148: -: 149:Imaging function ImagingChopSubtractModulo called 74 returned 100% blocks executed 100% 74: 150:ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2) -: 151:{ 74: 152: CHOP2(in1[x] - in2[x], NULL); call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 99% branch 4 taken 1% (fallthrough) branch 5 taken 99% branch 6 taken 1% (fallthrough) -: 153:} -: 154: -: 155:Imaging function ImagingChopSoftLight called 2 returned 100% blocks executed 100% 2: 156:ImagingChopSoftLight(Imaging imIn1, Imaging imIn2) -: 157:{ 2: 158: CHOP2( (((255-in1[x]) * (in1[x]*in2[x]) ) / 65536) + call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 99% branch 4 taken 1% (fallthrough) branch 5 taken 99% branch 6 taken 1% (fallthrough) -: 159: (in1[x] * ( 255 - ( (255 - in1[x]) * (255 - in2[x] ) / 255) )) / 255 -: 160: , NULL ); -: 161:} -: 162: -: 163:Imaging function ImagingChopHardLight called 2 returned 100% blocks executed 100% 2: 164:ImagingChopHardLight(Imaging imIn1, Imaging imIn2) -: 165:{ 2: 166: CHOP2( (in2[x]<128) ? ( (in1[x]*in2[x])/127) call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 53% (fallthrough) branch 4 taken 47% branch 5 taken 99% branch 6 taken 1% (fallthrough) branch 7 taken 99% branch 8 taken 1% (fallthrough) -: 167: : 255 - ( ((255-in2[x]) * (255-in1[x])) / 127) -: 168: , NULL); -: 169:} -: 170: -: 171:Imaging function ImagingOverlay called 2 returned 100% blocks executed 100% 2: 172:ImagingOverlay(Imaging imIn1, Imaging imIn2) -: 173:{ 2: 174: CHOP2( (in1[x]<128) ? ( (in1[x]*in2[x])/127) call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% branch 3 taken 55% (fallthrough) branch 4 taken 45% branch 5 taken 99% branch 6 taken 1% (fallthrough) branch 7 taken 99% branch 8 taken 1% (fallthrough) -: 175: : 255 - ( ((255-in1[x]) * (255-in2[x])) / 127) -: 176: , NULL); -: 177:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#display.c.gcov -: 0:Source:src/display.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/display.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/display.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * -: 4: * display support (and other windows-related stuff) -: 5: * -: 6: * History: -: 7: * 1996-05-13 fl Windows DIB support -: 8: * 1996-05-21 fl Added palette stuff -: 9: * 1996-05-28 fl Added display_mode stuff -: 10: * 1997-09-21 fl Added draw primitive -: 11: * 2001-09-17 fl Added ImagingGrabScreen (from _grabscreen.c) -: 12: * 2002-05-12 fl Added ImagingListWindows -: 13: * 2002-11-19 fl Added clipboard support -: 14: * 2002-11-25 fl Added GetDC/ReleaseDC helpers -: 15: * 2003-05-21 fl Added create window support (including window callback) -: 16: * 2003-09-05 fl Added fromstring/tostring methods -: 17: * 2009-03-14 fl Added WMF support (from pilwmf) -: 18: * -: 19: * Copyright (c) 1997-2003 by Secret Labs AB. -: 20: * Copyright (c) 1996-1997 by Fredrik Lundh. -: 21: * -: 22: * See the README file for information on usage and redistribution. -: 23: */ -: 24: -: 25: -: 26:#include "Python.h" -: 27: -: 28:#include "libImaging/Imaging.h" -: 29: -: 30:/* -------------------------------------------------------------------- */ -: 31:/* Windows DIB support */ -: 32: -: 33:#ifdef _WIN32 -: 34: -: 35:#include "libImaging/ImDib.h" -: 36: -: 37:#if SIZEOF_VOID_P == 8 -: 38:#define F_HANDLE "K" -: 39:#else -: 40:#define F_HANDLE "k" -: 41:#endif -: 42: -: 43:typedef struct { -: 44: PyObject_HEAD -: 45: ImagingDIB dib; -: 46:} ImagingDisplayObject; -: 47: -: 48:static PyTypeObject ImagingDisplayType; -: 49: -: 50:static ImagingDisplayObject* -: 51:_new(const char* mode, int xsize, int ysize) -: 52:{ -: 53: ImagingDisplayObject *display; -: 54: -: 55: if (PyType_Ready(&ImagingDisplayType) < 0) { -: 56: return NULL; -: 57: } -: 58: -: 59: display = PyObject_New(ImagingDisplayObject, &ImagingDisplayType); -: 60: if (display == NULL) { -: 61: return NULL; -: 62: } -: 63: -: 64: display->dib = ImagingNewDIB(mode, xsize, ysize); -: 65: if (!display->dib) { -: 66: Py_DECREF(display); -: 67: return NULL; -: 68: } -: 69: -: 70: return display; -: 71:} -: 72: -: 73:static void -: 74:_delete(ImagingDisplayObject* display) -: 75:{ -: 76: if (display->dib) { -: 77: ImagingDeleteDIB(display->dib); -: 78: } -: 79: PyObject_Del(display); -: 80:} -: 81: -: 82:static PyObject* -: 83:_expose(ImagingDisplayObject* display, PyObject* args) -: 84:{ -: 85: HDC hdc; -: 86: if (!PyArg_ParseTuple(args, F_HANDLE, &hdc)) { -: 87: return NULL; -: 88: } -: 89: -: 90: ImagingExposeDIB(display->dib, hdc); -: 91: -: 92: Py_INCREF(Py_None); -: 93: return Py_None; -: 94:} -: 95: -: 96:static PyObject* -: 97:_draw(ImagingDisplayObject* display, PyObject* args) -: 98:{ -: 99: HDC hdc; -: 100: int dst[4]; -: 101: int src[4]; -: 102: if (!PyArg_ParseTuple(args, F_HANDLE "(iiii)(iiii)", &hdc, -: 103: dst+0, dst+1, dst+2, dst+3, -: 104: src+0, src+1, src+2, src+3)) { -: 105: return NULL; -: 106: } -: 107: -: 108: ImagingDrawDIB(display->dib, hdc, dst, src); -: 109: -: 110: Py_INCREF(Py_None); -: 111: return Py_None; -: 112:} -: 113: -: 114:extern Imaging PyImaging_AsImaging(PyObject *op); -: 115: -: 116:static PyObject* -: 117:_paste(ImagingDisplayObject* display, PyObject* args) -: 118:{ -: 119: Imaging im; -: 120: -: 121: PyObject* op; -: 122: int xy[4]; -: 123: xy[0] = xy[1] = xy[2] = xy[3] = 0; -: 124: if (!PyArg_ParseTuple(args, "O|(iiii)", &op, xy+0, xy+1, xy+2, xy+3)) { -: 125: return NULL; -: 126: } -: 127: im = PyImaging_AsImaging(op); -: 128: if (!im) { -: 129: return NULL; -: 130: } -: 131: -: 132: if (xy[2] <= xy[0]) { -: 133: xy[2] = xy[0] + im->xsize; -: 134: } -: 135: if (xy[3] <= xy[1]) { -: 136: xy[3] = xy[1] + im->ysize; -: 137: } -: 138: -: 139: ImagingPasteDIB(display->dib, im, xy); -: 140: -: 141: Py_INCREF(Py_None); -: 142: return Py_None; -: 143:} -: 144: -: 145:static PyObject* -: 146:_query_palette(ImagingDisplayObject* display, PyObject* args) -: 147:{ -: 148: HDC hdc; -: 149: int status; -: 150: -: 151: if (!PyArg_ParseTuple(args, F_HANDLE, &hdc)) { -: 152: return NULL; -: 153: } -: 154: -: 155: status = ImagingQueryPaletteDIB(display->dib, hdc); -: 156: -: 157: return Py_BuildValue("i", status); -: 158:} -: 159: -: 160:static PyObject* -: 161:_getdc(ImagingDisplayObject* display, PyObject* args) -: 162:{ -: 163: HWND window; -: 164: HDC dc; -: 165: -: 166: if (!PyArg_ParseTuple(args, F_HANDLE, &window)) { -: 167: return NULL; -: 168: } -: 169: -: 170: dc = GetDC(window); -: 171: if (!dc) { -: 172: PyErr_SetString(PyExc_OSError, "cannot create dc"); -: 173: return NULL; -: 174: } -: 175: -: 176: return Py_BuildValue(F_HANDLE, dc); -: 177:} -: 178: -: 179:static PyObject* -: 180:_releasedc(ImagingDisplayObject* display, PyObject* args) -: 181:{ -: 182: HWND window; -: 183: HDC dc; -: 184: -: 185: if (!PyArg_ParseTuple(args, F_HANDLE F_HANDLE, &window, &dc)) { -: 186: return NULL; -: 187: } -: 188: -: 189: ReleaseDC(window, dc); -: 190: -: 191: Py_INCREF(Py_None); -: 192: return Py_None; -: 193:} -: 194: -: 195:static PyObject* -: 196:_frombytes(ImagingDisplayObject* display, PyObject* args) -: 197:{ -: 198: char* ptr; -: 199: int bytes; -: 200: -: 201: if (!PyArg_ParseTuple(args, "y#:frombytes", &ptr, &bytes)) { -: 202: return NULL; -: 203: } -: 204: -: 205: if (display->dib->ysize * display->dib->linesize != bytes) { -: 206: PyErr_SetString(PyExc_ValueError, "wrong size"); -: 207: return NULL; -: 208: } -: 209: -: 210: memcpy(display->dib->bits, ptr, bytes); -: 211: -: 212: Py_INCREF(Py_None); -: 213: return Py_None; -: 214:} -: 215: -: 216:static PyObject* -: 217:_tobytes(ImagingDisplayObject* display, PyObject* args) -: 218:{ -: 219: if (!PyArg_ParseTuple(args, ":tobytes")) { -: 220: return NULL; -: 221: } -: 222: -: 223: return PyBytes_FromStringAndSize( -: 224: display->dib->bits, display->dib->ysize * display->dib->linesize -: 225: ); -: 226:} -: 227: -: 228:static struct PyMethodDef methods[] = { -: 229: {"draw", (PyCFunction)_draw, 1}, -: 230: {"expose", (PyCFunction)_expose, 1}, -: 231: {"paste", (PyCFunction)_paste, 1}, -: 232: {"query_palette", (PyCFunction)_query_palette, 1}, -: 233: {"getdc", (PyCFunction)_getdc, 1}, -: 234: {"releasedc", (PyCFunction)_releasedc, 1}, -: 235: {"frombytes", (PyCFunction)_frombytes, 1}, -: 236: {"tobytes", (PyCFunction)_tobytes, 1}, -: 237: {"fromstring", (PyCFunction)_frombytes, 1}, -: 238: {"tostring", (PyCFunction)_tobytes, 1}, -: 239: {NULL, NULL} /* sentinel */ -: 240:}; -: 241: -: 242:static PyObject* -: 243:_getattr_mode(ImagingDisplayObject* self, void* closure) -: 244:{ -: 245: return Py_BuildValue("s", self->dib->mode); -: 246:} -: 247: -: 248:static PyObject* -: 249:_getattr_size(ImagingDisplayObject* self, void* closure) -: 250:{ -: 251: return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize); -: 252:} -: 253: -: 254:static struct PyGetSetDef getsetters[] = { -: 255: { "mode", (getter) _getattr_mode }, -: 256: { "size", (getter) _getattr_size }, -: 257: { NULL } -: 258:}; -: 259: -: 260:static PyTypeObject ImagingDisplayType = { -: 261: PyVarObject_HEAD_INIT(NULL, 0) -: 262: "ImagingDisplay", /*tp_name*/ -: 263: sizeof(ImagingDisplayObject),/*tp_size*/ -: 264: 0, /*tp_itemsize*/ -: 265: /* methods */ -: 266: (destructor)_delete, /*tp_dealloc*/ -: 267: 0, /*tp_print*/ -: 268: 0, /*tp_getattr*/ -: 269: 0, /*tp_setattr*/ -: 270: 0, /*tp_compare*/ -: 271: 0, /*tp_repr*/ -: 272: 0, /*tp_as_number */ -: 273: 0, /*tp_as_sequence */ -: 274: 0, /*tp_as_mapping */ -: 275: 0, /*tp_hash*/ -: 276: 0, /*tp_call*/ -: 277: 0, /*tp_str*/ -: 278: 0, /*tp_getattro*/ -: 279: 0, /*tp_setattro*/ -: 280: 0, /*tp_as_buffer*/ -: 281: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 282: 0, /*tp_doc*/ -: 283: 0, /*tp_traverse*/ -: 284: 0, /*tp_clear*/ -: 285: 0, /*tp_richcompare*/ -: 286: 0, /*tp_weaklistoffset*/ -: 287: 0, /*tp_iter*/ -: 288: 0, /*tp_iternext*/ -: 289: methods, /*tp_methods*/ -: 290: 0, /*tp_members*/ -: 291: getsetters, /*tp_getset*/ -: 292:}; -: 293: -: 294:PyObject* -: 295:PyImaging_DisplayWin32(PyObject* self, PyObject* args) -: 296:{ -: 297: ImagingDisplayObject* display; -: 298: char *mode; -: 299: int xsize, ysize; -: 300: -: 301: if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize)) { -: 302: return NULL; -: 303: } -: 304: -: 305: display = _new(mode, xsize, ysize); -: 306: if (display == NULL) { -: 307: return NULL; -: 308: } -: 309: -: 310: return (PyObject*) display; -: 311:} -: 312: -: 313:PyObject* -: 314:PyImaging_DisplayModeWin32(PyObject* self, PyObject* args) -: 315:{ -: 316: char *mode; -: 317: int size[2]; -: 318: -: 319: mode = ImagingGetModeDIB(size); -: 320: -: 321: return Py_BuildValue("s(ii)", mode, size[0], size[1]); -: 322:} -: 323: -: 324:/* -------------------------------------------------------------------- */ -: 325:/* Windows screen grabber */ -: 326: -: 327:typedef HANDLE(__stdcall* Func_SetThreadDpiAwarenessContext)(HANDLE); -: 328: -: 329:PyObject* -: 330:PyImaging_GrabScreenWin32(PyObject* self, PyObject* args) -: 331:{ -: 332: int x = 0, y = 0, width, height; -: 333: int includeLayeredWindows = 0, all_screens = 0; -: 334: HBITMAP bitmap; -: 335: BITMAPCOREHEADER core; -: 336: HDC screen, screen_copy; -: 337: DWORD rop; -: 338: PyObject* buffer; -: 339: HANDLE dpiAwareness; -: 340: HMODULE user32; -: 341: Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function; -: 342: -: 343: if (!PyArg_ParseTuple(args, "|ii", &includeLayeredWindows, &all_screens)) { -: 344: return NULL; -: 345: } -: 346: -: 347: /* step 1: create a memory DC large enough to hold the -: 348: entire screen */ -: 349: -: 350: screen = CreateDC("DISPLAY", NULL, NULL, NULL); -: 351: screen_copy = CreateCompatibleDC(screen); -: 352: -: 353: // added in Windows 10 (1607) -: 354: // loaded dynamically to avoid link errors -: 355: user32 = LoadLibraryA("User32.dll"); -: 356: SetThreadDpiAwarenessContext_function = -: 357: (Func_SetThreadDpiAwarenessContext) -: 358: GetProcAddress(user32, "SetThreadDpiAwarenessContext"); -: 359: if (SetThreadDpiAwarenessContext_function != NULL) { -: 360: // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = ((DPI_CONTEXT_HANDLE)-3) -: 361: dpiAwareness = SetThreadDpiAwarenessContext_function((HANDLE) -3); -: 362: } -: 363: -: 364: if (all_screens) { -: 365: x = GetSystemMetrics(SM_XVIRTUALSCREEN); -: 366: y = GetSystemMetrics(SM_YVIRTUALSCREEN); -: 367: width = GetSystemMetrics(SM_CXVIRTUALSCREEN); -: 368: height = GetSystemMetrics(SM_CYVIRTUALSCREEN); -: 369: } else { -: 370: width = GetDeviceCaps(screen, HORZRES); -: 371: height = GetDeviceCaps(screen, VERTRES); -: 372: } -: 373: -: 374: if (SetThreadDpiAwarenessContext_function != NULL) { -: 375: SetThreadDpiAwarenessContext_function(dpiAwareness); -: 376: } -: 377: -: 378: FreeLibrary(user32); -: 379: -: 380: bitmap = CreateCompatibleBitmap(screen, width, height); -: 381: if (!bitmap) { -: 382: goto error; -: 383: } -: 384: -: 385: if (!SelectObject(screen_copy, bitmap)) { -: 386: goto error; -: 387: } -: 388: -: 389: /* step 2: copy bits into memory DC bitmap */ -: 390: -: 391: rop = SRCCOPY; -: 392: if (includeLayeredWindows) { -: 393: rop |= CAPTUREBLT; -: 394: } -: 395: if (!BitBlt(screen_copy, 0, 0, width, height, screen, x, y, rop)) { -: 396: goto error; -: 397: } -: 398: -: 399: /* step 3: extract bits from bitmap */ -: 400: -: 401: buffer = PyBytes_FromStringAndSize(NULL, height * ((width*3 + 3) & -4)); -: 402: if (!buffer) { -: 403: return NULL; -: 404: } -: 405: -: 406: core.bcSize = sizeof(core); -: 407: core.bcWidth = width; -: 408: core.bcHeight = height; -: 409: core.bcPlanes = 1; -: 410: core.bcBitCount = 24; -: 411: if (!GetDIBits(screen_copy, bitmap, 0, height, PyBytes_AS_STRING(buffer), -: 412: (BITMAPINFO*) &core, DIB_RGB_COLORS)) { -: 413: goto error; -: 414: } -: 415: -: 416: DeleteObject(bitmap); -: 417: DeleteDC(screen_copy); -: 418: DeleteDC(screen); -: 419: -: 420: return Py_BuildValue("(ii)(ii)N", x, y, width, height, buffer); -: 421: -: 422:error: -: 423: PyErr_SetString(PyExc_OSError, "screen grab failed"); -: 424: -: 425: DeleteDC(screen_copy); -: 426: DeleteDC(screen); -: 427: -: 428: return NULL; -: 429:} -: 430: -: 431:static BOOL CALLBACK list_windows_callback(HWND hwnd, LPARAM lParam) -: 432:{ -: 433: PyObject* window_list = (PyObject*) lParam; -: 434: PyObject* item; -: 435: PyObject* title; -: 436: RECT inner, outer; -: 437: int title_size; -: 438: int status; -: 439: -: 440: /* get window title */ -: 441: title_size = GetWindowTextLength(hwnd); -: 442: if (title_size > 0) { -: 443: title = PyUnicode_FromStringAndSize(NULL, title_size); -: 444: if (title) { -: 445: GetWindowTextW(hwnd, PyUnicode_AS_UNICODE(title), title_size+1); -: 446: } -: 447: } else { -: 448: title = PyUnicode_FromString(""); -: 449: } -: 450: if (!title) { -: 451: return 0; -: 452: } -: 453: -: 454: /* get bounding boxes */ -: 455: GetClientRect(hwnd, &inner); -: 456: GetWindowRect(hwnd, &outer); -: 457: -: 458: item = Py_BuildValue( -: 459: F_HANDLE "N(iiii)(iiii)", hwnd, title, -: 460: inner.left, inner.top, inner.right, inner.bottom, -: 461: outer.left, outer.top, outer.right, outer.bottom -: 462: ); -: 463: if (!item) { -: 464: return 0; -: 465: } -: 466: -: 467: status = PyList_Append(window_list, item); -: 468: -: 469: Py_DECREF(item); -: 470: -: 471: if (status < 0) { -: 472: return 0; -: 473: } -: 474: -: 475: return 1; -: 476:} -: 477: -: 478:PyObject* -: 479:PyImaging_ListWindowsWin32(PyObject* self, PyObject* args) -: 480:{ -: 481: PyObject* window_list; -: 482: -: 483: window_list = PyList_New(0); -: 484: if (!window_list) { -: 485: return NULL; -: 486: } -: 487: -: 488: EnumWindows(list_windows_callback, (LPARAM) window_list); -: 489: -: 490: if (PyErr_Occurred()) { -: 491: Py_DECREF(window_list); -: 492: return NULL; -: 493: } -: 494: -: 495: return window_list; -: 496:} -: 497: -: 498:/* -------------------------------------------------------------------- */ -: 499:/* Windows clipboard grabber */ -: 500: -: 501:PyObject* -: 502:PyImaging_GrabClipboardWin32(PyObject* self, PyObject* args) -: 503:{ -: 504: int clip; -: 505: HANDLE handle = NULL; -: 506: int size; -: 507: void* data; -: 508: PyObject* result; -: 509: UINT format; -: 510: UINT formats[] = { CF_DIB, CF_DIBV5, CF_HDROP, RegisterClipboardFormatA("PNG"), 0 }; -: 511: LPCSTR format_names[] = { "DIB", "DIB", "file", "png", NULL }; -: 512: -: 513: if (!OpenClipboard(NULL)) { -: 514: PyErr_SetString(PyExc_OSError, "failed to open clipboard"); -: 515: return NULL; -: 516: } -: 517: -: 518: // find best format as set by clipboard owner -: 519: format = 0; -: 520: while (!handle && (format = EnumClipboardFormats(format))) { -: 521: for (UINT i = 0; formats[i] != 0; i++) { -: 522: if (format == formats[i]) { -: 523: handle = GetClipboardData(format); -: 524: format = i; -: 525: break; -: 526: } -: 527: } -: 528: } -: 529: -: 530: if (!handle) { -: 531: CloseClipboard(); -: 532: return Py_BuildValue("zO", NULL, Py_None); -: 533: } -: 534: -: 535: data = GlobalLock(handle); -: 536: size = GlobalSize(handle); -: 537: -: 538: result = PyBytes_FromStringAndSize(data, size); -: 539: -: 540: GlobalUnlock(handle); -: 541: CloseClipboard(); -: 542: -: 543: return Py_BuildValue("zN", format_names[format], result); -: 544:} -: 545: -: 546:/* -------------------------------------------------------------------- */ -: 547:/* Windows class */ -: 548: -: 549:#ifndef WM_MOUSEWHEEL -: 550:#define WM_MOUSEWHEEL 522 -: 551:#endif -: 552: -: 553:static int mainloop = 0; -: 554: -: 555:static void -: 556:callback_error(const char* handler) -: 557:{ -: 558: PyObject* sys_stderr; -: 559: -: 560: sys_stderr = PySys_GetObject("stderr"); -: 561: -: 562: if (sys_stderr) { -: 563: PyFile_WriteString("*** ImageWin: error in ", sys_stderr); -: 564: PyFile_WriteString((char*) handler, sys_stderr); -: 565: PyFile_WriteString(":\n", sys_stderr); -: 566: } -: 567: -: 568: PyErr_Print(); -: 569: PyErr_Clear(); -: 570:} -: 571: -: 572:static LRESULT CALLBACK -: 573:windowCallback(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) -: 574:{ -: 575: PAINTSTRUCT ps; -: 576: PyObject* callback = NULL; -: 577: PyObject* result; -: 578: PyThreadState* threadstate; -: 579: PyThreadState* current_threadstate; -: 580: HDC dc; -: 581: RECT rect; -: 582: LRESULT status = 0; -: 583: -: 584: /* set up threadstate for messages that calls back into python */ -: 585: switch (message) { -: 586: case WM_CREATE: -: 587: mainloop++; -: 588: break; -: 589: case WM_DESTROY: -: 590: mainloop--; -: 591: /* fall through... */ -: 592: case WM_PAINT: -: 593: case WM_SIZE: -: 594: callback = (PyObject*) GetWindowLongPtr(wnd, 0); -: 595: if (callback) { -: 596: threadstate = (PyThreadState*) -: 597: GetWindowLongPtr(wnd, sizeof(PyObject*)); -: 598: current_threadstate = PyThreadState_Swap(NULL); -: 599: PyEval_RestoreThread(threadstate); -: 600: } else { -: 601: return DefWindowProc(wnd, message, wParam, lParam); -: 602: } -: 603: } -: 604: -: 605: /* process message */ -: 606: switch (message) { -: 607: -: 608: case WM_PAINT: -: 609: /* redraw (part of) window. this generates a WCK-style -: 610: damage/clear/repair cascade */ -: 611: BeginPaint(wnd, &ps); -: 612: dc = GetDC(wnd); -: 613: GetWindowRect(wnd, &rect); /* in screen coordinates */ -: 614: -: 615: result = PyObject_CallFunction( -: 616: callback, "siiii", "damage", -: 617: ps.rcPaint.left, ps.rcPaint.top, -: 618: ps.rcPaint.right, ps.rcPaint.bottom -: 619: ); -: 620: if (result) { -: 621: Py_DECREF(result); -: 622: } else { -: 623: callback_error("window damage callback"); -: 624: } -: 625: -: 626: result = PyObject_CallFunction( -: 627: callback, "s" F_HANDLE "iiii", "clear", dc, -: 628: 0, 0, rect.right-rect.left, rect.bottom-rect.top -: 629: ); -: 630: if (result) { -: 631: Py_DECREF(result); -: 632: } else { -: 633: callback_error("window clear callback"); -: 634: } -: 635: -: 636: result = PyObject_CallFunction( -: 637: callback, "s" F_HANDLE "iiii", "repair", dc, -: 638: 0, 0, rect.right-rect.left, rect.bottom-rect.top -: 639: ); -: 640: if (result) { -: 641: Py_DECREF(result); -: 642: } else { -: 643: callback_error("window repair callback"); -: 644: } -: 645: -: 646: ReleaseDC(wnd, dc); -: 647: EndPaint(wnd, &ps); -: 648: break; -: 649: -: 650: case WM_SIZE: -: 651: /* resize window */ -: 652: result = PyObject_CallFunction( -: 653: callback, "sii", "resize", LOWORD(lParam), HIWORD(lParam) -: 654: ); -: 655: if (result) { -: 656: InvalidateRect(wnd, NULL, 1); -: 657: Py_DECREF(result); -: 658: } else { -: 659: callback_error("window resize callback"); -: 660: } -: 661: break; -: 662: -: 663: case WM_DESTROY: -: 664: /* destroy window */ -: 665: result = PyObject_CallFunction(callback, "s", "destroy"); -: 666: if (result) { -: 667: Py_DECREF(result); -: 668: } else { -: 669: callback_error("window destroy callback"); -: 670: } -: 671: Py_DECREF(callback); -: 672: break; -: 673: -: 674: default: -: 675: status = DefWindowProc(wnd, message, wParam, lParam); -: 676: } -: 677: -: 678: if (callback) { -: 679: /* restore thread state */ -: 680: PyEval_SaveThread(); -: 681: PyThreadState_Swap(threadstate); -: 682: } -: 683: -: 684: return status; -: 685:} -: 686: -: 687:PyObject* -: 688:PyImaging_CreateWindowWin32(PyObject* self, PyObject* args) -: 689:{ -: 690: HWND wnd; -: 691: WNDCLASS windowClass; -: 692: -: 693: char* title; -: 694: PyObject* callback; -: 695: int width = 0, height = 0; -: 696: if (!PyArg_ParseTuple(args, "sO|ii", &title, &callback, &width, &height)) { -: 697: return NULL; -: 698: } -: 699: -: 700: if (width <= 0) { -: 701: width = CW_USEDEFAULT; -: 702: } -: 703: if (height <= 0) { -: 704: height = CW_USEDEFAULT; -: 705: } -: 706: -: 707: /* register toplevel window class */ -: 708: windowClass.style = CS_CLASSDC; -: 709: windowClass.cbClsExtra = 0; -: 710: windowClass.cbWndExtra = sizeof(PyObject*) + sizeof(PyThreadState*); -: 711: windowClass.hInstance = GetModuleHandle(NULL); -: 712: /* windowClass.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); */ -: 713: windowClass.hbrBackground = NULL; -: 714: windowClass.lpszMenuName = NULL; -: 715: windowClass.lpszClassName = "pilWindow"; -: 716: windowClass.lpfnWndProc = windowCallback; -: 717: windowClass.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(1)); -: 718: windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); /* CROSS? */ -: 719: -: 720: RegisterClass(&windowClass); /* FIXME: check return status */ -: 721: -: 722: wnd = CreateWindowEx( -: 723: 0, windowClass.lpszClassName, title, -: 724: WS_OVERLAPPEDWINDOW, -: 725: CW_USEDEFAULT, CW_USEDEFAULT, width, height, -: 726: HWND_DESKTOP, NULL, NULL, NULL -: 727: ); -: 728: -: 729: if (!wnd) { -: 730: PyErr_SetString(PyExc_OSError, "failed to create window"); -: 731: return NULL; -: 732: } -: 733: -: 734: /* register window callback */ -: 735: Py_INCREF(callback); -: 736: SetWindowLongPtr(wnd, 0, (LONG_PTR) callback); -: 737: SetWindowLongPtr(wnd, sizeof(callback), (LONG_PTR) PyThreadState_Get()); -: 738: -: 739: Py_BEGIN_ALLOW_THREADS -: 740: ShowWindow(wnd, SW_SHOWNORMAL); -: 741: SetForegroundWindow(wnd); /* to make sure it's visible */ -: 742: Py_END_ALLOW_THREADS -: 743: -: 744: return Py_BuildValue(F_HANDLE, wnd); -: 745:} -: 746: -: 747:PyObject* -: 748:PyImaging_EventLoopWin32(PyObject* self, PyObject* args) -: 749:{ -: 750: MSG msg; -: 751: -: 752: Py_BEGIN_ALLOW_THREADS -: 753: while (mainloop && GetMessage(&msg, NULL, 0, 0)) { -: 754: TranslateMessage(&msg); -: 755: DispatchMessage(&msg); -: 756: } -: 757: Py_END_ALLOW_THREADS -: 758: -: 759: Py_INCREF(Py_None); -: 760: return Py_None; -: 761:} -: 762: -: 763:/* -------------------------------------------------------------------- */ -: 764:/* windows WMF renderer */ -: 765: -: 766:#define GET32(p,o) ((DWORD*)(p+o))[0] -: 767: -: 768:PyObject * -: 769:PyImaging_DrawWmf(PyObject* self, PyObject* args) -: 770:{ -: 771: HBITMAP bitmap; -: 772: HENHMETAFILE meta; -: 773: BITMAPCOREHEADER core; -: 774: HDC dc; -: 775: RECT rect; -: 776: PyObject* buffer = NULL; -: 777: char* ptr; -: 778: -: 779: char* data; -: 780: int datasize; -: 781: int width, height; -: 782: int x0, y0, x1, y1; -: 783: if (!PyArg_ParseTuple(args, "y#(ii)(iiii):_load", &data, &datasize, -: 784: &width, &height, &x0, &x1, &y0, &y1)) { -: 785: return NULL; -: 786: } -: 787: -: 788: /* step 1: copy metafile contents into METAFILE object */ -: 789: -: 790: if (datasize > 22 && GET32(data, 0) == 0x9ac6cdd7) { -: 791: -: 792: /* placeable windows metafile (22-byte aldus header) */ -: 793: meta = SetWinMetaFileBits(datasize-22, data+22, NULL, NULL); -: 794: -: 795: } else if (datasize > 80 && GET32(data, 0) == 1 && -: 796: GET32(data, 40) == 0x464d4520) { -: 797: -: 798: /* enhanced metafile */ -: 799: meta = SetEnhMetaFileBits(datasize, data); -: 800: -: 801: } else { -: 802: -: 803: /* unknown meta format */ -: 804: meta = NULL; -: 805: -: 806: } -: 807: -: 808: if (!meta) { -: 809: PyErr_SetString(PyExc_OSError, "cannot load metafile"); -: 810: return NULL; -: 811: } -: 812: -: 813: /* step 2: create bitmap */ -: 814: -: 815: core.bcSize = sizeof(core); -: 816: core.bcWidth = width; -: 817: core.bcHeight = height; -: 818: core.bcPlanes = 1; -: 819: core.bcBitCount = 24; -: 820: -: 821: dc = CreateCompatibleDC(NULL); -: 822: -: 823: bitmap = CreateDIBSection( -: 824: dc, (BITMAPINFO*) &core, DIB_RGB_COLORS, &ptr, NULL, 0 -: 825: ); -: 826: -: 827: if (!bitmap) { -: 828: PyErr_SetString(PyExc_OSError, "cannot create bitmap"); -: 829: goto error; -: 830: } -: 831: -: 832: if (!SelectObject(dc, bitmap)) { -: 833: PyErr_SetString(PyExc_OSError, "cannot select bitmap"); -: 834: goto error; -: 835: } -: 836: -: 837: /* step 3: render metafile into bitmap */ -: 838: -: 839: rect.left = rect.top = 0; -: 840: rect.right = width; -: 841: rect.bottom = height; -: 842: -: 843: /* FIXME: make background transparent? configurable? */ -: 844: FillRect(dc, &rect, GetStockObject(WHITE_BRUSH)); -: 845: -: 846: if (!PlayEnhMetaFile(dc, meta, &rect)) { -: 847: PyErr_SetString(PyExc_OSError, "cannot render metafile"); -: 848: goto error; -: 849: } -: 850: -: 851: /* step 4: extract bits from bitmap */ -: 852: -: 853: GdiFlush(); -: 854: -: 855: buffer = PyBytes_FromStringAndSize(ptr, height * ((width*3 + 3) & -4)); -: 856: -: 857:error: -: 858: DeleteEnhMetaFile(meta); -: 859: -: 860: if (bitmap) { -: 861: DeleteObject(bitmap); -: 862: } -: 863: -: 864: DeleteDC(dc); -: 865: -: 866: return buffer; -: 867:} -: 868: -: 869:#endif /* _WIN32 */ -: 870: -: 871:/* -------------------------------------------------------------------- */ -: 872:/* X11 support */ -: 873: -: 874:#ifdef HAVE_XCB -: 875:#include -: 876: -: 877:/* -------------------------------------------------------------------- */ -: 878:/* X11 screen grabber */ -: 879: -: 880:PyObject* function PyImaging_GrabScreenX11 called 2 returned 100% blocks executed 28% 2: 881:PyImaging_GrabScreenX11(PyObject* self, PyObject* args) -: 882:{ -: 883: int width, height; -: 884: char* display_name; -: 885: xcb_connection_t* connection; -: 886: int screen_number; -: 887: xcb_screen_iterator_t iter; 2: 888: xcb_screen_t* screen = NULL; -: 889: xcb_get_image_reply_t* reply; -: 890: xcb_generic_error_t* error; 2: 891: PyObject* buffer = NULL; -: 892: 2: 893: if (!PyArg_ParseTuple(args, "|z", &display_name)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 894: return NULL; -: 895: } -: 896: -: 897: /* connect to X and get screen data */ -: 898: 2: 899: connection = xcb_connect(display_name, &screen_number); call 0 returned 100% 2: 900: if (xcb_connection_has_error(connection)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 2: 901: PyErr_Format(PyExc_OSError, "X connection failed: error %i", xcb_connection_has_error(connection)); call 0 returned 100% call 1 returned 100% 2: 902: xcb_disconnect(connection); call 0 returned 100% 2: 903: return NULL; -: 904: } -: 905: #####: 906: iter = xcb_setup_roots_iterator(xcb_get_setup(connection)); call 0 never executed call 1 never executed #####: 907: for (; iter.rem; --screen_number, xcb_screen_next(&iter)) { call 0 never executed branch 1 never executed branch 2 never executed #####: 908: if (screen_number == 0) { branch 0 never executed branch 1 never executed #####: 909: screen = iter.data; #####: 910: break; -: 911: } -: 912: } #####: 913: if (screen == NULL || screen->root == 0) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed -: 914: // this case is usually caught with "X connection failed: error 6" above #####: 915: xcb_disconnect(connection); call 0 never executed #####: 916: PyErr_SetString(PyExc_OSError, "X screen not found"); call 0 never executed #####: 917: return NULL; -: 918: } -: 919: #####: 920: width = screen->width_in_pixels; #####: 921: height = screen->height_in_pixels; -: 922: -: 923: /* get image data */ -: 924: #####: 925: reply = xcb_get_image_reply(connection, call 0 never executed call 1 never executed -: 926: xcb_get_image(connection, XCB_IMAGE_FORMAT_Z_PIXMAP, screen->root, -: 927: 0, 0, width, height, 0x00ffffff), -: 928: &error); #####: 929: if (reply == NULL) { branch 0 never executed branch 1 never executed #####: 930: PyErr_Format(PyExc_OSError, "X get_image failed: error %i (%i, %i, %i)", call 0 never executed #####: 931: error->error_code, error->major_code, error->minor_code, error->resource_id); #####: 932: free(error); #####: 933: xcb_disconnect(connection); call 0 never executed #####: 934: return NULL; -: 935: } -: 936: -: 937: /* store data in Python buffer */ -: 938: #####: 939: if (reply->depth == 24) { branch 0 never executed branch 1 never executed #####: 940: buffer = PyBytes_FromStringAndSize((char*)xcb_get_image_data(reply), call 0 never executed call 1 never executed #####: 941: xcb_get_image_data_length(reply)); call 0 never executed -: 942: } else { #####: 943: PyErr_Format(PyExc_OSError, "unsupported bit depth: %i", reply->depth); call 0 never executed -: 944: } -: 945: #####: 946: free(reply); #####: 947: xcb_disconnect(connection); call 0 never executed -: 948: #####: 949: if (!buffer) { branch 0 never executed branch 1 never executed -: 950: return NULL; -: 951: } -: 952: #####: 953: return Py_BuildValue("(ii)N", width, height, buffer); call 0 never executed -: 954:} -: 955: -: 956:#endif /* HAVE_XCB */ <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Matrix.c.gcov -: 0:Source:src/libImaging/Matrix.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Matrix.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Matrix.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * colour and luminance matrix transforms -: 6: * -: 7: * history: -: 8: * 1996-05-18 fl: created (brute force implementation) -: 9: * -: 10: * Copyright (c) Fredrik Lundh 1996. -: 11: * Copyright (c) Secret Labs AB 1997. -: 12: * -: 13: * See the README file for information on usage and redistribution. -: 14: */ -: 15: -: 16: -: 17:#include "Imaging.h" -: 18: -: 19: -: 20:#define CLIPF(v) ((v <= 0.0) ? 0 : (v >= 255.0F) ? 255 : (UINT8) v) -: 21: -: 22: -: 23:Imaging function ImagingConvertMatrix called 4 returned 100% blocks executed 97% 4: 24:ImagingConvertMatrix(Imaging im, const char *mode, float m[]) -: 25:{ -: 26: Imaging imOut; -: 27: int x, y; -: 28: -: 29: /* Assume there's enough data in the buffer */ 4: 30: if (!im) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 31: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 32: } -: 33: 4: 34: if (strcmp(mode, "L") == 0 && im->bands == 3) { branch 0 taken 50% (fallthrough) branch 1 taken 50% branch 2 taken 50% (fallthrough) branch 3 taken 50% branch 4 taken 50% (fallthrough) branch 5 taken 50% -: 35: 1: 36: imOut = ImagingNewDirty("L", im->xsize, im->ysize); call 0 returned 100% 1: 37: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 38: return NULL; -: 39: } -: 40: 128: 41: for (y = 0; y < im->ysize; y++) { branch 0 taken 99% branch 1 taken 1% 128: 42: UINT8* in = (UINT8*) im->image[y]; 128: 43: UINT8* out = (UINT8*) imOut->image[y]; -: 44: 16512: 45: for (x = 0; x < im->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16384: 46: float v = m[0]*in[0] + m[1]*in[1] + m[2]*in[2] + m[3] + 0.5; 16384: 47: out[x] = CLIPF(v); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 16384: 48: in += 4; -: 49: } -: 50: } -: 51: 3: 52: } else if (strlen(mode) == 3 && im->bands == 3) { branch 0 taken 67% (fallthrough) branch 1 taken 33% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 53: 2: 54: imOut = ImagingNewDirty(mode, im->xsize, im->ysize); call 0 returned 100% 2: 55: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 56: return NULL; -: 57: } -: 58: 256: 59: for (y = 0; y < im->ysize; y++) { branch 0 taken 99% branch 1 taken 1% 256: 60: UINT8* in = (UINT8*) im->image[y]; 256: 61: UINT8* out = (UINT8*) imOut->image[y]; -: 62: 33024: 63: for (x = 0; x < im->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 32768: 64: float v0 = m[0]*in[0] + m[1]*in[1] + m[2]*in[2] + m[3] + 0.5; 32768: 65: float v1 = m[4]*in[0] + m[5]*in[1] + m[6]*in[2] + m[7] + 0.5; 32768: 66: float v2 = m[8]*in[0] + m[9]*in[1] + m[10]*in[2] + m[11] + 0.5; 32768: 67: out[0] = CLIPF(v0); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 99% (fallthrough) branch 3 taken 1% 32768: 68: out[1] = CLIPF(v1); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 99% (fallthrough) branch 3 taken 1% 32768: 69: out[2] = CLIPF(v2); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 99% (fallthrough) branch 3 taken 1% 32768: 70: in += 4; out += 4; -: 71: } -: 72: } -: 73: } else { 1: 74: return (Imaging) ImagingError_ModeError(); call 0 returned 100% -: 75: } -: 76: -: 77: return imOut; -: 78:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#outline.c.gcov -: 0:Source:src/outline.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/outline.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/outline.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * THIS IS WORK IN PROGRESS. -: 3: * -: 4: * The Python Imaging Library. -: 5: * -: 6: * "arrow" outline stuff. the contents of this module -: 7: * will be merged with the path module and the rest of -: 8: * the arrow graphics package, but not before PIL 1.1. -: 9: * use at your own risk. -: 10: * -: 11: * history: -: 12: * 99-01-10 fl Added to PIL (experimental) -: 13: * -: 14: * Copyright (c) Secret Labs AB 1999. -: 15: * Copyright (c) Fredrik Lundh 1999. -: 16: * -: 17: * See the README file for information on usage and redistribution. -: 18: */ -: 19: -: 20:#include "Python.h" -: 21: -: 22:#include "libImaging/Imaging.h" -: 23: -: 24: -: 25:/* -------------------------------------------------------------------- */ -: 26:/* Class */ -: 27: -: 28:typedef struct { -: 29: PyObject_HEAD -: 30: ImagingOutline outline; -: 31:} OutlineObject; -: 32: -: 33:static PyTypeObject OutlineType; -: 34: -: 35:#define PyOutline_Check(op) (Py_TYPE(op) == &OutlineType) -: 36: -: 37:static OutlineObject* function _outline_new called 3 returned 100% blocks executed 100% 3: 38:_outline_new(void) -: 39:{ -: 40: OutlineObject *self; -: 41: 3: 42: if (PyType_Ready(&OutlineType) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 43: return NULL; -: 44: } -: 45: 3: 46: self = PyObject_New(OutlineObject, &OutlineType); call 0 returned 100% 3: 47: if (self == NULL) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 48: return NULL; -: 49: } -: 50: 3: 51: self->outline = ImagingOutlineNew(); call 0 returned 100% -: 52: 3: 53: return self; -: 54:} -: 55: -: 56:static void function _outline_dealloc called 3 returned 100% blocks executed 100% 3: 57:_outline_dealloc(OutlineObject* self) -: 58:{ 3: 59: ImagingOutlineDelete(self->outline); call 0 returned 100% 3: 60: PyObject_Del(self); call 0 returned 100% 3: 61:} -: 62: -: 63:ImagingOutline function PyOutline_AsOutline called 8 returned 100% blocks executed 100% 8: 64:PyOutline_AsOutline(PyObject* outline) -: 65:{ 8: 66: if (PyOutline_Check(outline)) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 8: 67: return ((OutlineObject*) outline)->outline; -: 68: } -: 69: -: 70: return NULL; -: 71:} -: 72: -: 73: -: 74:/* -------------------------------------------------------------------- */ -: 75:/* Factories */ -: 76: -: 77:PyObject* function PyOutline_Create called 3 returned 100% blocks executed 100% 3: 78:PyOutline_Create(PyObject* self, PyObject* args) -: 79:{ 3: 80: if (!PyArg_ParseTuple(args, ":outline")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 81: return NULL; -: 82: } -: 83: 3: 84: return (PyObject*) _outline_new(); call 0 returned 100% -: 85:} -: 86: -: 87: -: 88:/* -------------------------------------------------------------------- */ -: 89:/* Methods */ -: 90: -: 91:static PyObject* function _outline_move called 3 returned 100% blocks executed 100% 3: 92:_outline_move(OutlineObject* self, PyObject* args) -: 93:{ -: 94: float x0, y0; 3: 95: if (!PyArg_ParseTuple(args, "ff", &x0, &y0)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 96: return NULL; -: 97: } -: 98: 3: 99: ImagingOutlineMove(self->outline, x0, y0); call 0 returned 100% -: 100: 3: 101: Py_INCREF(Py_None); 3: 102: return Py_None; -: 103:} -: 104: -: 105:static PyObject* function _outline_line called 3 returned 100% blocks executed 100% 3: 106:_outline_line(OutlineObject* self, PyObject* args) -: 107:{ -: 108: float x1, y1; 3: 109: if (!PyArg_ParseTuple(args, "ff", &x1, &y1)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 110: return NULL; -: 111: } -: 112: 3: 113: ImagingOutlineLine(self->outline, x1, y1); call 0 returned 100% -: 114: 3: 115: Py_INCREF(Py_None); 3: 116: return Py_None; -: 117:} -: 118: -: 119:static PyObject* function _outline_curve called 3 returned 100% blocks executed 100% 3: 120:_outline_curve(OutlineObject* self, PyObject* args) -: 121:{ -: 122: float x1, y1, x2, y2, x3, y3; 3: 123: if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 124: return NULL; -: 125: } -: 126: 3: 127: ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3); call 0 returned 100% -: 128: 3: 129: Py_INCREF(Py_None); 3: 130: return Py_None; -: 131:} -: 132: -: 133:static PyObject* function _outline_close called 8 returned 100% blocks executed 100% 8: 134:_outline_close(OutlineObject* self, PyObject* args) -: 135:{ 8: 136: if (!PyArg_ParseTuple(args, ":close")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 137: return NULL; -: 138: } -: 139: 8: 140: ImagingOutlineClose(self->outline); call 0 returned 100% -: 141: 8: 142: Py_INCREF(Py_None); 8: 143: return Py_None; -: 144:} -: 145: -: 146:static PyObject* function _outline_transform called 0 returned 0% blocks executed 0% #####: 147:_outline_transform(OutlineObject* self, PyObject* args) -: 148:{ -: 149: double a[6]; #####: 150: if (!PyArg_ParseTuple(args, "(dddddd)", a+0, a+1, a+2, a+3, a+4, a+5)) { call 0 never executed branch 1 never executed branch 2 never executed -: 151: return NULL; -: 152: } -: 153: #####: 154: ImagingOutlineTransform(self->outline, a); call 0 never executed -: 155: #####: 156: Py_INCREF(Py_None); #####: 157: return Py_None; -: 158:} -: 159: -: 160:static struct PyMethodDef _outline_methods[] = { -: 161: {"line", (PyCFunction)_outline_line, 1}, -: 162: {"curve", (PyCFunction)_outline_curve, 1}, -: 163: {"move", (PyCFunction)_outline_move, 1}, -: 164: {"close", (PyCFunction)_outline_close, 1}, -: 165: {"transform", (PyCFunction)_outline_transform, 1}, -: 166: {NULL, NULL} /* sentinel */ -: 167:}; -: 168: -: 169:static PyTypeObject OutlineType = { -: 170: PyVarObject_HEAD_INIT(NULL, 0) -: 171: "Outline", /*tp_name*/ -: 172: sizeof(OutlineObject), /*tp_size*/ -: 173: 0, /*tp_itemsize*/ -: 174: /* methods */ -: 175: (destructor)_outline_dealloc,/*tp_dealloc*/ -: 176: 0, /*tp_print*/ -: 177: 0, /*tp_getattr*/ -: 178: 0, /*tp_setattr*/ -: 179: 0, /*tp_compare*/ -: 180: 0, /*tp_repr*/ -: 181: 0, /*tp_as_number */ -: 182: 0, /*tp_as_sequence */ -: 183: 0, /*tp_as_mapping */ -: 184: 0, /*tp_hash*/ -: 185: 0, /*tp_call*/ -: 186: 0, /*tp_str*/ -: 187: 0, /*tp_getattro*/ -: 188: 0, /*tp_setattro*/ -: 189: 0, /*tp_as_buffer*/ -: 190: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 191: 0, /*tp_doc*/ -: 192: 0, /*tp_traverse*/ -: 193: 0, /*tp_clear*/ -: 194: 0, /*tp_richcompare*/ -: 195: 0, /*tp_weaklistoffset*/ -: 196: 0, /*tp_iter*/ -: 197: 0, /*tp_iternext*/ -: 198: _outline_methods, /*tp_methods*/ -: 199: 0, /*tp_members*/ -: 200: 0, /*tp_getset*/ -: 201:}; <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#ColorLUT.c.gcov -: 0:Source:src/libImaging/ColorLUT.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/ColorLUT.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/ColorLUT.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:#include "Imaging.h" -: 2:#include -: 3: -: 4: -: 5:/* 8 bits for result. Table can overflow [0, 1.0] range, -: 6: so we need extra bits for overflow and negative values. -: 7: NOTE: This value should be the same as in _imaging/_prepare_lut_table() */ -: 8:#define PRECISION_BITS (16 - 8 - 2) -: 9:#define PRECISION_ROUNDING (1<<(PRECISION_BITS-1)) -: 10: -: 11:/* 8 — scales are multiplied on byte. -: 12: 6 — max index in the table -: 13: (max size is 65, but index 64 is not reachable) */ -: 14:#define SCALE_BITS (32 - 8 - 6) -: 15:#define SCALE_MASK ((1<> PRECISION_BITS]; -: 23:} -: 24: -: 25:static inline void -: 26:interpolate3(INT16 out[3], const INT16 a[3], const INT16 b[3], INT16 shift) -: 27:{ 8263136: 28: out[0] = (a[0] * ((1<> SHIFT_BITS; 8263136: 29: out[1] = (a[1] * ((1<> SHIFT_BITS; 8263136: 30: out[2] = (a[2] * ((1<> SHIFT_BITS; -: 31:} -: 32: -: 33:static inline void function interpolate4 called 460852 returned 100% blocks executed 100% 460852: 34:interpolate4(INT16 out[4], const INT16 a[4], const INT16 b[4], INT16 shift) -: 35:{ 460852: 36: out[0] = (a[0] * ((1<> SHIFT_BITS; 460852: 37: out[1] = (a[1] * ((1<> SHIFT_BITS; 460852: 38: out[2] = (a[2] * ((1<> SHIFT_BITS; 460852: 39: out[3] = (a[3] * ((1<> SHIFT_BITS; 460852: 40:} -: 41: -: 42:static inline int -: 43:table_index3D(int index1D, int index2D, int index3D, -: 44: int size1D, int size1D_2D) -: 45:{ 1246284: 46: return index1D + index2D * size1D + index3D * size1D_2D; -: 47:} -: 48: -: 49: -: 50:/* -: 51: Transforms colors of imIn using provided 3D lookup table -: 52: and puts the result in imOut. Returns imOut on success or 0 on error. -: 53: -: 54: imOut, imIn — images, should be the same size and may be the same image. -: 55: Should have 3 or 4 channels. -: 56: table_channels — number of channels in the lookup table, 3 or 4. -: 57: Should be less or equal than number of channels in imOut image; -: 58: size1D, size_2D and size3D — dimensions of provided table; -: 59: table — flat table, -: 60: array with table_channels × size1D × size2D × size3D elements, -: 61: where channels are changed first, then 1D, then​ 2D, then 3D. -: 62: Each element is signed 16-bit int where 0 is lowest output value -: 63: and 255 << PRECISION_BITS (16320) is highest value. -: 64:*/ -: 65:Imaging function ImagingColorLUT3D_linear called 37 returned 100% blocks executed 100% 37: 66:ImagingColorLUT3D_linear(Imaging imOut, Imaging imIn, int table_channels, -: 67: int size1D, int size2D, int size3D, -: 68: INT16* table) -: 69:{ -: 70: /* This float to int conversion doesn't have rounding -: 71: error compensation (+0.5) for two reasons: -: 72: 1. As we don't hit the highest value, -: 73: we can use one extra bit for precision. -: 74: 2. For every pixel, we interpolate 8 elements from the table: -: 75: current and +1 for every dimension and their combinations. -: 76: If we hit the upper cells from the table, -: 77: +1 cells will be outside of the table. -: 78: With this compensation we never hit the upper cells -: 79: but this also doesn't introduce any noticeable difference. */ 37: 80: UINT32 scale1D = (size1D - 1) / 255.0 * (1< 4) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 2: 88: PyErr_SetString(PyExc_ValueError, "table_channels could be 3 or 4"); call 0 returned 100% 2: 89: return NULL; -: 90: } -: 91: 70: 92: if (imIn->type != IMAGING_TYPE_UINT8 || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 70: 93: imOut->type != IMAGING_TYPE_UINT8 || branch 0 taken 94% (fallthrough) branch 1 taken 6% 68: 94: imIn->bands < 3 || branch 0 taken 6% (fallthrough) branch 1 taken 94% 33: 95: imOut->bands < table_channels -: 96: ) { 4: 97: return (Imaging) ImagingError_ModeError(); call 0 returned 100% -: 98: } -: 99: -: 100: /* In case we have one extra band in imOut and don't have in imIn.*/ 31: 101: if (imOut->bands > table_channels && imOut->bands > imIn->bands) { branch 0 taken 10% (fallthrough) branch 1 taken 90% branch 2 taken 33% (fallthrough) branch 3 taken 67% 1: 102: return (Imaging) ImagingError_ModeError(); call 0 returned 100% -: 103: } -: 104: 30: 105: ImagingSectionEnter(&cookie); 5004: 106: for (y = 0; y < imOut->ysize; y++) { call 0 returned 100% branch 1 taken 99% branch 2 taken 1% (fallthrough) 4974: 107: UINT8* rowIn = (UINT8 *)imIn->image[y]; 4974: 108: char* rowOut = (char *)imOut->image[y]; 1251258: 109: for (x = 0; x < imOut->xsize; x++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 1246284: 110: UINT32 index1D = rowIn[x*4 + 0] * scale1D; 1246284: 111: UINT32 index2D = rowIn[x*4 + 1] * scale2D; 1246284: 112: UINT32 index3D = rowIn[x*4 + 2] * scale3D; 1246284: 113: INT16 shift1D = (SCALE_MASK & index1D) >> (SCALE_BITS - SHIFT_BITS); 1246284: 114: INT16 shift2D = (SCALE_MASK & index2D) >> (SCALE_BITS - SHIFT_BITS); 1246284: 115: INT16 shift3D = (SCALE_MASK & index3D) >> (SCALE_BITS - SHIFT_BITS); 4985136: 116: int idx = table_channels * table_index3D( 2492568: 117: index1D >> SCALE_BITS, index2D >> SCALE_BITS, 1246284: 118: index3D >> SCALE_BITS, size1D, size1D_2D); -: 119: INT16 result[4], left[4], right[4]; -: 120: INT16 leftleft[4], leftright[4], rightleft[4], rightright[4]; -: 121: 1246284: 122: if (table_channels == 3) { branch 0 taken 95% (fallthrough) branch 1 taken 5% -: 123: UINT32 v; 2360896: 124: interpolate3(leftleft, &table[idx + 0], &table[idx + 3], shift1D); 2360896: 125: interpolate3(leftright, &table[idx + size1D*3], 1180448: 126: &table[idx + size1D*3 + 3], shift1D); 1180448: 127: interpolate3(left, leftleft, leftright, shift2D); -: 128: 2360896: 129: interpolate3(rightleft, &table[idx + size1D_2D*3], 1180448: 130: &table[idx + size1D_2D*3 + 3], shift1D); 2360896: 131: interpolate3(rightright, &table[idx + size1D_2D*3 + size1D*3], 1180448: 132: &table[idx + size1D_2D*3 + size1D*3 + 3], shift1D); 1180448: 133: interpolate3(right, rightleft, rightright, shift2D); -: 134: 1180448: 135: interpolate3(result, left, right, shift3D); -: 136: 4721792: 137: v = MAKE_UINT32( -: 138: clip8(result[0]), clip8(result[1]), -: 139: clip8(result[2]), rowIn[x*4 + 3]); 2360896: 140: memcpy(rowOut + x * sizeof(v), &v, sizeof(v)); -: 141: } -: 142: 1246284: 143: if (table_channels == 4) { branch 0 taken 5% (fallthrough) branch 1 taken 95% -: 144: UINT32 v; 65836: 145: interpolate4(leftleft, &table[idx + 0], &table[idx + 4], shift1D); call 0 returned 100% 131672: 146: interpolate4(leftright, &table[idx + size1D*4], call 0 returned 100% 65836: 147: &table[idx + size1D*4 + 4], shift1D); 65836: 148: interpolate4(left, leftleft, leftright, shift2D); call 0 returned 100% -: 149: 131672: 150: interpolate4(rightleft, &table[idx + size1D_2D*4], call 0 returned 100% 65836: 151: &table[idx + size1D_2D*4 + 4], shift1D); 131672: 152: interpolate4(rightright, &table[idx + size1D_2D*4 + size1D*4], call 0 returned 100% 65836: 153: &table[idx + size1D_2D*4 + size1D*4 + 4], shift1D); 65836: 154: interpolate4(right, rightleft, rightright, shift2D); call 0 returned 100% -: 155: 65836: 156: interpolate4(result, left, right, shift3D); call 0 returned 100% -: 157: 329180: 158: v = MAKE_UINT32( -: 159: clip8(result[0]), clip8(result[1]), -: 160: clip8(result[2]), clip8(result[3])); 131672: 161: memcpy(rowOut + x * sizeof(v), &v, sizeof(v)); -: 162: } -: 163: } -: 164: } 30: 165: ImagingSectionLeave(&cookie); call 0 returned 100% -: 166: 30: 167: return imOut; -: 168:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#PcxDecode.c.gcov -: 0:Source:src/libImaging/PcxDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/PcxDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/PcxDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for PCX image data. -: 6: * -: 7: * history: -: 8: * 95-09-14 fl Created -: 9: * -: 10: * Copyright (c) Fredrik Lundh 1995. -: 11: * Copyright (c) Secret Labs AB 1997. -: 12: * -: 13: * See the README file for information on usage and redistribution. -: 14: */ -: 15: -: 16: -: 17:#include "Imaging.h" -: 18: -: 19:int function ImagingPcxDecode called 45 returned 100% blocks executed 96% 45: 20:ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) -: 21:{ -: 22: UINT8 n; -: 23: UINT8* ptr; -: 24: 45: 25: if ((state->xsize * state->bits + 7) / 8 > state->bytes) { branch 0 taken 93% (fallthrough) branch 1 taken 7% 3: 26: state->errcode = IMAGING_CODEC_OVERRUN; 3: 27: return -1; -: 28: } -: 29: -: 30: ptr = buf; -: 31: -: 32: for (;;) { -: 33: 1084658: 34: if (bytes < 1) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 16: 35: return ptr - buf; -: 36: } -: 37: 1084642: 38: if ((*ptr & 0xC0) == 0xC0) { branch 0 taken 39% (fallthrough) branch 1 taken 61% -: 39: -: 40: /* Run */ 421242: 41: if (bytes < 2) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 4: 42: return ptr - buf; -: 43: } -: 44: 421238: 45: n = ptr[0] & 0x3F; -: 46: 2817038: 47: while (n > 0) { branch 0 taken 82% branch 1 taken 18% (fallthrough) 1974562: 48: if (state->x >= state->bytes) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 49: state->errcode = IMAGING_CODEC_OVERRUN; #####: 50: break; -: 51: } 1974562: 52: state->buffer[state->x++] = ptr[1]; 1974562: 53: n--; -: 54: } -: 55: 421238: 56: ptr += 2; bytes -= 2; -: 57: -: 58: } else { -: 59: -: 60: /* Literal */ 663400: 61: state->buffer[state->x++] = ptr[0]; 663400: 62: ptr++; bytes--; -: 63: -: 64: } -: 65: 1084638: 66: if (state->x >= state->bytes) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 4499: 67: if (state->bytes % state->xsize && state->bytes > state->xsize) { branch 0 taken 52% (fallthrough) branch 1 taken 48% branch 2 taken 66% (fallthrough) branch 3 taken 34% 1538: 68: int bands = state->bytes / state->xsize; 1538: 69: int stride = state->bytes / bands; -: 70: int i; 2560: 71: for (i=1; i< bands; i++) { // note -- skipping first band branch 0 taken 40% branch 1 taken 60% (fallthrough) 3066: 72: memmove(&state->buffer[i*state->xsize], 1022: 73: &state->buffer[i*stride], -: 74: state->xsize); -: 75: } -: 76: } -: 77: /* Got a full line, unpack it */ 13497: 78: state->shuffle((UINT8*) im->image[state->y + state->yoff] + call 0 returned 100% 8998: 79: state->xoff * im->pixelsize, state->buffer, -: 80: state->xsize); -: 81: 4499: 82: state->x = 0; -: 83: 4499: 84: if (++state->y >= state->ysize) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 85: /* End of file (errcode = 0) */ -: 86: return -1; -: 87: } -: 88: } -: 89: -: 90: } -: 91:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Storage.c.gcov -: 0:Source:src/libImaging/Storage.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Storage.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Storage.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * imaging storage object -: 6: * -: 7: * This baseline implementation is designed to efficiently handle -: 8: * large images, provided they fit into the available memory. -: 9: * -: 10: * history: -: 11: * 1995-06-15 fl Created -: 12: * 1995-09-12 fl Updated API, compiles silently under ANSI C++ -: 13: * 1995-11-26 fl Compiles silently under Borland 4.5 as well -: 14: * 1996-05-05 fl Correctly test status from Prologue -: 15: * 1997-05-12 fl Increased THRESHOLD (to speed up Tk interface) -: 16: * 1997-05-30 fl Added support for floating point images -: 17: * 1997-11-17 fl Added support for "RGBX" images -: 18: * 1998-01-11 fl Added support for integer images -: 19: * 1998-03-05 fl Exported Prologue/Epilogue functions -: 20: * 1998-07-01 fl Added basic "YCrCb" support -: 21: * 1998-07-03 fl Attach palette in prologue for "P" images -: 22: * 1998-07-09 hk Don't report MemoryError on zero-size images -: 23: * 1998-07-12 fl Change "YCrCb" to "YCbCr" (!) -: 24: * 1998-10-26 fl Added "I;16" and "I;16B" storage modes (experimental) -: 25: * 1998-12-29 fl Fixed allocation bug caused by previous fix -: 26: * 1999-02-03 fl Added "RGBa" and "BGR" modes (experimental) -: 27: * 2001-04-22 fl Fixed potential memory leak in ImagingCopyPalette -: 28: * 2003-09-26 fl Added "LA" and "PA" modes (experimental) -: 29: * 2005-10-02 fl Added image counter -: 30: * -: 31: * Copyright (c) 1998-2005 by Secret Labs AB -: 32: * Copyright (c) 1995-2005 by Fredrik Lundh -: 33: * -: 34: * See the README file for information on usage and redistribution. -: 35: */ -: 36: -: 37: -: 38:#include "Imaging.h" -: 39:#include -: 40: -: 41: -: 42:int ImagingNewCount = 0; -: 43: -: 44:/* -------------------------------------------------------------------- -: 45: * Standard image object. -: 46: */ -: 47: -: 48:Imaging function ImagingNewPrologueSubtype called 1088083 returned 100% blocks executed 97% 1088083: 49:ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) -: 50:{ -: 51: Imaging im; -: 52: -: 53: /* linesize overflow check, roughly the current largest space req'd */ 1088083: 54: if (xsize > (INT_MAX / 4) - 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 55: return (Imaging) ImagingError_MemoryError(); call 0 never executed -: 56: } -: 57: 1088083: 58: im = (Imaging) calloc(1, size); 1088083: 59: if (!im) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 60: return (Imaging) ImagingError_MemoryError(); call 0 never executed -: 61: } -: 62: -: 63: /* Setup image descriptor */ 1088083: 64: im->xsize = xsize; 1088083: 65: im->ysize = ysize; -: 66: 1088083: 67: im->type = IMAGING_TYPE_UINT8; -: 68: 1088083: 69: if (strcmp(mode, "1") == 0) { branch 0 taken 96% (fallthrough) branch 1 taken 4% branch 2 taken 96% (fallthrough) branch 3 taken 4% -: 70: /* 1-bit images */ 1041541: 71: im->bands = im->pixelsize = 1; 1041541: 72: im->linesize = xsize; -: 73: 46542: 74: } else if (strcmp(mode, "P") == 0) { branch 0 taken 4% (fallthrough) branch 1 taken 96% branch 2 taken 4% (fallthrough) branch 3 taken 96% -: 75: /* 8-bit palette mapped images */ 1935: 76: im->bands = im->pixelsize = 1; 1935: 77: im->linesize = xsize; 1935: 78: im->palette = ImagingPaletteNew("RGB"); call 0 returned 100% -: 79: 44607: 80: } else if (strcmp(mode, "PA") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 1% (fallthrough) branch 5 taken 99% -: 81: /* 8-bit palette with alpha */ 74: 82: im->bands = 2; 74: 83: im->pixelsize = 4; /* store in image32 memory */ 74: 84: im->linesize = xsize * 4; 74: 85: im->palette = ImagingPaletteNew("RGB"); call 0 returned 100% -: 86: 44533: 87: } else if (strcmp(mode, "L") == 0) { branch 0 taken 21% (fallthrough) branch 1 taken 79% branch 2 taken 18% (fallthrough) branch 3 taken 82% -: 88: /* 8-bit greyscale (luminance) images */ 8102: 89: im->bands = im->pixelsize = 1; 8102: 90: im->linesize = xsize; -: 91: 36431: 92: } else if (strcmp(mode, "LA") == 0) { branch 0 taken 3% (fallthrough) branch 1 taken 97% branch 2 taken 40% (fallthrough) branch 3 taken 60% branch 4 taken 1% (fallthrough) branch 5 taken 99% -: 93: /* 8-bit greyscale (luminance) with alpha */ 375: 94: im->bands = 2; 375: 95: im->pixelsize = 4; /* store in image32 memory */ 375: 96: im->linesize = xsize * 4; -: 97: 36056: 98: } else if (strcmp(mode, "La") == 0) { branch 0 taken 2% (fallthrough) branch 1 taken 98% branch 2 taken 95% (fallthrough) branch 3 taken 5% branch 4 taken 2% (fallthrough) branch 5 taken 98% -: 99: /* 8-bit greyscale (luminance) with premultiplied alpha */ 619: 100: im->bands = 2; 619: 101: im->pixelsize = 4; /* store in image32 memory */ 619: 102: im->linesize = xsize * 4; -: 103: 35437: 104: } else if (strcmp(mode, "F") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% branch 2 taken 1% (fallthrough) branch 3 taken 99% -: 105: /* 32-bit floating point images */ 444: 106: im->bands = 1; 444: 107: im->pixelsize = 4; 444: 108: im->linesize = xsize * 4; 444: 109: im->type = IMAGING_TYPE_FLOAT32; -: 110: 34993: 111: } else if (strcmp(mode, "I") == 0) { branch 0 taken 22% (fallthrough) branch 1 taken 78% branch 2 taken 21% (fallthrough) branch 3 taken 79% -: 112: /* 32-bit integer images */ 7411: 113: im->bands = 1; 7411: 114: im->pixelsize = 4; 7411: 115: im->linesize = xsize * 4; 7411: 116: im->type = IMAGING_TYPE_INT32; -: 117: 27582: 118: } else if (strcmp(mode, "I;16") == 0 || strcmp(mode, "I;16L") == 0 \ branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 99% (fallthrough) branch 3 taken 1% 27391: 119: || strcmp(mode, "I;16B") == 0 || strcmp(mode, "I;16N") == 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 1% (fallthrough) branch 3 taken 99% -: 120: /* EXPERIMENTAL */ -: 121: /* 16-bit raw integer images */ 288: 122: im->bands = 1; 288: 123: im->pixelsize = 2; 288: 124: im->linesize = xsize * 2; 288: 125: im->type = IMAGING_TYPE_SPECIAL; -: 126: 27294: 127: } else if (strcmp(mode, "RGB") == 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 88% (fallthrough) branch 7 taken 12% -: 128: /* 24-bit true colour images */ 23971: 129: im->bands = 3; 23971: 130: im->pixelsize = 4; 23971: 131: im->linesize = xsize * 4; -: 132: 3323: 133: } else if (strcmp(mode, "BGR;15") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 134: /* EXPERIMENTAL */ -: 135: /* 15-bit reversed true colour */ 6: 136: im->bands = 1; 6: 137: im->pixelsize = 2; 6: 138: im->linesize = (xsize*2 + 3) & -4; 6: 139: im->type = IMAGING_TYPE_SPECIAL; -: 140: 3317: 141: } else if (strcmp(mode, "BGR;16") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 142: /* EXPERIMENTAL */ -: 143: /* 16-bit reversed true colour */ 1: 144: im->bands = 1; 1: 145: im->pixelsize = 2; 1: 146: im->linesize = (xsize*2 + 3) & -4; 1: 147: im->type = IMAGING_TYPE_SPECIAL; -: 148: 3316: 149: } else if (strcmp(mode, "BGR;24") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 150: /* EXPERIMENTAL */ -: 151: /* 24-bit reversed true colour */ 1: 152: im->bands = 1; 1: 153: im->pixelsize = 3; 1: 154: im->linesize = (xsize*3 + 3) & -4; 1: 155: im->type = IMAGING_TYPE_SPECIAL; -: 156: 3315: 157: } else if (strcmp(mode, "BGR;32") == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 158: /* EXPERIMENTAL */ -: 159: /* 32-bit reversed true colour */ 1: 160: im->bands = 1; 1: 161: im->pixelsize = 4; 1: 162: im->linesize = (xsize*4 + 3) & -4; 1: 163: im->type = IMAGING_TYPE_SPECIAL; -: 164: 3314: 165: } else if (strcmp(mode, "RGBX") == 0) { branch 0 taken 3% (fallthrough) branch 1 taken 97% -: 166: /* 32-bit true colour images with padding */ 111: 167: im->bands = im->pixelsize = 4; 111: 168: im->linesize = xsize * 4; -: 169: 3203: 170: } else if (strcmp(mode, "RGBA") == 0) { branch 0 taken 69% (fallthrough) branch 1 taken 31% -: 171: /* 32-bit true colour images with alpha */ 2197: 172: im->bands = im->pixelsize = 4; 2197: 173: im->linesize = xsize * 4; -: 174: 1006: 175: } else if (strcmp(mode, "RGBa") == 0) { branch 0 taken 64% (fallthrough) branch 1 taken 36% -: 176: /* 32-bit true colour images with premultiplied alpha */ 647: 177: im->bands = im->pixelsize = 4; 647: 178: im->linesize = xsize * 4; -: 179: 359: 180: } else if (strcmp(mode, "CMYK") == 0) { branch 0 taken 50% (fallthrough) branch 1 taken 50% -: 181: /* 32-bit colour separation */ 178: 182: im->bands = im->pixelsize = 4; 178: 183: im->linesize = xsize * 4; -: 184: 181: 185: } else if (strcmp(mode, "YCbCr") == 0) { branch 0 taken 44% (fallthrough) branch 1 taken 56% -: 186: /* 24-bit video format */ 79: 187: im->bands = 3; 79: 188: im->pixelsize = 4; 79: 189: im->linesize = xsize * 4; -: 190: 102: 191: } else if (strcmp(mode, "LAB") == 0) { branch 0 taken 33% (fallthrough) branch 1 taken 67% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 33% (fallthrough) branch 7 taken 67% -: 192: /* 24-bit color, luminance, + 2 color channels */ -: 193: /* L is uint8, a,b are int8 */ 34: 194: im->bands = 3; 34: 195: im->pixelsize = 4; 34: 196: im->linesize = xsize * 4; -: 197: 68: 198: } else if (strcmp(mode, "HSV") == 0) { branch 0 taken 91% (fallthrough) branch 1 taken 9% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 91% (fallthrough) branch 7 taken 9% -: 199: /* 24-bit color, luminance, + 2 color channels */ -: 200: /* L is uint8, a,b are int8 */ 62: 201: im->bands = 3; 62: 202: im->pixelsize = 4; 62: 203: im->linesize = xsize * 4; -: 204: -: 205: } else { 6: 206: free(im); 6: 207: return (Imaging) ImagingError_ValueError("unrecognized image mode"); call 0 returned 100% -: 208: } -: 209: -: 210: /* Setup image descriptor */ 2176154: 211: strcpy(im->mode, mode); -: 212: -: 213: /* Pointer array (allocate at least one line, to avoid MemoryError -: 214: exceptions on platforms where calloc(0, x) returns NULL) */ 1088077: 215: im->image = (char **) calloc((ysize > 0) ? ysize : 1, sizeof(void *)); -: 216: 1088077: 217: if ( ! im->image) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 218: free(im); #####: 219: return (Imaging) ImagingError_MemoryError(); call 0 never executed -: 220: } -: 221: -: 222: /* Initialize alias pointers to pixel data. */ 1088077: 223: switch (im->pixelsize) { branch 0 taken 97% branch 1 taken 3% branch 2 taken 0% -: 224: case 1: case 2: case 3: 1051874: 225: im->image8 = (UINT8 **) im->image; 1051874: 226: break; -: 227: case 4: 36203: 228: im->image32 = (INT32 **) im->image; 36203: 229: break; -: 230: } -: 231: 1088077: 232: ImagingDefaultArena.stats_new_count += 1; -: 233: 1088077: 234: return im; -: 235:} -: 236: -: 237:Imaging function ImagingNewPrologue called 1087977 returned 100% blocks executed 100% 1087977: 238:ImagingNewPrologue(const char *mode, int xsize, int ysize) -: 239:{ 1087977: 240: return ImagingNewPrologueSubtype( call 0 returned 100% -: 241: mode, xsize, ysize, sizeof(struct ImagingMemoryInstance)); -: 242:} -: 243: -: 244:void function ImagingDelete called 1088105 returned 100% blocks executed 100% 1088105: 245:ImagingDelete(Imaging im) -: 246:{ 1088105: 247: if (!im) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 248: return; -: 249: } -: 250: 1088037: 251: if (im->palette) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 2136: 252: ImagingPaletteDelete(im->palette); call 0 returned 100% -: 253: } -: 254: 1088037: 255: if (im->destroy) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 1087547: 256: im->destroy(im); call 0 returned 100% -: 257: } -: 258: 1088037: 259: if (im->image) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 1088037: 260: free(im->image); -: 261: } -: 262: 1088037: 263: free(im); -: 264:} -: 265: -: 266: -: 267:/* Array Storage Type */ -: 268:/* ------------------ */ -: 269:/* Allocate image as an array of line buffers. */ -: 270: -: 271:#define IMAGING_PAGE_SIZE (4096) -: 272: -: 273:struct ImagingMemoryArena ImagingDefaultArena = { -: 274: 1, // alignment -: 275: 16*1024*1024, // block_size -: 276: 0, // blocks_max -: 277: 0, // blocks_cached -: 278: NULL, // blocks_pool -: 279: 0, 0, 0, 0, 0 // Stats -: 280:}; -: 281: -: 282:int function ImagingMemorySetBlocksMax called 20 returned 100% blocks executed 100% 20: 283:ImagingMemorySetBlocksMax(ImagingMemoryArena arena, int blocks_max) -: 284:{ -: 285: void *p; -: 286: /* Free already cached blocks */ 20: 287: ImagingMemoryClearCache(arena, blocks_max); call 0 returned 100% -: 288: 20: 289: if (blocks_max == 0 && arena->blocks_pool != NULL) { branch 0 taken 75% (fallthrough) branch 1 taken 25% branch 2 taken 60% (fallthrough) branch 3 taken 40% 9: 290: free(arena->blocks_pool); 9: 291: arena->blocks_pool = NULL; 11: 292: } else if (arena->blocks_pool != NULL) { branch 0 taken 9% (fallthrough) branch 1 taken 91% 1: 293: p = realloc(arena->blocks_pool, sizeof(*arena->blocks_pool) * blocks_max); 1: 294: if ( ! p) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 295: // Leave previous blocks_max value -: 296: return 0; -: 297: } 1: 298: arena->blocks_pool = p; -: 299: } else { 10: 300: arena->blocks_pool = calloc(sizeof(*arena->blocks_pool), blocks_max); 10: 301: if ( ! arena->blocks_pool) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 302: return 0; -: 303: } -: 304: } 20: 305: arena->blocks_max = blocks_max; -: 306: 20: 307: return 1; -: 308:} -: 309: -: 310:void function ImagingMemoryClearCache called 38 returned 100% blocks executed 100% 38: 311:ImagingMemoryClearCache(ImagingMemoryArena arena, int new_size) -: 312:{ 205: 313: while (arena->blocks_cached > new_size) { branch 0 taken 77% branch 1 taken 23% (fallthrough) 129: 314: arena->blocks_cached -= 1; 129: 315: free(arena->blocks_pool[arena->blocks_cached].ptr); 129: 316: arena->stats_freed_blocks += 1; -: 317: } 38: 318:} -: 319: -: 320:ImagingMemoryBlock function memory_get_block called 1089084 returned 100% blocks executed 73% 1089084: 321:memory_get_block(ImagingMemoryArena arena, int requested_size, int dirty) -: 322:{ 1089084: 323: ImagingMemoryBlock block = {NULL, 0}; -: 324: 1089084: 325: if (arena->blocks_cached > 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 326: // Get block from cache 129: 327: arena->blocks_cached -= 1; 129: 328: block = arena->blocks_pool[arena->blocks_cached]; -: 329: // Reallocate if needed 129: 330: if (block.size != requested_size){ branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 331: block.ptr = realloc(block.ptr, requested_size); -: 332: } 129: 333: if ( ! block.ptr) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 334: // Can't allocate, free previous pointer (it is still valid) #####: 335: free(arena->blocks_pool[arena->blocks_cached].ptr); #####: 336: arena->stats_freed_blocks += 1; #####: 337: return block; -: 338: } 129: 339: if ( ! dirty) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 340: memset(block.ptr, 0, requested_size); -: 341: } 129: 342: arena->stats_reused_blocks += 1; 129: 343: if (block.ptr != arena->blocks_pool[arena->blocks_cached].ptr) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 344: arena->stats_reallocated_blocks += 1; -: 345: } -: 346: } else { 1088955: 347: if (dirty) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 1082250: 348: block.ptr = malloc(requested_size); -: 349: } else { 6705: 350: block.ptr = calloc(1, requested_size); -: 351: } 1088955: 352: arena->stats_allocated_blocks += 1; -: 353: } 1089084: 354: block.size = requested_size; 1089084: 355: return block; -: 356:} -: 357: -: 358:void function memory_return_block called 1089044 returned 100% blocks executed 83% 1089044: 359:memory_return_block(ImagingMemoryArena arena, ImagingMemoryBlock block) -: 360:{ 1089044: 361: if (arena->blocks_cached < arena->blocks_max) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 362: // Reduce block size 258: 363: if (block.size > arena->block_size) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 364: block.size = arena->block_size; #####: 365: block.ptr = realloc(block.ptr, arena->block_size); -: 366: } 258: 367: arena->blocks_pool[arena->blocks_cached] = block; 258: 368: arena->blocks_cached += 1; -: 369: } else { 1088786: 370: free(block.ptr); 1088786: 371: arena->stats_freed_blocks += 1; -: 372: } 1089044: 373:} -: 374: -: 375: -: 376:static void function ImagingDestroyArray called 1087441 returned 100% blocks executed 100% 1087441: 377:ImagingDestroyArray(Imaging im) -: 378:{ 1087441: 379: int y = 0; -: 380: 1087441: 381: if (im->blocks) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 2176485: 382: while (im->blocks[y].ptr) { branch 0 taken 50% branch 1 taken 50% (fallthrough) 1089044: 383: memory_return_block(&ImagingDefaultArena, im->blocks[y]); call 0 returned 100% 1089044: 384: y += 1; -: 385: } 1087441: 386: free(im->blocks); -: 387: } 1087441: 388:} -: 389: -: 390:Imaging function ImagingAllocateArray called 1087971 returned 100% blocks executed 86% 1087971: 391:ImagingAllocateArray(Imaging im, int dirty, int block_size) -: 392:{ -: 393: int y, line_in_block, current_block; 1087971: 394: ImagingMemoryArena arena = &ImagingDefaultArena; 1087971: 395: ImagingMemoryBlock block = {NULL, 0}; -: 396: int aligned_linesize, lines_per_block, blocks_count; 1087971: 397: char *aligned_ptr = NULL; -: 398: -: 399: /* 0-width or 0-height image. No need to do anything */ 1087971: 400: if ( ! im->linesize || ! im->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 99% (fallthrough) branch 3 taken 1% -: 401: return im; -: 402: } -: 403: 1087481: 404: aligned_linesize = (im->linesize + arena->alignment - 1) & -arena->alignment; 1087481: 405: lines_per_block = (block_size - (arena->alignment - 1)) / aligned_linesize; 1087481: 406: if (lines_per_block == 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1: 407: lines_per_block = 1; -: 408: } 1087481: 409: blocks_count = (im->ysize + lines_per_block - 1) / lines_per_block; -: 410: // printf("NEW size: %dx%d, ls: %d, lpb: %d, blocks: %d\n", -: 411: // im->xsize, im->ysize, aligned_linesize, lines_per_block, blocks_count); -: 412: -: 413: /* One extra pointer is always NULL */ 1087481: 414: im->blocks = calloc(sizeof(*im->blocks), blocks_count + 1); 1087481: 415: if ( ! im->blocks) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 416: return (Imaging) ImagingError_MemoryError(); call 0 never executed -: 417: } -: 418: -: 419: /* Allocate image as an array of lines */ -: 420: line_in_block = 0; -: 421: current_block = 0; 9368277: 422: for (y = 0; y < im->ysize; y++) { branch 0 taken 90% branch 1 taken 10% (fallthrough) 9368277: 423: if (line_in_block == 0) { branch 0 taken 12% (fallthrough) branch 1 taken 88% -: 424: int required; 1089084: 425: int lines_remaining = lines_per_block; 1089084: 426: if (lines_remaining > im->ysize - y) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 1087373: 427: lines_remaining = im->ysize - y; -: 428: } 1089084: 429: required = lines_remaining * aligned_linesize + arena->alignment - 1; 1089084: 430: block = memory_get_block(arena, required, dirty); call 0 returned 100% 1089084: 431: if ( ! block.ptr) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 432: ImagingDestroyArray(im); call 0 never executed #####: 433: return (Imaging) ImagingError_MemoryError(); call 0 never executed -: 434: } 1089084: 435: im->blocks[current_block] = block; -: 436: /* Bulletproof code from libc _int_memalign */ 1089084: 437: aligned_ptr = (char *)( 2178168: 438: ((size_t) (block.ptr + arena->alignment - 1)) & 1089084: 439: -((Py_ssize_t) arena->alignment)); -: 440: } -: 441: 9368277: 442: im->image[y] = aligned_ptr + aligned_linesize * line_in_block; -: 443: 9368277: 444: line_in_block += 1; 9368277: 445: if (line_in_block >= lines_per_block) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 446: /* Reset counter and start new block */ 1711: 447: line_in_block = 0; 1711: 448: current_block += 1; -: 449: } -: 450: } -: 451: 1087481: 452: im->destroy = ImagingDestroyArray; -: 453: 1087481: 454: return im; -: 455:} -: 456: -: 457: -: 458:/* Block Storage Type */ -: 459:/* ------------------ */ -: 460:/* Allocate image as a single block. */ -: 461: -: 462:static void function ImagingDestroyBlock called 0 returned 0% blocks executed 0% #####: 463:ImagingDestroyBlock(Imaging im) -: 464:{ #####: 465: if (im->block) { branch 0 never executed branch 1 never executed #####: 466: free(im->block); -: 467: } #####: 468:} -: 469: -: 470:Imaging function ImagingAllocateBlock called 0 returned 0% blocks executed 0% #####: 471:ImagingAllocateBlock(Imaging im) -: 472:{ -: 473: Py_ssize_t y, i; -: 474: -: 475: /* overflow check for malloc */ #####: 476: if (im->linesize && branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 477: im->ysize > INT_MAX / im->linesize) { #####: 478: return (Imaging) ImagingError_MemoryError(); call 0 never executed -: 479: } -: 480: #####: 481: if (im->ysize * im->linesize <= 0) { branch 0 never executed branch 1 never executed -: 482: /* some platforms return NULL for malloc(0); this fix -: 483: prevents MemoryError on zero-sized images on such -: 484: platforms */ #####: 485: im->block = (char *) malloc(1); -: 486: } else { -: 487: /* malloc check ok, overflow check above */ #####: 488: im->block = (char *) calloc(im->ysize, im->linesize); -: 489: } -: 490: #####: 491: if ( ! im->block) { branch 0 never executed branch 1 never executed #####: 492: return (Imaging) ImagingError_MemoryError(); call 0 never executed -: 493: } -: 494: #####: 495: for (y = i = 0; y < im->ysize; y++) { branch 0 never executed branch 1 never executed #####: 496: im->image[y] = im->block + i; #####: 497: i += im->linesize; -: 498: } -: 499: #####: 500: im->destroy = ImagingDestroyBlock; -: 501: #####: 502: return im; -: 503:} -: 504: -: 505:/* -------------------------------------------------------------------- -: 506: * Create a new, internally allocated, image. -: 507: */ -: 508: -: 509:Imaging function ImagingNewInternal called 1087978 returned 100% blocks executed 62% 1087978: 510:ImagingNewInternal(const char* mode, int xsize, int ysize, int dirty) -: 511:{ -: 512: Imaging im; -: 513: 1087978: 514: if (xsize < 0 || ysize < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 1% (fallthrough) branch 3 taken 99% 1: 515: return (Imaging) ImagingError_ValueError("bad image size"); call 0 returned 100% -: 516: } -: 517: 1087977: 518: im = ImagingNewPrologue(mode, xsize, ysize); call 0 returned 100% 1087977: 519: if ( ! im) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 520: return NULL; -: 521: } -: 522: 1087971: 523: if (ImagingAllocateArray(im, dirty, ImagingDefaultArena.block_size)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% -: 524: return im; -: 525: } -: 526: #####: 527: ImagingError_Clear(); call 0 never executed -: 528: -: 529: // Try to allocate the image once more with smallest possible block size #####: 530: if (ImagingAllocateArray(im, dirty, IMAGING_PAGE_SIZE)) { call 0 never executed branch 1 never executed branch 2 never executed -: 531: return im; -: 532: } -: 533: #####: 534: ImagingDelete(im); call 0 never executed #####: 535: return NULL; -: 536:} -: 537: -: 538:Imaging function ImagingNew called 6129 returned 100% blocks executed 100% 6129: 539:ImagingNew(const char* mode, int xsize, int ysize) -: 540:{ 6129: 541: return ImagingNewInternal(mode, xsize, ysize, 0); call 0 returned 100% -: 542:} -: 543: -: 544:Imaging function ImagingNewDirty called 1081849 returned 100% blocks executed 100% 1081849: 545:ImagingNewDirty(const char* mode, int xsize, int ysize) -: 546:{ 1081849: 547: return ImagingNewInternal(mode, xsize, ysize, 1); call 0 returned 100% -: 548:} -: 549: -: 550:Imaging function ImagingNewBlock called 0 returned 0% blocks executed 0% #####: 551:ImagingNewBlock(const char* mode, int xsize, int ysize) -: 552:{ -: 553: Imaging im; -: 554: #####: 555: if (xsize < 0 || ysize < 0) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 556: return (Imaging) ImagingError_ValueError("bad image size"); call 0 never executed -: 557: } -: 558: #####: 559: im = ImagingNewPrologue(mode, xsize, ysize); call 0 never executed #####: 560: if ( ! im) { branch 0 never executed branch 1 never executed -: 561: return NULL; -: 562: } -: 563: #####: 564: if (ImagingAllocateBlock(im)) { call 0 never executed branch 1 never executed branch 2 never executed -: 565: return im; -: 566: } -: 567: #####: 568: ImagingDelete(im); call 0 never executed #####: 569: return NULL; -: 570:} -: 571: -: 572:Imaging function ImagingNew2Dirty called 10306 returned 100% blocks executed 89% 10306: 573:ImagingNew2Dirty(const char* mode, Imaging imOut, Imaging imIn) -: 574:{ -: 575: /* allocate or validate output image */ -: 576: 10306: 577: if (imOut) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 578: /* make sure images match */ 20: 579: if (strcmp(imOut->mode, mode) != 0 branch 0 taken 100% (fallthrough) branch 1 taken 0% 20: 580: || imOut->xsize != imIn->xsize branch 0 taken 100% (fallthrough) branch 1 taken 0% 20: 581: || imOut->ysize != imIn->ysize) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 582: return ImagingError_Mismatch(); call 0 never executed -: 583: } -: 584: } else { -: 585: /* create new image */ 10286: 586: imOut = ImagingNewDirty(mode, imIn->xsize, imIn->ysize); call 0 returned 100% 10286: 587: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 588: return NULL; -: 589: } -: 590: } -: 591: -: 592: return imOut; -: 593:} -: 594: -: 595:void function ImagingCopyPalette called 1032267 returned 100% blocks executed 100% 1032267: 596:ImagingCopyPalette(Imaging destination, Imaging source) -: 597:{ 1032267: 598: if (source->palette) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1331: 599: if (destination->palette) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 1331: 600: ImagingPaletteDelete(destination->palette); call 0 returned 100% -: 601: } 1331: 602: destination->palette = ImagingPaletteDuplicate(source->palette); call 0 returned 100% -: 603: } 1032267: 604:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Jpeg2KEncode.c.gcov -: 0:Source:src/libImaging/Jpeg2KEncode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Jpeg2KEncode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Jpeg2KEncode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for JPEG2000 image data. -: 6: * -: 7: * history: -: 8: * 2014-03-12 ajh Created -: 9: * -: 10: * Copyright (c) 2014 Coriolis Systems Limited -: 11: * Copyright (c) 2014 Alastair Houghton -: 12: * -: 13: * See the README file for details on usage and redistribution. -: 14: */ -: 15: -: 16:#include "Imaging.h" -: 17: -: 18:#ifdef HAVE_OPENJPEG -: 19: -: 20:#include "Jpeg2K.h" -: 21: -: 22:#define CINEMA_24_CS_LENGTH 1302083 -: 23:#define CINEMA_48_CS_LENGTH 651041 -: 24:#define COMP_24_CS_MAX_LENGTH 1041666 -: 25:#define COMP_48_CS_MAX_LENGTH 520833 -: 26: -: 27:/* -------------------------------------------------------------------- */ -: 28:/* Error handler */ -: 29:/* -------------------------------------------------------------------- */ -: 30: -: 31:static void function j2k_error called 1 returned 100% blocks executed 100% 1: 32:j2k_error(const char *msg, void *client_data) -: 33:{ 1: 34: JPEG2KENCODESTATE *state = (JPEG2KENCODESTATE *) client_data; 1: 35: free((void *)state->error_msg); 1: 36: state->error_msg = strdup(msg); call 0 returned 100% 1: 37:} -: 38: -: 39:static void function j2k_warn called 55 returned 100% blocks executed 100% 55: 40:j2k_warn(const char *msg, void *client_data) -: 41:{ -: 42: // Null handler 55: 43:} -: 44: -: 45:/* -------------------------------------------------------------------- */ -: 46:/* Buffer output stream */ -: 47:/* -------------------------------------------------------------------- */ -: 48: -: 49:static OPJ_SIZE_T function j2k_write called 40 returned 100% blocks executed 100% 40: 50:j2k_write(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data) -: 51:{ 40: 52: ImagingCodecState state = (ImagingCodecState)p_user_data; -: 53: unsigned int result; -: 54: 40: 55: result = _imaging_write_pyFd(state->fd, p_buffer, p_nb_bytes); call 0 returned 100% -: 56: 40: 57: return result ? result : (OPJ_SIZE_T)-1; branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 58:} -: 59: -: 60: -: 61:static OPJ_OFF_T function j2k_skip called 14 returned 100% blocks executed 100% 14: 62:j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data) -: 63:{ 14: 64: ImagingCodecState state = (ImagingCodecState)p_user_data; -: 65: char *buffer; -: 66: int result; -: 67: -: 68: /* Explicitly write zeros */ 14: 69: buffer = calloc(p_nb_bytes,1); 14: 70: if (!buffer) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 71: return (OPJ_OFF_T)-1; -: 72: } -: 73: 14: 74: result = _imaging_write_pyFd(state->fd, buffer, p_nb_bytes); call 0 returned 100% -: 75: 14: 76: free(buffer); -: 77: 14: 78: return result ? result : p_nb_bytes; branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 79:} -: 80: -: 81:static OPJ_BOOL function j2k_seek called 26 returned 100% blocks executed 100% 26: 82:j2k_seek(OPJ_OFF_T p_nb_bytes, void *p_user_data) -: 83:{ 26: 84: ImagingCodecState state = (ImagingCodecState)p_user_data; 26: 85: off_t pos = 0; -: 86: 26: 87: _imaging_seek_pyFd(state->fd, p_nb_bytes, SEEK_SET); call 0 returned 100% 26: 88: pos = _imaging_tell_pyFd(state->fd); call 0 returned 100% -: 89: 26: 90: return pos == p_nb_bytes; -: 91:} -: 92: -: 93:/* -------------------------------------------------------------------- */ -: 94:/* Encoder */ -: 95:/* -------------------------------------------------------------------- */ -: 96: -: 97:typedef void (*j2k_pack_tile_t)(Imaging im, UINT8 *buf, -: 98: unsigned x0, unsigned y0, -: 99: unsigned w, unsigned h); -: 100: -: 101:static void function j2k_pack_l called 0 returned 0% blocks executed 0% #####: 102:j2k_pack_l(Imaging im, UINT8 *buf, -: 103: unsigned x0, unsigned y0, unsigned w, unsigned h) -: 104:{ #####: 105: UINT8 *ptr = buf; -: 106: unsigned x,y; #####: 107: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 108: UINT8 *data = (UINT8 *)(im->image[y + y0] + x0); #####: 109: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 110: *ptr++ = *data++; -: 111: } -: 112: } #####: 113:} -: 114: -: 115:static void function j2k_pack_i16 called 2 returned 100% blocks executed 100% 2: 116:j2k_pack_i16(Imaging im, UINT8 *buf, -: 117: unsigned x0, unsigned y0, unsigned w, unsigned h) -: 118:{ 2: 119: UINT8 *ptr = buf; -: 120: unsigned x,y; 130: 121: for (y = 0; y < h; ++y) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 128: 122: UINT8 *data = (UINT8 *)(im->image[y + y0] + x0); 8320: 123: for (x = 0; x < w; ++x) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 8192: 124: *ptr++ = *data++; 8192: 125: *ptr++ = *data++; -: 126: } -: 127: } 2: 128:} -: 129: -: 130: -: 131:static void function j2k_pack_la called 0 returned 0% blocks executed 0% #####: 132:j2k_pack_la(Imaging im, UINT8 *buf, -: 133: unsigned x0, unsigned y0, unsigned w, unsigned h) -: 134:{ #####: 135: UINT8 *ptr = buf; #####: 136: UINT8 *ptra = buf + w * h; -: 137: unsigned x,y; #####: 138: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 139: UINT8 *data = (UINT8 *)(im->image[y + y0] + 4 * x0); #####: 140: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 141: *ptr++ = data[0]; #####: 142: *ptra++ = data[3]; #####: 143: data += 4; -: 144: } -: 145: } #####: 146:} -: 147: -: 148:static void function j2k_pack_rgb called 53 returned 100% blocks executed 100% 53: 149:j2k_pack_rgb(Imaging im, UINT8 *buf, -: 150: unsigned x0, unsigned y0, unsigned w, unsigned h) -: 151:{ 53: 152: UINT8 *pr = buf; 53: 153: UINT8 *pg = pr + w * h; 53: 154: UINT8 *pb = pg + w * h; -: 155: unsigned x,y; 9653: 156: for (y = 0; y < h; ++y) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 9600: 157: UINT8 *data = (UINT8 *)(im->image[y + y0] + 4 * x0); 3388800: 158: for (x = 0; x < w; ++x) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 3379200: 159: *pr++ = data[0]; 3379200: 160: *pg++ = data[1]; 3379200: 161: *pb++ = data[2]; 3379200: 162: data += 4; -: 163: } -: 164: } 53: 165:} -: 166: -: 167:static void function j2k_pack_rgba called 0 returned 0% blocks executed 0% #####: 168:j2k_pack_rgba(Imaging im, UINT8 *buf, -: 169: unsigned x0, unsigned y0, unsigned w, unsigned h) -: 170:{ #####: 171: UINT8 *pr = buf; #####: 172: UINT8 *pg = pr + w * h; #####: 173: UINT8 *pb = pg + w * h; #####: 174: UINT8 *pa = pb + w * h; -: 175: unsigned x,y; #####: 176: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 177: UINT8 *data = (UINT8 *)(im->image[y + y0] + 4 * x0); #####: 178: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 179: *pr++ = *data++; #####: 180: *pg++ = *data++; #####: 181: *pb++ = *data++; #####: 182: *pa++ = *data++; -: 183: } -: 184: } #####: 185:} -: 186: -: 187:enum { -: 188: J2K_STATE_START = 0, -: 189: J2K_STATE_ENCODING = 1, -: 190: J2K_STATE_DONE = 2, -: 191: J2K_STATE_FAILED = 3, -: 192:}; -: 193: -: 194:static void function j2k_set_cinema_params.isra.0 called 0 returned 0% blocks executed 0% #####: 195:j2k_set_cinema_params(Imaging im, int components, opj_cparameters_t *params) -: 196:{ -: 197: float rate; -: 198: int n; -: 199: -: 200: /* These settings have been copied from opj_compress in the OpenJPEG -: 201: sources. */ -: 202: #####: 203: params->tile_size_on = OPJ_FALSE; #####: 204: params->cp_tdx = params->cp_tdy = 1; #####: 205: params->tp_flag = 'C'; #####: 206: params->tp_on = 1; #####: 207: params->cp_tx0 = params->cp_ty0 = 0; #####: 208: params->image_offset_x0 = params->image_offset_y0 = 0; #####: 209: params->cblockw_init = 32; #####: 210: params->cblockh_init = 32; #####: 211: params->csty |= 0x01; #####: 212: params->prog_order = OPJ_CPRL; #####: 213: params->roi_compno = -1; #####: 214: params->subsampling_dx = params->subsampling_dy = 1; #####: 215: params->irreversible = 1; -: 216: #####: 217: if (params->cp_cinema == OPJ_CINEMA4K_24) { branch 0 never executed branch 1 never executed #####: 218: float max_rate = ((float)(components * im->xsize * im->ysize * 8) -: 219: / (CINEMA_24_CS_LENGTH * 8)); -: 220: #####: 221: params->POC[0].tile = 1; #####: 222: params->POC[0].resno0 = 0; #####: 223: params->POC[0].compno0 = 0; #####: 224: params->POC[0].layno1 = 1; #####: 225: params->POC[0].resno1 = params->numresolution - 1; #####: 226: params->POC[0].compno1 = 3; #####: 227: params->POC[0].prg1 = OPJ_CPRL; #####: 228: params->POC[1].tile = 1; #####: 229: params->POC[1].resno0 = 0; #####: 230: params->POC[1].compno0 = 0; #####: 231: params->POC[1].layno1 = 1; #####: 232: params->POC[1].resno1 = params->numresolution - 1; #####: 233: params->POC[1].compno1 = 3; #####: 234: params->POC[1].prg1 = OPJ_CPRL; #####: 235: params->numpocs = 2; -: 236: #####: 237: for (n = 0; n < params->tcp_numlayers; ++n) { branch 0 never executed branch 1 never executed #####: 238: rate = 0; #####: 239: if (params->tcp_rates[0] == 0) { branch 0 never executed branch 1 never executed #####: 240: params->tcp_rates[n] = max_rate; -: 241: } else { #####: 242: rate = ((float)(components * im->xsize * im->ysize * 8) #####: 243: / (params->tcp_rates[n] * 8)); #####: 244: if (rate > CINEMA_24_CS_LENGTH) { branch 0 never executed branch 1 never executed #####: 245: params->tcp_rates[n] = max_rate; -: 246: } -: 247: } -: 248: } -: 249: #####: 250: params->max_comp_size = COMP_24_CS_MAX_LENGTH; -: 251: } else { #####: 252: float max_rate = ((float)(components * im->xsize * im->ysize * 8) -: 253: / (CINEMA_48_CS_LENGTH * 8)); -: 254: #####: 255: for (n = 0; n < params->tcp_numlayers; ++n) { branch 0 never executed branch 1 never executed #####: 256: rate = 0; #####: 257: if (params->tcp_rates[0] == 0) { branch 0 never executed branch 1 never executed #####: 258: params->tcp_rates[n] = max_rate; -: 259: } else { #####: 260: rate = ((float)(components * im->xsize * im->ysize * 8) #####: 261: / (params->tcp_rates[n] * 8)); #####: 262: if (rate > CINEMA_48_CS_LENGTH) { branch 0 never executed branch 1 never executed #####: 263: params->tcp_rates[n] = max_rate; -: 264: } -: 265: } -: 266: } -: 267: #####: 268: params->max_comp_size = COMP_48_CS_MAX_LENGTH; -: 269: } #####: 270:} -: 271: -: 272:static int function j2k_encode_entry called 14 returned 100% blocks executed 76% 14: 273:j2k_encode_entry(Imaging im, ImagingCodecState state) -: 274:{ 14: 275: JPEG2KENCODESTATE *context = (JPEG2KENCODESTATE *)state->context; 14: 276: opj_stream_t *stream = NULL; 14: 277: opj_image_t *image = NULL; 14: 278: opj_codec_t *codec = NULL; -: 279: opj_cparameters_t params; -: 280: unsigned components; -: 281: OPJ_COLOR_SPACE color_space; -: 282: opj_image_cmptparm_t image_params[4]; -: 283: unsigned xsiz, ysiz; -: 284: unsigned tile_width, tile_height; -: 285: unsigned tiles_x, tiles_y; -: 286: unsigned x, y, tile_ndx; -: 287: unsigned n; -: 288: j2k_pack_tile_t pack; 14: 289: int ret = -1; -: 290: 14: 291: unsigned prec = 8; 14: 292: unsigned bpp = 8; -: 293: unsigned _overflow_scale_factor; -: 294: 14: 295: stream = opj_stream_create(BUFFER_SIZE, OPJ_FALSE); call 0 returned 100% -: 296: 14: 297: if (!stream) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 298: state->errcode = IMAGING_CODEC_BROKEN; #####: 299: state->state = J2K_STATE_FAILED; #####: 300: goto quick_exit; -: 301: } -: 302: 14: 303: opj_stream_set_write_function(stream, j2k_write); call 0 returned 100% 14: 304: opj_stream_set_skip_function(stream, j2k_skip); call 0 returned 100% 14: 305: opj_stream_set_seek_function(stream, j2k_seek); call 0 returned 100% -: 306: -: 307: /* OpenJPEG 2.0 doesn't have OPJ_VERSION_MAJOR */ -: 308:#ifndef OPJ_VERSION_MAJOR -: 309: opj_stream_set_user_data(stream, state); -: 310:#else 14: 311: opj_stream_set_user_data(stream, state, NULL); call 0 returned 100% -: 312:#endif -: 313: -: 314: /* Setup an opj_image */ 14: 315: if (strcmp (im->mode, "L") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 316: components = 1; -: 317: color_space = OPJ_CLRSPC_GRAY; -: 318: pack = j2k_pack_l; 14: 319: } else if (strcmp (im->mode, "I;16") == 0){ branch 0 taken 86% (fallthrough) branch 1 taken 14% -: 320: components = 1; -: 321: color_space = OPJ_CLRSPC_GRAY; -: 322: pack = j2k_pack_i16; -: 323: prec = 16; -: 324: bpp = 12; 12: 325: } else if (strcmp (im->mode, "I;16B") == 0){ branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 326: components = 1; -: 327: color_space = OPJ_CLRSPC_GRAY; -: 328: pack = j2k_pack_i16; -: 329: prec = 16; -: 330: bpp = 12; 12: 331: } else if (strcmp (im->mode, "LA") == 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 332: components = 2; -: 333: color_space = OPJ_CLRSPC_GRAY; -: 334: pack = j2k_pack_la; 12: 335: } else if (strcmp (im->mode, "RGB") == 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% branch 4 taken 100% (fallthrough) branch 5 taken 0% branch 6 taken 0% (fallthrough) branch 7 taken 100% -: 336: components = 3; -: 337: color_space = OPJ_CLRSPC_SRGB; -: 338: pack = j2k_pack_rgb; #####: 339: } else if (strcmp (im->mode, "YCbCr") == 0) { branch 0 never executed branch 1 never executed -: 340: components = 3; -: 341: color_space = OPJ_CLRSPC_SYCC; -: 342: pack = j2k_pack_rgb; #####: 343: } else if (strcmp (im->mode, "RGBA") == 0) { branch 0 never executed branch 1 never executed -: 344: components = 4; -: 345: color_space = OPJ_CLRSPC_SRGB; -: 346: pack = j2k_pack_rgba; -: 347: } else { #####: 348: state->errcode = IMAGING_CODEC_BROKEN; #####: 349: state->state = J2K_STATE_FAILED; #####: 350: goto quick_exit; -: 351: } -: 352: 52: 353: for (n = 0; n < components; ++n) { branch 0 taken 73% branch 1 taken 27% (fallthrough) 38: 354: image_params[n].dx = image_params[n].dy = 1; 38: 355: image_params[n].w = im->xsize; 38: 356: image_params[n].h = im->ysize; 38: 357: image_params[n].x0 = image_params[n].y0 = 0; 38: 358: image_params[n].prec = prec; 38: 359: image_params[n].bpp = bpp; 38: 360: image_params[n].sgnd = 0; -: 361: } -: 362: 14: 363: image = opj_image_create(components, image_params, color_space); call 0 returned 100% 14: 364: if (!image) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 365: state->errcode = IMAGING_CODEC_BROKEN; #####: 366: state->state = J2K_STATE_FAILED; #####: 367: goto quick_exit; -: 368: } -: 369: -: 370: /* Setup compression context */ 14: 371: context->error_msg = NULL; -: 372: 14: 373: opj_set_default_encoder_parameters(¶ms); call 0 returned 100% -: 374: 14: 375: params.image_offset_x0 = context->offset_x; 14: 376: params.image_offset_y0 = context->offset_y; -: 377: 14: 378: if (context->tile_size_x && context->tile_size_y) { branch 0 taken 14% (fallthrough) branch 1 taken 86% branch 2 taken 100% (fallthrough) branch 3 taken 0% 2: 379: params.tile_size_on = OPJ_TRUE; 2: 380: params.cp_tx0 = context->tile_offset_x; 2: 381: params.cp_ty0 = context->tile_offset_y; 2: 382: params.cp_tdx = context->tile_size_x; 2: 383: params.cp_tdy = context->tile_size_y; -: 384: 2: 385: tile_width = params.cp_tdx; 2: 386: tile_height = params.cp_tdy; -: 387: } else { 12: 388: params.cp_tx0 = 0; 12: 389: params.cp_ty0 = 0; 12: 390: params.cp_tdx = 1; 12: 391: params.cp_tdy = 1; -: 392: 12: 393: tile_width = im->xsize; 12: 394: tile_height = im->ysize; -: 395: } -: 396: 14: 397: if (context->quality_layers && PySequence_Check(context->quality_layers)) { branch 0 taken 43% (fallthrough) branch 1 taken 57% call 2 returned 100% branch 3 taken 100% (fallthrough) branch 4 taken 0% 6: 398: Py_ssize_t len = PySequence_Length(context->quality_layers); call 0 returned 100% -: 399: Py_ssize_t n; -: 400: float *pq; -: 401: 6: 402: if (len > 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 6: 403: if ((unsigned)len > sizeof(params.tcp_rates) / sizeof(params.tcp_rates[0])) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 404: len = sizeof(params.tcp_rates)/sizeof(params.tcp_rates[0]); -: 405: } -: 406: 6: 407: params.tcp_numlayers = (int)len; -: 408: 6: 409: if (context->quality_is_in_db) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 410: params.cp_disto_alloc = params.cp_fixed_alloc = 0; #####: 411: params.cp_fixed_quality = 1; #####: 412: pq = params.tcp_distoratio; -: 413: } else { 6: 414: params.cp_disto_alloc = 1; 6: 415: params.cp_fixed_alloc = params.cp_fixed_quality = 0; 6: 416: pq = params.tcp_rates; -: 417: } -: 418: 20: 419: for (n = 0; n < len; ++n) { branch 0 taken 70% branch 1 taken 30% 14: 420: PyObject *obj = PySequence_ITEM(context->quality_layers, n); call 0 returned 100% 14: 421: pq[n] = PyFloat_AsDouble(obj); call 0 returned 100% -: 422: } -: 423: } -: 424: } else { 8: 425: params.tcp_numlayers = 1; 8: 426: params.tcp_rates[0] = 0; 8: 427: params.cp_disto_alloc = 1; -: 428: } -: 429: 14: 430: if (context->num_resolutions) { branch 0 taken 7% (fallthrough) branch 1 taken 93% 1: 431: params.numresolution = context->num_resolutions; -: 432: } -: 433: 14: 434: if (context->cblk_width >= 4 && context->cblk_width <= 1024 branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 435: && context->cblk_height >= 4 && context->cblk_height <= 1024 branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 436: && context->cblk_width * context->cblk_height <= 4096) { branch 0 never executed branch 1 never executed #####: 437: params.cblockw_init = context->cblk_width; #####: 438: params.cblockh_init = context->cblk_height; -: 439: } -: 440: 14: 441: if (context->precinct_width >= 4 && context->precinct_height >= 4 branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed #####: 442: && context->precinct_width >= context->cblk_width branch 0 never executed branch 1 never executed #####: 443: && context->precinct_height > context->cblk_height) { branch 0 never executed branch 1 never executed #####: 444: params.prcw_init[0] = context->precinct_width; #####: 445: params.prch_init[0] = context->precinct_height; #####: 446: params.res_spec = 1; #####: 447: params.csty |= 0x01; -: 448: } -: 449: 14: 450: params.irreversible = context->irreversible; -: 451: 14: 452: params.prog_order = context->progression; -: 453: 14: 454: params.cp_cinema = context->cinema_mode; -: 455: 14: 456: switch (params.cp_cinema) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% -: 457: case OPJ_OFF: 14: 458: params.cp_rsiz = OPJ_STD_RSIZ; 14: 459: break; -: 460: case OPJ_CINEMA2K_24: -: 461: case OPJ_CINEMA2K_48: #####: 462: params.cp_rsiz = OPJ_CINEMA2K; #####: 463: if (params.numresolution > 6) { branch 0 never executed branch 1 never executed #####: 464: params.numresolution = 6; -: 465: } -: 466: break; -: 467: case OPJ_CINEMA4K_24: #####: 468: params.cp_rsiz = OPJ_CINEMA4K; #####: 469: if (params.numresolution > 7) { branch 0 never executed branch 1 never executed #####: 470: params.numresolution = 7; -: 471: } -: 472: break; -: 473: } -: 474: 14: 475: if (context->cinema_mode != OPJ_OFF) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 476: j2k_set_cinema_params(im, components, ¶ms); call 0 never executed -: 477: } -: 478: -: 479: /* Set up the reference grid in the image */ 14: 480: image->x0 = params.image_offset_x0; 14: 481: image->y0 = params.image_offset_y0; 14: 482: image->x1 = xsiz = im->xsize + params.image_offset_x0; 14: 483: image->y1 = ysiz = im->ysize + params.image_offset_y0; -: 484: -: 485: /* Create the compressor */ 14: 486: codec = opj_create_compress(context->format); call 0 returned 100% -: 487: 14: 488: if (!codec) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 489: state->errcode = IMAGING_CODEC_BROKEN; #####: 490: state->state = J2K_STATE_FAILED; #####: 491: goto quick_exit; -: 492: } -: 493: 14: 494: opj_set_error_handler(codec, j2k_error, context); call 0 returned 100% 14: 495: opj_set_info_handler(codec, j2k_warn, context); call 0 returned 100% 14: 496: opj_set_warning_handler(codec, j2k_warn, context); call 0 returned 100% 14: 497: opj_setup_encoder(codec, ¶ms, image); call 0 returned 100% -: 498: -: 499: /* Start encoding */ 14: 500: if (!opj_start_compress(codec, image, stream)) { call 0 returned 100% branch 1 taken 7% (fallthrough) branch 2 taken 93% 1: 501: state->errcode = IMAGING_CODEC_BROKEN; 1: 502: state->state = J2K_STATE_FAILED; 1: 503: goto quick_exit; -: 504: } -: 505: -: 506: /* Write each tile */ 26: 507: tiles_x = (im->xsize + (params.image_offset_x0 - params.cp_tx0) 13: 508: + tile_width - 1) / tile_width; 26: 509: tiles_y = (im->ysize + (params.image_offset_y0 - params.cp_ty0) 13: 510: + tile_height - 1) / tile_height; -: 511: -: 512: /* check for integer overflow for the malloc line, checking any expression -: 513: that may multiply either tile_width or tile_height */ 13: 514: _overflow_scale_factor = components * prec; 13: 515: if (( tile_width > UINT_MAX / _overflow_scale_factor ) || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 13: 516: ( tile_height > UINT_MAX / _overflow_scale_factor ) || branch 0 taken 100% (fallthrough) branch 1 taken 0% 26: 517: ( tile_width > UINT_MAX / (tile_height * _overflow_scale_factor )) || branch 0 taken 0% (fallthrough) branch 1 taken 100% 13: 518: ( tile_height > UINT_MAX / (tile_width * _overflow_scale_factor ))) { #####: 519: state->errcode = IMAGING_CODEC_BROKEN; #####: 520: state->state = J2K_STATE_FAILED; #####: 521: goto quick_exit; -: 522: } -: 523: /* malloc check ok, checked for overflow above */ 13: 524: state->buffer = malloc (tile_width * tile_height * components * prec / 8); 13: 525: if (!state->buffer) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 526: state->errcode = IMAGING_CODEC_BROKEN; #####: 527: state->state = J2K_STATE_FAILED; #####: 528: goto quick_exit; -: 529: } -: 530: -: 531: tile_ndx = 0; 19: 532: for (y = 0; y < tiles_y; ++y) { branch 0 taken 59% branch 1 taken 41% (fallthrough) 19: 533: int ty0 = params.cp_ty0 + y * tile_height; 19: 534: unsigned ty1 = ty0 + tile_height; -: 535: unsigned pixy, pixh; -: 536: 19: 537: if (ty0 < params.image_offset_y0) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 1: 538: ty0 = params.image_offset_y0; -: 539: } 19: 540: if (ty1 > ysiz) { branch 0 taken 5% (fallthrough) branch 1 taken 95% 1: 541: ty1 = ysiz; -: 542: } -: 543: 19: 544: pixy = ty0 - params.image_offset_y0; 19: 545: pixh = ty1 - ty0; -: 546: 74: 547: for (x = 0; x < tiles_x; ++x) { branch 0 taken 74% branch 1 taken 26% (fallthrough) 55: 548: int tx0 = params.cp_tx0 + x * tile_width; 55: 549: unsigned tx1 = tx0 + tile_width; -: 550: unsigned pixx, pixw; -: 551: unsigned data_size; -: 552: 55: 553: if (tx0 < params.image_offset_x0) { branch 0 taken 7% (fallthrough) branch 1 taken 93% 4: 554: tx0 = params.image_offset_x0; -: 555: } 55: 556: if (tx1 > xsiz) { branch 0 taken 7% (fallthrough) branch 1 taken 93% 4: 557: tx1 = xsiz; -: 558: } -: 559: 55: 560: pixx = tx0 - params.image_offset_x0; 55: 561: pixw = tx1 - tx0; -: 562: 55: 563: pack(im, state->buffer, pixx, pixy, pixw, pixh); call 0 returned 100% -: 564: 55: 565: data_size = pixw * pixh * components * prec / 8; -: 566: 55: 567: if (!opj_write_tile(codec, tile_ndx++, state->buffer, call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% -: 568: data_size, stream)) { #####: 569: state->errcode = IMAGING_CODEC_BROKEN; #####: 570: state->state = J2K_STATE_FAILED; #####: 571: goto quick_exit; -: 572: } -: 573: } -: 574: } -: 575: 13: 576: if (!opj_end_compress(codec, stream)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 577: state->errcode = IMAGING_CODEC_BROKEN; #####: 578: state->state = J2K_STATE_FAILED; #####: 579: goto quick_exit; -: 580: } -: 581: 13: 582: state->errcode = IMAGING_CODEC_END; 13: 583: state->state = J2K_STATE_DONE; 13: 584: ret = -1; -: 585: -: 586: quick_exit: 14: 587: if (codec) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 14: 588: opj_destroy_codec(codec); call 0 returned 100% -: 589: } 14: 590: if (image) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 14: 591: opj_image_destroy(image); call 0 returned 100% -: 592: } 14: 593: if (stream) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 14: 594: opj_stream_destroy(stream); call 0 returned 100% -: 595: } -: 596: 14: 597: return ret; -: 598:} -: 599: -: 600:int function ImagingJpeg2KEncode called 14 returned 100% blocks executed 100% 14: 601:ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) -: 602:{ 14: 603: if (state->state == J2K_STATE_FAILED) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 604: return -1; -: 605: } -: 606: 14: 607: if (state->state == J2K_STATE_START) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 608: 14: 609: state->state = J2K_STATE_ENCODING; -: 610: 14: 611: return j2k_encode_entry(im, state); call 0 returned 100% -: 612: } -: 613: -: 614: return -1; -: 615:} -: 616: -: 617:/* -------------------------------------------------------------------- */ -: 618:/* Cleanup */ -: 619:/* -------------------------------------------------------------------- */ -: 620: -: 621:int function ImagingJpeg2KEncodeCleanup called 28 returned 100% blocks executed 88% 28: 622:ImagingJpeg2KEncodeCleanup(ImagingCodecState state) { 28: 623: JPEG2KENCODESTATE *context = (JPEG2KENCODESTATE *)state->context; -: 624: 28: 625: if (context->quality_layers) { branch 0 taken 21% (fallthrough) branch 1 taken 79% 6: 626: Py_XDECREF(context->quality_layers); branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% call 4 never executed 6: 627: context->quality_layers = NULL; -: 628: } -: 629: 28: 630: if (context->error_msg) { branch 0 taken 4% (fallthrough) branch 1 taken 96% 1: 631: free ((void *)context->error_msg); -: 632: } -: 633: 28: 634: context->error_msg = NULL; -: 635: -: 636: 28: 637: return -1; -: 638:} -: 639: -: 640:#endif /* HAVE_OPENJPEG */ -: 641: -: 642:/* -: 643: * Local Variables: -: 644: * c-basic-offset: 4 -: 645: * End: -: 646: * -: 647: */ <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#FliDecode.c.gcov -: 0:Source:src/libImaging/FliDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/FliDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/FliDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for Autodesk Animator FLI/FLC animations -: 6: * -: 7: * history: -: 8: * 97-01-03 fl Created -: 9: * 97-01-17 fl Added SS2 support (FLC) -: 10: * -: 11: * Copyright (c) Fredrik Lundh 1997. -: 12: * Copyright (c) Secret Labs AB 1997. -: 13: * -: 14: * See the README file for information on usage and redistribution. -: 15: */ -: 16: -: 17: -: 18:#include "Imaging.h" -: 19: -: 20: -: 21:#define I16(ptr)\ -: 22: ((ptr)[0] + ((ptr)[1] << 8)) -: 23: -: 24:#define I32(ptr)\ -: 25: ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24)) -: 26: -: 27:#define ERR_IF_DATA_OOB(offset) \ -: 28: if ((data + (offset)) > ptr + bytes) {\ -: 29: state->errcode = IMAGING_CODEC_OVERRUN; \ -: 30: return -1; \ -: 31: } -: 32: -: 33:int function ImagingFliDecode called 444 returned 100% blocks executed 45% 444: 34:ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) -: 35:{ -: 36: UINT8* ptr; -: 37: int framesize; -: 38: int c, chunks, advance; -: 39: int l, lines; 444: 40: int i, j, x = 0, y, ymax; -: 41: -: 42: /* If not even the chunk size is present, we'd better leave */ -: 43: 444: 44: if (bytes < 4) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 45: return 0; -: 46: } -: 47: -: 48: /* We don't decode anything unless we have a full chunk in the -: 49: input buffer */ -: 50: 443: 51: ptr = buf; -: 52: 443: 53: framesize = I32(ptr); -: 54: if (framesize < I32(ptr)) { -: 55: return 0; -: 56: } -: 57: -: 58: /* Make sure this is a frame chunk. The Python driver takes -: 59: case of other chunk types. */ -: 60: 443: 61: if (bytes < 8) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1: 62: state->errcode = IMAGING_CODEC_OVERRUN; 1: 63: return -1; -: 64: } 442: 65: if (I16(ptr+4) != 0xF1FA) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 66: state->errcode = IMAGING_CODEC_UNKNOWN; #####: 67: return -1; -: 68: } -: 69: 442: 70: chunks = I16(ptr+6); 442: 71: ptr += 16; 442: 72: bytes -= 16; -: 73: -: 74: /* Process subchunks */ 660: 75: for (c = 0; c < chunks; c++) { branch 0 taken 33% branch 1 taken 67% (fallthrough) -: 76: UINT8* data; 219: 77: if (bytes < 10) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 78: state->errcode = IMAGING_CODEC_OVERRUN; #####: 79: return -1; -: 80: } 219: 81: data = ptr + 6; 219: 82: switch (I16(ptr+4)) { branch 0 taken 4% branch 1 taken 0% branch 2 taken 0% branch 3 taken 91% branch 4 taken 0% branch 5 taken 0% branch 6 taken 5% -: 83: case 4: case 11: -: 84: /* FLI COLOR chunk */ -: 85: break; /* ignored; handled by Python code */ -: 86: case 7: -: 87: /* FLI SS2 chunk (word delta) */ -: 88: /* OOB ok, we've got 4 bytes min on entry */ #####: 89: lines = I16(data); data += 2; #####: 90: for (l = y = 0; l < lines && y < state->ysize; l++, y++) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 91: UINT8* local_buf = (UINT8*) im->image[y]; -: 92: int p, packets; #####: 93: ERR_IF_DATA_OOB(2) branch 0 never executed branch 1 never executed #####: 94: packets = I16(data); data += 2; #####: 95: while (packets & 0x8000) { branch 0 never executed branch 1 never executed -: 96: /* flag word */ #####: 97: if (packets & 0x4000) { branch 0 never executed branch 1 never executed #####: 98: y += 65536 - packets; /* skip lines */ #####: 99: if (y >= state->ysize) { branch 0 never executed branch 1 never executed #####: 100: state->errcode = IMAGING_CODEC_OVERRUN; #####: 101: return -1; -: 102: } #####: 103: local_buf = (UINT8*) im->image[y]; -: 104: } else { -: 105: /* store last byte (used if line width is odd) */ #####: 106: local_buf[state->xsize-1] = (UINT8) packets; -: 107: } #####: 108: ERR_IF_DATA_OOB(2) branch 0 never executed branch 1 never executed #####: 109: packets = I16(data); data += 2; -: 110: } #####: 111: for (p = x = 0; p < packets; p++) { branch 0 never executed branch 1 never executed #####: 112: ERR_IF_DATA_OOB(2) branch 0 never executed branch 1 never executed #####: 113: x += data[0]; /* pixel skip */ #####: 114: if (data[1] >= 128) { branch 0 never executed branch 1 never executed #####: 115: ERR_IF_DATA_OOB(4) branch 0 never executed branch 1 never executed #####: 116: i = 256-data[1]; /* run */ #####: 117: if (x + i + i > state->xsize) { branch 0 never executed branch 1 never executed -: 118: break; -: 119: } #####: 120: for (j = 0; j < i; j++) { branch 0 never executed branch 1 never executed #####: 121: local_buf[x++] = data[2]; #####: 122: local_buf[x++] = data[3]; -: 123: } -: 124: data += 2 + 2; -: 125: } else { #####: 126: i = 2 * (int) data[1]; /* chunk */ #####: 127: if (x + i > state->xsize) { branch 0 never executed branch 1 never executed -: 128: break; -: 129: } #####: 130: ERR_IF_DATA_OOB(2+i) branch 0 never executed branch 1 never executed #####: 131: memcpy(local_buf + x, data + 2, i); #####: 132: data += 2 + i; #####: 133: x += i; -: 134: } -: 135: } #####: 136: if (p < packets) { branch 0 never executed branch 1 never executed -: 137: break; /* didn't process all packets */ -: 138: } -: 139: } #####: 140: if (l < lines) { branch 0 never executed branch 1 never executed -: 141: /* didn't process all lines */ #####: 142: state->errcode = IMAGING_CODEC_OVERRUN; #####: 143: return -1; -: 144: } -: 145: break; -: 146: case 12: -: 147: /* FLI LC chunk (byte delta) */ -: 148: /* OOB Check ok, we have 4 bytes min here */ 200: 149: y = I16(data); ymax = y + I16(data+2); data += 4; 4518: 150: for (; y < ymax && y < state->ysize; y++) { branch 0 taken 96% (fallthrough) branch 1 taken 4% branch 2 taken 100% branch 3 taken 0% (fallthrough) 4318: 151: UINT8* out = (UINT8*) im->image[y]; 4318: 152: ERR_IF_DATA_OOB(1) branch 0 taken 0% (fallthrough) branch 1 taken 100% 4318: 153: int p, packets = *data++; 27803: 154: for (p = x = 0; p < packets; p++, x += i) { branch 0 taken 84% branch 1 taken 16% (fallthrough) 23485: 155: ERR_IF_DATA_OOB(2) branch 0 taken 0% (fallthrough) branch 1 taken 100% 23485: 156: x += data[0]; /* skip pixels */ 23485: 157: if (data[1] & 0x80) { branch 0 taken 53% (fallthrough) branch 1 taken 47% 12556: 158: i = 256-data[1]; /* run */ 12556: 159: if (x + i > state->xsize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 160: break; -: 161: } 12556: 162: ERR_IF_DATA_OOB(3) branch 0 taken 0% (fallthrough) branch 1 taken 100% 25112: 163: memset(out + x, data[2], i); 12556: 164: data += 3; -: 165: } else { 10929: 166: i = data[1]; /* chunk */ 10929: 167: if (x + i > state->xsize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 168: break; -: 169: } 10929: 170: ERR_IF_DATA_OOB(2+i) branch 0 taken 0% (fallthrough) branch 1 taken 100% 21858: 171: memcpy(out + x, data + 2, i); 10929: 172: data += i + 2; -: 173: } -: 174: } 4318: 175: if (p < packets) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 176: break; /* didn't process all packets */ -: 177: } -: 178: } 200: 179: if (y < ymax) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 180: /* didn't process all lines */ #####: 181: state->errcode = IMAGING_CODEC_OVERRUN; #####: 182: return -1; -: 183: } -: 184: break; -: 185: case 13: -: 186: /* FLI BLACK chunk */ #####: 187: for (y = 0; y < state->ysize; y++) { branch 0 never executed branch 1 never executed #####: 188: memset(im->image[y], 0, state->xsize); -: 189: } -: 190: break; -: 191: case 15: -: 192: /* FLI BRUN chunk */ -: 193: /* OOB, ok, we've got 4 bytes min on entry */ 1312: 194: for (y = 0; y < state->ysize; y++) { branch 0 taken 99% branch 1 taken 1% 1312: 195: UINT8* out = (UINT8*) im->image[y]; 1312: 196: data += 1; /* ignore packetcount byte */ 15620: 197: for (x = 0; x < state->xsize; x += i) { branch 0 taken 92% branch 1 taken 8% (fallthrough) 14308: 198: ERR_IF_DATA_OOB(2) branch 0 taken 0% (fallthrough) branch 1 taken 100% 14308: 199: if (data[0] & 0x80) { branch 0 taken 39% (fallthrough) branch 1 taken 61% 5532: 200: i = 256 - data[0]; 5532: 201: if (x + i > state->xsize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 202: break; /* safety first */ -: 203: } 5532: 204: ERR_IF_DATA_OOB(i+1) branch 0 taken 0% (fallthrough) branch 1 taken 100% 11064: 205: memcpy(out + x, data + 1, i); 5532: 206: data += i + 1; -: 207: } else { 8776: 208: i = data[0]; 8776: 209: if (x + i > state->xsize) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 210: break; /* safety first */ -: 211: } 17552: 212: memset(out + x, data[1], i); 8776: 213: data += 2; -: 214: } -: 215: } 1312: 216: if (x != state->xsize) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 217: /* didn't unpack whole line */ #####: 218: state->errcode = IMAGING_CODEC_OVERRUN; #####: 219: return -1; -: 220: } -: 221: } -: 222: break; -: 223: case 16: -: 224: /* COPY chunk */ #####: 225: if (state->xsize > bytes/state->ysize) { branch 0 never executed branch 1 never executed -: 226: /* not enough data for frame */ #####: 227: return ptr - buf; /* bytes consumed */ -: 228: } #####: 229: for (y = 0; y < state->ysize; y++) { branch 0 never executed branch 1 never executed #####: 230: UINT8* local_buf = (UINT8*) im->image[y]; #####: 231: memcpy(local_buf, data, state->xsize); #####: 232: data += state->xsize; -: 233: } -: 234: break; -: 235: case 18: -: 236: /* PSTAMP chunk */ -: 237: break; /* ignored */ -: 238: default: -: 239: /* unknown chunk */ -: 240: /* printf("unknown FLI/FLC chunk: %d\n", I16(ptr+4)); */ #####: 241: state->errcode = IMAGING_CODEC_UNKNOWN; #####: 242: return -1; -: 243: } 219: 244: advance = I32(ptr); 219: 245: if (advance < 0 || advance > bytes) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 1% (fallthrough) branch 3 taken 99% 1: 246: state->errcode = IMAGING_CODEC_OVERRUN; 1: 247: return -1; -: 248: } 218: 249: ptr += advance; 218: 250: bytes -= advance; -: 251: } -: 252: -: 253: return -1; /* end of frame */ -: 254:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Jpeg2KDecode.c.gcov -: 0:Source:src/libImaging/Jpeg2KDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Jpeg2KDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Jpeg2KDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for JPEG2000 image data. -: 6: * -: 7: * history: -: 8: * 2014-03-12 ajh Created -: 9: * -: 10: * Copyright (c) 2014 Coriolis Systems Limited -: 11: * Copyright (c) 2014 Alastair Houghton -: 12: * -: 13: * See the README file for details on usage and redistribution. -: 14: */ -: 15: -: 16:#include "Imaging.h" -: 17: -: 18:#ifdef HAVE_OPENJPEG -: 19: -: 20:#include -: 21:#include "Jpeg2K.h" -: 22: -: 23:typedef struct { -: 24: OPJ_UINT32 tile_index; -: 25: OPJ_UINT32 data_size; -: 26: OPJ_INT32 x0, y0, x1, y1; -: 27: OPJ_UINT32 nb_comps; -: 28:} JPEG2KTILEINFO; -: 29: -: 30:/* -------------------------------------------------------------------- */ -: 31:/* Error handler */ -: 32:/* -------------------------------------------------------------------- */ -: 33: -: 34:static void function j2k_error called 0 returned 0% blocks executed 0% #####: 35:j2k_error(const char *msg, void *client_data) -: 36:{ #####: 37: JPEG2KDECODESTATE *state = (JPEG2KDECODESTATE *) client_data; #####: 38: free((void *)state->error_msg); #####: 39: state->error_msg = strdup(msg); call 0 never executed #####: 40:} -: 41: -: 42:/* -------------------------------------------------------------------- */ -: 43:/* Buffer input stream */ -: 44:/* -------------------------------------------------------------------- */ -: 45: -: 46:static OPJ_SIZE_T function j2k_read called 62 returned 100% blocks executed 100% 62: 47:j2k_read(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data) -: 48:{ 62: 49: ImagingCodecState state = (ImagingCodecState)p_user_data; -: 50: 62: 51: size_t len = _imaging_read_pyFd(state->fd, p_buffer, p_nb_bytes); call 0 returned 100% -: 52: 62: 53: return len ? len : (OPJ_SIZE_T)-1; branch 0 taken 53% (fallthrough) branch 1 taken 47% -: 54:} -: 55: -: 56:static OPJ_OFF_T function j2k_skip called 0 returned 0% blocks executed 0% #####: 57:j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data) -: 58:{ -: 59: off_t pos; #####: 60: ImagingCodecState state = (ImagingCodecState)p_user_data; -: 61: #####: 62: _imaging_seek_pyFd(state->fd, p_nb_bytes, SEEK_CUR); call 0 never executed #####: 63: pos = _imaging_tell_pyFd(state->fd); call 0 never executed -: 64: #####: 65: return pos ? pos : (OPJ_OFF_T)-1; branch 0 never executed branch 1 never executed -: 66:} -: 67: -: 68:/* -------------------------------------------------------------------- */ -: 69:/* Unpackers */ -: 70:/* -------------------------------------------------------------------- */ -: 71: -: 72:typedef void (*j2k_unpacker_t)(opj_image_t *in, -: 73: const JPEG2KTILEINFO *tileInfo, -: 74: const UINT8 *data, -: 75: Imaging im); -: 76: -: 77:struct j2k_decode_unpacker { -: 78: const char *mode; -: 79: OPJ_COLOR_SPACE color_space; -: 80: unsigned components; -: 81: j2k_unpacker_t unpacker; -: 82:}; -: 83: -: 84:static inline -: 85:unsigned j2ku_shift(unsigned x, int n) -: 86:{ 19927296: 87: if (n < 0) { branch 0 never executed branch 1 never executed branch 2 taken 0% (fallthrough) branch 3 taken 100% branch 4 never executed branch 5 never executed branch 6 taken 0% (fallthrough) branch 7 taken 100% branch 8 never executed branch 9 never executed branch 10 never executed branch 11 never executed branch 12 never executed branch 13 never executed branch 14 never executed branch 15 never executed branch 16 never executed branch 17 never executed branch 18 never executed branch 19 never executed branch 20 taken 0% (fallthrough) branch 21 taken 100% branch 22 never executed branch 23 never executed branch 24 never executed branch 25 never executed branch 26 never executed branch 27 never executed branch 28 never executed branch 29 never executed #####: 88: return x >> -n; -: 89: } else { 19927296: 90: return x << n; -: 91: } -: 92:} -: 93: -: 94:static void function j2ku_gray_l called 0 returned 0% blocks executed 0% #####: 95:j2ku_gray_l(opj_image_t *in, const JPEG2KTILEINFO *tileinfo, -: 96: const UINT8 *tiledata, Imaging im) -: 97:{ #####: 98: unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; #####: 99: unsigned w = tileinfo->x1 - tileinfo->x0; #####: 100: unsigned h = tileinfo->y1 - tileinfo->y0; -: 101: #####: 102: int shift = 8 - in->comps[0].prec; #####: 103: int offset = in->comps[0].sgnd ? 1 << (in->comps[0].prec - 1) : 0; branch 0 never executed branch 1 never executed #####: 104: int csiz = (in->comps[0].prec + 7) >> 3; -: 105: -: 106: unsigned x, y; -: 107: #####: 108: if (csiz == 3) { branch 0 never executed branch 1 never executed #####: 109: csiz = 4; -: 110: } -: 111: #####: 112: if (shift < 0) { branch 0 never executed branch 1 never executed #####: 113: offset += 1 << (-shift - 1); -: 114: } -: 115: -: 116: /* csiz*h*w + offset = tileinfo.datasize */ #####: 117: switch (csiz) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed -: 118: case 1: #####: 119: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 120: const UINT8 *data = &tiledata[y * w]; #####: 121: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0; #####: 122: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 123: *row++ = j2ku_shift(offset + *data++, shift); -: 124: } -: 125: } -: 126: break; -: 127: case 2: #####: 128: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 129: const UINT16 *data = (const UINT16 *)&tiledata[2 * y * w]; #####: 130: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0; #####: 131: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 132: *row++ = j2ku_shift(offset + *data++, shift); -: 133: } -: 134: } -: 135: break; -: 136: case 4: #####: 137: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 138: const UINT32 *data = (const UINT32 *)&tiledata[4 * y * w]; #####: 139: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0; #####: 140: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 141: *row++ = j2ku_shift(offset + *data++, shift); -: 142: } -: 143: } -: 144: break; -: 145: } #####: 146:} -: 147: -: 148: -: 149:static void function j2ku_gray_i called 8 returned 100% blocks executed 37% 8: 150:j2ku_gray_i(opj_image_t *in, const JPEG2KTILEINFO *tileinfo, -: 151: const UINT8 *tiledata, Imaging im) -: 152:{ 8: 153: unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; 8: 154: unsigned w = tileinfo->x1 - tileinfo->x0; 8: 155: unsigned h = tileinfo->y1 - tileinfo->y0; -: 156: 8: 157: int shift = 16 - in->comps[0].prec; 8: 158: int offset = in->comps[0].sgnd ? 1 << (in->comps[0].prec - 1) : 0; branch 0 taken 0% (fallthrough) branch 1 taken 100% 8: 159: int csiz = (in->comps[0].prec + 7) >> 3; -: 160: -: 161: unsigned x, y; -: 162: 8: 163: if (csiz == 3) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 164: csiz = 4; -: 165: } -: 166: 8: 167: if (shift < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 168: offset += 1 << (-shift - 1); -: 169: } -: 170: 8: 171: switch (csiz) { branch 0 taken 0% branch 1 taken 100% branch 2 taken 0% branch 3 taken 0% -: 172: case 1: #####: 173: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 174: const UINT8 *data = &tiledata[y * w]; #####: 175: UINT16 *row = (UINT16 *)im->image[y0 + y] + x0; #####: 176: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 177: *row++ = j2ku_shift(offset + *data++, shift); -: 178: } -: 179: } -: 180: break; -: 181: case 2: 512: 182: for (y = 0; y < h; ++y) { branch 0 taken 98% branch 1 taken 2% 512: 183: const UINT16 *data = (const UINT16 *)&tiledata[2 * y * w]; 512: 184: UINT16 *row = (UINT16 *)im->image[y0 + y] + x0; 33280: 185: for (x = 0; x < w; ++x) { branch 0 taken 98% branch 1 taken 2% (fallthrough) 65536: 186: *row++ = j2ku_shift(offset + *data++, shift); -: 187: } -: 188: } -: 189: break; -: 190: case 4: #####: 191: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 192: const UINT32 *data = (const UINT32 *)&tiledata[4 * y * w]; #####: 193: UINT16 *row = (UINT16 *)im->image[y0 + y] + x0; #####: 194: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 195: *row++ = j2ku_shift(offset + *data++, shift); -: 196: } -: 197: } -: 198: break; -: 199: } 8: 200:} -: 201: -: 202: -: 203:static void function j2ku_gray_rgb called 0 returned 0% blocks executed 0% #####: 204:j2ku_gray_rgb(opj_image_t *in, const JPEG2KTILEINFO *tileinfo, -: 205: const UINT8 *tiledata, Imaging im) -: 206:{ #####: 207: unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; #####: 208: unsigned w = tileinfo->x1 - tileinfo->x0; #####: 209: unsigned h = tileinfo->y1 - tileinfo->y0; -: 210: #####: 211: int shift = 8 - in->comps[0].prec; #####: 212: int offset = in->comps[0].sgnd ? 1 << (in->comps[0].prec - 1) : 0; branch 0 never executed branch 1 never executed #####: 213: int csiz = (in->comps[0].prec + 7) >> 3; -: 214: -: 215: unsigned x, y; -: 216: #####: 217: if (shift < 0) { branch 0 never executed branch 1 never executed #####: 218: offset += 1 << (-shift - 1); -: 219: } -: 220: #####: 221: if (csiz == 3) { branch 0 never executed branch 1 never executed #####: 222: csiz = 4; -: 223: } -: 224: #####: 225: switch (csiz) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed -: 226: case 1: #####: 227: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 228: const UINT8 *data = &tiledata[y * w]; #####: 229: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0; #####: 230: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 231: UINT8 byte = j2ku_shift(offset + *data++, shift); #####: 232: row[0] = row[1] = row[2] = byte; #####: 233: row[3] = 0xff; #####: 234: row += 4; -: 235: } -: 236: } -: 237: break; -: 238: case 2: #####: 239: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 240: const UINT16 *data = (UINT16 *)&tiledata[2 * y * w]; #####: 241: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0; #####: 242: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 243: UINT8 byte = j2ku_shift(offset + *data++, shift); #####: 244: row[0] = row[1] = row[2] = byte; #####: 245: row[3] = 0xff; #####: 246: row += 4; -: 247: } -: 248: } -: 249: break; -: 250: case 4: #####: 251: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 252: const UINT32 *data = (UINT32 *)&tiledata[4 * y * w]; #####: 253: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0; #####: 254: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 255: UINT8 byte = j2ku_shift(offset + *data++, shift); #####: 256: row[0] = row[1] = row[2] = byte; #####: 257: row[3] = 0xff; #####: 258: row += 4; -: 259: } -: 260: } -: 261: break; -: 262: } #####: 263:} -: 264: -: 265:static void function j2ku_graya_la called 0 returned 0% blocks executed 0% #####: 266:j2ku_graya_la(opj_image_t *in, const JPEG2KTILEINFO *tileinfo, -: 267: const UINT8 *tiledata, Imaging im) -: 268:{ #####: 269: unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; #####: 270: unsigned w = tileinfo->x1 - tileinfo->x0; #####: 271: unsigned h = tileinfo->y1 - tileinfo->y0; -: 272: #####: 273: int shift = 8 - in->comps[0].prec; #####: 274: int offset = in->comps[0].sgnd ? 1 << (in->comps[0].prec - 1) : 0; branch 0 never executed branch 1 never executed #####: 275: int csiz = (in->comps[0].prec + 7) >> 3; #####: 276: int ashift = 8 - in->comps[1].prec; #####: 277: int aoffset = in->comps[1].sgnd ? 1 << (in->comps[1].prec - 1) : 0; branch 0 never executed branch 1 never executed #####: 278: int acsiz = (in->comps[1].prec + 7) >> 3; -: 279: const UINT8 *atiledata; -: 280: -: 281: unsigned x, y; -: 282: #####: 283: if (csiz == 3) { branch 0 never executed branch 1 never executed #####: 284: csiz = 4; -: 285: } #####: 286: if (acsiz == 3) { branch 0 never executed branch 1 never executed #####: 287: acsiz = 4; -: 288: } -: 289: #####: 290: if (shift < 0) { branch 0 never executed branch 1 never executed #####: 291: offset += 1 << (-shift - 1); -: 292: } #####: 293: if (ashift < 0) { branch 0 never executed branch 1 never executed #####: 294: aoffset += 1 << (-ashift - 1); -: 295: } -: 296: #####: 297: atiledata = tiledata + csiz * w * h; -: 298: #####: 299: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed #####: 300: const UINT8 *data = &tiledata[csiz * y * w]; #####: 301: const UINT8 *adata = &atiledata[acsiz * y * w]; #####: 302: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4; #####: 303: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 304: UINT32 word = 0, aword = 0, byte; -: 305: #####: 306: switch (csiz) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 307: case 1: word = *data++; break; #####: 308: case 2: word = *(const UINT16 *)data; data += 2; break; #####: 309: case 4: word = *(const UINT32 *)data; data += 4; break; -: 310: } -: 311: #####: 312: switch (acsiz) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 313: case 1: aword = *adata++; break; #####: 314: case 2: aword = *(const UINT16 *)adata; adata += 2; break; #####: 315: case 4: aword = *(const UINT32 *)adata; adata += 4; break; -: 316: } -: 317: #####: 318: byte = j2ku_shift(offset + word, shift); #####: 319: row[0] = row[1] = row[2] = byte; #####: 320: row[3] = j2ku_shift(aoffset + aword, ashift); #####: 321: row += 4; -: 322: } -: 323: } #####: 324:} -: 325: -: 326:static void function j2ku_srgb_rgb called 76 returned 100% blocks executed 79% 76: 327:j2ku_srgb_rgb(opj_image_t *in, const JPEG2KTILEINFO *tileinfo, -: 328: const UINT8 *tiledata, Imaging im) -: 329:{ 76: 330: unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; 76: 331: unsigned w = tileinfo->x1 - tileinfo->x0; 76: 332: unsigned h = tileinfo->y1 - tileinfo->y0; -: 333: -: 334: int shifts[3], offsets[3], csiz[3]; -: 335: const UINT8 *cdata[3]; 76: 336: const UINT8 *cptr = tiledata; -: 337: unsigned n, x, y; -: 338: 304: 339: for (n = 0; n < 3; ++n) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 228: 340: cdata[n] = cptr; 228: 341: shifts[n] = 8 - in->comps[n].prec; 228: 342: offsets[n] = in->comps[n].sgnd ? 1 << (in->comps[n].prec - 1) : 0; branch 0 taken 0% (fallthrough) branch 1 taken 100% 228: 343: csiz[n] = (in->comps[n].prec + 7) >> 3; -: 344: 228: 345: if (csiz[n] == 3) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 346: csiz[n] = 4; -: 347: } -: 348: 228: 349: if (shifts[n] < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 350: offsets[n] += 1 << (-shifts[n] - 1); -: 351: } -: 352: 228: 353: cptr += csiz[n] * w * h; -: 354: } -: 355: 13080: 356: for (y = 0; y < h; ++y) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 357: const UINT8 *data[3]; 13080: 358: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4; 52320: 359: for (n = 0; n < 3; ++n) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 39240: 360: data[n] = &cdata[n][csiz[n] * y * w]; -: 361: } -: 362: 4320000: 363: for (x = 0; x < w; ++x) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 12960000: 364: for (n = 0; n < 3; ++n) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 12960000: 365: UINT32 word = 0; -: 366: 12960000: 367: switch (csiz[n]) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% 12960000: 368: case 1: word = *data[n]++; break; #####: 369: case 2: word = *(const UINT16 *)data[n]; data[n] += 2; break; #####: 370: case 4: word = *(const UINT32 *)data[n]; data[n] += 4; break; -: 371: } -: 372: 25920000: 373: row[n] = j2ku_shift(offsets[n] + word, shifts[n]); -: 374: } 4320000: 375: row[3] = 0xff; 4320000: 376: row += 4; -: 377: } -: 378: } 76: 379:} -: 380: -: 381:static void function j2ku_sycc_rgb called 0 returned 0% blocks executed 0% #####: 382:j2ku_sycc_rgb(opj_image_t *in, const JPEG2KTILEINFO *tileinfo, -: 383: const UINT8 *tiledata, Imaging im) -: 384:{ #####: 385: unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; #####: 386: unsigned w = tileinfo->x1 - tileinfo->x0; #####: 387: unsigned h = tileinfo->y1 - tileinfo->y0; -: 388: -: 389: int shifts[3], offsets[3], csiz[3]; -: 390: const UINT8 *cdata[3]; #####: 391: const UINT8 *cptr = tiledata; -: 392: unsigned n, x, y; -: 393: #####: 394: for (n = 0; n < 3; ++n) { branch 0 never executed branch 1 never executed #####: 395: cdata[n] = cptr; #####: 396: shifts[n] = 8 - in->comps[n].prec; #####: 397: offsets[n] = in->comps[n].sgnd ? 1 << (in->comps[n].prec - 1) : 0; branch 0 never executed branch 1 never executed #####: 398: csiz[n] = (in->comps[n].prec + 7) >> 3; -: 399: #####: 400: if (csiz[n] == 3) { branch 0 never executed branch 1 never executed #####: 401: csiz[n] = 4; -: 402: } -: 403: #####: 404: if (shifts[n] < 0) { branch 0 never executed branch 1 never executed #####: 405: offsets[n] += 1 << (-shifts[n] - 1); -: 406: } -: 407: #####: 408: cptr += csiz[n] * w * h; -: 409: } -: 410: #####: 411: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed -: 412: const UINT8 *data[3]; #####: 413: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4; #####: 414: UINT8 *row_start = row; #####: 415: for (n = 0; n < 3; ++n) { branch 0 never executed branch 1 never executed #####: 416: data[n] = &cdata[n][csiz[n] * y * w]; -: 417: } -: 418: #####: 419: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 420: for (n = 0; n < 3; ++n) { branch 0 never executed branch 1 never executed #####: 421: UINT32 word = 0; -: 422: #####: 423: switch (csiz[n]) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 424: case 1: word = *data[n]++; break; #####: 425: case 2: word = *(const UINT16 *)data[n]; data[n] += 2; break; #####: 426: case 4: word = *(const UINT32 *)data[n]; data[n] += 4; break; -: 427: } -: 428: #####: 429: row[n] = j2ku_shift(offsets[n] + word, shifts[n]); -: 430: } #####: 431: row[3] = 0xff; #####: 432: row += 4; -: 433: } -: 434: #####: 435: ImagingConvertYCbCr2RGB(row_start, row_start, w); call 0 never executed -: 436: } #####: 437:} -: 438: -: 439:static void function j2ku_srgba_rgba called 10 returned 100% blocks executed 79% 10: 440:j2ku_srgba_rgba(opj_image_t *in, const JPEG2KTILEINFO *tileinfo, -: 441: const UINT8 *tiledata, Imaging im) -: 442:{ 10: 443: unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; 10: 444: unsigned w = tileinfo->x1 - tileinfo->x0; 10: 445: unsigned h = tileinfo->y1 - tileinfo->y0; -: 446: -: 447: int shifts[4], offsets[4], csiz[4]; -: 448: const UINT8 *cdata[4]; 10: 449: const UINT8 *cptr = tiledata; -: 450: unsigned n, x, y; -: 451: 50: 452: for (n = 0; n < 4; ++n) { branch 0 taken 80% branch 1 taken 20% (fallthrough) 40: 453: cdata[n] = cptr; 40: 454: shifts[n] = 8 - in->comps[n].prec; 40: 455: offsets[n] = in->comps[n].sgnd ? 1 << (in->comps[n].prec - 1) : 0; branch 0 taken 0% (fallthrough) branch 1 taken 100% 40: 456: csiz[n] = (in->comps[n].prec + 7) >> 3; -: 457: 40: 458: if (csiz[n] == 3) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 459: csiz[n] = 4; -: 460: } -: 461: 40: 462: if (shifts[n] < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 463: offsets[n] += 1 << (-shifts[n] - 1); -: 464: } -: 465: 40: 466: cptr += csiz[n] * w * h; -: 467: } -: 468: 2912: 469: for (y = 0; y < h; ++y) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 470: const UINT8 *data[4]; 2912: 471: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4; 14560: 472: for (n = 0; n < 4; ++n) { branch 0 taken 80% branch 1 taken 20% (fallthrough) 11648: 473: data[n] = &cdata[n][csiz[n] * y * w]; -: 474: } -: 475: 1733632: 476: for (x = 0; x < w; ++x) { branch 0 taken 99% (fallthrough) branch 1 taken 1% 6934528: 477: for (n = 0; n < 4; ++n) { branch 0 taken 80% branch 1 taken 20% (fallthrough) 6934528: 478: UINT32 word = 0; -: 479: 6934528: 480: switch (csiz[n]) { branch 0 taken 100% branch 1 taken 0% branch 2 taken 0% branch 3 taken 0% 6934528: 481: case 1: word = *data[n]++; break; #####: 482: case 2: word = *(const UINT16 *)data[n]; data[n] += 2; break; #####: 483: case 4: word = *(const UINT32 *)data[n]; data[n] += 4; break; -: 484: } -: 485: 13869056: 486: row[n] = j2ku_shift(offsets[n] + word, shifts[n]); -: 487: } 1733632: 488: row += 4; -: 489: } -: 490: } 10: 491:} -: 492: -: 493:static void function j2ku_sycca_rgba called 0 returned 0% blocks executed 0% #####: 494:j2ku_sycca_rgba(opj_image_t *in, const JPEG2KTILEINFO *tileinfo, -: 495: const UINT8 *tiledata, Imaging im) -: 496:{ #####: 497: unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; #####: 498: unsigned w = tileinfo->x1 - tileinfo->x0; #####: 499: unsigned h = tileinfo->y1 - tileinfo->y0; -: 500: -: 501: int shifts[4], offsets[4], csiz[4]; -: 502: const UINT8 *cdata[4]; #####: 503: const UINT8 *cptr = tiledata; -: 504: unsigned n, x, y; -: 505: #####: 506: for (n = 0; n < 4; ++n) { branch 0 never executed branch 1 never executed #####: 507: cdata[n] = cptr; #####: 508: shifts[n] = 8 - in->comps[n].prec; #####: 509: offsets[n] = in->comps[n].sgnd ? 1 << (in->comps[n].prec - 1) : 0; branch 0 never executed branch 1 never executed #####: 510: csiz[n] = (in->comps[n].prec + 7) >> 3; -: 511: #####: 512: if (csiz[n] == 3) { branch 0 never executed branch 1 never executed #####: 513: csiz[n] = 4; -: 514: } -: 515: #####: 516: if (shifts[n] < 0) { branch 0 never executed branch 1 never executed #####: 517: offsets[n] += 1 << (-shifts[n] - 1); -: 518: } -: 519: #####: 520: cptr += csiz[n] * w * h; -: 521: } -: 522: #####: 523: for (y = 0; y < h; ++y) { branch 0 never executed branch 1 never executed -: 524: const UINT8 *data[4]; #####: 525: UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4; #####: 526: UINT8 *row_start = row; #####: 527: for (n = 0; n < 4; ++n) { branch 0 never executed branch 1 never executed #####: 528: data[n] = &cdata[n][csiz[n] * y * w]; -: 529: } -: 530: #####: 531: for (x = 0; x < w; ++x) { branch 0 never executed branch 1 never executed #####: 532: for (n = 0; n < 4; ++n) { branch 0 never executed branch 1 never executed #####: 533: UINT32 word = 0; -: 534: #####: 535: switch (csiz[n]) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 536: case 1: word = *data[n]++; break; #####: 537: case 2: word = *(const UINT16 *)data[n]; data[n] += 2; break; #####: 538: case 4: word = *(const UINT32 *)data[n]; data[n] += 4; break; -: 539: } -: 540: #####: 541: row[n] = j2ku_shift(offsets[n] + word, shifts[n]); -: 542: } #####: 543: row += 4; -: 544: } -: 545: #####: 546: ImagingConvertYCbCr2RGB(row_start, row_start, w); call 0 never executed -: 547: } #####: 548:} -: 549: -: 550:static const struct j2k_decode_unpacker j2k_unpackers[] = { -: 551: { "L", OPJ_CLRSPC_GRAY, 1, j2ku_gray_l }, -: 552: { "I;16", OPJ_CLRSPC_GRAY, 1, j2ku_gray_i }, -: 553: { "I;16B", OPJ_CLRSPC_GRAY, 1, j2ku_gray_i }, -: 554: { "LA", OPJ_CLRSPC_GRAY, 2, j2ku_graya_la }, -: 555: { "RGB", OPJ_CLRSPC_GRAY, 1, j2ku_gray_rgb }, -: 556: { "RGB", OPJ_CLRSPC_GRAY, 2, j2ku_gray_rgb }, -: 557: { "RGB", OPJ_CLRSPC_SRGB, 3, j2ku_srgb_rgb }, -: 558: { "RGB", OPJ_CLRSPC_SYCC, 3, j2ku_sycc_rgb }, -: 559: { "RGB", OPJ_CLRSPC_SRGB, 4, j2ku_srgb_rgb }, -: 560: { "RGB", OPJ_CLRSPC_SYCC, 4, j2ku_sycc_rgb }, -: 561: { "RGBA", OPJ_CLRSPC_GRAY, 1, j2ku_gray_rgb }, -: 562: { "RGBA", OPJ_CLRSPC_GRAY, 2, j2ku_graya_la }, -: 563: { "RGBA", OPJ_CLRSPC_SRGB, 3, j2ku_srgb_rgb }, -: 564: { "RGBA", OPJ_CLRSPC_SYCC, 3, j2ku_sycc_rgb }, -: 565: { "RGBA", OPJ_CLRSPC_SRGB, 4, j2ku_srgba_rgba }, -: 566: { "RGBA", OPJ_CLRSPC_SYCC, 4, j2ku_sycca_rgba }, -: 567:}; -: 568: -: 569:/* -------------------------------------------------------------------- */ -: 570:/* Decoder */ -: 571:/* -------------------------------------------------------------------- */ -: 572: -: 573:enum { -: 574: J2K_STATE_START = 0, -: 575: J2K_STATE_DECODING = 1, -: 576: J2K_STATE_DONE = 2, -: 577: J2K_STATE_FAILED = 3, -: 578:}; -: 579: -: 580:static int function j2k_decode_entry called 33 returned 100% blocks executed 80% 33: 581:j2k_decode_entry(Imaging im, ImagingCodecState state) -: 582:{ 33: 583: JPEG2KDECODESTATE *context = (JPEG2KDECODESTATE *) state->context; 33: 584: opj_stream_t *stream = NULL; 33: 585: opj_image_t *image = NULL; 33: 586: opj_codec_t *codec = NULL; -: 587: opj_dparameters_t params; -: 588: OPJ_COLOR_SPACE color_space; 33: 589: j2k_unpacker_t unpack = NULL; 33: 590: size_t buffer_size = 0, tile_bytes = 0; -: 591: unsigned n, tile_height, tile_width; -: 592: int components; -: 593: -: 594: 33: 595: stream = opj_stream_create(BUFFER_SIZE, OPJ_TRUE); call 0 returned 100% -: 596: 33: 597: if (!stream) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 598: state->errcode = IMAGING_CODEC_BROKEN; #####: 599: state->state = J2K_STATE_FAILED; #####: 600: goto quick_exit; -: 601: } -: 602: 33: 603: opj_stream_set_read_function(stream, j2k_read); call 0 returned 100% 33: 604: opj_stream_set_skip_function(stream, j2k_skip); call 0 returned 100% -: 605: -: 606: /* OpenJPEG 2.0 doesn't have OPJ_VERSION_MAJOR */ -: 607:#ifndef OPJ_VERSION_MAJOR -: 608: opj_stream_set_user_data(stream, state); -: 609:#else 33: 610: opj_stream_set_user_data(stream, state, NULL); call 0 returned 100% -: 611: -: 612: /* Hack: if we don't know the length, the largest file we can -: 613: possibly support is 4GB. We can't go larger than this, because -: 614: OpenJPEG truncates this value for the final box in the file, and -: 615: the box lengths in OpenJPEG are currently 32 bit. */ 33: 616: if (context->length < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 617: opj_stream_set_user_data_length(stream, 0xffffffff); call 0 never executed -: 618: } else { 33: 619: opj_stream_set_user_data_length(stream, context->length); call 0 returned 100% -: 620: } -: 621:#endif -: 622: -: 623: /* Setup decompression context */ 33: 624: context->error_msg = NULL; -: 625: 33: 626: opj_set_default_decoder_parameters(¶ms); call 0 returned 100% 33: 627: params.cp_reduce = context->reduce; 33: 628: params.cp_layer = context->layers; -: 629: 33: 630: codec = opj_create_decompress(context->format); call 0 returned 100% -: 631: 33: 632: if (!codec) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 633: state->errcode = IMAGING_CODEC_BROKEN; #####: 634: state->state = J2K_STATE_FAILED; #####: 635: goto quick_exit; -: 636: } -: 637: 33: 638: opj_set_error_handler(codec, j2k_error, context); call 0 returned 100% 33: 639: opj_setup_decoder(codec, ¶ms); call 0 returned 100% -: 640: 33: 641: if (!opj_read_header(stream, codec, &image)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 642: state->errcode = IMAGING_CODEC_BROKEN; #####: 643: state->state = J2K_STATE_FAILED; #####: 644: goto quick_exit; -: 645: } -: 646: -: 647: /* Check that this image is something we can handle */ 33: 648: if (image->numcomps < 1 || image->numcomps > 4 branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 649: || image->color_space == OPJ_CLRSPC_UNKNOWN) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 650: state->errcode = IMAGING_CODEC_BROKEN; #####: 651: state->state = J2K_STATE_FAILED; #####: 652: goto quick_exit; -: 653: } -: 654: 60: 655: for (n = 1; n < image->numcomps; ++n) { branch 0 taken 65% branch 1 taken 35% (fallthrough) 60: 656: if (image->comps[n].dx != 1 || image->comps[n].dy != 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 657: state->errcode = IMAGING_CODEC_BROKEN; #####: 658: state->state = J2K_STATE_FAILED; #####: 659: goto quick_exit; -: 660: } -: 661: } -: 662: -: 663: /* -: 664: Colorspace Number of components PIL mode -: 665: ------------------------------------------------------ -: 666: sRGB 3 RGB -: 667: sRGB 4 RGBA -: 668: gray 1 L or I -: 669: gray 2 LA -: 670: YCC 3 YCbCr -: 671: -: 672: -: 673: If colorspace is unspecified, we assume: -: 674: -: 675: Number of components Colorspace -: 676: ----------------------------------------- -: 677: 1 gray -: 678: 2 gray (+ alpha) -: 679: 3 sRGB -: 680: 4 sRGB (+ alpha) -: 681: -: 682: */ -: 683: -: 684: /* Find the correct unpacker */ 33: 685: color_space = image->color_space; -: 686: 33: 687: if (color_space == OPJ_CLRSPC_UNSPECIFIED) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 688: switch (image->numcomps) { branch 0 taken 24% branch 1 taken 76% branch 2 taken 0% 8: 689: case 1: case 2: color_space = OPJ_CLRSPC_GRAY; break; 25: 690: case 3: case 4: color_space = OPJ_CLRSPC_SRGB; break; -: 691: } -: 692: } -: 693: 271: 694: for (n = 0; n < sizeof(j2k_unpackers) / sizeof (j2k_unpackers[0]); ++n) { branch 0 taken 100% branch 1 taken 0% (fallthrough) 271: 695: if (color_space == j2k_unpackers[n].color_space branch 0 taken 26% (fallthrough) branch 1 taken 74% 71: 696: && image->numcomps == j2k_unpackers[n].components branch 0 taken 72% (fallthrough) branch 1 taken 28% 51: 697: && strcmp (im->mode, j2k_unpackers[n].mode) == 0) { branch 0 taken 65% (fallthrough) branch 1 taken 35% 33: 698: unpack = j2k_unpackers[n].unpacker; 33: 699: break; -: 700: } -: 701: } -: 702: 33: 703: if (!unpack) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 704: state->errcode = IMAGING_CODEC_BROKEN; #####: 705: state->state = J2K_STATE_FAILED; #####: 706: goto quick_exit; -: 707: } -: 708: -: 709: /* Decode the image tile-by-tile; this means we only need use as much -: 710: memory as is required for one tile's worth of components. */ -: 711: for (;;) { -: 712: JPEG2KTILEINFO tile_info; -: 713: OPJ_BOOL should_continue; 127: 714: unsigned correction = (1 << params.cp_reduce) - 1; -: 715: 127: 716: if (!opj_read_tile_header(codec, call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% -: 717: stream, -: 718: &tile_info.tile_index, -: 719: &tile_info.data_size, -: 720: &tile_info.x0, &tile_info.y0, -: 721: &tile_info.x1, &tile_info.y1, -: 722: &tile_info.nb_comps, -: 723: &should_continue)) { #####: 724: state->errcode = IMAGING_CODEC_BROKEN; #####: 725: state->state = J2K_STATE_FAILED; #####: 726: goto quick_exit; -: 727: } -: 728: 127: 729: if (!should_continue) { branch 0 taken 74% (fallthrough) branch 1 taken 26% -: 730: break; -: 731: } -: 732: -: 733: /* Adjust the tile co-ordinates based on the reduction (OpenJPEG -: 734: doesn't do this for us) */ 94: 735: tile_info.x0 = (tile_info.x0 + correction) >> context->reduce; 94: 736: tile_info.y0 = (tile_info.y0 + correction) >> context->reduce; 94: 737: tile_info.x1 = (tile_info.x1 + correction) >> context->reduce; 94: 738: tile_info.y1 = (tile_info.y1 + correction) >> context->reduce; -: 739: -: 740: /* Check the tile bounds; if the tile is outside the image area, -: 741: or if it has a negative width or height (i.e. the coordinates are -: 742: swapped), bail. */ 94: 743: if (tile_info.x0 >= tile_info.x1 branch 0 taken 100% (fallthrough) branch 1 taken 0% 94: 744: || tile_info.y0 >= tile_info.y1 branch 0 taken 100% (fallthrough) branch 1 taken 0% 94: 745: || tile_info.x0 < (OPJ_INT32)image->x0 branch 0 taken 100% (fallthrough) branch 1 taken 0% 94: 746: || tile_info.y0 < (OPJ_INT32)image->y0 branch 0 taken 100% (fallthrough) branch 1 taken 0% 94: 747: || tile_info.x1 - image->x0 > im->xsize branch 0 taken 100% (fallthrough) branch 1 taken 0% 94: 748: || tile_info.y1 - image->y0 > im->ysize) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 749: state->errcode = IMAGING_CODEC_BROKEN; #####: 750: state->state = J2K_STATE_FAILED; #####: 751: goto quick_exit; -: 752: } -: 753: -: 754: /* Sometimes the tile_info.datasize we get back from openjpeg -: 755: is less than numcomps*w*h, and we overflow in the -: 756: shuffle stage */ -: 757: 94: 758: tile_width = tile_info.x1 - tile_info.x0; 94: 759: tile_height = tile_info.y1 - tile_info.y0; 94: 760: components = tile_info.nb_comps == 3 ? 4 : tile_info.nb_comps; branch 0 taken 19% (fallthrough) branch 1 taken 81% 94: 761: if (( tile_width > UINT_MAX / components ) || branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 94: 762: ( tile_height > UINT_MAX / components ) || branch 0 taken 100% (fallthrough) branch 1 taken 0% 188: 763: ( tile_width > UINT_MAX / (tile_height * components )) || branch 0 taken 0% (fallthrough) branch 1 taken 100% 94: 764: ( tile_height > UINT_MAX / (tile_width * components ))) { #####: 765: state->errcode = IMAGING_CODEC_BROKEN; #####: 766: state->state = J2K_STATE_FAILED; #####: 767: goto quick_exit; -: 768: } -: 769: 94: 770: tile_bytes = tile_width * tile_height * components; -: 771: 94: 772: if (tile_bytes > tile_info.data_size) { branch 0 taken 81% (fallthrough) branch 1 taken 19% 76: 773: tile_info.data_size = tile_bytes; -: 774: } -: 775: 94: 776: if (buffer_size < tile_info.data_size) { branch 0 taken 37% (fallthrough) branch 1 taken 63% -: 777: /* malloc check ok, overflow and tile size sanity check above */ 35: 778: UINT8 *new = realloc (state->buffer, tile_info.data_size); 35: 779: if (!new) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 780: state->errcode = IMAGING_CODEC_MEMORY; #####: 781: state->state = J2K_STATE_FAILED; #####: 782: goto quick_exit; -: 783: } 35: 784: state->buffer = new; 35: 785: buffer_size = tile_info.data_size; -: 786: } -: 787: -: 788: 188: 789: if (!opj_decode_tile_data(codec, call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% -: 790: tile_info.tile_index, 94: 791: (OPJ_BYTE *)state->buffer, -: 792: tile_info.data_size, -: 793: stream)) { #####: 794: state->errcode = IMAGING_CODEC_BROKEN; #####: 795: state->state = J2K_STATE_FAILED; #####: 796: goto quick_exit; -: 797: } -: 798: 94: 799: unpack(image, &tile_info, state->buffer, im); call 0 returned 100% 94: 800: } -: 801: 33: 802: if (!opj_end_decompress(codec, stream)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 803: state->errcode = IMAGING_CODEC_BROKEN; #####: 804: state->state = J2K_STATE_FAILED; #####: 805: goto quick_exit; -: 806: } -: 807: 33: 808: state->state = J2K_STATE_DONE; 33: 809: state->errcode = IMAGING_CODEC_END; -: 810: 33: 811: if (context->pfile) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 812: if(fclose(context->pfile)){ call 0 never executed branch 1 never executed branch 2 never executed #####: 813: context->pfile = NULL; -: 814: } -: 815: } -: 816: -: 817: quick_exit: 33: 818: if (codec) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 819: opj_destroy_codec(codec); call 0 returned 100% -: 820: } 33: 821: if (image) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 822: opj_image_destroy(image); call 0 returned 100% -: 823: } 33: 824: if (stream) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 825: opj_stream_destroy(stream); call 0 returned 100% -: 826: } -: 827: 33: 828: return -1; -: 829:} -: 830: -: 831:int function ImagingJpeg2KDecode called 33 returned 100% blocks executed 63% 33: 832:ImagingJpeg2KDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) -: 833:{ -: 834: 33: 835: if (bytes){ branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 836: state->errcode = IMAGING_CODEC_BROKEN; #####: 837: state->state = J2K_STATE_FAILED; #####: 838: return -1; -: 839: } -: 840: 33: 841: if (state->state == J2K_STATE_DONE || state->state == J2K_STATE_FAILED) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 842: return -1; -: 843: } -: 844: 33: 845: if (state->state == J2K_STATE_START) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 33: 846: state->state = J2K_STATE_DECODING; -: 847: 33: 848: return j2k_decode_entry(im, state); call 0 returned 100% -: 849: } -: 850: #####: 851: if (state->state == J2K_STATE_DECODING) { branch 0 never executed branch 1 never executed #####: 852: state->errcode = IMAGING_CODEC_BROKEN; #####: 853: state->state = J2K_STATE_FAILED; #####: 854: return -1; -: 855: } -: 856: return -1; -: 857:} -: 858: -: 859:/* -------------------------------------------------------------------- */ -: 860:/* Cleanup */ -: 861:/* -------------------------------------------------------------------- */ -: 862: -: 863:int function ImagingJpeg2KDecodeCleanup called 67 returned 100% blocks executed 67% 67: 864:ImagingJpeg2KDecodeCleanup(ImagingCodecState state) { 67: 865: JPEG2KDECODESTATE *context = (JPEG2KDECODESTATE *)state->context; -: 866: 67: 867: if (context->error_msg) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 868: free ((void *)context->error_msg); -: 869: } -: 870: 67: 871: context->error_msg = NULL; -: 872: 67: 873: return -1; -: 874:} -: 875: -: 876:const char * function ImagingJpeg2KVersion called 3 returned 100% blocks executed 100% 3: 877:ImagingJpeg2KVersion(void) -: 878:{ 3: 879: return opj_version(); call 0 returned 100% -: 880:} -: 881: -: 882:#endif /* HAVE_OPENJPEG */ -: 883: -: 884:/* -: 885: * Local Variables: -: 886: * c-basic-offset: 4 -: 887: * End: -: 888: * -: 889: */ <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/#usr#include#powerpc64le-linux-gnu#bits#stdio2.h.gcov -: 0:Source:/usr/include/powerpc64le-linux-gnu/bits/stdio2.h -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Access.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Access.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* Checking macros for stdio functions. -: 2: Copyright (C) 2004-2016 Free Software Foundation, Inc. -: 3: This file is part of the GNU C Library. -: 4: -: 5: The GNU C Library is free software; you can redistribute it and/or -: 6: modify it under the terms of the GNU Lesser General Public -: 7: License as published by the Free Software Foundation; either -: 8: version 2.1 of the License, or (at your option) any later version. -: 9: -: 10: The GNU C Library is distributed in the hope that it will be useful, -: 11: but WITHOUT ANY WARRANTY; without even the implied warranty of -: 12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -: 13: Lesser General Public License for more details. -: 14: -: 15: You should have received a copy of the GNU Lesser General Public -: 16: License along with the GNU C Library; if not, see -: 17: . */ -: 18: -: 19:#ifndef _STDIO_H -: 20:# error "Never include directly; use instead." -: 21:#endif -: 22: -: 23:extern int __sprintf_chk (char *__restrict __s, int __flag, size_t __slen, -: 24: const char *__restrict __format, ...) __THROW; -: 25:extern int __vsprintf_chk (char *__restrict __s, int __flag, size_t __slen, -: 26: const char *__restrict __format, -: 27: _G_va_list __ap) __THROW; -: 28: -: 29:#ifdef __va_arg_pack -: 30:__fortify_function int -: 31:__NTH (sprintf (char *__restrict __s, const char *__restrict __fmt, ...)) -: 32:{ -: 33: return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, -: 34: __bos (__s), __fmt, __va_arg_pack ()); -: 35:} -: 36:#elif !defined __cplusplus -: 37:# define sprintf(str, ...) \ -: 38: __builtin___sprintf_chk (str, __USE_FORTIFY_LEVEL - 1, __bos (str), \ -: 39: __VA_ARGS__) -: 40:#endif -: 41: -: 42:__fortify_function int -: 43:__NTH (vsprintf (char *__restrict __s, const char *__restrict __fmt, -: 44: _G_va_list __ap)) -: 45:{ -: 46: return __builtin___vsprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, -: 47: __bos (__s), __fmt, __ap); -: 48:} -: 49: -: 50:#if defined __USE_ISOC99 || defined __USE_UNIX98 -: 51: -: 52:extern int __snprintf_chk (char *__restrict __s, size_t __n, int __flag, -: 53: size_t __slen, const char *__restrict __format, -: 54: ...) __THROW; -: 55:extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag, -: 56: size_t __slen, const char *__restrict __format, -: 57: _G_va_list __ap) __THROW; -: 58: -: 59:# ifdef __va_arg_pack -: 60:__fortify_function int -: 61:__NTH (snprintf (char *__restrict __s, size_t __n, -: 62: const char *__restrict __fmt, ...)) -: 63:{ -: 64: return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, -: 65: __bos (__s), __fmt, __va_arg_pack ()); -: 66:} -: 67:# elif !defined __cplusplus -: 68:# define snprintf(str, len, ...) \ -: 69: __builtin___snprintf_chk (str, len, __USE_FORTIFY_LEVEL - 1, __bos (str), \ -: 70: __VA_ARGS__) -: 71:# endif -: 72: -: 73:__fortify_function int -: 74:__NTH (vsnprintf (char *__restrict __s, size_t __n, -: 75: const char *__restrict __fmt, _G_va_list __ap)) -: 76:{ -: 77: return __builtin___vsnprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, -: 78: __bos (__s), __fmt, __ap); -: 79:} -: 80: -: 81:#endif -: 82: -: 83:#if __USE_FORTIFY_LEVEL > 1 -: 84: -: 85:extern int __fprintf_chk (FILE *__restrict __stream, int __flag, -: 86: const char *__restrict __format, ...); -: 87:extern int __printf_chk (int __flag, const char *__restrict __format, ...); -: 88:extern int __vfprintf_chk (FILE *__restrict __stream, int __flag, -: 89: const char *__restrict __format, _G_va_list __ap); -: 90:extern int __vprintf_chk (int __flag, const char *__restrict __format, -: 91: _G_va_list __ap); -: 92: -: 93:# ifdef __va_arg_pack -: 94:__fortify_function int -: 95:fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...) -: 96:{ #####: 97: return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, call 0 never executed -: 98: __va_arg_pack ()); -: 99:} -: 100: -: 101:__fortify_function int -: 102:printf (const char *__restrict __fmt, ...) -: 103:{ -: 104: return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); -: 105:} -: 106:# elif !defined __cplusplus -: 107:# define printf(...) \ -: 108: __printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -: 109:# define fprintf(stream, ...) \ -: 110: __fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -: 111:# endif -: 112: -: 113:__fortify_function int -: 114:vprintf (const char *__restrict __fmt, _G_va_list __ap) -: 115:{ -: 116:#ifdef __USE_EXTERN_INLINES -: 117: return __vfprintf_chk (stdout, __USE_FORTIFY_LEVEL - 1, __fmt, __ap); -: 118:#else -: 119: return __vprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __ap); -: 120:#endif -: 121:} -: 122: -: 123:__fortify_function int -: 124:vfprintf (FILE *__restrict __stream, -: 125: const char *__restrict __fmt, _G_va_list __ap) -: 126:{ -: 127: return __vfprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, __ap); -: 128:} -: 129: -: 130:# ifdef __USE_XOPEN2K8 -: 131:extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt, -: 132: ...) __attribute__ ((__format__ (__printf__, 3, 4))); -: 133:extern int __vdprintf_chk (int __fd, int __flag, -: 134: const char *__restrict __fmt, _G_va_list __arg) -: 135: __attribute__ ((__format__ (__printf__, 3, 0))); -: 136: -: 137:# ifdef __va_arg_pack -: 138:__fortify_function int -: 139:dprintf (int __fd, const char *__restrict __fmt, ...) -: 140:{ -: 141: return __dprintf_chk (__fd, __USE_FORTIFY_LEVEL - 1, __fmt, -: 142: __va_arg_pack ()); -: 143:} -: 144:# elif !defined __cplusplus -: 145:# define dprintf(fd, ...) \ -: 146: __dprintf_chk (fd, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -: 147:# endif -: 148: -: 149:__fortify_function int -: 150:vdprintf (int __fd, const char *__restrict __fmt, _G_va_list __ap) -: 151:{ -: 152: return __vdprintf_chk (__fd, __USE_FORTIFY_LEVEL - 1, __fmt, __ap); -: 153:} -: 154:# endif -: 155: -: 156:# ifdef __USE_GNU -: 157: -: 158:extern int __asprintf_chk (char **__restrict __ptr, int __flag, -: 159: const char *__restrict __fmt, ...) -: 160: __THROW __attribute__ ((__format__ (__printf__, 3, 4))) __wur; -: 161:extern int __vasprintf_chk (char **__restrict __ptr, int __flag, -: 162: const char *__restrict __fmt, _G_va_list __arg) -: 163: __THROW __attribute__ ((__format__ (__printf__, 3, 0))) __wur; -: 164:extern int __obstack_printf_chk (struct obstack *__restrict __obstack, -: 165: int __flag, const char *__restrict __format, -: 166: ...) -: 167: __THROW __attribute__ ((__format__ (__printf__, 3, 4))); -: 168:extern int __obstack_vprintf_chk (struct obstack *__restrict __obstack, -: 169: int __flag, -: 170: const char *__restrict __format, -: 171: _G_va_list __args) -: 172: __THROW __attribute__ ((__format__ (__printf__, 3, 0))); -: 173: -: 174:# ifdef __va_arg_pack -: 175:__fortify_function int -: 176:__NTH (asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...)) -: 177:{ -: 178: return __asprintf_chk (__ptr, __USE_FORTIFY_LEVEL - 1, __fmt, -: 179: __va_arg_pack ()); -: 180:} -: 181: -: 182:__fortify_function int -: 183:__NTH (__asprintf (char **__restrict __ptr, const char *__restrict __fmt, -: 184: ...)) -: 185:{ -: 186: return __asprintf_chk (__ptr, __USE_FORTIFY_LEVEL - 1, __fmt, -: 187: __va_arg_pack ()); -: 188:} -: 189: -: 190:__fortify_function int -: 191:__NTH (obstack_printf (struct obstack *__restrict __obstack, -: 192: const char *__restrict __fmt, ...)) -: 193:{ -: 194: return __obstack_printf_chk (__obstack, __USE_FORTIFY_LEVEL - 1, __fmt, -: 195: __va_arg_pack ()); -: 196:} -: 197:# elif !defined __cplusplus -: 198:# define asprintf(ptr, ...) \ -: 199: __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -: 200:# define __asprintf(ptr, ...) \ -: 201: __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -: 202:# define obstack_printf(obstack, ...) \ -: 203: __obstack_printf_chk (obstack, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) -: 204:# endif -: 205: -: 206:__fortify_function int -: 207:__NTH (vasprintf (char **__restrict __ptr, const char *__restrict __fmt, -: 208: _G_va_list __ap)) -: 209:{ -: 210: return __vasprintf_chk (__ptr, __USE_FORTIFY_LEVEL - 1, __fmt, __ap); -: 211:} -: 212: -: 213:__fortify_function int -: 214:__NTH (obstack_vprintf (struct obstack *__restrict __obstack, -: 215: const char *__restrict __fmt, _G_va_list __ap)) -: 216:{ -: 217: return __obstack_vprintf_chk (__obstack, __USE_FORTIFY_LEVEL - 1, __fmt, -: 218: __ap); -: 219:} -: 220: -: 221:# endif -: 222: -: 223:#endif -: 224: -: 225:#if !defined __USE_ISOC11 \ -: 226: || (defined __cplusplus && __cplusplus <= 201103L && !defined __USE_GNU) -: 227:extern char *__gets_chk (char *__str, size_t) __wur; -: 228:extern char *__REDIRECT (__gets_warn, (char *__str), gets) -: 229: __wur __warnattr ("please use fgets or getline instead, gets can't " -: 230: "specify buffer size"); -: 231: -: 232:__fortify_function __wur char * -: 233:gets (char *__str) -: 234:{ -: 235: if (__bos (__str) != (size_t) -1) -: 236: return __gets_chk (__str, __bos (__str)); -: 237: return __gets_warn (__str); -: 238:} -: 239:#endif -: 240: -: 241:extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n, -: 242: FILE *__restrict __stream) __wur; -: 243:extern char *__REDIRECT (__fgets_alias, -: 244: (char *__restrict __s, int __n, -: 245: FILE *__restrict __stream), fgets) __wur; -: 246:extern char *__REDIRECT (__fgets_chk_warn, -: 247: (char *__restrict __s, size_t __size, int __n, -: 248: FILE *__restrict __stream), __fgets_chk) -: 249: __wur __warnattr ("fgets called with bigger size than length " -: 250: "of destination buffer"); -: 251: -: 252:__fortify_function __wur char * -: 253:fgets (char *__restrict __s, int __n, FILE *__restrict __stream) -: 254:{ -: 255: if (__bos (__s) != (size_t) -1) -: 256: { -: 257: if (!__builtin_constant_p (__n) || __n <= 0) -: 258: return __fgets_chk (__s, __bos (__s), __n, __stream); -: 259: -: 260: if ((size_t) __n > __bos (__s)) -: 261: return __fgets_chk_warn (__s, __bos (__s), __n, __stream); -: 262: } -: 263: return __fgets_alias (__s, __n, __stream); -: 264:} -: 265: -: 266:extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen, -: 267: size_t __size, size_t __n, -: 268: FILE *__restrict __stream) __wur; -: 269:extern size_t __REDIRECT (__fread_alias, -: 270: (void *__restrict __ptr, size_t __size, -: 271: size_t __n, FILE *__restrict __stream), -: 272: fread) __wur; -: 273:extern size_t __REDIRECT (__fread_chk_warn, -: 274: (void *__restrict __ptr, size_t __ptrlen, -: 275: size_t __size, size_t __n, -: 276: FILE *__restrict __stream), -: 277: __fread_chk) -: 278: __wur __warnattr ("fread called with bigger size * nmemb than length " -: 279: "of destination buffer"); -: 280: -: 281:__fortify_function __wur size_t -: 282:fread (void *__restrict __ptr, size_t __size, size_t __n, -: 283: FILE *__restrict __stream) -: 284:{ -: 285: if (__bos0 (__ptr) != (size_t) -1) -: 286: { -: 287: if (!__builtin_constant_p (__size) -: 288: || !__builtin_constant_p (__n) -: 289: || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2))) -: 290: return __fread_chk (__ptr, __bos0 (__ptr), __size, __n, __stream); -: 291: -: 292: if (__size * __n > __bos0 (__ptr)) -: 293: return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream); -: 294: } -: 295: return __fread_alias (__ptr, __size, __n, __stream); -: 296:} -: 297: -: 298:#ifdef __USE_GNU -: 299:extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size, -: 300: int __n, FILE *__restrict __stream) __wur; -: 301:extern char *__REDIRECT (__fgets_unlocked_alias, -: 302: (char *__restrict __s, int __n, -: 303: FILE *__restrict __stream), fgets_unlocked) __wur; -: 304:extern char *__REDIRECT (__fgets_unlocked_chk_warn, -: 305: (char *__restrict __s, size_t __size, int __n, -: 306: FILE *__restrict __stream), __fgets_unlocked_chk) -: 307: __wur __warnattr ("fgets_unlocked called with bigger size than length " -: 308: "of destination buffer"); -: 309: -: 310:__fortify_function __wur char * -: 311:fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) -: 312:{ -: 313: if (__bos (__s) != (size_t) -1) -: 314: { -: 315: if (!__builtin_constant_p (__n) || __n <= 0) -: 316: return __fgets_unlocked_chk (__s, __bos (__s), __n, __stream); -: 317: -: 318: if ((size_t) __n > __bos (__s)) -: 319: return __fgets_unlocked_chk_warn (__s, __bos (__s), __n, __stream); -: 320: } -: 321: return __fgets_unlocked_alias (__s, __n, __stream); -: 322:} -: 323:#endif -: 324: -: 325:#ifdef __USE_MISC -: 326:# undef fread_unlocked -: 327:extern size_t __fread_unlocked_chk (void *__restrict __ptr, size_t __ptrlen, -: 328: size_t __size, size_t __n, -: 329: FILE *__restrict __stream) __wur; -: 330:extern size_t __REDIRECT (__fread_unlocked_alias, -: 331: (void *__restrict __ptr, size_t __size, -: 332: size_t __n, FILE *__restrict __stream), -: 333: fread_unlocked) __wur; -: 334:extern size_t __REDIRECT (__fread_unlocked_chk_warn, -: 335: (void *__restrict __ptr, size_t __ptrlen, -: 336: size_t __size, size_t __n, -: 337: FILE *__restrict __stream), -: 338: __fread_unlocked_chk) -: 339: __wur __warnattr ("fread_unlocked called with bigger size * nmemb than " -: 340: "length of destination buffer"); -: 341: -: 342:__fortify_function __wur size_t -: 343:fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n, -: 344: FILE *__restrict __stream) -: 345:{ -: 346: if (__bos0 (__ptr) != (size_t) -1) -: 347: { -: 348: if (!__builtin_constant_p (__size) -: 349: || !__builtin_constant_p (__n) -: 350: || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2))) -: 351: return __fread_unlocked_chk (__ptr, __bos0 (__ptr), __size, __n, -: 352: __stream); -: 353: -: 354: if (__size * __n > __bos0 (__ptr)) -: 355: return __fread_unlocked_chk_warn (__ptr, __bos0 (__ptr), __size, __n, -: 356: __stream); -: 357: } -: 358: -: 359:# ifdef __USE_EXTERN_INLINES -: 360: if (__builtin_constant_p (__size) -: 361: && __builtin_constant_p (__n) -: 362: && (__size | __n) < (((size_t) 1) << (8 * sizeof (size_t) / 2)) -: 363: && __size * __n <= 8) -: 364: { -: 365: size_t __cnt = __size * __n; -: 366: char *__cptr = (char *) __ptr; -: 367: if (__cnt == 0) -: 368: return 0; -: 369: -: 370: for (; __cnt > 0; --__cnt) -: 371: { -: 372: int __c = _IO_getc_unlocked (__stream); -: 373: if (__c == EOF) -: 374: break; -: 375: *__cptr++ = __c; -: 376: } -: 377: return (__cptr - (char *) __ptr) / __size; -: 378: } -: 379:# endif -: 380: return __fread_unlocked_alias (__ptr, __size, __n, __stream); -: 381:} -: 382:#endif <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Access.c.gcov -: 0:Source:src/libImaging/Access.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Access.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Access.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * imaging access objects -: 6: * -: 7: * Copyright (c) Fredrik Lundh 2009. -: 8: * -: 9: * See the README file for information on usage and redistribution. -: 10: */ -: 11: -: 12: -: 13:#include "Imaging.h" -: 14: -: 15:/* use Tests/make_hash.py to calculate these values */ -: 16:#define ACCESS_TABLE_SIZE 27 -: 17:#define ACCESS_TABLE_HASH 3078 -: 18: -: 19:static struct ImagingAccessInstance access_table[ACCESS_TABLE_SIZE]; -: 20: -: 21:static inline UINT32 -: 22:hash(const char* mode) -: 23:{ 53080: 24: UINT32 i = ACCESS_TABLE_HASH; 145245: 25: while (*mode) { branch 0 taken 63% branch 1 taken 37% (fallthrough) branch 2 taken 76% branch 3 taken 24% (fallthrough) 92165: 26: i = ((i<<5) + i) ^ (UINT8) *mode++; -: 27: } 53080: 28: return i % ACCESS_TABLE_SIZE; -: 29:} -: 30: -: 31:static ImagingAccess function add_item called 63 returned 100% blocks executed 63% 63: 32:add_item(const char* mode) -: 33:{ 63: 34: UINT32 i = hash(mode); -: 35: /* printf("hash %s => %d\n", mode, i); */ 63: 36: if (access_table[i].mode && strcmp(access_table[i].mode, mode) != 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% branch 2 never executed branch 3 never executed #####: 37: fprintf(stderr, "AccessInit: hash collision: %d for both %s and %s\n", -: 38: i, mode, access_table[i].mode); #####: 39: exit(1); call 0 never executed -: 40: } 63: 41: access_table[i].mode = mode; 63: 42: return &access_table[i]; -: 43:} -: 44: -: 45:/* fetch pointer to pixel line */ -: 46: -: 47:static void* function line_8 called 0 returned 0% blocks executed 0% #####: 48:line_8(Imaging im, int x, int y) -: 49:{ #####: 50: return &im->image8[y][x]; -: 51:} -: 52: -: 53:static void* function line_16 called 0 returned 0% blocks executed 0% #####: 54:line_16(Imaging im, int x, int y) -: 55:{ #####: 56: return &im->image8[y][x+x]; -: 57:} -: 58: -: 59:static void* function line_32 called 0 returned 0% blocks executed 0% #####: 60:line_32(Imaging im, int x, int y) -: 61:{ #####: 62: return &im->image32[y][x]; -: 63:} -: 64: -: 65:/* fetch individual pixel */ -: 66: -: 67:static void function get_pixel called 30335 returned 100% blocks executed 71% 30335: 68:get_pixel(Imaging im, int x, int y, void* color) -: 69:{ 30335: 70: char* out = color; -: 71: -: 72: /* generic pixel access*/ -: 73: 30335: 74: if (im->image8) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 75: out[0] = im->image8[y][x]; -: 76: } else { 30335: 77: UINT8* p = (UINT8*) &im->image32[y][x]; 30335: 78: if (im->type == IMAGING_TYPE_UINT8 && im->bands == 2) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 30335: 79: out[0] = p[0]; 30335: 80: out[1] = p[3]; 30335: 81: return; -: 82: } #####: 83: memcpy(out, p, im->pixelsize); -: 84: } -: 85:} -: 86: -: 87:static void function get_pixel_8 called 4120100 returned 100% blocks executed 100% 4120100: 88:get_pixel_8(Imaging im, int x, int y, void* color) -: 89:{ 4120100: 90: char* out = color; 4120100: 91: out[0] = im->image8[y][x]; 4120100: 92:} -: 93: -: 94:static void function get_pixel_16L called 18034 returned 100% blocks executed 100% 18034: 95:get_pixel_16L(Imaging im, int x, int y, void* color) -: 96:{ 18034: 97: UINT8* in = (UINT8*) &im->image[y][x+x]; -: 98:#ifdef WORDS_BIGENDIAN -: 99: UINT16 out = in[0] + (in[1]<<8); -: 100: memcpy(color, &out, sizeof(out)); -: 101:#else 18034: 102: memcpy(color, in, sizeof(UINT16)); -: 103:#endif 18034: 104:} -: 105: -: 106:static void function get_pixel_16B called 9426 returned 100% blocks executed 100% 9426: 107:get_pixel_16B(Imaging im, int x, int y, void* color) -: 108:{ 9426: 109: UINT8* in = (UINT8*) &im->image[y][x+x]; -: 110:#ifdef WORDS_BIGENDIAN -: 111: memcpy(color, in, sizeof(UINT16)); -: 112:#else 9426: 113: UINT16 out = in[1] + (in[0]<<8); 9426: 114: memcpy(color, &out, sizeof(out)); -: 115:#endif 9426: 116:} -: 117: -: 118:static void function get_pixel_32 called 463561 returned 100% blocks executed 100% 463561: 119:get_pixel_32(Imaging im, int x, int y, void* color) -: 120:{ 927122: 121: memcpy(color, &im->image32[y][x], sizeof(INT32)); 463561: 122:} -: 123: -: 124:static void function get_pixel_32L called 0 returned 0% blocks executed 0% #####: 125:get_pixel_32L(Imaging im, int x, int y, void* color) -: 126:{ #####: 127: UINT8* in = (UINT8*) &im->image[y][x*4]; -: 128:#ifdef WORDS_BIGENDIAN -: 129: INT32 out = in[0] + (in[1]<<8) + (in[2]<<16) + (in[3]<<24); -: 130: memcpy(color, &out, sizeof(out)); -: 131:#else #####: 132: memcpy(color, in, sizeof(INT32)); -: 133:#endif #####: 134:} -: 135: -: 136:static void function get_pixel_32B called 0 returned 0% blocks executed 0% #####: 137:get_pixel_32B(Imaging im, int x, int y, void* color) -: 138:{ #####: 139: UINT8* in = (UINT8*) &im->image[y][x*4]; -: 140:#ifdef WORDS_BIGENDIAN -: 141: memcpy(color, in, sizeof(INT32)); -: 142:#else #####: 143: INT32 out = in[3] + (in[2]<<8) + (in[1]<<16) + (in[0]<<24); #####: 144: memcpy(color, &out, sizeof(out)); -: 145:#endif #####: 146:} -: 147: -: 148:/* store individual pixel */ -: 149: -: 150:static void function put_pixel called 5139 returned 100% blocks executed 75% 5139: 151:put_pixel(Imaging im, int x, int y, const void* color) -: 152:{ 5139: 153: if (im->image8) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 154: im->image8[y][x] = *((UINT8*) color); -: 155: } else { 5139: 156: memcpy(&im->image32[y][x], color, sizeof(INT32)); -: 157: } 5139: 158:} -: 159: -: 160:static void function put_pixel_8 called 211306 returned 100% blocks executed 100% 211306: 161:put_pixel_8(Imaging im, int x, int y, const void* color) -: 162:{ 211306: 163: im->image8[y][x] = *((UINT8*) color); 211306: 164:} -: 165: -: 166:static void function put_pixel_16L called 10546 returned 100% blocks executed 100% 10546: 167:put_pixel_16L(Imaging im, int x, int y, const void* color) -: 168:{ 21092: 169: memcpy(&im->image8[y][x+x], color, 2); 10546: 170:} -: 171: -: 172:static void function put_pixel_16B called 232 returned 100% blocks executed 100% 232: 173:put_pixel_16B(Imaging im, int x, int y, const void* color) -: 174:{ 232: 175: const char* in = color; 232: 176: UINT8* out = (UINT8*) &im->image8[y][x+x]; 232: 177: out[0] = in[1]; 232: 178: out[1] = in[0]; 232: 179:} -: 180: -: 181:static void function put_pixel_32L called 0 returned 0% blocks executed 0% #####: 182:put_pixel_32L(Imaging im, int x, int y, const void* color) -: 183:{ #####: 184: memcpy(&im->image8[y][x*4], color, 4); #####: 185:} -: 186: -: 187:static void function put_pixel_32B called 0 returned 0% blocks executed 0% #####: 188:put_pixel_32B(Imaging im, int x, int y, const void* color) -: 189:{ #####: 190: const char* in = color; #####: 191: UINT8* out = (UINT8*) &im->image8[y][x*4]; #####: 192: out[0] = in[3]; #####: 193: out[1] = in[2]; #####: 194: out[2] = in[1]; #####: 195: out[3] = in[0]; #####: 196:} -: 197: -: 198:static void function put_pixel_32 called 141120 returned 100% blocks executed 100% 141120: 199:put_pixel_32(Imaging im, int x, int y, const void* color) -: 200:{ 282240: 201: memcpy(&im->image32[y][x], color, sizeof(INT32)); 141120: 202:} -: 203: -: 204:void function ImagingAccessInit called 3 returned 100% blocks executed 100% 3: 205:ImagingAccessInit() -: 206:{ -: 207:#define ADD(mode_, line_, get_pixel_, put_pixel_) \ -: 208: { ImagingAccess access = add_item(mode_); \ -: 209: access->line = line_; \ -: 210: access->get_pixel = get_pixel_; \ -: 211: access->put_pixel = put_pixel_; \ -: 212: } -: 213: -: 214: /* populate access table */ 3: 215: ADD("1", line_8, get_pixel_8, put_pixel_8); call 0 returned 100% 3: 216: ADD("L", line_8, get_pixel_8, put_pixel_8); call 0 returned 100% 3: 217: ADD("LA", line_32, get_pixel, put_pixel); call 0 returned 100% 3: 218: ADD("La", line_32, get_pixel, put_pixel); call 0 returned 100% 3: 219: ADD("I", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 220: ADD("I;16", line_16, get_pixel_16L, put_pixel_16L); call 0 returned 100% 3: 221: ADD("I;16L", line_16, get_pixel_16L, put_pixel_16L); call 0 returned 100% 3: 222: ADD("I;16B", line_16, get_pixel_16B, put_pixel_16B); call 0 returned 100% 3: 223: ADD("I;32L", line_32, get_pixel_32L, put_pixel_32L); call 0 returned 100% 3: 224: ADD("I;32B", line_32, get_pixel_32B, put_pixel_32B); call 0 returned 100% 3: 225: ADD("F", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 226: ADD("P", line_8, get_pixel_8, put_pixel_8); call 0 returned 100% 3: 227: ADD("PA", line_32, get_pixel, put_pixel); call 0 returned 100% 3: 228: ADD("RGB", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 229: ADD("RGBA", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 230: ADD("RGBa", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 231: ADD("RGBX", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 232: ADD("CMYK", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 233: ADD("YCbCr", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 234: ADD("LAB", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 235: ADD("HSV", line_32, get_pixel_32, put_pixel_32); call 0 returned 100% 3: 236:} -: 237: -: 238:ImagingAccess function ImagingAccessNew called 53017 returned 100% blocks executed 100% 53017: 239:ImagingAccessNew(Imaging im) -: 240:{ 106034: 241: ImagingAccess access = &access_table[hash(im->mode)]; 53017: 242: if (im->mode[0] != access->mode[0] || strcmp(im->mode, access->mode) != 0) { branch 0 taken 99% (fallthrough) branch 1 taken 1% branch 2 taken 100% (fallthrough) branch 3 taken 0% -: 243: return NULL; -: 244: } 53010: 245: return access; -: 246:} -: 247: -: 248:void function _ImagingAccessDelete called 0 returned 0% blocks executed 0% #####: 249:_ImagingAccessDelete(Imaging im, ImagingAccess access) -: 250:{ -: 251: #####: 252:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#SunRleDecode.c.gcov -: 0:Source:src/libImaging/SunRleDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/SunRleDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/SunRleDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * THIS IS WORK IN PROGRESS -: 3: * -: 4: * The Python Imaging Library. -: 5: * $Id$ -: 6: * -: 7: * decoder for SUN RLE data. -: 8: * -: 9: * history: -: 10: * 97-01-04 fl Created -: 11: * -: 12: * Copyright (c) Fredrik Lundh 1997. -: 13: * Copyright (c) Secret Labs AB 1997. -: 14: * -: 15: * See the README file for information on usage and redistribution. -: 16: */ -: 17: -: 18: -: 19:#include "Imaging.h" -: 20: -: 21: -: 22:int function ImagingSunRleDecode called 19 returned 100% blocks executed 100% 19: 23:ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) -: 24:{ -: 25: int n; -: 26: UINT8* ptr; 19: 27: UINT8 extra_data = 0; 19: 28: UINT8 extra_bytes = 0; -: 29: 19: 30: ptr = buf; -: 31: -: 32: for (;;) { -: 33: 1043968: 34: if (bytes < 1) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 14: 35: return ptr - buf; -: 36: } -: 37: 1043954: 38: if (ptr[0] == 0x80) { branch 0 taken 2% (fallthrough) branch 1 taken 98% -: 39: 18634: 40: if (bytes < 2) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 41: break; -: 42: } -: 43: 18633: 44: n = ptr[1]; -: 45: -: 46: 18633: 47: if (n == 0) { branch 0 taken 27% (fallthrough) branch 1 taken 73% -: 48: -: 49: /* Literal 0x80 (2 bytes) */ 5101: 50: n = 1; -: 51: 5101: 52: state->buffer[state->x] = 0x80; -: 53: 5101: 54: ptr += 2; 5101: 55: bytes -= 2; -: 56: -: 57: } else { -: 58: -: 59: /* Run (3 bytes) */ 13532: 60: if (bytes < 3) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 61: break; -: 62: } -: 63: -: 64: /* from (https://www.fileformat.info/format/sunraster/egff.htm) -: 65: -: 66: For example, a run of 100 pixels with the value of -: 67: 0Ah would encode as the values 80h 64h 0Ah. A -: 68: single pixel value of 80h would encode as the -: 69: values 80h 00h. The four unencoded bytes 12345678h -: 70: would be stored in the RLE stream as 12h 34h 56h -: 71: 78h. 100 pixels, n=100, not 100 pixels, n=99. -: 72: -: 73: But Wait! There's More! -: 74: (https://www.fileformat.info/format/sunraster/spec/598a59c4fac64c52897585d390d86360/view.htm) -: 75: -: 76: If the first byte is 0x80, and the second byte is -: 77: not zero, the record is three bytes long. The -: 78: second byte is a count and the third byte is a -: 79: value. Output (count+1) pixels of that value. -: 80: -: 81: 2 specs, same site, but Imagemagick and GIMP seem -: 82: to agree on the second one. -: 83: */ 13532: 84: n += 1; -: 85: 13532: 86: if (state->x + n > state->bytes) { branch 0 taken 2% (fallthrough) branch 1 taken 98% 325: 87: extra_bytes = n; /* full value */ 325: 88: n = state->bytes - state->x; 325: 89: extra_bytes -= n; 325: 90: extra_data = ptr[2]; -: 91: } -: 92: 27064: 93: memset(state->buffer + state->x, ptr[2], n); -: 94: 13532: 95: ptr += 3; 13532: 96: bytes -= 3; -: 97: -: 98: } -: 99: -: 100: } else { -: 101: -: 102: /* Literal byte */ 1025320: 103: n = 1; -: 104: 1025320: 105: state->buffer[state->x] = ptr[0]; -: 106: 1025320: 107: ptr += 1; 1025320: 108: bytes -= 1; -: 109: -: 110: } -: 111: -: 112: for (;;) { 1044359: 113: state->x += n; -: 114: 1044359: 115: if (state->x >= state->bytes) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 116: -: 117: /* Got a full line, unpack it */ 5808: 118: state->shuffle((UINT8*) im->image[state->y + state->yoff] + call 0 returned 100% 3872: 119: state->xoff * im->pixelsize, state->buffer, -: 120: state->xsize); -: 121: 1936: 122: state->x = 0; -: 123: 1936: 124: if (++state->y >= state->ysize) { branch 0 taken 99% (fallthrough) branch 1 taken 1% -: 125: /* End of file (errcode = 0) */ -: 126: return -1; -: 127: } -: 128: } -: 129: 1044355: 130: if (extra_bytes == 0) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 131: break; -: 132: } -: 133: 406: 134: if (state->x > 0) { branch 0 taken 0% branch 1 taken 100% (fallthrough) -: 135: break; // assert -: 136: } -: 137: 406: 138: if (extra_bytes >= state->bytes) { branch 0 taken 80% (fallthrough) branch 1 taken 20% -: 139: n = state->bytes; -: 140: } else { 324: 141: n = extra_bytes; -: 142: } 812: 143: memset(state->buffer + state->x, extra_data, n); 406: 144: extra_bytes -= n; 406: 145: } -: 146: } -: 147: 1: 148: return ptr - buf; -: 149:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#path.c.gcov -: 0:Source:src/path.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/path.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/path.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * -: 4: * 2D path utilities -: 5: * -: 6: * history: -: 7: * 1996-11-04 fl Added to PIL (incomplete) -: 8: * 1996-11-05 fl Added sequence semantics -: 9: * 1997-02-28 fl Fixed getbbox -: 10: * 1997-06-12 fl Added id attribute -: 11: * 1997-06-14 fl Added slicing and setitem -: 12: * 1998-12-29 fl Improved sequence handling (from Richard Jones) -: 13: * 1999-01-10 fl Fixed IndexError test for 1.5 (from Fred Drake) -: 14: * 2000-10-12 fl Added special cases for tuples and lists -: 15: * 2002-10-27 fl Added clipping boilerplate -: 16: * 2004-09-19 fl Added tolist(flat) variant -: 17: * 2005-05-06 fl Added buffer interface support to path constructor -: 18: * -: 19: * notes: -: 20: * FIXME: fill in remaining slots in the sequence api -: 21: * -: 22: * Copyright (c) 1997-2005 by Secret Labs AB -: 23: * Copyright (c) 1997-2005 by Fredrik Lundh -: 24: * -: 25: * See the README file for information on usage and redistribution. -: 26: */ -: 27: -: 28: -: 29:#include "Python.h" -: 30:#include "libImaging/Imaging.h" -: 31: -: 32:#include -: 33: -: 34:/* compatibility wrappers (defined in _imaging.c) */ -: 35:extern int PyImaging_CheckBuffer(PyObject* buffer); -: 36:extern int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view); -: 37: -: 38:/* -------------------------------------------------------------------- */ -: 39:/* Class */ -: 40:/* -------------------------------------------------------------------- */ -: 41: -: 42:typedef struct { -: 43: PyObject_HEAD -: 44: Py_ssize_t count; -: 45: double *xy; -: 46: int index; /* temporary use, e.g. in decimate */ -: 47:} PyPathObject; -: 48: -: 49:static PyTypeObject PyPathType; -: 50: -: 51:static double* function alloc_array called 2934 returned 100% blocks executed 67% 2934: 52:alloc_array(Py_ssize_t count) -: 53:{ -: 54: double* xy; 2934: 55: if (count < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 56: PyErr_NoMemory(); call 0 never executed #####: 57: return NULL; -: 58: } 2934: 59: if ((unsigned long long)count > (SIZE_MAX / (2 * sizeof(double))) - 1 ) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 1: 60: PyErr_NoMemory(); call 0 returned 100% 1: 61: return NULL; -: 62: } 2933: 63: xy = malloc(2 * count * sizeof(double) + 1); 2933: 64: if (!xy) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 65: PyErr_NoMemory(); call 0 never executed -: 66: } -: 67: return xy; -: 68:} -: 69: -: 70:static PyPathObject* function path_new called 11 returned 100% blocks executed 83% 11: 71:path_new(Py_ssize_t count, double* xy, int duplicate) -: 72:{ -: 73: PyPathObject *path; -: 74: 11: 75: if (duplicate) { branch 0 taken 9% (fallthrough) branch 1 taken 91% -: 76: /* duplicate path */ 1: 77: double* p = alloc_array(count); call 0 returned 100% 1: 78: if (!p) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 79: return NULL; -: 80: } 2: 81: memcpy(p, xy, count * 2 * sizeof(double)); 1: 82: xy = p; -: 83: } -: 84: 11: 85: if (PyType_Ready(&PyPathType) < 0) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 86: free(xy); #####: 87: return NULL; -: 88: } -: 89: 11: 90: path = PyObject_New(PyPathObject, &PyPathType); call 0 returned 100% 11: 91: if (path == NULL) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 92: free(xy); #####: 93: return NULL; -: 94: } -: 95: 11: 96: path->count = count; 11: 97: path->xy = xy; -: 98: 11: 99: return path; -: 100:} -: 101: -: 102:static void function path_dealloc called 11 returned 100% blocks executed 100% 11: 103:path_dealloc(PyPathObject* path) -: 104:{ 11: 105: free(path->xy); 11: 106: PyObject_Del(path); call 0 returned 100% 11: 107:} -: 108: -: 109:/* -------------------------------------------------------------------- */ -: 110:/* Helpers */ -: 111:/* -------------------------------------------------------------------- */ -: 112: -: 113:#define PyPath_Check(op) (Py_TYPE(op) == &PyPathType) -: 114: -: 115:Py_ssize_t function PyPath_Flatten called 2932 returned 100% blocks executed 57% 2932: 116:PyPath_Flatten(PyObject* data, double **pxy) -: 117:{ -: 118: Py_ssize_t i, j, n; -: 119: double *xy; -: 120: 2932: 121: if (PyPath_Check(data)) { branch 0 taken 1% (fallthrough) branch 1 taken 99% -: 122: /* This was another path object. */ 1: 123: PyPathObject *path = (PyPathObject*) data; 1: 124: xy = alloc_array(path->count); call 0 returned 100% 1: 125: if (!xy) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 126: return -1; -: 127: } 2: 128: memcpy(xy, path->xy, 2 * path->count * sizeof(double)); 1: 129: *pxy = xy; 1: 130: return path->count; -: 131: } -: 132: 2931: 133: if (PyImaging_CheckBuffer(data)) { call 0 returned 100% branch 1 taken 1% (fallthrough) branch 2 taken 99% -: 134: /* Assume the buffer contains floats */ -: 135: Py_buffer buffer; 2: 136: if (PyImaging_GetBuffer(data, &buffer) == 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 2: 137: float *ptr = (float*) buffer.buf; 2: 138: n = buffer.len / (2 * sizeof(float)); 2: 139: xy = alloc_array(n); call 0 returned 100% 2: 140: if (!xy) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 2: 141: return -1; -: 142: } 4: 143: for (i = 0; i < n+n; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 4: 144: xy[i] = ptr[i]; -: 145: } 2: 146: *pxy = xy; 2: 147: PyBuffer_Release(&buffer); call 0 returned 100% 2: 148: return n; -: 149: } #####: 150: PyErr_Clear(); call 0 never executed -: 151: } -: 152: 2929: 153: if (!PySequence_Check(data)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 154: PyErr_SetString(PyExc_TypeError, "argument must be sequence"); call 0 never executed #####: 155: return -1; -: 156: } -: 157: 2929: 158: j = 0; 2929: 159: n = PyObject_Length(data); call 0 returned 100% -: 160: /* Just in case __len__ breaks (or doesn't exist) */ 2929: 161: if (PyErr_Occurred()) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 162: return -1; -: 163: } -: 164: -: 165: /* Allocate for worst case */ 2929: 166: xy = alloc_array(n); call 0 returned 100% 2929: 167: if (!xy) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 168: return -1; -: 169: } -: 170: -: 171: /* Copy table to path array */ 2929: 172: if (PyList_Check(data)) { branch 0 taken 78% (fallthrough) branch 1 taken 22% 9014: 173: for (i = 0; i < n; i++) { branch 0 taken 80% branch 1 taken 20% -: 174: double x, y; 9014: 175: PyObject *op = PyList_GET_ITEM(data, i); 9014: 176: if (PyFloat_Check(op)) { branch 0 taken 99% (fallthrough) branch 1 taken 1% call 2 returned 100% branch 3 taken 0% (fallthrough) branch 4 taken 100% 4: 177: xy[j++] = PyFloat_AS_DOUBLE(op); 9010: 178: } else if (PyLong_Check(op)) { branch 0 taken 95% (fallthrough) branch 1 taken 5% 8558: 179: xy[j++] = (float) PyLong_AS_LONG(op); call 0 returned 100% 452: 180: } else if (PyNumber_Check(op)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 181: xy[j++] = PyFloat_AsDouble(op); call 0 never executed 452: 182: } else if (PyArg_ParseTuple(op, "dd", &x, &y)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 452: 183: xy[j++] = x; 452: 184: xy[j++] = y; -: 185: } else { #####: 186: free(xy); #####: 187: return -1; -: 188: } -: 189: } 643: 190: } else if (PyTuple_Check(data)) { branch 0 taken 0% (fallthrough) branch 1 taken 100% 1582: 191: for (i = 0; i < n; i++) { branch 0 taken 71% branch 1 taken 29% -: 192: double x, y; 1582: 193: PyObject *op = PyTuple_GET_ITEM(data, i); 1582: 194: if (PyFloat_Check(op)) { branch 0 taken 87% (fallthrough) branch 1 taken 13% call 2 returned 100% branch 3 taken 0% (fallthrough) branch 4 taken 100% 200: 195: xy[j++] = PyFloat_AS_DOUBLE(op); 1382: 196: } else if (PyLong_Check(op)) { branch 0 taken 77% (fallthrough) branch 1 taken 23% 1070: 197: xy[j++] = (float) PyLong_AS_LONG(op); call 0 returned 100% 312: 198: } else if (PyNumber_Check(op)) { call 0 returned 100% branch 1 taken 0% (fallthrough) branch 2 taken 100% #####: 199: xy[j++] = PyFloat_AsDouble(op); call 0 never executed 312: 200: } else if (PyArg_ParseTuple(op, "dd", &x, &y)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% 312: 201: xy[j++] = x; 312: 202: xy[j++] = y; -: 203: } else { #####: 204: free(xy); #####: 205: return -1; -: 206: } -: 207: } -: 208: } else { #####: 209: for (i = 0; i < n; i++) { branch 0 never executed branch 1 never executed -: 210: double x, y; #####: 211: PyObject *op = PySequence_GetItem(data, i); call 0 never executed #####: 212: if (!op) { branch 0 never executed branch 1 never executed -: 213: /* treat IndexError as end of sequence */ #####: 214: if (PyErr_Occurred() && call 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed branch 4 never executed #####: 215: PyErr_ExceptionMatches(PyExc_IndexError)) { call 0 never executed #####: 216: PyErr_Clear(); call 0 never executed #####: 217: break; -: 218: } else { #####: 219: free(xy); #####: 220: return -1; -: 221: } -: 222: } #####: 223: if (PyFloat_Check(op)) { branch 0 never executed branch 1 never executed call 2 never executed branch 3 never executed branch 4 never executed #####: 224: xy[j++] = PyFloat_AS_DOUBLE(op); #####: 225: } else if (PyLong_Check(op)) { branch 0 never executed branch 1 never executed #####: 226: xy[j++] = (float) PyLong_AS_LONG(op); call 0 never executed #####: 227: } else if (PyNumber_Check(op)) { call 0 never executed branch 1 never executed branch 2 never executed #####: 228: xy[j++] = PyFloat_AsDouble(op); call 0 never executed #####: 229: } else if (PyArg_ParseTuple(op, "dd", &x, &y)) { call 0 never executed branch 1 never executed branch 2 never executed #####: 230: xy[j++] = x; #####: 231: xy[j++] = y; -: 232: } else { #####: 233: Py_DECREF(op); branch 0 never executed branch 1 never executed call 2 never executed #####: 234: free(xy); #####: 235: return -1; -: 236: } #####: 237: Py_DECREF(op); branch 0 never executed branch 1 never executed call 2 never executed -: 238: } -: 239: } -: 240: 2929: 241: if (j & 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 242: PyErr_SetString(PyExc_ValueError, "wrong number of coordinates"); call 0 never executed #####: 243: free(xy); #####: 244: return -1; -: 245: } -: 246: 2929: 247: *pxy = xy; 2929: 248: return j/2; -: 249:} -: 250: -: 251: -: 252:/* -------------------------------------------------------------------- */ -: 253:/* Factories */ -: 254:/* -------------------------------------------------------------------- */ -: 255: -: 256:PyObject* function PyPath_Create called 11 returned 100% blocks executed 100% 11: 257:PyPath_Create(PyObject* self, PyObject* args) -: 258:{ -: 259: PyObject* data; -: 260: Py_ssize_t count; -: 261: double *xy; -: 262: 11: 263: if (PyArg_ParseTuple(args, "n:Path", &count)) { call 0 returned 100% branch 1 taken 9% (fallthrough) branch 2 taken 91% -: 264: -: 265: /* number of vertices */ 1: 266: xy = alloc_array(count); call 0 returned 100% 1: 267: if (!xy) { branch 0 taken 0% branch 1 taken 100% -: 268: return NULL; -: 269: } -: 270: -: 271: } else { -: 272: -: 273: /* sequence or other path */ 10: 274: PyErr_Clear(); call 0 returned 100% 10: 275: if (!PyArg_ParseTuple(args, "O", &data)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 276: return NULL; -: 277: } -: 278: 10: 279: count = PyPath_Flatten(data, &xy); call 0 returned 100% 10: 280: if (count < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 281: return NULL; -: 282: } -: 283: } -: 284: 10: 285: return (PyObject*) path_new(count, xy, 0); call 0 returned 100% -: 286:} -: 287: -: 288: -: 289:/* -------------------------------------------------------------------- */ -: 290:/* Methods */ -: 291:/* -------------------------------------------------------------------- */ -: 292: -: 293:static PyObject* function path_compact called 1 returned 100% blocks executed 100% 1: 294:path_compact(PyPathObject* self, PyObject* args) -: 295:{ -: 296: /* Simple-minded method to shorten path. A point is removed if -: 297: the city block distance to the previous point is less than the -: 298: given distance */ -: 299: Py_ssize_t i, j; -: 300: double *xy; -: 301: 1: 302: double cityblock = 2.0; -: 303: 1: 304: if (!PyArg_ParseTuple(args, "|d:compact", &cityblock)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 305: return NULL; -: 306: } -: 307: 1: 308: xy = self->xy; -: 309: -: 310: /* remove bogus vertices */ 5: 311: for (i = j = 1; i < self->count; i++) { branch 0 taken 80% branch 1 taken 20% (fallthrough) 4: 312: if (fabs(xy[j+j-2]-xy[i+i]) + fabs(xy[j+j-1]-xy[i+i+1]) >= cityblock) { branch 0 taken 50% (fallthrough) branch 1 taken 50% 2: 313: xy[j+j] = xy[i+i]; 2: 314: xy[j+j+1] = xy[i+i+1]; 2: 315: j++; -: 316: } -: 317: } -: 318: 1: 319: i = self->count - j; 1: 320: self->count = j; -: 321: -: 322: /* shrink coordinate array */ -: 323: /* malloc check ok, self->count is smaller than it was before */ 1: 324: self->xy = realloc(self->xy, 2 * self->count * sizeof(double)); -: 325: 1: 326: return Py_BuildValue("i", i); /* number of removed vertices */ call 0 returned 100% -: 327:} -: 328: -: 329:static PyObject* function path_getbbox called 1 returned 100% blocks executed 87% 1: 330:path_getbbox(PyPathObject* self, PyObject* args) -: 331:{ -: 332: /* Find bounding box */ -: 333: Py_ssize_t i; -: 334: double *xy; -: 335: double x0, y0, x1, y1; -: 336: 1: 337: if (!PyArg_ParseTuple(args, ":getbbox")) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 338: return NULL; -: 339: } -: 340: 1: 341: xy = self->xy; -: 342: 1: 343: x0 = x1 = xy[0]; 1: 344: y0 = y1 = xy[1]; -: 345: 5: 346: for (i = 1; i < self->count; i++) { branch 0 taken 80% branch 1 taken 20% (fallthrough) 4: 347: if (xy[i+i] < x0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 348: x0 = xy[i+i]; -: 349: } 4: 350: if (xy[i+i] > x1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 4: 351: x1 = xy[i+i]; -: 352: } 4: 353: if (xy[i+i+1] < y0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 354: y0 = xy[i+i+1]; -: 355: } 4: 356: if (xy[i+i+1] > y1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 4: 357: y1 = xy[i+i+1]; -: 358: } -: 359: } -: 360: 1: 361: return Py_BuildValue("dddd", x0, y0, x1, y1); call 0 returned 100% -: 362:} -: 363: -: 364:static PyObject* function path_getitem called 36 returned 100% blocks executed 100% 36: 365:path_getitem(PyPathObject* self, Py_ssize_t i) -: 366:{ 36: 367: if (i < 0) { branch 0 taken 3% (fallthrough) branch 1 taken 97% 1: 368: i = self->count + i; -: 369: } 36: 370: if (i < 0 || i >= self->count) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 36% (fallthrough) branch 3 taken 64% 13: 371: PyErr_SetString(PyExc_IndexError, "path index out of range"); call 0 returned 100% 13: 372: return NULL; -: 373: } -: 374: 23: 375: return Py_BuildValue("dd", self->xy[i+i], self->xy[i+i+1]); call 0 returned 100% -: 376:} -: 377: -: 378:static PyObject* function path_getslice called 1 returned 100% blocks executed 70% 1: 379:path_getslice(PyPathObject* self, Py_ssize_t ilow, Py_ssize_t ihigh) -: 380:{ -: 381: /* adjust arguments */ 1: 382: if (ilow < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 383: ilow = 0; 1: 384: } else if (ilow >= self->count) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 385: ilow = self->count; -: 386: } 1: 387: if (ihigh < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 388: ihigh = 0; -: 389: } 1: 390: if (ihigh < ilow) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 391: ihigh = ilow; 1: 392: } else if (ihigh > self->count) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 393: ihigh = self->count; -: 394: } -: 395: 1: 396: return (PyObject*) path_new(ihigh - ilow, self->xy + ilow * 2, 1); call 0 returned 100% -: 397:} -: 398: -: 399:static Py_ssize_t function path_len called 14 returned 100% blocks executed 100% 14: 400:path_len(PyPathObject* self) -: 401:{ 14: 402: return self->count; -: 403:} -: 404: -: 405:static PyObject* function path_map called 0 returned 0% blocks executed 0% #####: 406:path_map(PyPathObject* self, PyObject* args) -: 407:{ -: 408: /* Map coordinate set through function */ -: 409: Py_ssize_t i; -: 410: double *xy; -: 411: PyObject* function; -: 412: #####: 413: if (!PyArg_ParseTuple(args, "O:map", &function)) { call 0 never executed branch 1 never executed branch 2 never executed -: 414: return NULL; -: 415: } -: 416: #####: 417: xy = self->xy; -: 418: -: 419: /* apply function to coordinate set */ #####: 420: for (i = 0; i < self->count; i++) { branch 0 never executed branch 1 never executed #####: 421: double x = xy[i+i]; #####: 422: double y = xy[i+i+1]; #####: 423: PyObject* item = PyObject_CallFunction(function, "dd", x, y); call 0 never executed #####: 424: if (!item || !PyArg_ParseTuple(item, "dd", &x, &y)) { branch 0 never executed branch 1 never executed call 2 never executed branch 3 never executed branch 4 never executed #####: 425: Py_XDECREF(item); branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed call 4 never executed #####: 426: return NULL; -: 427: } #####: 428: xy[i+i] = x; #####: 429: xy[i+i+1] = y; #####: 430: Py_DECREF(item); branch 0 never executed branch 1 never executed call 2 never executed -: 431: } -: 432: #####: 433: Py_INCREF(Py_None); #####: 434: return Py_None; -: 435:} -: 436: -: 437:static int function path_setitem called 0 returned 0% blocks executed 0% #####: 438:path_setitem(PyPathObject* self, Py_ssize_t i, PyObject* op) -: 439:{ -: 440: double* xy; -: 441: #####: 442: if (i < 0 || i >= self->count) { branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed #####: 443: PyErr_SetString(PyExc_IndexError, call 0 never executed -: 444: "path assignment index out of range"); #####: 445: return -1; -: 446: } -: 447: #####: 448: if (op == NULL) { branch 0 never executed branch 1 never executed #####: 449: PyErr_SetString(PyExc_TypeError, call 0 never executed -: 450: "cannot delete from path"); #####: 451: return -1; -: 452: } -: 453: #####: 454: xy = &self->xy[i+i]; -: 455: #####: 456: if (!PyArg_ParseTuple(op, "dd", &xy[0], &xy[1])) { call 0 never executed branch 1 never executed branch 2 never executed -: 457: return -1; -: 458: } -: 459: #####: 460: return 0; -: 461:} -: 462: -: 463:static PyObject* function path_tolist called 4 returned 100% blocks executed 90% 4: 464:path_tolist(PyPathObject* self, PyObject* args) -: 465:{ -: 466: PyObject *list; -: 467: Py_ssize_t i; -: 468: 4: 469: int flat = 0; 4: 470: if (!PyArg_ParseTuple(args, "|i:tolist", &flat)) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 471: return NULL; -: 472: } -: 473: 4: 474: if (flat) { branch 0 taken 50% (fallthrough) branch 1 taken 50% 2: 475: list = PyList_New(self->count*2); 14: 476: for (i = 0; i < self->count*2; i++) { call 0 returned 100% branch 1 taken 86% branch 2 taken 14% -: 477: PyObject* item; 12: 478: item = PyFloat_FromDouble(self->xy[i]); call 0 returned 100% 12: 479: if (!item) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 480: goto error; -: 481: } 12: 482: PyList_SetItem(list, i, item); call 0 returned 100% -: 483: } -: 484: } else { 2: 485: list = PyList_New(self->count); 8: 486: for (i = 0; i < self->count; i++) { call 0 returned 100% branch 1 taken 75% branch 2 taken 25% -: 487: PyObject* item; 6: 488: item = Py_BuildValue("dd", self->xy[i+i], self->xy[i+i+1]); call 0 returned 100% 6: 489: if (!item) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 490: goto error; -: 491: } 6: 492: PyList_SetItem(list, i, item); call 0 returned 100% -: 493: } -: 494: } -: 495: -: 496: return list; -: 497: -: 498:error: #####: 499: Py_DECREF(list); branch 0 never executed branch 1 never executed call 2 never executed -: 500: return NULL; -: 501:} -: 502: -: 503:static PyObject* function path_transform called 1 returned 100% blocks executed 63% 1: 504:path_transform(PyPathObject* self, PyObject* args) -: 505:{ -: 506: /* Apply affine transform to coordinate set */ -: 507: Py_ssize_t i; -: 508: double *xy; -: 509: double a, b, c, d, e, f; -: 510: 1: 511: double wrap = 0.0; -: 512: 1: 513: if (!PyArg_ParseTuple(args, "(dddddd)|d:transform", call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% -: 514: &a, &b, &c, &d, &e, &f, -: 515: &wrap)) { -: 516: return NULL; -: 517: } -: 518: 1: 519: xy = self->xy; -: 520: -: 521: /* transform the coordinate set */ 1: 522: if (b == 0.0 && d == 0.0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% -: 523: /* scaling */ 3: 524: for (i = 0; i < self->count; i++) { branch 0 taken 75% branch 1 taken 25% 3: 525: xy[i+i] = a*xy[i+i]+c; 3: 526: xy[i+i+1] = e*xy[i+i+1]+f; -: 527: } -: 528: } else { -: 529: /* affine transform */ #####: 530: for (i = 0; i < self->count; i++) { branch 0 never executed branch 1 never executed #####: 531: double x = xy[i+i]; #####: 532: double y = xy[i+i+1]; #####: 533: xy[i+i] = a*x+b*y+c; #####: 534: xy[i+i+1] = d*x+e*y+f; -: 535: } -: 536: } -: 537: -: 538: /* special treatment of geographical map data */ 1: 539: if (wrap != 0.0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 540: for (i = 0; i < self->count; i++) { branch 0 never executed branch 1 never executed #####: 541: xy[i+i] = fmod(xy[i+i], wrap); -: 542: } -: 543: } -: 544: 1: 545: Py_INCREF(Py_None); 1: 546: return Py_None; -: 547:} -: 548: -: 549:static struct PyMethodDef methods[] = { -: 550: {"getbbox", (PyCFunction)path_getbbox, 1}, -: 551: {"tolist", (PyCFunction)path_tolist, 1}, -: 552: {"compact", (PyCFunction)path_compact, 1}, -: 553: {"map", (PyCFunction)path_map, 1}, -: 554: {"transform", (PyCFunction)path_transform, 1}, -: 555: {NULL, NULL} /* sentinel */ -: 556:}; -: 557: -: 558:static PyObject* function path_getattr_id called 0 returned 0% blocks executed 0% #####: 559:path_getattr_id(PyPathObject* self, void* closure) -: 560:{ #####: 561: return Py_BuildValue("n", (Py_ssize_t) self->xy); call 0 never executed -: 562:} -: 563: -: 564:static struct PyGetSetDef getsetters[] = { -: 565: { "id", (getter) path_getattr_id }, -: 566: { NULL } -: 567:}; -: 568: -: 569:static PyObject* function path_subscript called 4 returned 100% blocks executed 83% 4: 570:path_subscript(PyPathObject* self, PyObject* item) { 4: 571: if (PyIndex_Check(item)) { branch 0 taken 75% (fallthrough) branch 1 taken 25% branch 2 taken 67% (fallthrough) branch 3 taken 33% -: 572: Py_ssize_t i; 2: 573: i = PyNumber_AsSsize_t(item, PyExc_IndexError); call 0 returned 100% 2: 574: if (i == -1 && PyErr_Occurred()) { branch 0 taken 50% (fallthrough) branch 1 taken 50% call 2 returned 100% branch 3 taken 100% (fallthrough) branch 4 taken 0% -: 575: return NULL; -: 576: } 2: 577: return path_getitem(self, i); call 0 returned 100% -: 578: } 2: 579: if (PySlice_Check(item)) { branch 0 taken 50% (fallthrough) branch 1 taken 50% 1: 580: int len = 4; -: 581: Py_ssize_t start, stop, step, slicelength; -: 582: 1: 583: if (PySlice_GetIndicesEx(item, len, &start, &stop, &step, &slicelength) < 0) { call 0 returned 100% branch 1 taken 100% (fallthrough) branch 2 taken 0% call 3 returned 100% branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 584: return NULL; -: 585: } -: 586: 1: 587: if (slicelength <= 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 588: double *xy = alloc_array(0); call 0 never executed #####: 589: return (PyObject*) path_new(0, xy, 0); call 0 never executed -: 590: } 1: 591: else if (step == 1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% 1: 592: return path_getslice(self, start, stop); call 0 returned 100% -: 593: } -: 594: else { #####: 595: PyErr_SetString(PyExc_TypeError, "slice steps not supported"); call 0 never executed #####: 596: return NULL; -: 597: } -: 598: } -: 599: else { 1: 600: PyErr_Format(PyExc_TypeError, call 0 returned 100% -: 601: "Path indices must be integers, not %.200s", -: 602: Py_TYPE(item)->tp_name); 1: 603: return NULL; -: 604: } -: 605:} -: 606: -: 607:static PySequenceMethods path_as_sequence = { -: 608: (lenfunc)path_len, /*sq_length*/ -: 609: (binaryfunc)0, /*sq_concat*/ -: 610: (ssizeargfunc)0, /*sq_repeat*/ -: 611: (ssizeargfunc)path_getitem, /*sq_item*/ -: 612: (ssizessizeargfunc)path_getslice, /*sq_slice*/ -: 613: (ssizeobjargproc)path_setitem, /*sq_ass_item*/ -: 614: (ssizessizeobjargproc)0, /*sq_ass_slice*/ -: 615:}; -: 616: -: 617:static PyMappingMethods path_as_mapping = { -: 618: (lenfunc)path_len, -: 619: (binaryfunc)path_subscript, -: 620: NULL -: 621:}; -: 622: -: 623:static PyTypeObject PyPathType = { -: 624: PyVarObject_HEAD_INIT(NULL, 0) -: 625: "Path", /*tp_name*/ -: 626: sizeof(PyPathObject), /*tp_size*/ -: 627: 0, /*tp_itemsize*/ -: 628: /* methods */ -: 629: (destructor)path_dealloc, /*tp_dealloc*/ -: 630: 0, /*tp_print*/ -: 631: 0, /*tp_getattr*/ -: 632: 0, /*tp_setattr*/ -: 633: 0, /*tp_compare*/ -: 634: 0, /*tp_repr*/ -: 635: 0, /*tp_as_number */ -: 636: &path_as_sequence, /*tp_as_sequence */ -: 637: &path_as_mapping, /*tp_as_mapping */ -: 638: 0, /*tp_hash*/ -: 639: 0, /*tp_call*/ -: 640: 0, /*tp_str*/ -: 641: 0, /*tp_getattro*/ -: 642: 0, /*tp_setattro*/ -: 643: 0, /*tp_as_buffer*/ -: 644: Py_TPFLAGS_DEFAULT, /*tp_flags*/ -: 645: 0, /*tp_doc*/ -: 646: 0, /*tp_traverse*/ -: 647: 0, /*tp_clear*/ -: 648: 0, /*tp_richcompare*/ -: 649: 0, /*tp_weaklistoffset*/ -: 650: 0, /*tp_iter*/ -: 651: 0, /*tp_iternext*/ -: 652: methods, /*tp_methods*/ -: 653: 0, /*tp_members*/ -: 654: getsetters, /*tp_getset*/ -: 655:}; -: 656: <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#HexDecode.c.gcov -: 0:Source:src/libImaging/HexDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/HexDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/HexDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for hex encoded image data -: 6: * -: 7: * history: -: 8: * 96-05-16 fl Created -: 9: * -: 10: * Copyright (c) Fredrik Lundh 1996. -: 11: * Copyright (c) Secret Labs AB 1997. -: 12: * -: 13: * See the README file for information on usage and redistribution. -: 14: */ -: 15: -: 16: -: 17:#include "Imaging.h" -: 18: -: 19:#define HEX(v) ((v >= '0' && v <= '9') ? v - '0' :\ -: 20: (v >= 'a' && v <= 'f') ? v - 'a' + 10 :\ -: 21: (v >= 'A' && v <= 'F') ? v - 'A' + 10 : -1) -: 22: -: 23:int function ImagingHexDecode called 194 returned 100% blocks executed 83% 194: 24:ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) -: 25:{ -: 26: UINT8* ptr; -: 27: int a, b; -: 28: 194: 29: ptr = buf; -: 30: -: 31: for (;;) { -: 32: 1254: 33: if (bytes < 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 34: return ptr - buf; -: 35: } -: 36: 1254: 37: a = HEX(ptr[0]); branch 0 taken 69% (fallthrough) branch 1 taken 31% branch 2 taken 0% (fallthrough) branch 3 taken 100% branch 4 taken 100% (fallthrough) branch 5 taken 0% 1254: 38: b = HEX(ptr[1]); branch 0 taken 80% (fallthrough) branch 1 taken 20% branch 2 taken 0% (fallthrough) branch 3 taken 100% branch 4 taken 100% (fallthrough) branch 5 taken 0% -: 39: 1254: 40: if (a < 0 || b < 0) { branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 0% (fallthrough) branch 3 taken 100% -: 41: #####: 42: ptr++; #####: 43: bytes--; -: 44: -: 45: } else { -: 46: 1254: 47: ptr += 2; 1254: 48: bytes -= 2; -: 49: 1254: 50: state->buffer[state->x] = (a<<4) + b; -: 51: 1254: 52: if (++state->x >= state->bytes) { branch 0 taken 0% branch 1 taken 100% (fallthrough) -: 53: -: 54: /* Got a full line, unpack it */ 1254: 55: state->shuffle((UINT8*) im->image[state->y], state->buffer, call 0 returned 100% -: 56: state->xsize); -: 57: 1254: 58: state->x = 0; -: 59: 1254: 60: if (++state->y >= state->ysize) { branch 0 taken 85% branch 1 taken 15% (fallthrough) -: 61: /* End of file (errcode = 0) */ -: 62: return -1; -: 63: } -: 64: } -: 65: -: 66: } -: 67: } -: 68:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#PackDecode.c.gcov -: 0:Source:src/libImaging/PackDecode.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/PackDecode.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/PackDecode.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * decoder for PackBits image data. -: 6: * -: 7: * history: -: 8: * 96-04-19 fl Created -: 9: * -: 10: * Copyright (c) Fredrik Lundh 1996. -: 11: * Copyright (c) Secret Labs AB 1997. -: 12: * -: 13: * See the README file for information on usage and redistribution. -: 14: */ -: 15: -: 16: -: 17:#include "Imaging.h" -: 18: -: 19:int function ImagingPackbitsDecode called 21 returned 100% blocks executed 84% 21: 20:ImagingPackbitsDecode(Imaging im, ImagingCodecState state, -: 21: UINT8* buf, Py_ssize_t bytes) -: 22:{ -: 23: UINT8 n; -: 24: UINT8* ptr; -: 25: int i; -: 26: 21: 27: ptr = buf; -: 28: -: 29: for (;;) { -: 30: 24288: 31: if (bytes < 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 32: return ptr - buf; -: 33: } -: 34: 24288: 35: if (ptr[0] & 0x80) { branch 0 taken 59% (fallthrough) branch 1 taken 41% -: 36: 14438: 37: if (ptr[0] == 0x80) { branch 0 taken 0% (fallthrough) branch 1 taken 100% -: 38: /* Nop */ #####: 39: ptr++; bytes--; #####: 40: continue; -: 41: } -: 42: -: 43: /* Run */ 14438: 44: if (bytes < 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 45: return ptr - buf; -: 46: } -: 47: 80260: 48: for (n = 257 - ptr[0]; n > 0; n--) { branch 0 taken 82% branch 1 taken 18% (fallthrough) 65822: 49: if (state->x >= state->bytes) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 50: /* state->errcode = IMAGING_CODEC_OVERRUN; */ -: 51: break; -: 52: } 65822: 53: state->buffer[state->x++] = ptr[1]; -: 54: } -: 55: 14438: 56: ptr += 2; bytes -= 2; -: 57: -: 58: } else { -: 59: -: 60: /* Literal */ 9850: 61: n = ptr[0]+2; -: 62: 9850: 63: if (bytes < n) { branch 0 taken 100% (fallthrough) branch 1 taken 0% #####: 64: return ptr - buf; -: 65: } -: 66: 278242: 67: for (i = 1; i < n; i++) { branch 0 taken 97% branch 1 taken 3% (fallthrough) 278242: 68: if (state->x >= state->bytes) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 69: /* state->errcode = IMAGING_CODEC_OVERRUN; */ -: 70: break; -: 71: } 278242: 72: state->buffer[state->x++] = ptr[i]; -: 73: } -: 74: 9850: 75: ptr += n; bytes -= n; -: 76: -: 77: } -: 78: 24288: 79: if (state->x >= state->bytes) { branch 0 taken 89% branch 1 taken 11% (fallthrough) -: 80: -: 81: /* Got a full line, unpack it */ 8064: 82: state->shuffle((UINT8*) im->image[state->y + state->yoff] + call 0 returned 100% 5376: 83: state->xoff * im->pixelsize, state->buffer, -: 84: state->xsize); -: 85: 2688: 86: state->x = 0; -: 87: 2688: 88: if (++state->y >= state->ysize) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 89: /* End of file (errcode = 0) */ -: 90: return -1; -: 91: } -: 92: } -: 93: -: 94: } -: 95:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Offset.c.gcov -: 0:Source:src/libImaging/Offset.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Offset.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Offset.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1:/* -: 2: * The Python Imaging Library -: 3: * $Id$ -: 4: * -: 5: * offset an image in x and y directions -: 6: * -: 7: * history: -: 8: * 96-07-22 fl: Created -: 9: * 98-11-01 cgw@pgt.com: Fixed negative-array index bug -: 10: * -: 11: * Copyright (c) Fredrik Lundh 1996. -: 12: * Copyright (c) Secret Labs AB 1997. -: 13: * -: 14: * See the README file for information on usage and redistribution. -: 15: */ -: 16: -: 17: -: 18:#include "Imaging.h" -: 19: -: 20: -: 21:Imaging function ImagingOffset called 5 returned 100% blocks executed 87% 5: 22:ImagingOffset(Imaging im, int xoffset, int yoffset) -: 23:{ -: 24: int x, y; -: 25: Imaging imOut; -: 26: 5: 27: if (!im) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 28: return (Imaging) ImagingError_ModeError(); call 0 never executed -: 29: } -: 30: 5: 31: imOut = ImagingNewDirty(im->mode, im->xsize, im->ysize); call 0 returned 100% 5: 32: if (!imOut) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 33: return NULL; -: 34: } -: 35: 5: 36: ImagingCopyPalette(imOut, im); call 0 returned 100% -: 37: -: 38: /* make offsets positive to avoid negative coordinates */ 5: 39: xoffset %= im->xsize; 5: 40: xoffset = im->xsize - xoffset; 5: 41: if (xoffset < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 42: xoffset += im->xsize; -: 43: } -: 44: 5: 45: yoffset %= im->ysize; 5: 46: yoffset = im->ysize - yoffset; 5: 47: if (yoffset < 0) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 48: yoffset += im->ysize; -: 49: } -: 50: -: 51:#define OFFSET(image)\ -: 52: for (y = 0; y < im->ysize; y++) {\ -: 53: for (x = 0; x < im->xsize; x++) {\ -: 54: int yi = (y + yoffset) % im->ysize;\ -: 55: int xi = (x + xoffset) % im->xsize;\ -: 56: imOut->image[y][x] = im->image[yi][xi];\ -: 57: }\ -: 58: } -: 59: 5: 60: if (im->image8) { branch 0 taken 60% (fallthrough) branch 1 taken 40% 32768: 61: OFFSET(image8) branch 0 taken 99% branch 1 taken 1% (fallthrough) branch 2 taken 99% (fallthrough) branch 3 taken 1% -: 62: } else { 30000: 63: OFFSET(image32) branch 0 taken 99% branch 1 taken 1% (fallthrough) branch 2 taken 99% (fallthrough) branch 3 taken 1% -: 64: } -: 65: -: 66: return imOut; -: 67:} <<<<<< EOF # path=/home/travis/build/python-pillow/Pillow/src#libImaging#Pack.c.gcov -: 0:Source:src/libImaging/Pack.c -: 0:Graph:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Pack.gcno -: 0:Data:/home/travis/build/python-pillow/Pillow/build/temp.linux-ppc64le-3.7/src/libImaging/Pack.gcda -: 0:Runs:3 -: 0:Programs:1 -: 1: /* -: 2: * The Python Imaging Library. -: 3: * $Id$ -: 4: * -: 5: * code to pack raw data -: 6: * -: 7: * history: -: 8: * 1996-04-30 fl Created -: 9: * 1996-05-12 fl Published a few RGB packers -: 10: * 1996-11-01 fl More RGB packers (Tk booster stuff) -: 11: * 1996-12-30 fl Added P;1, P;2 and P;4 packers -: 12: * 1997-06-02 fl Added F (F;32NF) packer -: 13: * 1997-08-28 fl Added 1 as L packer -: 14: * 1998-02-08 fl Added I packer -: 15: * 1998-03-09 fl Added mode field, RGBA/RGBX as RGB packers -: 16: * 1998-07-01 fl Added YCbCr support -: 17: * 1998-07-12 fl Added I 16 packer -: 18: * 1999-02-03 fl Added BGR packers -: 19: * 2003-09-26 fl Added LA/PA packers -: 20: * 2006-06-22 fl Added CMYK;I packer -: 21: * -: 22: * Copyright (c) 1997-2006 by Secret Labs AB. -: 23: * Copyright (c) 1996-1997 by Fredrik Lundh. -: 24: * -: 25: * See the README file for information on usage and redistribution. -: 26: */ -: 27: -: 28: -: 29:#include "Imaging.h" -: 30: -: 31:#define R 0 -: 32:#define G 1 -: 33:#define B 2 -: 34:#define X 3 -: 35:#define A 3 -: 36: -: 37:#define C 0 -: 38:#define M 1 -: 39:#define Y 2 -: 40:#define K 3 -: 41: -: 42:/* byte swapping macros */ -: 43: -: 44:#define C16N\ -: 45: (out[0]=tmp[0], out[1]=tmp[1]); -: 46:#define C16S\ -: 47: (out[1]=tmp[0], out[0]=tmp[1]); -: 48:#define C32N\ -: 49: (out[0]=tmp[0], out[1]=tmp[1], out[2]=tmp[2], out[3]=tmp[3]); -: 50:#define C32S\ -: 51: (out[3]=tmp[0], out[2]=tmp[1], out[1]=tmp[2], out[0]=tmp[3]); -: 52:#define C64N\ -: 53: (out[0]=tmp[0], out[1]=tmp[1], out[2]=tmp[2], out[3]=tmp[3],\ -: 54: out[4]=tmp[4], out[5]=tmp[5], out[6]=tmp[6], out[7]=tmp[7]); -: 55:#define C64S\ -: 56: (out[7]=tmp[0], out[6]=tmp[1], out[5]=tmp[2], out[4]=tmp[3],\ -: 57: out[3]=tmp[4], out[2]=tmp[5], out[1]=tmp[6], out[0]=tmp[7]); -: 58: -: 59:#ifdef WORDS_BIGENDIAN -: 60:#define C16B C16N -: 61:#define C16L C16S -: 62:#define C32B C32N -: 63:#define C32L C32S -: 64:#define C64B C64N -: 65:#define C64L C64S -: 66:#else -: 67:#define C16B C16S -: 68:#define C16L C16N -: 69:#define C32B C32S -: 70:#define C32L C32N -: 71:#define C64B C64S -: 72:#define C64L C64N -: 73:#endif -: 74: -: 75: -: 76:static void function pack1 called 23398 returned 100% blocks executed 100% 23398: 77:pack1(UINT8* out, const UINT8* in, int pixels) -: 78:{ -: 79: int i, m, b; -: 80: /* bilevel (black is 0) */ 23398: 81: b = 0; m = 128; 15596631: 82: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 15573233: 83: if (in[i] != 0) { branch 0 taken 46% (fallthrough) branch 1 taken 54% 7136230: 84: b |= m; -: 85: } 15573233: 86: m >>= 1; 15573233: 87: if (m == 0) { branch 0 taken 12% (fallthrough) branch 1 taken 88% 1944082: 88: *out++ = b; 1944082: 89: b = 0; m = 128; -: 90: } -: 91: } 23398: 92: if (m != 128) { branch 0 taken 30% (fallthrough) branch 1 taken 70% 6955: 93: *out++ = b; -: 94: } 23398: 95:} -: 96: -: 97:static void function pack1I called 258 returned 100% blocks executed 90% 258: 98:pack1I(UINT8* out, const UINT8* in, int pixels) -: 99:{ -: 100: int i, m, b; -: 101: /* bilevel (black is 1) */ 258: 102: b = 0; m = 128; 33042: 103: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 32784: 104: if (in[i] == 0) { branch 0 taken 67% (fallthrough) branch 1 taken 33% 21993: 105: b |= m; -: 106: } 32784: 107: m >>= 1; 32784: 108: if (m == 0) { branch 0 taken 13% (fallthrough) branch 1 taken 88% 4098: 109: *out++ = b; 4098: 110: b = 0; m = 128; -: 111: } -: 112: } 258: 113: if (m != 128) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 114: *out++ = b; -: 115: } 258: 116:} -: 117: -: 118:static void function pack1R called 1386 returned 100% blocks executed 90% 1386: 119:pack1R(UINT8* out, const UINT8* in, int pixels) -: 120:{ -: 121: int i, m, b; -: 122: /* bilevel, lsb first (black is 0) */ 1386: 123: b = 0; m = 1; 1050554: 124: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 1049168: 125: if (in[i] != 0) { branch 0 taken 33% (fallthrough) branch 1 taken 67% 348100: 126: b |= m; -: 127: } 1049168: 128: m <<= 1; 1049168: 129: if (m == 256){ branch 0 taken 13% (fallthrough) branch 1 taken 88% 131146: 130: *out++ = b; 131146: 131: b = 0; m = 1; -: 132: } -: 133: } 1386: 134: if (m != 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 135: *out++ = b; -: 136: } 1386: 137:} -: 138: -: 139:static void function pack1IR called 2 returned 100% blocks executed 90% 2: 140:pack1IR(UINT8* out, const UINT8* in, int pixels) -: 141:{ -: 142: int i, m, b; -: 143: /* bilevel, lsb first (black is 1) */ 2: 144: b = 0; m = 1; 18: 145: for (i = 0; i < pixels; i++) { branch 0 taken 89% branch 1 taken 11% (fallthrough) 16: 146: if (in[i] == 0) { branch 0 taken 31% (fallthrough) branch 1 taken 69% 5: 147: b |= m; -: 148: } 16: 149: m <<= 1; 16: 150: if (m == 256){ branch 0 taken 13% (fallthrough) branch 1 taken 88% 2: 151: *out++ = b; 2: 152: b = 0; m = 1; -: 153: } -: 154: } 2: 155: if (m != 1) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 156: *out++ = b; -: 157: } 2: 158:} -: 159: -: 160:static void function pack1L called 45 returned 100% blocks executed 100% 45: 161:pack1L(UINT8* out, const UINT8* in, int pixels) -: 162:{ -: 163: int i; -: 164: /* bilevel, stored as bytes */ 663: 165: for (i = 0; i < pixels; i++) { branch 0 taken 93% branch 1 taken 7% (fallthrough) 618: 166: out[i] = (in[i] != 0) ? 255 : 0; branch 0 taken 96% (fallthrough) branch 1 taken 4% -: 167: } 45: 168:} -: 169: -: 170:static void function packP4 called 1 returned 100% blocks executed 83% 1: 171:packP4(UINT8* out, const UINT8* in, int pixels) -: 172:{ 4: 173: while (pixels >= 2) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 4: 174: *out++ = (in[0] << 4) | 2: 175: (in[1] & 15); 2: 176: in += 2; pixels -= 2; -: 177: } -: 178: 1: 179: if (pixels) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 180: out[0] = (in[0] << 4); -: 181: } 1: 182:} -: 183: -: 184:static void function packP2 called 2 returned 100% blocks executed 75% 2: 185:packP2(UINT8* out, const UINT8* in, int pixels) -: 186:{ 6: 187: while (pixels >= 4) { branch 0 taken 50% branch 1 taken 50% (fallthrough) 8: 188: *out++ = (in[0] << 6) | 2: 189: ((in[1] & 3) << 4) | 2: 190: ((in[2] & 3) << 2) | 2: 191: (in[3] & 3); 2: 192: in += 4; pixels -= 4; -: 193: } -: 194: 2: 195: switch (pixels) { branch 0 taken 0% branch 1 taken 50% branch 2 taken 0% branch 3 taken 50% -: 196: case 3: #####: 197: out[0] = (in[0] << 6) | #####: 198: ((in[1] & 3) << 4) | #####: 199: ((in[2] & 3) << 2); #####: 200: break; -: 201: case 2: 2: 202: out[0] = (in[0] << 6) | 1: 203: ((in[1] & 3) << 4); 1: 204: break; -: 205: case 1: #####: 206: out[0] = (in[0] << 6); -: 207: } 2: 208:} -: 209: -: 210:static void function packL16 called 1 returned 100% blocks executed 100% 1: 211:packL16(UINT8* out, const UINT8* in, int pixels) -: 212:{ -: 213: int i; -: 214: /* L -> L;16, e.g: \xff77 -> \x00\xff\x00\x77 */ 3: 215: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 2: 216: out[0] = 0; 2: 217: out[1] = in[i]; 2: 218: out += 2; -: 219: } 1: 220:} -: 221: -: 222:static void function packL16B called 385 returned 100% blocks executed 100% 385: 223:packL16B(UINT8* out, const UINT8* in, int pixels) -: 224:{ -: 225: int i; -: 226: /* L -> L;16B, e.g: \xff77 -> \xff\x00\x77\x00 */ 49539: 227: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 49154: 228: out[0] = in[i]; 49154: 229: out[1] = 0; 49154: 230: out += 2; -: 231: } 385: 232:} -: 233: -: 234: -: 235:static void function packLA called 13122 returned 100% blocks executed 100% 13122: 236:packLA(UINT8* out, const UINT8* in, int pixels) -: 237:{ -: 238: int i; -: 239: /* LA, pixel interleaved */ 1411686: 240: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 1398564: 241: out[0] = in[R]; 1398564: 242: out[1] = in[A]; 1398564: 243: out += 2; in += 4; -: 244: } 13122: 245:} -: 246: -: 247:static void function packLAL called 130 returned 100% blocks executed 100% 130: 248:packLAL(UINT8* out, const UINT8* in, int pixels) -: 249:{ -: 250: int i; -: 251: /* LA, line interleaved */ 16520: 252: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 16390: 253: out[i] = in[R]; 16390: 254: out[i+pixels] = in[A]; 16390: 255: in += 4; -: 256: } 130: 257:} -: 258: -: 259:void function ImagingPackRGB called 188815 returned 100% blocks executed 100% 188815: 260:ImagingPackRGB(UINT8* out, const UINT8* in, int pixels) -: 261:{ 188815: 262: int i = 0; -: 263: /* RGB triplets */ -: 264:#ifdef __sparc -: 265: /* SPARC CPUs cannot read integers from nonaligned addresses. */ -: 266: for (; i < pixels; i++) { -: 267: out[0] = in[R]; -: 268: out[1] = in[G]; -: 269: out[2] = in[B]; -: 270: out += 3; in += 4; -: 271: } -: 272:#else 195550569: 273: for (; i < pixels-1; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 390723508: 274: memcpy(out, in + i * 4, 4); 195361754: 275: out += 3; -: 276: } 188815: 277: for (; i < pixels; i++) { branch 0 taken 50% branch 1 taken 50% (fallthrough) 188815: 278: out[0] = in[i*4+R]; 188815: 279: out[1] = in[i*4+G]; 188815: 280: out[2] = in[i*4+B]; 188815: 281: out += 3; -: 282: } -: 283:#endif 188815: 284:} -: 285: -: 286:void function ImagingPackXRGB called 1 returned 100% blocks executed 100% 1: 287:ImagingPackXRGB(UINT8* out, const UINT8* in, int pixels) -: 288:{ -: 289: int i; -: 290: /* XRGB, triplets with left padding */ 3: 291: for (i = 0; i < pixels; i++) { branch 0 taken 67% branch 1 taken 33% (fallthrough) 2: 292: out[0] = 0; 2: 293: out[1] = in[R]; 2: 294: out[2] = in[G]; 2: 295: out[3] = in[B]; 2: 296: out += 4; in += 4; -: 297: } 1: 298:} -: 299: -: 300:void function ImagingPackBGR called 1379 returned 100% blocks executed 100% 1379: 301:ImagingPackBGR(UINT8* out, const UINT8* in, int pixels) -: 302:{ -: 303: int i; -: 304: /* RGB, reversed bytes */ 208412: 305: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 207033: 306: out[0] = in[B]; 207033: 307: out[1] = in[G]; 207033: 308: out[2] = in[R]; 207033: 309: out += 3; in += 4; -: 310: } 1379: 311:} -: 312: -: 313:void function ImagingPackBGRX called 3 returned 100% blocks executed 100% 3: 314:ImagingPackBGRX(UINT8* out, const UINT8* in, int pixels) -: 315:{ -: 316: int i; -: 317: /* BGRX, reversed bytes with right padding */ 264: 318: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 261: 319: out[0] = in[B]; 261: 320: out[1] = in[G]; 261: 321: out[2] = in[R]; 261: 322: out[3] = 0; 261: 323: out += 4; in += 4; -: 324: } 3: 325:} -: 326: -: 327:void function ImagingPackXBGR called 2 returned 100% blocks executed 100% 2: 328:ImagingPackXBGR(UINT8* out, const UINT8* in, int pixels) -: 329:{ -: 330: int i; -: 331: /* XBGR, reversed bytes with left padding */ 7: 332: for (i = 0; i < pixels; i++) { branch 0 taken 71% branch 1 taken 29% (fallthrough) 5: 333: out[0] = 0; 5: 334: out[1] = in[B]; 5: 335: out[2] = in[G]; 5: 336: out[3] = in[R]; 5: 337: out += 4; in += 4; -: 338: } 2: 339:} -: 340: -: 341:void function ImagingPackBGRA called 1687 returned 100% blocks executed 100% 1687: 342:ImagingPackBGRA(UINT8* out, const UINT8* in, int pixels) -: 343:{ -: 344: int i; -: 345: /* BGRX, reversed bytes with right padding */ 322628: 346: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 320941: 347: out[0] = in[B]; 320941: 348: out[1] = in[G]; 320941: 349: out[2] = in[R]; 320941: 350: out[3] = in[A]; 320941: 351: out += 4; in += 4; -: 352: } 1687: 353:} -: 354: -: 355:void function ImagingPackABGR called 2 returned 100% blocks executed 100% 2: 356:ImagingPackABGR(UINT8* out, const UINT8* in, int pixels) -: 357:{ -: 358: int i; -: 359: /* XBGR, reversed bytes with left padding */ 8: 360: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 6: 361: out[0] = in[A]; 6: 362: out[1] = in[B]; 6: 363: out[2] = in[G]; 6: 364: out[3] = in[R]; 6: 365: out += 4; in += 4; -: 366: } 2: 367:} -: 368: -: 369:void function ImagingPackBGRa called 1 returned 100% blocks executed 100% 1: 370:ImagingPackBGRa(UINT8* out, const UINT8* in, int pixels) -: 371:{ -: 372: int i; -: 373: /* BGRa, reversed bytes with premultiplied alpha */ 4: 374: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 3: 375: int alpha = out[3] = in[A]; -: 376: int tmp; 3: 377: out[0] = MULDIV255(in[B], alpha, tmp); 3: 378: out[1] = MULDIV255(in[G], alpha, tmp); 3: 379: out[2] = MULDIV255(in[R], alpha, tmp); 3: 380: out += 4; in += 4; -: 381: } 1: 382:} -: 383: -: 384:static void function packRGBL called 1033 returned 100% blocks executed 100% 1033: 385:packRGBL(UINT8* out, const UINT8* in, int pixels) -: 386:{ -: 387: int i; -: 388: /* RGB, line interleaved */ 329744: 389: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 328711: 390: out[i] = in[R]; 328711: 391: out[i+pixels] = in[G]; 328711: 392: out[i+pixels+pixels] = in[B]; 328711: 393: in += 4; -: 394: } 1033: 395:} -: 396: -: 397:static void function packRGBXL called 3 returned 100% blocks executed 100% 3: 398:packRGBXL(UINT8* out, const UINT8* in, int pixels) -: 399:{ -: 400: int i; -: 401: /* RGBX, line interleaved */ 12: 402: for (i = 0; i < pixels; i++) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 9: 403: out[i] = in[R]; 9: 404: out[i+pixels] = in[G]; 9: 405: out[i+pixels+pixels] = in[B]; 9: 406: out[i+pixels+pixels+pixels] = in[X]; 9: 407: in += 4; -: 408: } 3: 409:} -: 410: -: 411:static void function packI16B called 293 returned 100% blocks executed 89% 293: 412:packI16B(UINT8* out, const UINT8* in_, int pixels) -: 413:{ -: 414: int i; -: 415: UINT16 tmp_; 293: 416: UINT8* tmp = (UINT8*) &tmp_; 22775: 417: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) -: 418: INT32 in; 22482: 419: memcpy(&in, in_, sizeof(in)); 22482: 420: if (in <= 0) { branch 0 taken 1% (fallthrough) branch 1 taken 99% 75: 421: tmp_ = 0; 22407: 422: } else if (in > 65535) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 423: tmp_ = 65535; -: 424: } else { 22407: 425: tmp_ = in; -: 426: } 22482: 427: C16B; 22482: 428: out += 2; in_ += sizeof(in); -: 429: } 293: 430:} -: 431: -: 432:static void function packI16N_I16B called 256 returned 100% blocks executed 100% 256: 433:packI16N_I16B(UINT8* out, const UINT8* in, int pixels){ -: 434: int i; 256: 435: UINT8* tmp = (UINT8*) in; 33024: 436: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 32768: 437: C16B; 32768: 438: out += 2; tmp += 2; -: 439: } -: 440: 256: 441:} -: 442:static void function packI16N_I16 called 0 returned 0% blocks executed 0% #####: 443:packI16N_I16(UINT8* out, const UINT8* in, int pixels){ -: 444: int i; #####: 445: UINT8* tmp = (UINT8*) in; #####: 446: for (i = 0; i < pixels; i++) { branch 0 never executed branch 1 never executed #####: 447: C16L; #####: 448: out += 2; tmp += 2; -: 449: } #####: 450:} -: 451: -: 452: -: 453:static void function packI32S called 290 returned 100% blocks executed 100% 290: 454:packI32S(UINT8* out, const UINT8* in, int pixels) -: 455:{ -: 456: int i; 290: 457: UINT8* tmp = (UINT8*) in; 34086: 458: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 33796: 459: C32L; 33796: 460: out += 4; tmp += 4; -: 461: } 290: 462:} -: 463: -: 464:void function ImagingPackLAB called 1025 returned 100% blocks executed 100% 1025: 465:ImagingPackLAB(UINT8* out, const UINT8* in, int pixels) -: 466:{ -: 467: int i; -: 468: /* LAB triplets */ 132100: 469: for (i = 0; i < pixels; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 131075: 470: out[0] = in[0]; 131075: 471: out[1] = in[1] ^ 128; /* signed in outside world */ 131075: 472: out[2] = in[2] ^ 128; 131075: 473: out += 3; in += 4; -: 474: } 1025: 475:} -: 476: -: 477:static void function copy1 called 195347 returned 100% blocks executed 100% 195347: 478:copy1(UINT8* out, const UINT8* in, int pixels) -: 479:{ -: 480: /* L, P */ 390694: 481: memcpy(out, in, pixels); 195347: 482:} -: 483: -: 484:static void function copy2 called 8121 returned 100% blocks executed 100% 8121: 485:copy2(UINT8* out, const UINT8* in, int pixels) -: 486:{ -: 487: /* I;16, etc */ 16242: 488: memcpy(out, in, pixels*2); 8121: 489:} -: 490: -: 491:static void function copy3 called 0 returned 0% blocks executed 0% #####: 492:copy3(UINT8* out, const UINT8* in, int pixels) -: 493:{ -: 494: /* BGR;24, etc */ #####: 495: memcpy(out, in, pixels*3); #####: 496:} -: 497: -: 498:static void function copy4 called 74849 returned 100% blocks executed 100% 74849: 499:copy4(UINT8* out, const UINT8* in, int pixels) -: 500:{ -: 501: /* RGBA, CMYK quadruples */ 149698: 502: memcpy(out, in, 4*pixels); 74849: 503:} -: 504: -: 505:static void function copy4I called 2189 returned 100% blocks executed 100% 2189: 506:copy4I(UINT8* out, const UINT8* in, int pixels) -: 507:{ -: 508: /* RGBA, CMYK quadruples, inverted */ -: 509: int i; 1022553: 510: for (i = 0; i < pixels*4; i++) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 1020364: 511: out[i] = ~in[i]; -: 512: } 2189: 513:} -: 514: -: 515:static void function band0 called 6 returned 100% blocks executed 100% 6: 516:band0(UINT8* out, const UINT8* in, int pixels) -: 517:{ -: 518: int i; 24: 519: for (i = 0; i < pixels; i++, in += 4) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 18: 520: out[i] = in[0]; -: 521: } 6: 522:} -: 523: -: 524:static void function band1 called 6 returned 100% blocks executed 100% 6: 525:band1(UINT8* out, const UINT8* in, int pixels) -: 526:{ -: 527: int i; 24: 528: for (i = 0; i < pixels; i++, in += 4) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 18: 529: out[i] = in[1]; -: 530: } 6: 531:} -: 532: -: 533:static void function band2 called 6 returned 100% blocks executed 100% 6: 534:band2(UINT8* out, const UINT8* in, int pixels) -: 535:{ -: 536: int i; 24: 537: for (i = 0; i < pixels; i++, in += 4) { branch 0 taken 75% branch 1 taken 25% (fallthrough) 18: 538: out[i] = in[2]; -: 539: } 6: 540:} -: 541: -: 542:static void function band3 called 5 returned 100% blocks executed 100% 5: 543:band3(UINT8* out, const UINT8* in, int pixels) -: 544:{ -: 545: int i; 526: 546: for (i = 0; i < pixels; i++, in += 4) { branch 0 taken 99% branch 1 taken 1% (fallthrough) 521: 547: out[i] = in[3]; -: 548: } 5: 549:} -: 550: -: 551:static struct { -: 552: const char* mode; -: 553: const char* rawmode; -: 554: int bits; -: 555: ImagingShuffler pack; -: 556:} packers[] = { -: 557: -: 558: /* bilevel */ -: 559: {"1", "1", 1, pack1}, -: 560: {"1", "1;I", 1, pack1I}, -: 561: {"1", "1;R", 1, pack1R}, -: 562: {"1", "1;IR", 1, pack1IR}, -: 563: {"1", "L", 8, pack1L}, -: 564: -: 565: /* greyscale */ -: 566: {"L", "L", 8, copy1}, -: 567: {"L", "L;16", 16, packL16}, -: 568: {"L", "L;16B", 16, packL16B}, -: 569: -: 570: /* greyscale w. alpha */ -: 571: {"LA", "LA", 16, packLA}, -: 572: {"LA", "LA;L", 16, packLAL}, -: 573: -: 574: /* greyscale w. alpha premultiplied */ -: 575: {"La", "La", 16, packLA}, -: 576: -: 577: /* palette */ -: 578: {"P", "P;1", 1, pack1}, -: 579: {"P", "P;2", 2, packP2}, -: 580: {"P", "P;4", 4, packP4}, -: 581: {"P", "P", 8, copy1}, -: 582: -: 583: /* palette w. alpha */ -: 584: {"PA", "PA", 16, packLA}, -: 585: {"PA", "PA;L", 16, packLAL}, -: 586: -: 587: /* true colour */ -: 588: {"RGB", "RGB", 24, ImagingPackRGB}, -: 589: {"RGB", "RGBX", 32, copy4}, -: 590: {"RGB", "XRGB", 32, ImagingPackXRGB}, -: 591: {"RGB", "BGR", 24, ImagingPackBGR}, -: 592: {"RGB", "BGRX", 32, ImagingPackBGRX}, -: 593: {"RGB", "XBGR", 32, ImagingPackXBGR}, -: 594: {"RGB", "RGB;L", 24, packRGBL}, -: 595: {"RGB", "R", 8, band0}, -: 596: {"RGB", "G", 8, band1}, -: 597: {"RGB", "B", 8, band2}, -: 598: -: 599: /* true colour w. alpha */ -: 600: {"RGBA", "RGBA", 32, copy4}, -: 601: {"RGBA", "RGBA;L", 32, packRGBXL}, -: 602: {"RGBA", "RGB", 24, ImagingPackRGB}, -: 603: {"RGBA", "BGR", 24, ImagingPackBGR}, -: 604: {"RGBA", "BGRA", 32, ImagingPackBGRA}, -: 605: {"RGBA", "ABGR", 32, ImagingPackABGR}, -: 606: {"RGBA", "BGRa", 32, ImagingPackBGRa}, -: 607: {"RGBA", "R", 8, band0}, -: 608: {"RGBA", "G", 8, band1}, -: 609: {"RGBA", "B", 8, band2}, -: 610: {"RGBA", "A", 8, band3}, -: 611: -: 612: /* true colour w. alpha premultiplied */ -: 613: {"RGBa", "RGBa", 32, copy4}, -: 614: {"RGBa", "BGRa", 32, ImagingPackBGRA}, -: 615: {"RGBa", "aBGR", 32, ImagingPackABGR}, -: 616: -: 617: /* true colour w. padding */ -: 618: {"RGBX", "RGBX", 32, copy4}, -: 619: {"RGBX", "RGBX;L", 32, packRGBXL}, -: 620: {"RGBX", "RGB", 24, ImagingPackRGB}, -: 621: {"RGBX", "BGR", 24, ImagingPackBGR}, -: 622: {"RGBX", "BGRX", 32, ImagingPackBGRX}, -: 623: {"RGBX", "XBGR", 32, ImagingPackXBGR}, -: 624: {"RGBX", "R", 8, band0}, -: 625: {"RGBX", "G", 8, band1}, -: 626: {"RGBX", "B", 8, band2}, -: 627: {"RGBX", "X", 8, band3}, -: 628: -: 629: /* colour separation */ -: 630: {"CMYK", "CMYK", 32, copy4}, -: 631: {"CMYK", "CMYK;I", 32, copy4I}, -: 632: {"CMYK", "CMYK;L", 32, packRGBXL}, -: 633: {"CMYK", "C", 8, band0}, -: 634: {"CMYK", "M", 8, band1}, -: 635: {"CMYK", "Y", 8, band2}, -: 636: {"CMYK", "K", 8, band3}, -: 637: -: 638: /* video (YCbCr) */ -: 639: {"YCbCr", "YCbCr", 24, ImagingPackRGB}, -: 640: {"YCbCr", "YCbCr;L", 24, packRGBL}, -: 641: {"YCbCr", "YCbCrX", 32, copy4}, -: 642: {"YCbCr", "YCbCrK", 32, copy4}, -: 643: {"YCbCr", "Y", 8, band0}, -: 644: {"YCbCr", "Cb", 8, band1}, -: 645: {"YCbCr", "Cr", 8, band2}, -: 646: -: 647: /* LAB Color */ -: 648: {"LAB", "LAB", 24, ImagingPackLAB}, -: 649: {"LAB", "L", 8, band0}, -: 650: {"LAB", "A", 8, band1}, -: 651: {"LAB", "B", 8, band2}, -: 652: -: 653: /* HSV */ -: 654: {"HSV", "HSV", 24, ImagingPackRGB}, -: 655: {"HSV", "H", 8, band0}, -: 656: {"HSV", "S", 8, band1}, -: 657: {"HSV", "V", 8, band2}, -: 658: -: 659: /* integer */ -: 660: {"I", "I", 32, copy4}, -: 661: {"I", "I;16B", 16, packI16B}, -: 662: {"I", "I;32S", 32, packI32S}, -: 663: {"I", "I;32NS", 32, copy4}, -: 664: -: 665: /* floating point */ -: 666: {"F", "F", 32, copy4}, -: 667: {"F", "F;32F", 32, packI32S}, -: 668: