DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

#### Mercurial (73d91719b677)

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
``````#!/usr/bin/env python
``````# This Source Code Form is subject to the terms of the Mozilla Public
``````# License, v. 2.0. If a copy of the MPL was not distributed with this
``````# file, You can obtain one at http://mozilla.org/MPL/2.0/.
``````
``````import png
``````import sys
``````import StringIO
``````import struct
``````import ctypes
``````
``````# ref: http://msdn.microsoft.com/en-us/library/ms997538
``````class ICONDIR(ctypes.LittleEndianStructure):
``````    _pack_ = 1
``````    _fields_ = [("idReserved", ctypes.c_ushort),
``````                ("idType", ctypes.c_ushort),
``````                ("idCount", ctypes.c_ushort)]
``````
``````class ICONDIRENTRY(ctypes.LittleEndianStructure):
``````    _pack_ = 1
``````    _fields_ = [("bWidth", ctypes.c_byte),
``````                ("bHeight", ctypes.c_byte),
``````                ("bColorCount", ctypes.c_byte),
``````                ("bReserved", ctypes.c_byte),
``````                ("wPlanes", ctypes.c_ushort),
``````                ("wBitCount", ctypes.c_ushort),
``````                ("dwBytesInRes", ctypes.c_ulong),
``````                ("dwImageOffset", ctypes.c_ulong)]
``````
``````# R, G, B, A, so 4 columns per pixel
``````COLS_PP = 4
``````
``````def main(infile, left, top, size, outfile):
``````    img = png.Reader(filename=infile)
``````    pixels = list(img.asRGBA())
``````    # Take the subarray out. This is the ugliest but probably most efficient way
``````    # to do it
``````    outpixels = [ * (size * COLS_PP) for x in xrange(size)]
``````    for row in xrange(size):
``````        for col in xrange(size * COLS_PP):
``````            outpixels[row][col] = pixels[top + row][left * COLS_PP + col]
``````
``````    # Set up a 32bpp RGBA PNG.
``````    writer = png.Writer(size=(size, size), bitdepth=8, alpha=True)
``````    # Write to a memory buffer
``````    outpng = StringIO.StringIO()
``````    writer.write(outpng, outpixels)
``````    outpngbuf = outpng.getvalue()
``````    outpng.close()
``````
``````    # Set up an icon header
``````    icondir = ICONDIR()
``````    icondir.idReserved = 0
``````    # Icons are type 1
``````    icondir.idType = 1
``````    icondir.idCount = 1
``````
``````    iconentry = ICONDIRENTRY()
``````    iconentry.bWidth = size
``````    iconentry.bHeight = size
``````    # Truecolor images have color count set to 0
``````    iconentry.bColorCount = 0
``````    iconentry.bReserved = 0
``````    # PNGs have 1 color plane
``````    iconentry.wPlanes = 1
``````    # We're RGBA, so 32 bits per pixel
``````    iconentry.wBitCount = 32
``````    # Length of the buffer
``````    iconentry.dwBytesInRes = len(outpngbuf)
``````    # The data will be right after the icondir and iconentry
``````    iconentry.dwImageOffset = ctypes.sizeof(icondir) + ctypes.sizeof(iconentry)
``````
``````    # Time to write everything out
``````    out = open(outfile, "wb")
``````    out.write(icondir)
``````    out.write(iconentry)
``````    out.write(outpngbuf)
``````    out.close()
``````
``````if __name__ == "__main__":
``````    # Convert left, top and size into integers
``````    main(*([sys.argv] + [int(val) for val in sys.argv[2:5]] + [sys.argv]))
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.50601757,"math_prob":0.8276906,"size":2591,"snap":"2020-24-2020-29","text_gpt3_token_len":860,"char_repetition_ratio":0.13374566,"word_repetition_ratio":0.005063291,"special_character_ratio":0.35970667,"punctuation_ratio":0.18560606,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9875485,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-12T17:29:19Z\",\"WARC-Record-ID\":\"<urn:uuid:4a178dca-7b02-47df-9f4d-057506bfa2bc>\",\"Content-Length\":\"93412\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:101cf558-7d66-46c6-9dba-5833a93413f1>\",\"WARC-Concurrent-To\":\"<urn:uuid:e1a27cce-6ea6-4b33-958c-450f8ac68a15>\",\"WARC-IP-Address\":\"63.245.208.205\",\"WARC-Target-URI\":\"https://dxr.mozilla.org/comm-esr45/source/mail/app/png2ico.py\",\"WARC-Payload-Digest\":\"sha1:2T5LX4G2NJJJZKNROGMDWIUVCSLYNSXG\",\"WARC-Block-Digest\":\"sha1:3TIGNVU53NCES5WSPOVFXXNCQAYNO7EW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593657138752.92_warc_CC-MAIN-20200712144738-20200712174738-00343.warc.gz\"}"}