AImageLabZip
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    <!--info title: Programming Exam start: 2021-02-19 14:00:00 stop: 2021-02-19 18:00:00 language: C++ type: upload --> # Esame MDP del 19/02/2021 ## Esercizio 1 <!--begin name: PPM-Load files: [process_ppm.cpp] topic: PPM level: 2 points: 7 --> Una software house sta realizzando una app per dispositivi mobili che deve trasmettere dati in formato JSON. Uno dei campi richiesti è però una piccola immagine a colori RGB e JSON non supporta la trasmissione di dati binari. Per questo motivo la software house decide di utilizzare un semplice encoding Base64. L’immagine viene compressa a piani separati con l’algoritmo PackBits e poi ogni piano così compresso viene codificato in Base64. Le informazioni vengono passate come campi di un dizionario JSON. Ad esempio: ```json { "width": 6, "height": 6, "red": "3f+A", "green": "/gD+//4A/v/+AP7//gD+//4A/v/+AP7/gA==", "blue": "3QCA" } ``` In questo esempio è codificata un'immagine con tre colonne rosse (255,0,0) e tre gialle (255,255,0), come in tabella: | r | r | r | g | g | g | |---|---|---|---|---|---| | **r** | **r** | **r** | **g** | **g** | **g** | | **r** | **r** | **r** | **g** | **g** | **g** | | **r** | **r** | **r** | **g** | **g** | **g** | | **r** | **r** | **r** | **g** | **g** | **g** | | **r** | **r** | **r** | **g** | **g** | **g** | quindi i piani colore contengono (i valori sono mostrati qui in esadecimale e c'è uno spazio più grande tra una riga e l'altra, solo per chiarezza): ``` R: FF,FF,FF,FF,FF,FF, FF,FF,FF,FF,FF,FF, FF,FF,FF,FF,FF,FF, FF,FF,FF,FF,FF,FF, FF,FF,FF,FF,FF,FF, FF,FF,FF,FF,FF,FF G: 00,00,00,FF,FF,FF, 00,00,00,FF,FF,FF, 00,00,00,FF,FF,FF, 00,00,00,FF,FF,FF, 00,00,00,FF,FF,FF, 00,00,00,FF,FF,FF B: 00,00,00,00,00,00, 00,00,00,00,00,00, 00,00,00,00,00,00, 00,00,00,00,00,00, 00,00,00,00,00,00, 00,00,00,00,00,00 ``` Dopo la codifica PackBits: ``` R: DD,FF,80 G: FE,00,FE,FF,FE,00,FE,FF,FE,00,FE,FF,FE,00,FE,FF,FE,00,FE,FF,FE,00,FE,FF,80 B: DD,00,80 ``` Dopo l'encoding in Base64: ``` R: 3f+A G: /gD+//4A/v/+AP7//gD+//4A/v/+AP7/gA== B: 3QCA ``` Nel file `process_ppm.cpp` implementare la funzione corrispondente alla seguente dichiarazione: ```c++ bool LoadPPM(const std::string& filename, mat<vec3b>& img); ``` La funzione deve caricare un'immagine a colori nel formato PPM, seguendo le specifiche allegate. Se la lettura va a buon fine la funzione ritorna `true`, altrimenti ritorna `false`. L'implementazione della classe `mat` e della classe `vec3b` sono disponibili nei file `mat.h`, `ppm.h` e `ppm.cpp`. Sono dati a titolo di esempio i file `test.ppm` e `facolta.ppm`. <!--end--> ## Esercizio 2 <!--begin name: PPM-Split files: [process_ppm.cpp] topic: PPM level: 2 points: 5 --> Sempre nel file `process_ppm.cpp` implementare la procedura corrispondente alla seguente dichiarazione: ```c++ void SplitRGB(const mat<vec3b>& img, mat<uint8_t>& img_r, mat<uint8_t>& img_g, mat<uint8_t>& img_b); ``` La procedura deve separare la matrice di valori RGB `img` in tre matrici (`img_r`, `img_g`, e `img_b`) ognuna contenente un solo piano colore, R, G, e B. ## Esercizio 3 <!--begin name: PackBits files: [compress.cpp] topic: PackBits level: 2 points: 8 --> Nel file `compress.cpp` implementare la procedura corrispondente alla seguente dichiarazione: ```c++ void PackBitsEncode(const mat<uint8_t>& img, vector<uint8_t>& encoded); ``` che applica l'algoritmo PackBits ad un piano colore, `img`, salvando il risultato in un vettore di `uint8_t`. Come visto a lezione, PackBits è uno schema di compressione veloce e semplice senza perdita di dati per la codifica dei dati in run-length. Il flusso di dati PackBits è costituito da pacchetti con un'intestazione da un byte seguita da uno o più byte di dati compressi. Nella tabella seguente è riportata l'associazione tra il valore del byte di intestazione, `L`, e i byte dei dati. |header (L) |byte di dati che seguono l'header | |-------------|--------------------------------------| |da 0 a 127 | (L+1) byte letterali di dati (copia) | |da 129 a 255 | un byte di dati, ripetuto (257-L) volte nell'output decompresso (run)| |128| End of data marker (EOD)| L'algoritmo deve scorrere l'input e per ogni sequenza di byte uguali emettere una run, altrimenti una copia per le sequenze prive di ripetizioni e al termine dei dati un EOD. <!--end--> ## Esercizio 4 <!--begin name: Base64 files: [compress.cpp] topic: Base64 level: 2 points: 8 --> Sempre nel file `compress.cpp` implementare la funzione corrispondente alla seguente dichiarazione: ```c++ std::string Base64Encode(const vector<uint8_t>& v); ``` che applica ad una sequenza `v` l'encoding Base64 e ritorna la stringa risultante. Si ricorda che il Base64 è un sistema di codifica che consente la traduzione di dati binari in stringhe di testo ASCII, rappresentando i dati sulla base di 64 caratteri ASCII diversi. L'algoritmo che effettua la conversione suddivide l'input in gruppi di tre byte da cui si ottengono quattro sottogruppi da 6 bit, i quali possono quindi contenere valori da 0 a 63. Ogni possibile valore viene convertito in un carattere ASCII secondo la seguente tabella: | Valore | ASCII | Valore | ASCII | Valore | ASCII | Valore | ASCII | |:-------:|:------:|:-------:|:------:|:-------:|:------:|:-------:|:------:| | 0 | A | 16 | Q | 32 | g | 48 | w | | 1 | B | 17 | R | 33 | h | 49 | x | | 2 | C | 18 | S | 34 | i | 50 | y | | 3 | D | 19 | T | 35 | j | 51 | z | | 4 | E | 20 | U | 36 | k | 52 | 0 | | 5 | F | 21 | V | 37 | l | 53 | 1 | | 6 | G | 22 | W | 38 | m | 54 | 2 | | 7 | H | 23 | X | 39 | n | 55 | 3 | | 8 | I | 24 | Y | 40 | o | 56 | 4 | | 9 | J | 25 | Z | 41 | p | 57 | 5 | | 10 | K | 26 | a | 42 | q | 58 | 6 | | 11 | L | 27 | b | 43 | r | 59 | 7 | | 12 | M | 28 | c | 44 | s | 60 | 8 | | 13 | N | 29 | d | 45 | t | 61 | 9 | | 14 | O | 30 | e | 46 | u | 62 | + | | 15 | P | 31 | f | 47 | v | 63 | / | Invece che implementare il padding standard del Base64, è sufficiente aggiungere byte uguali a 128 in fondo al vettore, in modo che la lunghezza sia un multiplo di 3 e quindi si ottengano sempre gruppi completi di 3 byte. <!--end--> ## Esercizio 5 <!--begin name: JSON files: [compress.cpp] topic: JSON level: 2 points: 5 --> Sempre nel file `compress.cpp` implementare la funzione corrispondente alla seguente dichiarazione: ```c++ string JSON(const std::string& filename); ``` che data un'immagine RGB in formato PPM costruisce e ritorna la stringa in formato JSON come richiesto dalla software house. <!--end-->

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully