/[projet1]/public/pc/tools/osdk/main/pictconv/sources/hires.cpp
Defence Force logotype

Contents of /public/pc/tools/osdk/main/pictconv/sources/hires.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1260 - (show annotations)
Sat Feb 14 20:26:49 2015 UTC (4 years, 7 months ago) by dbug
File size: 3166 byte(s)
PictConv 0.21
- Added support for 32bit picture, to handle things like masking/opacity in the picture formats
- The -a1 mode will generate bytes with null value for blocks of 6 pixels with transparent alpha values (only active in monochrome or AIC conversion modes)
- Added the -f7 conversion mode for Oric pictures using the AIC coloring method.

1
2 #define _CRT_SECURE_NO_WARNINGS
3
4 #include "FreeImage.h"
5
6 #include <fcntl.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11
12 #ifndef _WIN32
13 #include <unistd.h>
14 #endif
15
16 #include "defines.h"
17
18 #include "common.h"
19
20 #include "hires.h"
21 #include "oric_converter.h"
22 #include "atari_converter.h"
23 #include "image.h"
24 #include "dithering.h"
25
26
27 PictureConverter::PictureConverter(MACHINE machine)
28 : m_machine(machine)
29 , m_dither(DITHER_NONE)
30 , m_transparency(TRANSPARENCY_NONE)
31 , m_flag_debug(false)
32 {
33 }
34
35 PictureConverter::~PictureConverter()
36 {
37 }
38
39 PictureConverter* PictureConverter::GetConverter(MACHINE machine)
40 {
41 switch (machine)
42 {
43 case MACHINE_ORIC:
44 return new OricPictureConverter();
45 break;
46
47 case MACHINE_ATARIST:
48 return new AtariPictureConverter();
49 break;
50
51 default:
52 // Invalid type
53 return 0;
54 break;
55 }
56 }
57
58 void PictureConverter::SetDither(DITHER dither)
59 {
60 static bool flagDitherGenerated=false;
61 if (!flagDitherGenerated)
62 {
63 GenerateDitherTable();
64 flagDitherGenerated=true;
65 }
66 m_dither=dither;
67 }
68
69
70 bool PictureConverter::Save(int output_format,const std::string& output_filename,TextFileGenerator& textFileGenerator)
71 {
72 //
73 // Save the bitmap to TAP format
74 //
75 //char name[_MAX_FNAME];
76 //char ext[_MAX_EXT];
77 //_splitpath(output_filename.c_str(),0,0,name,ext);
78
79 //
80 // Save the hir buffer
81 //
82 switch (output_format)
83 {
84 case DEVICE_FORMAT_BASIC_TAPE:
85 case DEVICE_FORMAT_TAPE:
86 case DEVICE_FORMAT_RAWBUFFER:
87 case DEVICE_FORMAT_RAWBUFFER_WITH_XYHEADER:
88 case DEVICE_FORMAT_RAWBUFFER_WITH_PALETTE:
89 {
90 long handle=open(output_filename.c_str(),O_TRUNC|O_BINARY|O_CREAT|O_WRONLY,S_IREAD|S_IWRITE);
91 if (handle==-1)
92 {
93 printf("_openErrorwrite"); //write
94 exit(1);
95 }
96
97 SaveToFile(handle,output_format);
98
99 close(handle);
100 return true;
101 }
102 break;
103
104 case DEVICE_FORMAT_SOURCE_C:
105 case DEVICE_FORMAT_SOURCE_S:
106 case DEVICE_FORMAT_SOURCE_BASIC:
107 {
108 std::string destString;
109
110 destString+=textFileGenerator.ConvertData((unsigned char*)GetBufferData(),GetBufferSize());
111
112 // Possibly we have a second buffer to save
113 if (GetSecondaryBufferSize())
114 {
115 destString+=textFileGenerator.ConvertData((unsigned char*)GetSecondaryBufferData(),GetSecondaryBufferSize());
116 }
117
118 if (!SaveFile(output_filename.c_str(),destString.c_str(),destString.size()))
119 {
120 ShowError("Unable to save the destination file");
121 }
122 return true;
123 }
124 break;
125
126 case DEVICE_FORMAT_PICTURE:
127 {
128 //
129 // Convert the hires picture back to a RGB one
130 //
131 ImageContainer snapshot;
132 if (!TakeSnapShot(snapshot))
133 {
134 ShowError("Unable to take TakeSnapShot");
135 }
136
137 if (!snapshot.SavePicture(output_filename))
138 {
139 ShowError("Unable to save the snapshot file");
140 }
141 return true;
142 }
143 break;
144
145 default:
146 break;
147 }
148
149 return false;
150 }
151

  ViewVC Help
Powered by ViewVC 1.1.26