Momenteel ben ik bezig met een bitmap-class. Dat lukt best aardig, maar ik twijfel over mijn opzet. Mijn huidige opzet is alsvolgt:
opzet 1:
Voorlopig wil ik ondersteuning voor het BMP/DIB-formaat en het PCX-formaat. Later wil ik dit uitbreiden met andere formaten. Dan zal ik dus meer member-functies moeten toevoegen aan de class. Dat bevalt mij niet.
Ik zat te denken om de volgende opzet te gebruiken. Ik kan de load en save functies nu in een apart bestand zetten. Dat bestand hoef ik alleen toetevoegen als ik die functies ook daadwerkelijk nodig heb. Als ik bijvoorbeeld alleen met DIBs wil werken dan heb ik niet de overhead van de PCX-functies.
opzet 2:
Een andere mogelijkheid zou het volgende zijn:
opzet 3:
Het probleem met deze opzet is dat het bijvoorbeeld moeilijker is om een DIB te laden en vervolgens als PCX opteslaan.
mijn vraag: Welke opzet vinden jullie het best of kiezen jullie liever een andere opzet?
opzet 1:
C++:
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
| class bitmap { protected: unsigned long int _width; unsigned long int _height; rgba** _pixelgrid; public: bitmap(); bitmap(unsigned long int width, unsigned long int height); ~bitmap(); // Device Independent Bitmaps (Microsofts Paint file format): bool loadDIB(char* filename); bool saveDIB(char* filename); // PiCture eXchange (ZSofts PC Paintbrush file format): bool loadPCX(char* filename); bool savePCX(char* filename); unsigned long int getWidth(); unsigned long int setWidth(unsigned long int width); unsigned long int getHeight(); unsigned long int setHeight(unsigned long int height); rgba getPixel(unsigned long int x, unsigned long int y); bool setPixel(unsigned long int x, unsigned long int y, rgba color); }; |
Voorlopig wil ik ondersteuning voor het BMP/DIB-formaat en het PCX-formaat. Later wil ik dit uitbreiden met andere formaten. Dan zal ik dus meer member-functies moeten toevoegen aan de class. Dat bevalt mij niet.
Ik zat te denken om de volgende opzet te gebruiken. Ik kan de load en save functies nu in een apart bestand zetten. Dat bestand hoef ik alleen toetevoegen als ik die functies ook daadwerkelijk nodig heb. Als ik bijvoorbeeld alleen met DIBs wil werken dan heb ik niet de overhead van de PCX-functies.
opzet 2:
C++:
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
| // bitmap.h #ifndef __BITMAPJE #define __BITMAPJE class bitmap { protected: unsigned long int _width; unsigned long int _height; rgba** _pixelgrid; public: bitmap(); bitmap(unsigned long int width, unsigned long int height); ~bitmap(); unsigned long int getWidth(); unsigned long int setWidth(unsigned long int width); unsigned long int getHeight(); unsigned long int setHeight(unsigned long int height); rgba getPixel(unsigned long int x, unsigned long int y); bool setPixel(unsigned long int x, unsigned long int y, rgba color); }; #endif |
C++:
1
2
3
4
| #include <bitmap.h> // Device Independent Bitmaps (Microsofts Paint file format): bool loadDIB(char* filename, bitmap& bmp); bool saveDIB(char* filename, const bitmap& bmp); |
C++:
1
2
3
4
| #include <bitmap.h> // PiCture eXchange (ZSofts PC Paintbrush file format): bool loadPCX(char* filename, bitmap& bmp); bool savePCX(char* filename, const bitmap& bmp); |
Een andere mogelijkheid zou het volgende zijn:
opzet 3:
C++:
1
2
3
4
5
6
7
| #include <bitmap.h> // Device Independent Bitmaps (Microsofts Paint file format): struct DIB : public bitmap { bool load(char* filename); bool save(char* filename); }; |
C++:
1
2
3
4
5
6
7
| #include <bitmap.h> // PiCture eXchange (ZSofts PC Paintbrush file format): struct PCX : public bitmap { bool load(char* filename); bool save(char* filename); }; |
Het probleem met deze opzet is dat het bijvoorbeeld moeilijker is om een DIB te laden en vervolgens als PCX opteslaan.
mijn vraag: Welke opzet vinden jullie het best of kiezen jullie liever een andere opzet?
PC load letter? What the fuck does that mean?