xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #618: jpeg2000.patch

File jpeg2000.patch, 6.9 KB (added by Antoine Martin, 7 years ago)

adds support for jpeg2000 via PIL

  • tests/xpra/codecs/test_Pillow_perf.py

     
    1313from io import BytesIO
    1414
    1515
    16 def do_test_encode(rgb_data, w, h, encodings=["png", "png/P", "png/L", "jpeg", "webp", "rgb"], N=5, Q=[0, 50, 100], S=[0, 1, 50, 90, 100], has_alpha=False):
     16def do_test_encode(rgb_data, w, h, encodings=["png", "png/P", "png/L", "jpeg", "jpeg2000", "webp", "rgb"], N=5, Q=[0, 50, 100], S=[0, 1, 50, 90, 100], has_alpha=False):
    1717    from xpra.server.picture_encode import PIL_encode, rgb_encode
    1818    from xpra.codecs.image_wrapper import ImageWrapper
    1919    image = ImageWrapper(0, 0, w, h, rgb_data, "BGRA", 32, w*4, planes=ImageWrapper.PACKED, thread_safe=True)
     
    2121    #buf = get_source_data(w*h*4)
    2222    for encoding in encodings:
    2323        Q_options = Q
    24         if encoding in ("png", "png/P", "png/L", "rgb"):
     24        if encoding in ("png", "png/P", "png/L", "rgb", "jpeg2000"):
    2525            Q_options = [-1]
    2626        S_options = S
    27         if encoding=="webp":
     27        if encoding in ("webp", "jpeg2000"):
    2828            S_options = [-1]
    2929        if encoding in ("jpeg"):
    3030            S_options = [0, -1]
     
    4949                cdata = data[1]
    5050                ratio = 100.0 * len(cdata) / len(rgb_data)
    5151                print("%s : %s MPixels/s  %s%% compression ratio : %sx%s to: %s KBytes (quality=%s, speed=%s) %s times in %sms average" % \
    52                       (coding.ljust(5), ("%.1f" % mps).rjust(5), ("%.1f" % ratio).rjust(5), str(w).rjust(4), str(h).ljust(4), str(len(cdata)/1024).rjust(6), str(q).rjust(3), str(s).rjust(3),
     52                      (coding.ljust(8), ("%.1f" % mps).rjust(5), ("%.1f" % ratio).rjust(5), str(w).rjust(4), str(h).ljust(4), str(len(cdata)/1024).rjust(6), str(q).rjust(3), str(s).rjust(3),
    5353                       N, str(int((end-start)*1000.0/N)).rjust(5)))
    5454
    5555def test_files(filenames, extensions=[".png", ".jpg"], recurse=True):
  • xpra/client/ui_client_base.py

     
    432432    def do_get_core_encodings(self):
    433433        """
    434434            This method returns the actual encodings supported.
    435             ie: ["rgb24", "vp8", "webp", "png", "png/L", "png/P", "jpeg", "h264", "vpx"]
     435            ie: ["rgb24", "vp8", "webp", "png", "png/L", "png/P", "jpeg", "jpeg2000", "h264", "vpx"]
    436436            It is often overriden in the actual client class implementations,
    437437            where extra encodings can be added (generally just 'rgb32' for transparency),
    438438            or removed if the toolkit implementation class is more limited.
  • xpra/codecs/codec_constants.py

     
    66
    77import weakref
    88from xpra.log import Logger
    9 log = Logger("util")
     9log = Logger("util", "encoding")
    1010
    1111
    1212def do_get_PIL_codings(PIL, attr="SAVE"):
     
    1717    avalue = getattr(pi, attr)
    1818    log("PIL.Image.%s=%s", attr, avalue)
    1919    encodings = []
    20     test_options = ["png", "png/L", "png/P", "jpeg", "webp"]
     20    test_options = ["png", "png/L", "png/P", "jpeg", "jpeg2000", "webp"]
    2121    if attr=="OPEN":
    2222        #don't open 'webp' images as this leaks memory in
    2323        #all versions of PIL and Pillow so far!
  • xpra/codecs/loader.py

     
    164164
    165165#note: this is just for defining the order of encodings,
    166166#so we have both core encodings (rgb24/rgb32) and regular encodings (rgb) in here:
    167 PREFERED_ENCODING_ORDER = ["h264", "vp8", "png", "png/P", "png/L", "webp", "rgb", "rgb24", "rgb32", "jpeg", "h265", "vp9"]
     167PREFERED_ENCODING_ORDER = ["h264", "vp8", "png", "png/P", "png/L", "webp", "rgb", "rgb24", "rgb32", "jpeg", "h265", "vp9", "jpeg2000"]
    168168
    169169compressors = ["zlib"]
    170170try:
     
    184184      "png/L"   : "PNG (8bpp grayscale)",
    185185      "webp"    : "WebP",
    186186      "jpeg"    : "JPEG",
     187      "jpeg2000": "JPEG 2000",
    187188      "rgb"     : "Raw RGB + %s (24/32bpp)" % ("/".join(compressors)),
    188189    }
    189190
     
    197198      "png/L"   : "Portable Network Graphics (lossy, 8bpp grayscale)",
    198199      "webp"    : "WebP compression (lossless or lossy)",
    199200      "jpeg"    : "JPEG lossy compression",
     201      "jpeg2000": "JPEG 2000 lossy compression (slow)",
    200202      "rgb"     : "Raw RGB pixels, lossless, compressed using %s (24bpp or 32bpp for transparency)" % (" or ".join(compressors)),
    201203      }
    202204
    203 HELP_ORDER = ("h264", "h265", "vp8", "vp9", "png", "png/P", "png/L", "webp", "rgb", "jpeg")
     205HELP_ORDER = ("h264", "h265", "vp8", "vp9", "png", "png/P", "png/L", "webp", "rgb", "jpeg", "jpeg2000")
    204206
    205207def encodings_help(encodings):
    206208    h = []
  • xpra/server/picture_encode.py

     
    181181    buf = StringIOClass()
    182182    client_options = {}
    183183    #only optimize with Pillow>=2.2 and when speed is zero
    184     if coding in ("jpeg", "webp"):
     184    if coding in ("jpeg", "webp", "jpeg2000"):
    185185        q = int(min(99, max(1, quality)))
    186186        kwargs = im.info
    187187        kwargs["quality"] = q
  • xpra/server/window_source.py

     
    100100        self.generic_encodings = encoding_options.boolget("generic")
    101101        self.supports_transparency = HAS_ALPHA and encoding_options.boolget("transparency")
    102102        self.full_frames_only = encoding_options.boolget("full_frames_only")
    103         ropts = set(("png", "webp", "rgb", "jpeg"))     #default encodings for auto-refresh
     103        ropts = set(("png", "webp", "rgb", "jpeg", "jpeg2000"))     #default encodings for auto-refresh
    104104        if self.webp_leaks:
    105105            ropts.remove("webp")                        #don't use webp if the client is going to leak with it!
    106106        ropts = ropts.intersection(set(self.server_core_encodings)) #ensure the server has support for it
     
    926926        #log.info("get_encoding_options%s lossless_q=%s, smult=%s, max_rgb=%s, max_webp=%s", (batching, pixel_count, ww, wh, speed, quality, current_encoding), lossless_q, smult, max_rgb, max_webp)
    927927        if quality<lossless_q:
    928928            #add lossy options
    929             ALL_OPTIONS = ["jpeg", "png/P", "png/L", "rgb24"]
     929            ALL_OPTIONS = ["jpeg", "png/P", "png/L", "rgb24", "jpeg2000"]
    930930            if pixel_count<max_rgb:
    931931                #high speed and high quality, rgb is still good
    932932                options.append("rgb24")