MCPcopy Create free account
hub / github.com/andysworkshop/stm32plus / readImages

Method readImages

examples/pframe/BitmapManager.cpp:109–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107 */
108
109bool BitmapManager::readImages() {
110
111 char buffer[30];
112 uint8_t block[512];
113 uint32_t blockIndex,i,j,actuallyRead;
114 FileSystem& fs=_fsManager.getFileSystem();
115 File *file;
116 BlockDevice& sdcard=_fsManager.getSdCard();
117
118 // allocate enough blocks from the free space to hold the image data
119
120 if(!_fsManager.allocateBlocks(_imageCount))
121 return false;
122
123 // status
124
125 _term << "Caching images.\n";
126
127 blockIndex=_fsManager.getFirstCacheBlock();
128
129 for(i=0;i<_imageCount;i++) {
130
131 // read and cache the image
132
133 strcpy(buffer,"/pframe/img/");
134 StringUtil::itoa(i,buffer+12,10);
135 strcat(buffer,".262");
136
137 if(!fs.openFile(buffer,file))
138 return error("Failed to open file");
139
140 _term.clearLine();
141 _term << "Image: " << (i+1) << '/' << _imageCount;
142
143 // 640 blocks/image (2 per row, 320 rows / image)
144 // each block contains 1 scan line (240*4 bytes)
145
146 for(j=0;j<640;j++) {
147
148 if(!file->read(block,480,actuallyRead) || actuallyRead!=480)
149 return error("IO error reading image");
150
151 if(!sdcard.writeBlock(block,blockIndex++))
152 return error("IO error writing to card");
153 }
154
155 delete file;
156 }
157
158 _term << '\n';
159 return true;
160}
161
162
163/*

Callers

nothing calls this directly

Calls 7

itoaFunction · 0.85
allocateBlocksMethod · 0.80
getFirstCacheBlockMethod · 0.80
openFileMethod · 0.45
clearLineMethod · 0.45
readMethod · 0.45
writeBlockMethod · 0.45

Tested by

no test coverage detected